| 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 | |
| 29 | /** |
| 30 | * Class WebTest_Contribute_UpdateBatchPendingContributionTest |
| 31 | */ |
| 32 | class WebTest_Contribute_UpdateBatchPendingContributionTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | function testBatchUpdatePendingContribution() { |
| 39 | $this->webtestLogin(); |
| 40 | $this->_testOfflineContribution(); |
| 41 | $this->_testOfflineContribution(); |
| 42 | $this->_testOfflineContribution(); |
| 43 | |
| 44 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
| 45 | |
| 46 | $this->type("sort_name", "Individual"); |
| 47 | $this->click('contribution_status_id_2'); |
| 48 | $this->clickLink("_qf_Search_refresh"); |
| 49 | |
| 50 | $this->click('radio_ts', 'ts_all'); |
| 51 | |
| 52 | $this->select('task', "label=Update Pending Contribution Status"); |
| 53 | $this->clickLink("_qf_Search_next_action"); |
| 54 | $this->select('contribution_status_id', 'label=Completed'); |
| 55 | $this->click('_qf_Status_next'); |
| 56 | $this->waitForElementPresent("_qf_Result_done"); |
| 57 | $this->click("_qf_Result_done"); |
| 58 | |
| 59 | $this->waitForElementPresent("contribution_date_low"); |
| 60 | |
| 61 | $this->type("sort_name", "Individual"); |
| 62 | $this->click('contribution_status_id_1'); |
| 63 | $this->click("_qf_Search_refresh"); |
| 64 | |
| 65 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 66 | $this->click("xpath=//div[@id='contributionSearch']/table[@class='selector row-highlight']/tbody/tr[1]/td[11]/span/a[text()='View']"); |
| 67 | $this->waitForElementPresent("_qf_ContributionView_cancel-bottom"); |
| 68 | $expected = array( |
| 69 | 'Received Into' => "Deposit Bank Account", |
| 70 | 'Contribution Status' => "Completed", |
| 71 | ); |
| 72 | |
| 73 | $this->webtestVerifyTabularData($expected); |
| 74 | } |
| 75 | |
| 76 | function testParticipationAdd() { |
| 77 | // Log in using webtestLogin() method |
| 78 | $this->webtestLogin(); |
| 79 | |
| 80 | // Adding contact with randomized first name (so we can then select that contact when creating event registration) |
| 81 | // We're using Quick Add block on the main page for this. |
| 82 | $firstName1 = substr(sha1(rand()), 0, 7); |
| 83 | $this->webtestAddContact($firstName1, 'Anderson', TRUE); |
| 84 | $sortName1 = "Anderson, $firstName1"; |
| 85 | $this->_addParticipant($firstName1); |
| 86 | |
| 87 | $firstName2 = substr(sha1(rand()), 0, 7); |
| 88 | $this->webtestAddContact($firstName2, 'Anderson', TRUE); |
| 89 | $sortName2 = "Anderson, $firstName2"; |
| 90 | $this->_addParticipant($firstName2); |
| 91 | |
| 92 | // Search the participants |
| 93 | $this->openCiviPage("event/search", "reset=1", '_qf_Search_refresh'); |
| 94 | |
| 95 | $eventName = 'Rain'; |
| 96 | $this->select2("event_id", $eventName); |
| 97 | $this->click('_qf_Search_refresh'); |
| 98 | |
| 99 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
| 100 | |
| 101 | $this->type("sort_name", "Anderson"); |
| 102 | $this->click('contribution_status_id_2'); |
| 103 | $this->click("_qf_Search_refresh"); |
| 104 | |
| 105 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 106 | $this->click('radio_ts', 'ts_all'); |
| 107 | |
| 108 | $this->select('task', "label=Update Pending Contribution Status"); |
| 109 | $this->click("_qf_Search_next_action"); |
| 110 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 111 | $this->select('contribution_status_id', 'label=Completed'); |
| 112 | $this->click('_qf_Status_next'); |
| 113 | $this->waitForElementPresent("_qf_Result_done"); |
| 114 | $this->click("_qf_Result_done"); |
| 115 | |
| 116 | $this->waitForElementPresent("contribution_date_low"); |
| 117 | |
| 118 | $this->type("sort_name", "Anderson"); |
| 119 | $this->click('contribution_status_id_1'); |
| 120 | $this->click("_qf_Search_refresh"); |
| 121 | |
| 122 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 123 | $this->click("xpath=//div[@id='contributionSearch']/table[@class='selector row-highlight']/tbody/tr[1]/td[11]/span/a[text()='View']"); |
| 124 | $this->waitForElementPresent("_qf_ContributionView_cancel-bottom"); |
| 125 | $expected = array( |
| 126 | 'Received Into' => "Deposit Bank Account", |
| 127 | 'Contribution Status' => "Completed", |
| 128 | ); |
| 129 | |
| 130 | $this->webtestVerifyTabularData($expected); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * @param string $firstName |
| 135 | */ |
| 136 | function _addParticipant($firstName) { |
| 137 | |
| 138 | $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", '_qf_Participant_upload-bottom'); |
| 139 | |
| 140 | // Type contact last name in contact auto-complete, wait for dropdown and click first result |
| 141 | $this->webtestFillAutocomplete($firstName); |
| 142 | |
| 143 | // Select event. Based on label for now. |
| 144 | $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament"); |
| 145 | |
| 146 | // Select role |
| 147 | $this->multiselect2('role_id', array('Volunteer')); |
| 148 | |
| 149 | // Select participant status |
| 150 | $this->select('status_id', 'value=1'); |
| 151 | |
| 152 | // Setting registration source |
| 153 | $this->type('source', 'Event StandaloneAddTest Webtest'); |
| 154 | |
| 155 | // Since we're here, let's check of screen help is being displayed properly |
| 156 | $this->assertTrue($this->isTextPresent('Source for this registration (if applicable).')); |
| 157 | |
| 158 | // Select an event fee |
| 159 | $this->waitForElementPresent('priceset'); |
| 160 | |
| 161 | $this->click("xpath=//input[@class='crm-form-radio']"); |
| 162 | |
| 163 | // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle) |
| 164 | $this->type('total_amount', '800'); |
| 165 | |
| 166 | $this->select('contribution_status_id', "label=Pending"); |
| 167 | |
| 168 | // Clicking save. |
| 169 | $this->click('_qf_Participant_upload-bottom'); |
| 170 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 171 | |
| 172 | // Is status message correct? |
| 173 | $this->waitForText("crm-notification-container", "Event registration for $firstName Anderson has been added"); |
| 174 | |
| 175 | $this->waitForElementPresent("xpath=//form[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 176 | //click through to the participant view screen |
| 177 | $this->click("xpath=//form[@id='Search']//table//tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 178 | $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom'); |
| 179 | |
| 180 | $this->webtestVerifyTabularData( |
| 181 | array( |
| 182 | 'Event' => 'Rain-forest Cup Youth Soccer Tournament', |
| 183 | 'Participant Role' => 'Attendee', |
| 184 | 'Status' => 'Registered', |
| 185 | 'Event Source' => 'Event StandaloneAddTest Webtest', |
| 186 | 'Fees' => '$ 800.00', |
| 187 | ) |
| 188 | ); |
| 189 | } |
| 190 | |
| 191 | function _testOfflineContribution() { |
| 192 | $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload"); |
| 193 | |
| 194 | // create new contact using dialog |
| 195 | $this->createDialogContact(); |
| 196 | |
| 197 | // select financial type |
| 198 | $this->select( "financial_type_id", "value=1" ); |
| 199 | |
| 200 | //Contribution status |
| 201 | $this->select("contribution_status_id", "label=Pending"); |
| 202 | |
| 203 | // total amount |
| 204 | $this->type("total_amount", "100"); |
| 205 | |
| 206 | // Clicking save. |
| 207 | $this->click("_qf_Contribution_upload"); |
| 208 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 209 | |
| 210 | // Is status message correct? |
| 211 | $this->assertTrue($this->isTextPresent("The contribution record has been saved."), "Status message didn't show up after saving!"); |
| 212 | |
| 213 | // verify if Membership is created |
| 214 | $this->waitForElementPresent("xpath=//div[@class='view-content']//table[2]//tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 215 | |
| 216 | //click through to the Membership view screen |
| 217 | $this->click("xpath=//div[@class='view-content']//table[2]/tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 218 | $this->waitForElementPresent("_qf_ContributionView_cancel-bottom"); |
| 219 | |
| 220 | $expected = array( |
| 221 | 'Financial Type' => 'Donation', |
| 222 | 'Total Amount' => '100.00', |
| 223 | 'Contribution Status' => 'Pending', |
| 224 | ); |
| 225 | foreach ($expected as $label => $value) { |
| 226 | $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody//tr/td[1][text()='$label']/../td[2]", preg_quote($value)); |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |