Merge pull request #3342 from systopia/CRM-14741
[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
75 $this->click("_qf_Membership_upload");
76
77 //View Membership
78 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
79 $this->click("xpath=//div[@id='memberships']//table/tbody/tr[1]/td[9]/span/a[text()='View']");
80 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
81
82 $expected = array(
83 'Membership Type' => $membershipTypes['membership_type'],
84 'Status' => 'New',
85 'Source' => 'Membership StandaloneAddTest Webtest',
86 );
87 $this->webtestVerifyTabularData($expected);
88 }
89
90 function testStandaloneMemberOverrideAdd() {
91
92 $this->webtestLogin();
93
94 // add contact
95 $firstName = substr(sha1(rand()), 0, 7);
96 $this->webtestAddContact($firstName, "Memberson", "Memberson{$firstName}@memberson.name");
97 $contactName = "Memberson, $firstName";
98
99 // add membership type
100 $membershipTypes = $this->webtestAddMembershipType();
101
102 // add membership
103 $this->openCiviPage("member/add", "reset=1&action=add&context=standalone", "_qf_Membership_upload");
104
105 // select contact
106 $this->webtestFillAutocomplete($firstName);
107
108 // fill in Membership Organization
109 $this->select("membership_type_id[0]", "label={$membershipTypes['member_of_contact']}");
110
111 // select membership type
112 $this->select("membership_type_id[1]", "label={$membershipTypes['membership_type']}");
113
114 // fill in Source
115 $this->type("source", "Membership StandaloneAddTest Webtest");
116
117 // Let Join Date stay default
118
119 // fill in Start Date
120 $this->webtestFillDate('start_date');
121
122 // Let End Date be auto computed
123
124 // fill in Status Override?
125 $this->click("is_override", "value=1");
126 $this->waitForElementPresent("status_id");
127 $this->select("status_id", "value=3");
128
129 // fill in Record Membership Payment?
130 $this->click("record_contribution", "value=1");
131 $this->waitForElementPresent("contribution_status_id");
132 // let financial type be default
133
134 // let the amount be default
135
136 // select payment instrument type = Check and enter chk number
137 $this->select("payment_instrument_id", "value=4");
138 $this->waitForElementPresent("check_number");
139 $this->type("check_number", "check #12345");
140 $this->type("trxn_id", "P5476785" . rand(100, 10000));
141
142 // fill the payment status be default
143 $this->select("contribution_status_id", "value=2");
144
145 //----
146
147 // Clicking save.
148 $this->click("_qf_Membership_upload");
149 $this->waitForPageToLoad($this->getTimeoutMsec());
150
151 // page was loaded
152 $this->waitForTextPresent("Membership StandaloneAddTest Webtest");
153
154 // verify if Membership is created
155 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
156
157 //click through to the Membership view screen
158 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
159 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
160
161 $expected = array(
162 'Membership Type' => $membershipTypes['membership_type'],
163 'Status' => 'Grace',
164 'Source' => 'Membership StandaloneAddTest Webtest',
165 );
166 $this->webtestVerifyTabularData($expected);
167 }
168
169 function testAjaxCustomGroupLoad() {
170 $this->webtestLogin();
171 $triggerElement = array('name' => 'membership_type_id_1', 'type' => 'select');
172 $customSets = array(
173 array('entity' => 'Membership', 'subEntity' => 'General', 'triggerElement' => $triggerElement),
174 array('entity' => 'Membership', 'subEntity' => 'Student', 'triggerElement' => $triggerElement)
175 );
176
177 $pageUrl = array('url' => 'member/add', 'args' => 'reset=1&action=add&context=standalone');
178
179 //case where we should fire certain
180 //ui actions which helps triggering possible
181 $test = $this;
182 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl,
183 function() use ($test) {
184 $test->select('membership_type_id_0', 'value=1');
185 }
186 );
187 }
188 }