| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
| 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 | |
| 30 | /** |
| 31 | * Class WebTest_Financial_FinancialBatchExport |
| 32 | */ |
| 33 | class WebTest_Financial_FinancialBatchExport extends CiviSeleniumTestCase { |
| 34 | |
| 35 | protected function setUp() { |
| 36 | parent::setUp(); |
| 37 | } |
| 38 | |
| 39 | public function testAddFinancialBatch() { |
| 40 | // Log in using webtestLogin() method |
| 41 | $this->webtestLogin('admin'); |
| 42 | $this->openCiviPage("financial/batch", "reset=1&action=add", '_qf_FinancialBatch_next-botttom'); |
| 43 | $setTitle = 'Batch ' . substr(sha1(rand()), 0, 7) . date('Y-m-d'); |
| 44 | $setDescription = 'Test Batch Creation'; |
| 45 | $setPaymentInstrument = 'Credit Card'; |
| 46 | $numberOfTrxn = '10'; // can be 10, 25, 50, 100 |
| 47 | $totalAmt = '1000'; |
| 48 | $exportFormat = 'CSV'; |
| 49 | $batchId = $this->_testAddBatch( |
| 50 | $setTitle, |
| 51 | $setDescription, |
| 52 | $setPaymentInstrument, |
| 53 | $numberOfTrxn, |
| 54 | $totalAmt |
| 55 | ); |
| 56 | $this->_testAssignBatch($numberOfTrxn); |
| 57 | $this->_testExportBatch($setTitle, $batchId, $exportFormat); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @param $setTitle |
| 62 | * @param $setDescription |
| 63 | * @param $setPaymentInstrument |
| 64 | * @param $numberOfTrxn |
| 65 | * @param $totalAmt |
| 66 | * |
| 67 | * @return null |
| 68 | */ |
| 69 | public function _testAddBatch($setTitle, $setDescription, $setPaymentInstrument, $numberOfTrxn, $totalAmt) { |
| 70 | // Enter Optional Constraints |
| 71 | $this->type('title', $setTitle); |
| 72 | $this->type('description', $setDescription); |
| 73 | if ($setPaymentInstrument == 'Credit Card') { |
| 74 | $this->select("payment_instrument_id", "value=1"); |
| 75 | } |
| 76 | elseif ($setPaymentInstrument == 'Debit Card') { |
| 77 | $this->select("payment_instrument_id", "value=2"); |
| 78 | } |
| 79 | elseif ($setPaymentInstrument == 'Cash') { |
| 80 | $this->select("payment_instrument_id", "value=3"); |
| 81 | } |
| 82 | elseif ($setPaymentInstrument == 'Check') { |
| 83 | $this->select("payment_instrument_id", "value=4"); |
| 84 | } |
| 85 | elseif ($setPaymentInstrument == 'EFT') { |
| 86 | $this->select("payment_instrument_id", "value=5"); |
| 87 | } |
| 88 | $this->type('item_count', $numberOfTrxn); |
| 89 | $this->type('total', $totalAmt); |
| 90 | |
| 91 | $this->click('_qf_FinancialBatch_next-botttom'); |
| 92 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 93 | |
| 94 | // parse URL to grab the batch ID |
| 95 | $batchId = $this->urlArg('bid'); |
| 96 | return $batchId; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @param $numberOfTrxn |
| 101 | */ |
| 102 | public function _testAssignBatch($numberOfTrxn) { |
| 103 | $this->waitForAjaxContent(); |
| 104 | $this->select("xpath=//div[@class='dataTables_length']/label/select", "value={$numberOfTrxn}"); |
| 105 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
| 106 | // Sleep should never be used for wait for anything to load from the server |
| 107 | // Justification for this instance: FIXME |
| 108 | $this->waitForAjaxContent(); |
| 109 | $this->click('toggleSelect'); |
| 110 | $this->select('trans_assign', 'value=Assign'); |
| 111 | $this->click('Go'); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * @param $setTitle |
| 116 | * @param int $batchId |
| 117 | * @param $exportFormat |
| 118 | */ |
| 119 | public function _testExportBatch($setTitle, $batchId, $exportFormat) { |
| 120 | $this->openCiviPage("financial/batch", "reset=1&action=export&id=$batchId"); |
| 121 | if ($exportFormat == 'CSV') { |
| 122 | $this->click("xpath=//form[@id='FinancialBatch']/div[2]/table[@class='form-layout']/tbody/tr/td/input[1]"); |
| 123 | $this->click('_qf_FinancialBatch_next-botttom'); |
| 124 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 125 | } |
| 126 | else { |
| 127 | $this->click("xpath=//form[@id='FinancialBatch']/div[2]/table[@class='form-layout']/tbody/tr/td/input[1]"); |
| 128 | $this->click('_qf_FinancialBatch_next-botttom'); |
| 129 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 130 | } |
| 131 | $this->openCiviPage("dashboard", "reset=1"); |
| 132 | $this->clickLink("xpath=//div[@id='crm-recently-viewed']/ul/li[1]/a", "_qf_Activity_cancel-bottom"); |
| 133 | $this->webtestVerifyTabularData( |
| 134 | array( |
| 135 | 'Current Attachment(s)' => 'Financial_Transactions_', |
| 136 | ) |
| 137 | ); |
| 138 | } |
| 139 | |
| 140 | } |