Merge pull request #261 from eileenmcnaughton/CRM-12209
[civicrm-core.git] / tests / phpunit / WebTest / Financial / FinancialBatchExport.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_Financial_FinancialBatchExport extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testAddFinancialBatch() {
36 // Log in using webtestLogin() method
37 $this->webtestLogin('admin');
38 $this->openCiviPage("financial/batch", "reset=1&action=add", '_qf_FinancialBatch_next-botttom');
39 $setTitle = 'Batch ' . substr(sha1(rand()), 0, 7) . date('Y-m-d');
40 $setDescription = 'Test Batch Creation';
41 $setPaymentInstrument = 'Credit Card';
42 $numberOfTrxn = '10'; // can be 10, 25, 50, 100
43 $totalAmt = '1000';
44 $exportFormat = 'CSV';
45 $batchId = $this->_testAddBatch(
46 $setTitle,
47 $setDescription,
48 $setPaymentInstrument,
49 $numberOfTrxn,
50 $totalAmt
51 );
52 $this->_testAssignBatch($numberOfTrxn);
53 $this->_testExportBatch($setTitle, $batchId, $exportFormat);
54 }
55
56 function _testAddBatch($setTitle, $setDescription, $setPaymentInstrument, $numberOfTrxn, $totalAmt) {
57 // Enter Optional Constraints
58 $this->type('title', $setTitle);
59 $this->type('description', $setDescription);
60 if ($setPaymentInstrument == 'Credit Card') {
61 $this->select("payment_instrument_id", "value=1");
62 }
63 elseif ($setPaymentInstrument == 'Debit Card') {
64 $this->select("payment_instrument_id", "value=2");
65 }
66 elseif ($setPaymentInstrument == 'Cash') {
67 $this->select("payment_instrument_id", "value=3");
68 }
69 elseif ($setPaymentInstrument == 'Check') {
70 $this->select("payment_instrument_id", "value=4");
71 }
72 elseif ($setPaymentInstrument == 'EFT') {
73 $this->select("payment_instrument_id", "value=5");
74 }
75 $this->type('item_count', $numberOfTrxn);
76 $this->type('total', $totalAmt);
77
78 $this->click('_qf_FinancialBatch_next-botttom');
79 $this->waitForPageToLoad($this->getTimeoutMsec());
80
81 // parse URL to grab the batch ID
82 $batchId = $this->urlArg('bid');
83 return $batchId;
84 }
85
86 function _testAssignBatch($numberOfTrxn) {
87 $this->select( "xpath=//div[@id='crm-transaction-selector-assign_length']/label/select[@name='crm-transaction-selector-assign_length']", "value=$numberOfTrxn" );
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(5);
92 $this->click('toggleSelect');
93 $this->select('trans_assign', 'value=Assign');
94 $this->click('Go');
95 $this->waitForPageToLoad($this->getTimeoutMsec());
96 }
97
98 function _testExportBatch($setTitle, $batchId, $exportFormat) {
99 $this->openCiviPage("financial/batch", "reset=1&action=export&id=$batchId");
100 if ($exportFormat == 'CSV') {
101 $this->click("xpath=//form[@id='FinancialBatch']/div[2]/table[@class='form-layout']/tbody/tr/td/input[2]");
102 $this->click('_qf_FinancialBatch_next-botttom');
103 $this->waitForPageToLoad($this->getTimeoutMsec());
104 }
105 else {
106 $this->click("xpath=//form[@id='FinancialBatch']/div[2]/table[@class='form-layout']/tbody/tr/td/input[1]");
107 $this->click('_qf_FinancialBatch_next-botttom');
108 $this->waitForPageToLoad($this->getTimeoutMsec());
109 }
110 $this->openCiviPage("dashboard", "reset=1");
111 $this->waitForPageToLoad($this->getTimeoutMsec());
112
113 $this->clickLink("xpath=//div[@id='recently-viewed']/ul/li[1]/a", "_qf_Activity_cancel-bottom");
114 $this->webtestVerifyTabularData(
115 array(
116 'Current Attachment(s)' => 'Financial_Transactions_'
117 )
118 );
119 }
120 }