| 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_Contribute_AddBatchesTest extends CiviSeleniumTestCase { |
| 29 | |
| 30 | protected function setUp() { |
| 31 | parent::setUp(); |
| 32 | } |
| 33 | |
| 34 | function testBatchAddContribution() { |
| 35 | $this->webtestLogin(); |
| 36 | $itemCount = 5; |
| 37 | // create contact |
| 38 | $contact = array(); |
| 39 | |
| 40 | //Open Live Contribution Page |
| 41 | $this->openCiviPage("batch", "reset=1"); |
| 42 | $this->click("xpath=//div[@class='crm-submit-buttons']/a"); |
| 43 | $this->waitForElementPresent("_qf_Batch_next"); |
| 44 | $this->type("item_count", $itemCount); |
| 45 | $this->type("total", 500); |
| 46 | $this->click("_qf_Batch_next"); |
| 47 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 48 | // Add Contact Details |
| 49 | $data = array(); |
| 50 | for ($i = 1; $i <= $itemCount; $i++) { |
| 51 | $data[$i] = array( |
| 52 | 'first_name' => 'Ma' . substr(sha1(rand()), 0, 7), |
| 53 | 'last_name' => 'An' . substr(sha1(rand()), 0, 7), |
| 54 | 'financial_type' => 'Donation', |
| 55 | 'amount' => 100, |
| 56 | |
| 57 | ); |
| 58 | $this->_fillData($data[$i], $i, "Contribution"); |
| 59 | } |
| 60 | |
| 61 | $this->click("_qf_Entry_cancel"); |
| 62 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 63 | $this->_verifyData($data, "Contribution"); |
| 64 | } |
| 65 | |
| 66 | function testBatchAddMembership() { |
| 67 | $this->webtestLogin(); |
| 68 | $itemCount = 5; |
| 69 | // create contact |
| 70 | $contact = array(); |
| 71 | $batchTitle = 'Batch-' . substr(sha1(rand()), 0, 7); |
| 72 | |
| 73 | //Open Live Contribution Page |
| 74 | $this->openCiviPage("batch", "reset=1"); |
| 75 | $this->click("xpath=//div[@class='crm-submit-buttons']/a"); |
| 76 | $this->waitForElementPresent("_qf_Batch_next"); |
| 77 | $this->click("title"); |
| 78 | $this->type("title", $batchTitle); |
| 79 | $this->select("type_id", "Membership"); |
| 80 | $this->type("item_count", $itemCount); |
| 81 | $this->type("total", 500); |
| 82 | $this->click("_qf_Batch_next"); |
| 83 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 84 | |
| 85 | // Add Contact Details |
| 86 | $data = array(); |
| 87 | for ($i = 1; $i <= $itemCount; $i++) { |
| 88 | $data[$i] = array( |
| 89 | 'first_name' => 'Ma' . substr(sha1(rand()), 0, 7), |
| 90 | 'last_name' => 'An' . substr(sha1(rand()), 0, 7), |
| 91 | 'membership_type' => 'General', |
| 92 | 'amount' => 100, |
| 93 | 'financial_type' => 'Member Dues', |
| 94 | ); |
| 95 | $this->_fillData($data[$i], $i, "Membership"); |
| 96 | } |
| 97 | $this->click("_qf_Entry_cancel"); |
| 98 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 99 | |
| 100 | $this->_verifyData($data, "Membership"); |
| 101 | } |
| 102 | |
| 103 | function _fillData($data, $row, $type) { |
| 104 | $email = $data['first_name'] . '@example.com'; |
| 105 | $this->webtestNewDialogContact($data['first_name'], $data['last_name'], $email, 4, |
| 106 | "primary_profiles_{$row}", $row, 'primary'); |
| 107 | |
| 108 | if ($type == "Contribution") { |
| 109 | $this->select("field_{$row}_financial_type", $data['financial_type']); |
| 110 | $this->type("field_{$row}_total_amount", $data['amount']); |
| 111 | $this->webtestFillDateTime("field_{$row}_receive_date", "+1 week"); |
| 112 | $this->type("field_{$row}_contribution_source", substr(sha1(rand()), 0, 10)); |
| 113 | $this->select("field_{$row}_payment_instrument", "Check"); |
| 114 | $this->type("field_{$row}_check_number", rand()); |
| 115 | $this->click("field[{$row}][send_receipt]"); |
| 116 | $this->click("field_{$row}_invoice_id"); |
| 117 | $this->type("field_{$row}_invoice_id", substr(sha1(rand()), 0, 10)); |
| 118 | |
| 119 | } |
| 120 | elseif ($type == "Membership") { |
| 121 | $this->select("field[{$row}][membership_type][0]", "value=1"); |
| 122 | $this->select("field[{$row}][membership_type][1]", $data['membership_type']); |
| 123 | $this->webtestFillDate("field_{$row}_join_date", "now"); |
| 124 | $this->webtestFillDate("field_{$row}_membership_start_date", "now"); |
| 125 | $this->webtestFillDate("field_{$row}_membership_end_date", "+1 month"); |
| 126 | $this->type("field_{$row}_membership_source", substr(sha1(rand()), 0, 10)); |
| 127 | $this->click("field[{$row}][send_receipt]"); |
| 128 | $this->select("field_{$row}_financial_type", $data['financial_type']); |
| 129 | |
| 130 | $this->webtestFillDateTime("field_{$row}_receive_date", "+1 week"); |
| 131 | $this->select("field_{$row}_payment_instrument", "Check"); |
| 132 | $this->type("field_{$row}_check_number", rand()); |
| 133 | $this->select("field_{$row}_contribution_status_id", "Completed"); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | function _checkResult($data, $type) { |
| 138 | if ($type == "Contribution") { |
| 139 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
| 140 | $this->type("sort_name", "{$data['first_name']} {$data['last_name']}"); |
| 141 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); |
| 142 | $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom"); |
| 143 | $expected = array( |
| 144 | 'From' => "{$data['first_name']} {$data['last_name']}", |
| 145 | 'Financial Type' => $data['financial_type'], |
| 146 | 'Total Amount' => $data['amount'], |
| 147 | 'Contribution Status' => 'Completed', |
| 148 | ); |
| 149 | |
| 150 | $this->webtestVerifyTabularData($expected); |
| 151 | } |
| 152 | elseif ($type == "Membership") { |
| 153 | $this->openCiviPage("member/search", "reset=1", "member_join_date_low"); |
| 154 | |
| 155 | // select contact |
| 156 | $this->type("sort_name", "{$data['first_name']} {$data['last_name']}"); |
| 157 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); |
| 158 | $this->click("xpath=//div[@id='memberSearch']//table/tbody/tr[1]/td[11]/span/a[text()='View']"); |
| 159 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); |
| 160 | $expected = array( |
| 161 | 2 => 'General', |
| 162 | 4 => 'New' |
| 163 | ); |
| 164 | foreach ($expected as $label => $value) { |
| 165 | $this->verifyText("xpath=id('MembershipView')/div[2]/div/table[1]/tbody/tr[$label]/td[2]", preg_quote($value)); |
| 166 | } |
| 167 | //View Contribution |
| 168 | $this->waitForElementPresent("xpath=//div[@class='crm-block crm-content-block crm-membership-view-form-block']/table[2]/tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 169 | $this->click("xpath=//div[@class='crm-block crm-content-block crm-membership-view-form-block']/table[2]/tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 170 | $this->waitForElementPresent("_qf_ContributionView_cancel-bottom"); |
| 171 | $expected = array( |
| 172 | 'From' => "{$data['first_name']} {$data['last_name']}", |
| 173 | 'Financial Type' => $data['financial_type'], |
| 174 | 'Total Amount' => $data['amount'], |
| 175 | 'Contribution Status' => 'Completed', |
| 176 | ); |
| 177 | |
| 178 | $this->webtestVerifyTabularData($expected); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | function _verifyData($data, $type) { |
| 183 | $this->waitForElementPresent("xpath=//div[@id='crm-batch-selector_wrapper']//table//tbody/tr[1]/td[7]/span/a[text()='Enter records']"); |
| 184 | $this->clickLink("xpath=//div[@id='crm-batch-selector_wrapper']//table//tbody/tr[1]/td[7]/span/a[text()='Enter records']", "_qf_Entry_upload"); |
| 185 | $this->click("_qf_Entry_upload"); |
| 186 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 187 | foreach ($data as $value) { |
| 188 | $this->_checkResult($value, $type); |
| 189 | } |
| 190 | } |
| 191 | } |