| 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_Contribute_OfflineRecurContributionTest |
| 31 | */ |
| 32 | class WebTest_Contribute_OfflineRecurContributionTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function testOfflineRecurContribution() { |
| 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 new contact for whom recurring contribution is to be created |
| 46 | $firstName = 'Jane' . substr(sha1(rand()), 0, 7); |
| 47 | $middleName = 'Middle'; |
| 48 | $lastName = 'Recuroff_' . substr(sha1(rand()), 0, 7); |
| 49 | $this->webtestAddContact($firstName, $lastName, "{$firstName}@example.com"); |
| 50 | $contactName = "$firstName $lastName"; |
| 51 | |
| 52 | $this->click('css=li#tab_contribute a'); |
| 53 | |
| 54 | $this->waitForElementPresent('link=Record Contribution (Check, Cash, EFT ...)'); |
| 55 | // since we don't have live credentials we will switch to test mode |
| 56 | $url = $this->getAttribute("xpath=//*[@id='Search']/div[2]/div[2]/a[1]@href"); |
| 57 | $url .= '&mode=test'; |
| 58 | $this->open($url); |
| 59 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 60 | |
| 61 | // start filling out contribution form |
| 62 | $this->waitForElementPresent('payment_processor_id'); |
| 63 | $this->select('payment_processor_id', "label={$processorName}"); |
| 64 | |
| 65 | $this->click('financial_type_id'); |
| 66 | $this->select('financial_type_id', 'label=Donation'); |
| 67 | $this->type('total_amount', '10'); |
| 68 | |
| 69 | // recurring contribution fields |
| 70 | $this->click('is_recur'); |
| 71 | $this->type('frequency_interval', '1'); |
| 72 | $this->select('frequency_unit', 'label=month(s)'); |
| 73 | $this->type('installments', '12'); |
| 74 | |
| 75 | $this->click('is_email_receipt'); |
| 76 | $this->waitForElementPresent('credit_card_type'); |
| 77 | |
| 78 | // enter credit card info on form |
| 79 | $this->webtestAddCreditCardDetails(); |
| 80 | |
| 81 | // billing address |
| 82 | $this->webtestAddBillingDetails($firstName, $middleName, $lastName); |
| 83 | $this->click('_qf_Contribution_upload-bottom'); |
| 84 | $this->waitForElementPresent('link=Edit'); |
| 85 | $this->waitForText('crm-notification-container', "The contribution record has been saved."); |
| 86 | // Use Find Contributions to make sure test recurring contribution exists |
| 87 | $this->openCiviPage("contribute/search", "reset=1", 'contribution_currency_type'); |
| 88 | |
| 89 | $this->type('sort_name', "$lastName, $firstName"); |
| 90 | $this->click('contribution_test'); |
| 91 | $this->click('_qf_Search_refresh'); |
| 92 | |
| 93 | $this->waitForElementPresent('css=#contributionSearch table tbody tr td span a.action-item:first-child'); |
| 94 | $this->click('css=#contributionSearch table tbody tr td span a.action-item:first-child'); |
| 95 | $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); |
| 96 | |
| 97 | // View Recurring Contribution Record |
| 98 | $verifyData = array( |
| 99 | 'From' => "$contactName", |
| 100 | 'Financial Type' => 'Donation (test)', |
| 101 | 'Total Amount' => 'Installments: 12, Interval: 1 month(s)', |
| 102 | 'Contribution Status' => 'Pending : Incomplete Transaction', |
| 103 | 'Payment Method' => 'Credit Card', |
| 104 | ); |
| 105 | |
| 106 | foreach ($verifyData as $label => $value) { |
| 107 | $this->verifyText("xpath=//form[@id='ContributionView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td", |
| 108 | preg_quote($value) |
| 109 | ); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | } |