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