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