add missing comments - tests directory
[civicrm-core.git] / tests / phpunit / WebTest / Mailing / AddMessageTemplateTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 /**
35 * @param bool $useTokens
36 * @param null $msgTitle
37 */
38 function testTemplateAdd($useTokens = FALSE, $msgTitle = NULL) {
39 $this->webtestLogin();
40
41 $this->openCiviPage("admin/messageTemplates/add", "action=add&reset=1");
42
43 // Fill message title.
44 if (!$msgTitle) {
45 $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7);
46 }
47 $this->type("msg_title", $msgTitle);
48 if ($useTokens) {
49 //Add Tokens
50 $this->select2("msg_subject", "Display Name");
51 $this->select2("msg_subject", "Contact Type");
52 $this->select2("xpath=//*[contains(@data-field,'msg_text')]/../div/a", "Display Name", FALSE, TRUE);
53 $this->select2("xpath=//*[contains(@data-field,'msg_text')]/../div/a", "Contact Type", FALSE, TRUE);
54 $this->select2("xpath=//*[contains(@data-field,'html_message')]/../div/a", "Display Name", FALSE, TRUE);
55 $this->select2("xpath=//*[contains(@data-field,'html_message')]/../div/a", "Contact Type", FALSE, TRUE);
56 }
57 else {
58 // Fill message subject.
59 $msgSubject = "This is subject for message";
60 $this->type("msg_subject", $msgSubject);
61
62 // Fill text message.
63 $txtMsg = "This is text message";
64 $this->type("msg_text", $txtMsg);
65
66 // Fill html message.
67 $htmlMsg = "This is HTML message";
68 $this->type("msg_html", $htmlMsg);
69 }
70 // Clicking save.
71 $this->click("_qf_MessageTemplates_next");
72 $this->waitForPageToLoad($this->getTimeoutMsec());
73
74 // Is status message correct
75 $this->waitForText('crm-notification-container', "The Message Template '$msgTitle' has been saved.");
76
77 // Verify text.
78 $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[1][contains(text(), '$msgTitle')]"),
79 'Message Template Title not found!');
80 if (!$useTokens) {
81 $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[2][contains(text(), '$msgSubject')]"),
82 'Message Subject not found!');
83 }
84 }
85
86 function testAddMailingWithMessageTemplate() {
87 // Call the above test to set up our environment
88 $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7);
89 $this->testTemplateAdd(TRUE, $msgTitle);
90
91 // create new mailing group
92 $groupName = $this->WebtestAddGroup();
93
94 //Create new contact and add to mailing Group
95 $firstName = substr(sha1(rand()), 0, 7);
96 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
97 $this->click("css=li#tab_group a");
98 $this->waitForElementPresent("_qf_GroupContact_next");
99 $this->select("group_id", "$groupName");
100 $this->click("_qf_GroupContact_next");
101
102 // configure default mail-box
103 $this->setupDefaultMailbox();
104
105 $this->openCiviPage("mailing/send", "reset=1", "_qf_Group_cancel");
106
107 // fill mailing name
108 $mailingName = substr(sha1(rand()), 0, 7);
109 $this->type("name", "Mailing $mailingName Webtest");
110
111 // Add the test mailing group
112 $this->select("includeGroups-f", "$groupName");
113 $this->click("add");
114
115 // click next
116 $this->click("_qf_Group_next");
117 $this->waitForElementPresent("_qf_Settings_cancel");
118 // check for default settings options
119 $this->assertChecked("url_tracking");
120 $this->assertChecked("open_tracking");
121
122 // do check count for Recipient
123 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
124 $this->click("_qf_Settings_next");
125 $this->waitForElementPresent("_qf_Upload_cancel");
126
127 $this->click("template");
128 $this->select("template", "label=$msgTitle");
129 // Because it tends to cause problems, all uses of sleep() must be justified in comments
130 // Sleep should never be used for wait for anything to load from the server
131 // Justification for this instance: FIXME
132 sleep(5);
133 $this->click("xpath=id('Upload')/div[2]/fieldset[@id='compose_id']/div[2]/div[1]");
134 $this->click('subject');
135
136 // check for default header and footer ( with label )
137 $this->select('header_id', "label=Mailing Header");
138 $this->select('footer_id', "label=Mailing Footer");
139
140 // do check count for Recipient
141 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
142
143 // click next with nominal content
144 $this->click("_qf_Upload_upload");
145 $this->waitForElementPresent("_qf_Test_cancel");
146
147 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
148
149 // click next
150 $this->click("_qf_Test_next");
151 $this->waitForElementPresent("_qf_Schedule_cancel");
152
153 $this->assertChecked("now");
154
155 // do check count for Recipient
156 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
157
158 // finally schedule the mail by clicking submit
159 $this->click("_qf_Schedule_next");
160 $this->waitForPageToLoad($this->getTimeoutMsec());
161
162 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
163 $this->assertElementContainsText('page-title', "Find Mailings");
164 $this->isTextPresent("Mailing $mailingName Webtest");
165 $this->openCiviPage('mailing/queue', 'reset=1');
166
167 // verify status
168 $this->verifyText("xpath=id('Search')/table/tbody/tr[1]/td[2]", preg_quote("Complete"));
169
170 //View Activity
171 $this->openCiviPage('activity/search', "reset=1", "_qf_Search_refresh");
172 $this->type("sort_name", $firstName);
173 $this->click("activity_type_id[19]");
174 $this->click("_qf_Search_refresh");
175 $this->waitForElementPresent("_qf_Search_next_print");
176
177 $this->click("xpath=id('Search')/div[3]/div/div[2]/table/tbody/tr[2]/td[9]/span/a[text()='View']");
178 $this->waitForElementPresent("_qf_ActivityView_next");
179 $this->assertElementContainsText('help', "Bulk Email Sent.", "Status message didn't show up after saving!");
180 }
181 }