15d48f9e99ecc21de9cf76b9d36cbe0995088605
[civicrm-core.git] / tests / phpunit / WebTest / Member / OnlineAutoRenewMembershipGCTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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_OnlineAutoRenewMembershipGCTest
31 */
32 class WebTest_Member_OnlineAutoRenewMembershipGCTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testOnlineAutoRenewMembershipAnonymous() {
39 //configure membership signup page.
40 $pageId = $this->_configureMembershipPage();
41
42 //now do the test membership signup.
43 $this->openCiviPage('contribute/transact', "reset=1&action=preview&id={$pageId}", "_qf_Main_upload-bottom");
44
45 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[2]/span/label/span[1][contains(text(),'Student')]");
46 $this->click("auto_renew");
47
48 $firstName = 'John';
49 $lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
50 $this->type('email-5', "{$lastName}@example.com");
51
52 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next_checkout");
53
54 $text = 'I want this membership to be renewed automatically every 1 year(s).';
55 $this->assertElementContainsText('css=div.display-block', $text, 'Missing text: ' . $text);
56
57 $this->click("_qf_Confirm_next_checkout");
58
59 // FIXME: By this time pending records has already been created. Formatting for external page (google checkout in this case)
60
61 // has changed a bit. No point in adding test for external page as we 'll test with fake transactions.
62 }
63
64 public function testOnlineAutoRenewMembershipAuthenticated() {
65 //configure membership signup page.
66 $pageId = $this->_configureMembershipPage();
67
68 $this->webtestLogin();
69 $this->waitForPageToLoad($this->getTimeoutMsec());
70
71 //now do the test membership signup.
72 $this->openCiviPage('contribute/transact', "reset=1&action=preview&id={$pageId}", "_qf_Main_upload-bottom");
73 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[2]/span/label/span[1][contains(text(),'Student')]");
74
75 $this->click("auto_renew");
76
77 $firstName = 'John';
78 $lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
79 $this->type('email-5', "{$lastName}@example.com");
80
81 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next_checkout");
82
83 $text = 'I want this membership to be renewed automatically every 1 year(s).';
84 $this->assertElementContainsText('css=div.display-block', $text, 'Missing text: ' . $text);
85
86 $this->click("_qf_Confirm_next_checkout");
87
88 // FIXME: By this time pending records has already been created. Formatting for external page (google checkout in this case)
89
90 // has changed a bit. No point in adding test for external page as we 'll test with fake transactions.
91 }
92
93 /**
94 * @return null
95 */
96 public function _configureMembershipPage() {
97 static $pageId = NULL;
98
99 if (!$pageId) {
100 $this->webtestLogin();
101
102 //add payment processor.
103 $hash = substr(sha1(rand()), 0, 7);
104 $rand = 2 * rand(2, 50);
105 $processorName = "Webtest Auto Renew Google Checkout" . $hash;
106 $this->webtestAddPaymentProcessor($processorName, 'Google_Checkout');
107
108 // -- start updating membership types
109 $this->openCiviPage('admin/member/membershipType/add', 'action=update&id=1&reset=1');
110
111 $this->waitForElementPresent("xpath=//div[@id='membership_type_form']//table/tbody/tr[6]/td/label[contains(text(), 'Auto-renew Option')]/../../td[2]/label[contains(text(), 'Give option, but not required')]");
112 $this->click("xpath=//div[@id='membership_type_form']//table/tbody/tr[6]/td/label[contains(text(), 'Auto-renew Option')]/../../td[2]/label[contains(text(), 'Give option, but not required')]");
113
114 $this->type("duration_interval", "1");
115 $this->select("duration_unit", "label=year");
116
117 $this->click("_qf_MembershipType_upload-bottom");
118 $this->waitForPageToLoad($this->getTimeoutMsec());
119
120 $this->openCiviPage('admin/member/membershipType/add', 'action=update&id=2&reset=1');
121
122 $this->waitForElementPresent("xpath=//div[@id='membership_type_form']//table/tbody/tr[6]/td/label[contains(text(), 'Auto-renew Option')]/../../td[2]/label[contains(text(), 'Give option, but not required')]");
123 $this->click("xpath=//div[@id='membership_type_form']//table/tbody/tr[6]/td/label[contains(text(), 'Auto-renew Option')]/../../td[2]/label[contains(text(), 'Give option, but not required')]");
124
125 $this->type("duration_interval", "1");
126 $this->select("duration_unit", "label=year");
127
128 $this->click("_qf_MembershipType_upload-bottom");
129 $this->waitForPageToLoad($this->getTimeoutMsec());
130
131 // create contribution page with randomized title and default params
132 $amountSection = FALSE;
133 $payLater = TRUE;
134 $onBehalf = FALSE;
135 $pledges = FALSE;
136 $recurring = TRUE;
137 $membershipTypes = array(
138 array('id' => 1, 'auto_renew' => 1),
139 array('id' => 2, 'auto_renew' => 1),
140 );
141 $memPriceSetId = NULL;
142 $friend = TRUE;
143 $profilePreId = NULL;
144 $profilePostId = NULL;
145 $premiums = TRUE;
146 $widget = TRUE;
147 $pcp = TRUE;
148
149 $contributionTitle = "Title $hash";
150 $pageId = $this->webtestAddContributionPage($hash,
151 $rand,
152 $contributionTitle,
153 array($processorName => 'Google_Checkout'),
154 $amountSection,
155 $payLater,
156 $onBehalf,
157 $pledges,
158 $recurring,
159 $membershipTypes,
160 $memPriceSetId,
161 $friend,
162 $profilePreId,
163 $profilePostId,
164 $premiums,
165 $widget,
166 $pcp,
167 FALSE
168 );
169
170 //make sure we do have required permissions.
171 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
172 $this->changePermissions($permissions);
173
174 // now logout and do membership test that way
175 $this->webtestLogout();
176 }
177
178 return $pageId;
179 }
180
181 }