Merge pull request #220 from kurund/CRM-12155
[civicrm-core.git] / tests / phpunit / WebTest / Member / ContactContextAddTest.php
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 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Member_ContactContextAddTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testContactMemberAdd() {
35 $this->webtestLogin();
36
37 // Create a membership type to use for this test (defaults for this helper function are rolling 1 year membership)
38 $memTypeParams = $this->webtestAddMembershipType();
39 $lifeTimeMemTypeParams = $this->webtestAddMembershipType('rolling', 1, 'lifetime');
40
41 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
42
43 $firstName = "John_" . substr(sha1(rand()), 0, 7);
44
45 //fill in first name
46 $this->type("first_name", $firstName);
47
48 //fill in last name
49 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);
50 $this->type("last_name", $lastName);
51
52 //fill in email
53 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
54 $this->type("email_1_email", $email);
55
56 // Clicking save.
57 $this->click("_qf_Contact_upload_view");
58 $this->waitForPageToLoad($this->getTimeoutMsec());
59 $this->waitForText('crm-notification-container', "$firstName $lastName");
60
61 // click through to the membership view screen
62 $this->click("css=li#tab_member a");
63
64 $this->waitForElementPresent("link=Add Membership");
65 $this->click("link=Add Membership");
66
67 $this->waitForElementPresent("_qf_Membership_cancel-bottom");
68
69 // fill in Membership Organization and Type
70 $this->select("membership_type_id[0]", "label={$memTypeParams['member_of_contact']}");
71 // Wait for membership type select to reload
72 $this->waitForTextPresent($memTypeParams['membership_type']);
73 // Because it tends to cause problems, all uses of sleep() must be justified in comments
74 // Sleep should never be used for wait for anything to load from the server
75 // Justification for this instance: FIXME
76 sleep(3);
77 $this->select("membership_type_id[1]", "label={$memTypeParams['membership_type']}");
78
79 $sourceText = "Membership ContactAddTest Webtest";
80 // fill in Source
81 $this->type("source", $sourceText);
82
83 // Let Join Date stay default
84
85 // fill in Start Date
86 $this->webtestFillDate('start_date');
87
88 // Clicking save.
89 $this->click("_qf_Membership_upload");
90 $this->waitForPageToLoad($this->getTimeoutMsec());
91
92 // page was loaded
93 $this->waitForTextPresent($sourceText);
94
95 // Is status message correct?
96 $this->waitForText('crm-notification-container', "membership for $firstName $lastName has been added.");
97
98 // click through to the membership view screen
99 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
100 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
101
102 $verifyData = array(
103 'Membership Type' => $memTypeParams['membership_type'],
104 'Status' => 'New',
105 'Source' => $sourceText,
106 );
107 $this->webtestVerifyTabularData($verifyData);
108
109 $this->click("_qf_MembershipView_cancel-bottom");
110 $this->waitForPageToLoad($this->getTimeoutMsec());
111 // page was loaded
112 $this->waitForTextPresent($sourceText);
113
114 // click through to the activities screen
115 $this->click("css=li#tab_activity a");
116 // page was loaded
117 $this->waitForTextPresent('Membership Signup');
118
119 // click through to the activiy view screen (which is the membership view
120 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
121 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
122
123 $verifyData = array(
124 'Membership Type' => $memTypeParams['membership_type'],
125 'Status' => 'New',
126 'Source' => $sourceText,
127 );
128 $this->webtestVerifyTabularData($verifyData);
129 $this->clickLink("_qf_MembershipView_cancel-bottom", "xpath=//div[@id='memberships']/div/table/tbody//tr/td[1][text()='{$memTypeParams['membership_type']}']/../td[7]");
130 $this->click("xpath=//div[@id='memberships']/div/table/tbody//tr/td[1][text()='{$memTypeParams['membership_type']}']/../td[9]/span/a[2][text()='Edit']");
131 $this->waitForElementPresent("_qf_Membership_cancel-bottom");
132
133 // fill in Membership Organization and Type
134 $this->select("membership_type_id[0]", "label={$lifeTimeMemTypeParams['member_of_contact']}");
135 // Wait for membership type select to reload
136 $this->waitForTextPresent($lifeTimeMemTypeParams['membership_type']);
137 $this->select("membership_type_id[1]", "label={$lifeTimeMemTypeParams['membership_type']}");
138
139 $this->waitForElementPresent("xpath=//form[@id='Membership']/div[2]/div[2]//table/tbody//tr[@class='crm-membership-form-block-end_date']/td[2]");
140 $this->click("xpath=//form[@id='Membership']/div[2]/div[2]//table/tbody//tr[@class='crm-membership-form-block-end_date']/td[2]/span/a[text()='clear']");
141
142 $this->click("_qf_Membership_upload-bottom");
143 $this->waitForPageToLoad($this->getTimeoutMsec());
144
145 // page was loaded
146 $this->waitForTextPresent($sourceText);
147 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
148 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
149
150 $verifyData = array(
151 'Status' => 'New',
152 'Source' => $sourceText,
153 'End date' => '',
154 );
155 $this->webtestVerifyTabularData($verifyData);
156 }
157
158 function testMemberAddWithLifeTimeMembershipType() {
159 $this->webtestLogin();
160
161 // Create a membership type to use for this test (defaults for this helper function are rolling 1 year membership)
162 $lifeTimeMemTypeParams = $this->webtestAddMembershipType('rolling', 1, 'lifetime');
163
164 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
165
166 $firstName = "John_" . substr(sha1(rand()), 0, 7);
167
168 //fill in first name
169 $this->type("first_name", $firstName);
170
171 //fill in last name
172 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
173 $this->type("last_name", $lastName);
174
175 //fill in email
176 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
177 $this->type("email_1_email", $email);
178
179 // Clicking save.
180 $this->click("_qf_Contact_upload_view");
181 $this->waitForPageToLoad($this->getTimeoutMsec());
182 $this->waitForText('crm-notification-container', "$firstName $lastName has been created.");
183
184 // click through to the membership view screen
185 $this->click("css=li#tab_member a");
186
187 $this->waitForElementPresent("link=Add Membership");
188 $this->click("link=Add Membership");
189
190 $this->waitForElementPresent("_qf_Membership_cancel-bottom");
191
192 // fill in Membership Organization and Type
193 $this->select("membership_type_id[0]", "label={$lifeTimeMemTypeParams['member_of_contact']}");
194
195 // Wait for membership type select to reload
196 $this->waitForTextPresent($lifeTimeMemTypeParams['membership_type']);
197 // Because it tends to cause problems, all uses of sleep() must be justified in comments
198 // Sleep should never be used for wait for anything to load from the server
199 // Justification for this instance: FIXME
200 sleep(3);
201 $this->select("membership_type_id[1]", "label={$lifeTimeMemTypeParams['membership_type']}");
202
203 $sourceText = "Check Lifetime membership type webtest";
204 // fill in Source
205 $this->type("source", $sourceText);
206
207 // Let Join Date stay default
208
209 // fill in Start Date
210 $this->webtestFillDate('start_date');
211
212 // Clicking save.
213 $this->click("_qf_Membership_upload");
214 $this->waitForPageToLoad($this->getTimeoutMsec());
215
216 // page was loaded
217 $this->waitForTextPresent($sourceText);
218
219 // Is status message correct?
220 $this->waitForText('crm-notification-container', "membership for $firstName $lastName has been added.");
221
222 // click through to the membership view screen
223 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
224 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
225
226 $verifyData = array(
227 'Status' => 'New',
228 'Source' => $sourceText,
229 'End date' => '',
230 );
231 $this->webtestVerifyTabularData($verifyData);
232 $this->click("_qf_MembershipView_cancel-bottom");
233 $this->waitForPageToLoad($this->getTimeoutMsec());
234 }
235 }
236