Merge pull request #3828 from johanv/CRM-15104-line_item_issues_participant_api
[civicrm-core.git] / tests / phpunit / WebTest / Member / StandaloneAddTest.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
29 /**
30 * Class WebTest_Member_StandaloneAddTest
31 */
32 class WebTest_Member_StandaloneAddTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testStandaloneMemberAdd() {
39
40 $this->webtestLogin();
41
42 // create contact
43 $firstName = substr(sha1(rand()), 0, 7);
44 $this->webtestAddContact($firstName, "Memberson", "Memberson{$firstName}@memberson.name");
45 $contactName = "Memberson, $firstName";
46
47 // add membership type
48 $membershipTypes = $this->webtestAddMembershipType();
49
50 // now add membership
51 $this->openCiviPage("member/add", "reset=1&action=add&context=standalone", "_qf_Membership_upload");
52
53 // select contact
54 $this->webtestFillAutocomplete($firstName);
55
56 // fill in Membership Organization
57 $this->select("membership_type_id[0]", "label={$membershipTypes['member_of_contact']}");
58
59 // select membership type
60 $this->select("membership_type_id[1]", "label={$membershipTypes['membership_type']}");
61
62 // fill in Source
63 $this->type("source", "Membership StandaloneAddTest Webtest");
64
65 // Let Join Date stay default
66
67 // fill in Start Date
68 $this->webtestFillDate('start_date');
69
70 // Let End Date be auto computed
71
72 // fill in Status Override?
73 // fill in Record Membership Payment?
74 $this->click("send_receipt");
75 $this->assertTrue($this->isChecked("send_receipt"), 'Send Confirmation and Receipt checkbox should be checked.');
76 $this->click("_qf_Membership_upload");
77
78 //View Membership
79 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
80 $this->click("xpath=//div[@id='memberships']//table/tbody/tr[1]/td[9]/span/a[text()='View']");
81 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
82
83 $expected = array(
84 'Membership Type' => $membershipTypes['membership_type'],
85 'Status' => 'New',
86 'Source' => 'Membership StandaloneAddTest Webtest',
87 );
88 $this->webtestVerifyTabularData($expected);
89 }
90
91 function testStandaloneGiftMembership() {
92
93 $this->webtestLogin();
94
95 // create contact
96 $firstName = substr(sha1(rand()), 0, 7);
97 $this->webtestAddContact($firstName, "Memberson", "Memberson{$firstName}@memberson.name");
98 $contactName = "Memberson, $firstName";
99
100 $giftMemberfirstName = substr(sha1(rand()), 0, 7);
101 $this->webtestAddContact($giftMemberfirstName, "Memberson", "Memberson{$giftMemberfirstName}@memberson.name");
102 $giftMembercontactName = "Memberson, $giftMemberfirstName";
103
104 // add membership type
105 $membershipTypes = $this->webtestAddMembershipType();
106
107 // now add membership
108 $this->openCiviPage("member/add", "reset=1&action=add&context=standalone", "_qf_Membership_upload");
109
110 // select contact
111 $this->webtestFillAutocomplete($firstName);
112
113 // fill in Membership Organization
114 $this->select("membership_type_id[0]", "label={$membershipTypes['member_of_contact']}");
115
116 // select membership type
117 $this->select("membership_type_id[1]", "label={$membershipTypes['membership_type']}");
118
119 // fill in Source
120 $this->type("source", "Membership StandaloneAddTest Webtest");
121
122 // fill in Start Date
123 $this->webtestFillDate('start_date');
124
125 // add softcredit details
126 $totalAmount = 100;
127 $financialType = 'Donation';
128 $this->clickLink('is_different_contribution_contact','total_amount',FALSE);
129
130 $this->select('soft_credit_type_id', 'Gift');
131 $this->select2('soft_credit_contact_id', $giftMembercontactName);
132 $this->select('financial_type_id','Donation');
133 $this->type('total_amount', $totalAmount);
134 $this->select('payment_instrument_id', 'Check');
135 $this->select('contribution_status_id', 'Completed');
136
137 $this->click("_qf_Membership_upload");
138
139 //View Membership
140 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
141 $this->click("xpath=//div[@id='memberships']//table/tbody/tr[1]/td[9]/span/a[text()='View']");
142 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
143
144 // verify soft credit data
145 $expected = array(
146 '1' => $giftMemberfirstName.' Memberson',
147 '2' => $totalAmount,
148 '3' => 'Gift',
149 '4' => 'Donation',
150 '6' => 'Completed',
151 );
152
153 foreach($expected as $key => $value) {
154 $this->verifyText("xpath=//div[@class='crm-accordion-wrapper']//table/tbody//tr/td[$key]", $value);
155 }
156
157 }
158
159 function testStandaloneMemberOverrideAdd() {
160
161 $this->webtestLogin();
162
163 // add contact
164 $firstName = substr(sha1(rand()), 0, 7);
165 $this->webtestAddContact($firstName, "Memberson", "Memberson{$firstName}@memberson.name");
166 $contactName = "Memberson, $firstName";
167
168 // add membership type
169 $membershipTypes = $this->webtestAddMembershipType();
170
171 // add membership
172 $this->openCiviPage("member/add", "reset=1&action=add&context=standalone", "_qf_Membership_upload");
173
174 // select contact
175 $this->webtestFillAutocomplete($firstName);
176
177 // fill in Membership Organization
178 $this->select("membership_type_id[0]", "label={$membershipTypes['member_of_contact']}");
179
180 // select membership type
181 $this->select("membership_type_id[1]", "label={$membershipTypes['membership_type']}");
182
183 // fill in Source
184 $this->type("source", "Membership StandaloneAddTest Webtest");
185
186 // Let Join Date stay default
187
188 // fill in Start Date
189 $this->webtestFillDate('start_date');
190
191 // Let End Date be auto computed
192
193 // fill in Status Override?
194 $this->click("is_override", "value=1");
195 $this->waitForElementPresent("status_id");
196 $this->select("status_id", "value=3");
197
198 // fill in Record Membership Payment?
199 $this->click("record_contribution", "value=1");
200 $this->waitForElementPresent("contribution_status_id");
201 // let financial type be default
202
203 // let the amount be default
204
205 // select payment instrument type = Check and enter chk number
206 $this->select("payment_instrument_id", "value=4");
207 $this->waitForElementPresent("check_number");
208 $this->type("check_number", "check #12345");
209 $this->type("trxn_id", "P5476785" . rand(100, 10000));
210
211 // fill the payment status be default
212 $this->select("contribution_status_id", "value=2");
213
214 //----
215
216 // Clicking save.
217 $this->click("_qf_Membership_upload");
218 $this->waitForPageToLoad($this->getTimeoutMsec());
219
220 // page was loaded
221 $this->waitForTextPresent("Membership StandaloneAddTest Webtest");
222
223 // verify if Membership is created
224 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
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 $expected = array(
231 'Membership Type' => $membershipTypes['membership_type'],
232 'Status' => 'Grace',
233 'Source' => 'Membership StandaloneAddTest Webtest',
234 );
235 $this->webtestVerifyTabularData($expected);
236 }
237
238 function testAjaxCustomGroupLoad() {
239 $this->webtestLogin();
240 $triggerElement = array('name' => 'membership_type_id_1', 'type' => 'select');
241 $customSets = array(
242 array('entity' => 'Membership', 'subEntity' => 'General', 'triggerElement' => $triggerElement),
243 array('entity' => 'Membership', 'subEntity' => 'Student', 'triggerElement' => $triggerElement)
244 );
245
246 $pageUrl = array('url' => 'member/add', 'args' => 'reset=1&action=add&context=standalone');
247
248 //case where we should fire certain
249 //ui actions which helps triggering possible
250 $test = $this;
251 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl,
252 function() use ($test) {
253 $test->select('membership_type_id_0', 'value=1');
254 }
255 );
256 }
257 }