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