Merge pull request #12024 from yashodha/price_custom_search
[civicrm-core.git] / tests / phpunit / WebTest / Member / OfflineAutoRenewMembershipTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035 26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Member_OfflineAutoRenewMembershipTest
31 */
6a488035
TO
32class WebTest_Member_OfflineAutoRenewMembershipTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
00be9182 38 public function testOfflineAutoRenewMembership() {
6a488035
TO
39 $this->webtestLogin();
40
41 // We need a payment processor
42 $processorName = "Webtest AuthNet" . substr(sha1(rand()), 0, 7);
43 $this->webtestAddPaymentProcessor($processorName, 'AuthNet');
44
45 // Create a membership type to use for this test
92915c55 46 $periodType = 'rolling';
6a488035 47 $duration_interval = 1;
92915c55
TO
48 $duration_unit = 'year';
49 $auto_renew = "optional";
6a488035
TO
50
51 $memTypeParams = $this->webtestAddMembershipType($periodType, $duration_interval, $duration_unit, $auto_renew);
52
53 // create a new contact for whom membership is to be created
54 $firstName = 'Apt' . substr(sha1(rand()), 0, 4);
55 $lastName = 'Mem' . substr(sha1(rand()), 0, 7);
56 $this->webtestAddContact($firstName, $lastName, "{$firstName}@example.com");
57 $contactName = "$firstName $lastName";
58
59 $this->click('css=li#tab_member a');
60
e58b4a12 61 $this->waitForElementPresent('link=Add Membership');
6a488035
TO
62
63 // since we don't have live credentials we will switch to test mode
e58b4a12 64 $this->waitForElementPresent("xpath=//div[@class='view-content']//div[@class='action-link']/a[1]");
65 $url = $this->getAttribute("xpath=//a[contains(text(), 'Add Membership')]@href");
66 $url .= '&mode=test';
6a488035 67 $this->open($url);
a471a3b6 68 $this->waitForPageToLoad($this->getTimeoutMsec());
6a488035
TO
69
70 // start filling membership form
71 $this->waitForElementPresent('payment_processor_id');
72 $this->select("payment_processor_id", "label={$processorName}");
73
74 // fill in Membership Organization and Type
e58b4a12 75 $this->waitForElementPresent('membership_type_id[0]');
6a488035
TO
76 $this->select("membership_type_id[0]", "label={$memTypeParams['member_of_contact']}");
77 // Wait for membership type select to reload
78 $this->waitForTextPresent($memTypeParams['membership_type']);
79 $this->select("membership_type_id[1]", "label={$memTypeParams['membership_type']}");
80
81 $this->click("source");
82 $this->type("source", "Online Membership: Admin Interface");
83
84 $this->waitForElementPresent('auto_renew');
85 $this->click("auto_renew");
6a488035
TO
86 $this->webtestAddCreditCardDetails();
87
6a488035
TO
88 $this->webtestAddBillingDetails($firstName, NULL, $lastName);
89
b3d40287 90 $this->clickLink("_qf_Membership_upload-bottom");
6a488035
TO
91
92 // Use Find Members to make sure membership exists
42daf119 93 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
6a488035 94
e58b4a12 95 $this->type("sort_name", "$lastName, $firstName");
6a488035 96 $this->click("member_test");
225a8648 97 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr[1]/td[11]/span/a[text()='View']");
b3d40287 98 $this->clickAjaxLink("xpath=//div[@id='memberSearch']/table/tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_MembershipView_cancel-bottom");
6a488035
TO
99
100 // View Membership Record
101 $verifyData = array(
102 'Member' => "$firstName $lastName",
103 'Membership Type' => $memTypeParams['membership_type'],
104 'Source' => 'Online Membership: Admin Interface',
105 'Status' => 'Pending',
106 'Auto-renew' => 'Yes',
107 );
108 foreach ($verifyData as $label => $value) {
109 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
110 preg_quote($value)
111 );
112 }
6a488035 113 }
96025800 114
e3fcfdf5
WA
115 /**
116 * CRM-18050: create price set with auto-renewing memberships.
117 */
118 public function testCreatePriceSetWithAutoRenewMembershipType() {
119 $this->webtestLogin();
120
121 // Create a membership type to use for this test
122 $periodType = 'rolling';
123 $duration_interval = 1;
124 $duration_unit = 'year';
125 $auto_renew = "required";
126 $priceSetTitle = 'Membership PriceSet' . substr(sha1(rand()), 0, 7);
127 $memTypeParams = $this->webtestAddMembershipType($periodType, $duration_interval, $duration_unit, $auto_renew);
128
129 // Create a price set with membership type.
130 $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_cancel-bottom');
131 $this->type('title', $priceSetTitle);
132 $this->click("xpath=//table[@class='form-layout']/tbody//tr/td[2]/label[text()='Membership']");
133 $this->select('financial_type_id', "value=2");
134 $this->click("_qf_Set_next-bottom");
135 $this->waitForAjaxContent();
136 $this->waitForElementPresent('is_active');
137 $fieldLablel = 'Field Label' . substr(sha1(rand()), 0, 7);
138 $this->type('label', $fieldLablel);
139 $this->select('html_type', "value=Radio");
140 $this->waitForAjaxContent();
141 $this->waitForElementPresent('membership_type_id[1]');
142 $this->select('membership_type_id[1]', "label={$memTypeParams['membership_type']}");
143 $this->waitForAjaxContent();
144 $this->click("xpath=//div[@class='ui-dialog-buttonset']//button//span[text()='Save']");
145 $this->waitForElementPresent('field_page');
146 $this->assertElementContainsText("xpath=//div[@id='crm-main-content-wrapper']/div[@id='field_page']/table/tbody/tr/td[1]/div", "{$fieldLablel}");
147 }
148
6a488035 149}