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