Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License along with this program; if not, contact CiviCRM LLC | | |
21 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
22 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
24 | +--------------------------------------------------------------------+ | |
25 | */ | |
26 | ||
27 | ||
28 | require_once 'CiviTest/CiviSeleniumTestCase.php'; | |
29 | class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase { | |
30 | ||
31 | protected function setUp() { | |
32 | parent::setUp(); | |
33 | } | |
34 | ||
35 | function testTemplateAdd($useTokens = FALSE, $msgTitle = NULL) { | |
36 | $this->webtestLogin(); | |
37 | ||
38 | // Go directly to the URL of the screen that you will be testing (Add Message Template). | |
39 | $this->openCiviPage("admin/messageTemplates/add", "action=add&reset=1"); | |
40 | ||
41 | // Fill message title. | |
42 | if (!$msgTitle) { | |
43 | $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7); | |
44 | } | |
45 | $this->type("msg_title", $msgTitle); | |
46 | if ($useTokens) { | |
47 | //Add Tokens | |
48 | $this->click("css=#msg_subject + a"); | |
49 | $this->waitForElementPresent("css=#tokenSubject + .ui-dialog-buttonpane button"); | |
50 | $this->type("filter3", "display"); | |
51 | $this->addSelection("token3", "label=Display Name"); | |
52 | $this->type("filter3", "contact"); | |
53 | $this->addSelection("token3", "label=Contact Type"); | |
54 | $this->click("css=#tokenSubject + .ui-dialog-buttonpane button"); | |
55 | $this->click("//span[@id='helptext']/a/label"); | |
56 | $this->waitForElementPresent("css=#tokenText + .ui-dialog-buttonpane button"); | |
57 | $this->type("filter1", "display"); | |
58 | $this->addSelection("token1", "label=Display Name"); | |
59 | $this->type("filter1", "contact"); | |
60 | $this->addSelection("token1", "label=Contact Type"); | |
61 | $this->click("css=#tokenText + .ui-dialog-buttonpane button"); | |
62 | $this->click("//span[@id='helphtml']/a/label"); | |
63 | $this->waitForElementPresent("css=#tokenHtml + .ui-dialog-buttonpane button"); | |
64 | $this->type("filter2", "display"); | |
65 | $this->addSelection("token2", "label=Display Name"); | |
66 | $this->type("filter2", "contact"); | |
67 | $this->addSelection("token2", "label=Contact Type"); | |
68 | $this->click("css=#tokenHtml + .ui-dialog-buttonpane button"); | |
69 | } | |
70 | else { | |
71 | // Fill message subject. | |
72 | $msgSubject = "This is subject for message"; | |
73 | $this->type("msg_subject", $msgSubject); | |
74 | ||
75 | // Fill text message. | |
76 | $txtMsg = "This is text message"; | |
77 | $this->type("msg_text", $txtMsg); | |
78 | ||
79 | // Fill html message. | |
80 | $htmlMsg = "This is HTML message"; | |
81 | $this->type("msg_html", $htmlMsg); | |
82 | } | |
83 | // Clicking save. | |
84 | $this->click("_qf_MessageTemplates_next"); | |
85 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
86 | ||
87 | // Is status message correct | |
88 | $this->assertTrue($this->isTextPresent("The Message Template '$msgTitle' has been saved.")); | |
89 | ||
90 | // Verify text. | |
91 | $this->assertTrue($this->isTextPresent($msgTitle)); | |
92 | if (!$useTokens) { | |
93 | $this->assertTrue($this->isTextPresent($msgSubject)); | |
94 | } | |
95 | } | |
96 | ||
97 | function testAddMailingWithMessageTemplate() { | |
98 | // Call the above test to set up our environment | |
99 | $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7); | |
100 | $this->testTemplateAdd(TRUE, $msgTitle); | |
101 | ||
102 | // create new mailing group | |
103 | $groupName = $this->WebtestAddGroup(); | |
104 | ||
105 | //Create new contact and add to mailing Group | |
106 | $firstName = substr(sha1(rand()), 0, 7); | |
107 | $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in"); | |
108 | $this->click("css=li#tab_group a"); | |
109 | $this->waitForElementPresent("_qf_GroupContact_next"); | |
110 | $this->select("group_id", "$groupName"); | |
111 | $this->click("_qf_GroupContact_next"); | |
112 | ||
113 | // configure default mail-box | |
114 | $this->openCiviPage("admin/mailSettings", "action=update&id=1&reset=1", '_qf_MailSettings_cancel-bottom'); | |
115 | $this->type('name', 'Test Domain'); | |
116 | $this->type('domain', 'example.com'); | |
117 | $this->select('protocol', 'value=1'); | |
118 | $this->click('_qf_MailSettings_next-bottom'); | |
119 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
120 | ||
121 | // Go directly to Schedule and Send Mailing form | |
122 | $this->openCiviPage("mailing/send", "reset=1", "_qf_Group_cancel"); | |
123 | ||
124 | // fill mailing name | |
125 | $mailingName = substr(sha1(rand()), 0, 7); | |
126 | $this->type("name", "Mailing $mailingName Webtest"); | |
127 | ||
128 | // Add the test mailing group | |
129 | $this->select("includeGroups-f", "$groupName"); | |
130 | $this->click("add"); | |
131 | ||
132 | // click next | |
133 | $this->click("_qf_Group_next"); | |
134 | $this->waitForElementPresent("_qf_Settings_cancel"); | |
135 | // check for default settings options | |
136 | $this->assertChecked("url_tracking"); | |
137 | $this->assertChecked("open_tracking"); | |
138 | ||
139 | // do check count for Recipient | |
140 | $this->assertTrue($this->isTextPresent("Total Recipients: 1")); | |
141 | $this->click("_qf_Settings_next"); | |
142 | $this->waitForElementPresent("_qf_Upload_cancel"); | |
143 | ||
144 | $this->click("template"); | |
145 | $this->select("template", "label=$msgTitle"); | |
146 | sleep(5); | |
147 | $this->click("xpath=id('Upload')/div[2]/fieldset[@id='compose_id']/div[2]/div[1]"); | |
148 | $this->click('subject'); | |
149 | ||
150 | // check for default header and footer ( with label ) | |
151 | $this->select('header_id', "label=Mailing Header"); | |
152 | $this->select('footer_id', "label=Mailing Footer"); | |
153 | ||
154 | // do check count for Recipient | |
155 | $this->assertTrue($this->isTextPresent("Total Recipients: 1")); | |
156 | ||
157 | // click next with nominal content | |
158 | $this->click("_qf_Upload_upload"); | |
159 | $this->waitForElementPresent("_qf_Test_cancel"); | |
160 | ||
161 | $this->assertTrue($this->isTextPresent("Total Recipients: 1")); | |
162 | ||
163 | // click next | |
164 | $this->click("_qf_Test_next"); | |
165 | $this->waitForElementPresent("_qf_Schedule_cancel"); | |
166 | ||
167 | $this->assertChecked("now"); | |
168 | ||
169 | // do check count for Recipient | |
170 | $this->assertTrue($this->isTextPresent("Total Recipients: 1")); | |
171 | ||
172 | // finally schedule the mail by clicking submit | |
173 | $this->click("_qf_Schedule_next"); | |
174 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
175 | ||
176 | //check redirected page to Scheduled and Sent Mailings and verify for mailing name | |
177 | $this->assertTrue($this->isTextPresent("Scheduled and Sent Mailings")); | |
178 | $this->assertTrue($this->isTextPresent("Mailing $mailingName Webtest")); | |
179 | $this->openCiviPage('mailing/queue', 'reset=1'); | |
180 | ||
181 | // verify status | |
182 | $this->verifyText("xpath=id('Search')/table/tbody/tr[1]/td[2]", preg_quote("Complete")); | |
183 | ||
184 | //View Activity | |
185 | $this->openCiviPage('activity/search', "reset=1", "_qf_Search_refresh"); | |
186 | $this->type("sort_name", $firstName); | |
187 | $this->click("activity_type_id[19]"); | |
188 | $this->click("_qf_Search_refresh"); | |
189 | $this->waitForElementPresent("_qf_Search_next_print"); | |
190 | ||
191 | $this->click("xpath=id('Search')/div[3]/div/div[2]/table/tbody/tr[2]/td[9]/span/a[text()='View']"); | |
192 | $this->waitForElementPresent("_qf_ActivityView_next"); | |
193 | $this->assertTrue($this->isTextPresent("Bulk Email Sent."), "Status message didn't show up after saving!"); | |
194 | } | |
195 | } |