Web Test Fix
[civicrm-core.git] / tests / phpunit / WebTest / Member / OfflineAutoRenewMembershipTest.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 class WebTest_Member_OfflineAutoRenewMembershipTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testOfflineAutoRenewMembership() {
35 $this->webtestLogin();
36
37 // We need a payment processor
38 $processorName = "Webtest AuthNet" . substr(sha1(rand()), 0, 7);
39 $this->webtestAddPaymentProcessor($processorName, 'AuthNet');
40
41 // Create a membership type to use for this test
42 $periodType = 'rolling';
43 $duration_interval = 1;
44 $duration_unit = 'year';
45 $auto_renew = "optional";
46
47 $memTypeParams = $this->webtestAddMembershipType($periodType, $duration_interval, $duration_unit, $auto_renew);
48
49 // create a new contact for whom membership is to be created
50 $firstName = 'Apt' . substr(sha1(rand()), 0, 4);
51 $lastName = 'Mem' . substr(sha1(rand()), 0, 7);
52 $this->webtestAddContact($firstName, $lastName, "{$firstName}@example.com");
53 $contactName = "$firstName $lastName";
54
55 $this->click('css=li#tab_member a');
56
57 $this->waitForElementPresent('link=Submit Credit Card Membership');
58
59 // since we don't have live credentials we will switch to test mode
60 $url = $this->getAttribute("xpath=//div[@class='view-content']//div[@class='action-link']/a[2]@href");
61 $url = str_replace('mode=live', 'mode=test', $url);
62 $this->open($url);
63 $this->waitForPageToLoad($this->getTimeoutMsec());
64
65 // start filling membership form
66 $this->waitForElementPresent('payment_processor_id');
67 $this->select("payment_processor_id", "label={$processorName}");
68
69 // fill in Membership Organization and Type
70 $this->select("membership_type_id[0]", "label={$memTypeParams['member_of_contact']}");
71 // Wait for membership type select to reload
72 $this->waitForTextPresent($memTypeParams['membership_type']);
73 $this->select("membership_type_id[1]", "label={$memTypeParams['membership_type']}");
74
75 $this->click("source");
76 $this->type("source", "Online Membership: Admin Interface");
77
78 $this->waitForElementPresent('auto_renew');
79 $this->click("auto_renew");
80
81 $this->webtestAddCreditCardDetails();
82
83 // since country is not pre-selected for offline mode
84 $this->select("billing_country_id-5", "label=United States");
85 //wait for states to populate the select box
86 // Because it tends to cause problems, all uses of sleep() must be justified in comments
87 // Sleep should never be used for wait for anything to load from the server
88 // Justification for this instance: FIXME
89 sleep(2);
90 $this->click('billing_state_province_id-5');
91 $this->webtestAddBillingDetails($firstName, NULL, $lastName);
92
93 $this->click("_qf_Membership_upload-bottom");
94 $this->waitForPageToLoad($this->getTimeoutMsec());
95
96 // Use Find Members to make sure membership exists
97 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
98
99 $this->type("sort_name", "$firstName $lastName");
100 $this->click("member_test");
101 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr[1]/td[11]/span/a[text()='View']");
102 $this->click("xpath=//div[@id='memberSearch']/table/tbody/tr[1]/td[11]/span/a[text()='View']");
103 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
104
105 // View Membership Record
106 $verifyData = array(
107 'Member' => "$firstName $lastName",
108 'Membership Type' => $memTypeParams['membership_type'],
109 'Source' => 'Online Membership: Admin Interface',
110 'Status' => 'Pending',
111 'Auto-renew' => 'Yes',
112 );
113 foreach ($verifyData as $label => $value) {
114 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
115 preg_quote($value)
116 );
117 }
118 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
119 }
120 }
121