Merge pull request #140 from dlobo/CRM-12111
[civicrm-core.git] / tests / phpunit / WebTest / Member / SeperateMembershipPaymentTest.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_SeperateMembershipPaymentTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testSeperateMembershipCreate() {
36 // a random 7-char string and an even number to make this pass unique
37 $hash = substr(sha1(rand()), 0, 7);
38 $rand = 2 * rand(2, 50);
39 // This is the path where our testing install resides.
40 // The rest of URL is defined in CiviSeleniumTestCase base class, in
41 // class attributes.
42 $this->open($this->sboxPath);
43
44 // Log in using webtestLogin() method
45 $this->webtestLogin();
46
47 $firstName1 = 'Ma_' . substr(sha1(rand()), 0, 7);
48 $lastName1 = 'An_' . substr(sha1(rand()), 0, 7);
49 $this->webtestAddContact($firstName1, $lastName1, TRUE);
50 $this->assertElementContainsText('crm-notification-container', "$firstName1 $lastName1 has been created.");
51 $url = explode('&cid=', $this->getLocation());
52 $cid = $url[1];
53
54 // create contribution page with randomized title and default params
55 $amountSection = TRUE;
56 $payLater = TRUE;
57 $onBehalf = FALSE;
58 $pledges = FALSE;
59 $recurring = FALSE;
60 $memberships = TRUE;
61 $memPriceSetId = NULL;
62 $friend = TRUE;
63 $profilePreId = NULL;
64 $profilePostId = NULL;
65 $premiums = FALSE;
66 $widget = FALSE;
67 $pcp = FALSE;
68 $isAddPaymentProcessor = FALSE;
69 $isSeparatePayment = TRUE;
70
71 $contributionTitle = "Title $hash";
72 $pageId = $this->webtestAddContributionPage($hash,
73 $rand,
74 $contributionTitle,
75 NULL,
76 $amountSection,
77 $payLater,
78 $onBehalf,
79 $pledges,
80 $recurring,
81 $memberships,
82 $memPriceSetId,
83 $friend,
84 $profilePreId,
85 $profilePostId,
86 $premiums,
87 $widget,
88 $pcp,
89 $isAddPaymentProcessor,
90 FALSE,
91 $isSeparatePayment,
92 FALSE
93 );
94
95
96 // create new membership types
97 $memTypeParams1 = $this->webtestAddMembershipType();
98 $memTypeTitle1 = $memTypeParams1['membership_type'];
99 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
100 $memTypeId1 = $memTypeId1[1];
101
102 $memTypeParams2 = $this->webtestAddMembershipType();
103 $memTypeTitle2 = $memTypeParams2['membership_type'];
104 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href"));
105 $memTypeId2 = $memTypeId2[1];
106
107 // edit contribution page memberships tab to add two new membership types
108 $this->openCiviPage('admin/contribute/membership', "reset=1&action=update&id={$pageId}", "_qf_MembershipBlock_next-bottom");
109 $this->click("membership_type_$memTypeId1");
110 $this->click("membership_type_$memTypeId2");
111 $this->click('_qf_MembershipBlock_next');
112 $this->waitForPageToLoad($this->getTimeoutMsec());
113 $this->waitForElementPresent('_qf_MembershipBlock_next-bottom');
114 $text = "'MembershipBlock' information has been saved.";
115 $this->assertElementContainsText('crm-notification-container', $text, 'Missing text: ' . $text);
116 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle1, $cid);
117
118 //Find Member
119 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
120 $this->type("sort_name", "$firstName1 $lastName1");
121 $this->click("_qf_Search_refresh");
122 $this->waitForPageToLoad($this->getTimeoutMsec());
123 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr");
124 $this->click("xpath=//div[@id='memberSearch']/table/tbody/tr/td[11]/span/a[text()='View']");
125 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
126
127 //View Membership Record
128 $verifyData = array(
129 'Member' => $firstName1 . ' ' . $lastName1,
130 'Membership Type' => $memTypeTitle1,
131 'Status' => 'Pending',
132 'Source' => 'Online Contribution:' . ' ' . $contributionTitle,
133 );
134
135 $this->webtestVerifyTabularData($verifyData);
136
137 // Click View action link on associated contribution record
138 $this->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[@class='selector']/tbody/tr[1]/td[8]/span/a[text()='View']");
139 $this->click("xpath=//form[@id='MembershipView']/div[2]/div/table[@class='selector']/tbody/tr[1]/td[8]/span/a[text()='View']");
140 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
141
142 //View Contribution Record
143 $verifyData = array(
144 'From' => $firstName1 . ' ' . $lastName1,
145 'Total Amount' => '$ 100.00',
146 );
147 $this->webtestVerifyTabularData($verifyData);
148
149 $this->click("_qf_ContributionView_cancel-bottom");
150 $this->waitForPageToLoad($this->getTimeoutMsec());
151 }
152
153 function _testOnlineMembershipSignup($pageId, $memTypeId, $cid = NULL) {
154 //Open Live Contribution Page
155 if ($cid) {
156 $contribUrl = array('url' => "contribute/transact", 'args' => "reset=1&id=$pageId&cid=$cid");
157 }
158 else {
159 $contribUrl = array('url' => "contribute/transact", 'args' => "reset=1&id=$pageId");
160 }
161 $this->openCiviPage($contribUrl['url'], $contribUrl['args'], '_qf_Main_upload-bottom');
162
163 // Select membership type 1
164 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'$memTypeId')]");
165 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 60);
166 $this->click("_qf_Main_upload-bottom");
167 $this->waitForElementPresent("_qf_Confirm_next-bottom");
168 $this->click("_qf_Confirm_next-bottom");
169 $this->waitForPageToLoad($this->getTimeoutMsec());
170 }
171 }