f4f695368c47864f2b77888b62d9c59770a4a91f
[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 // This is the path where our testing install resides.
37 // The rest of URL is defined in CiviSeleniumTestCase base class, in
38 // class attributes.
39 $this->open($this->sboxPath);
40
41 // Log in using webtestLogin() method
42 $this->webtestLogin(TRUE);
43 $this->open($this->sboxPath . 'civicrm/financial/batch?reset=1&action=add');
44 $this->waitForPageToLoad($this->getTimeoutMsec());
45 $this->waitForElementPresent('_qf_FinancialBatch_next-botttom');
46 $setTitle = 'Batch ' . substr(sha1(rand()), 0, 7) . date('Y-m-d');
47 $setDescription = 'Test Batch Creation';
48 $setPaymentInstrument = 'Credit Card';
49 $numberOfTrxn = '10'; // can be 10, 25, 50, 100
50 $totalAmt = '1000';
51 $exportFormat = 'CSV';
52 $batchId = $this->_testAddBatch(
53 $setTitle,
54 $setDescription,
55 $setPaymentInstrument,
56 $numberOfTrxn,
57 $totalAmt
58 );
59 $this->_testAssignBatch($numberOfTrxn);
60 $this->_testExportBatch($setTitle, $batchId, $exportFormat);
61 }
62
63 function _testAddBatch($setTitle, $setDescription, $setPaymentInstrument, $numberOfTrxn, $totalAmt) {
64 // Enter Optional Constraints
65 $this->type('title', $setTitle);
66 $this->type('description', $setDescription);
67 if ($setPaymentInstrument == 'Credit Card') {
68 $this->select("payment_instrument_id", "value=1");
69 }
70 elseif ($setPaymentInstrument == 'Debit Card') {
71 $this->select("payment_instrument_id", "value=2");
72 }
73 elseif ($setPaymentInstrument == 'Cash') {
74 $this->select("payment_instrument_id", "value=3");
75 }
76 elseif ($setPaymentInstrument == 'Check') {
77 $this->select("payment_instrument_id", "value=4");
78 }
79 elseif ($setPaymentInstrument == 'EFT') {
80 $this->select("payment_instrument_id", "value=5");
81 }
82 $this->type('item_count', $numberOfTrxn);
83 $this->type('total', $totalAmt);
84
85 $this->click('_qf_FinancialBatch_next-botttom');
86 $this->waitForPageToLoad($this->getTimeoutMsec());
87
88 // parse URL to grab the batch ID
89 $elements = $this->parseURL();
90 $batchId = $elements['queryString']['bid'];
91 return $batchId;
92 }
93
94 function _testAssignBatch($numberOfTrxn) {
95 $this->select( "xpath=//div[@id='crm-transaction-selector-assign_length']/label/select[@name='crm-transaction-selector-assign_length']", "value=$numberOfTrxn" );
96 sleep(5);
97 $this->click('toggleSelect');
98 $this->select('trans_assign', 'value=Assign');
99 $this->click('Go');
100 sleep(5);
101 }
102
103 function _testExportBatch($setTitle, $batchId, $exportFormat) {
104 $this->open($this->sboxPath . "civicrm/financial/batch?reset=1&action=export&id=$batchId");
105 $this->waitForPageToLoad($this->getTimeoutMsec());
106 if ($exportFormat == 'CSV') {
107 $this->click("xpath=//form[@id='FinancialBatch']/div[2]/table[@class='form-layout']/tbody/tr/td/input[2]");
108 $this->click('_qf_FinancialBatch_next-botttom');
109 sleep(5);
110 }
111 else {
112 $this->click("xpath=//form[@id='FinancialBatch']/div[2]/table[@class='form-layout']/tbody/tr/td/input[1]");
113 $this->click('_qf_FinancialBatch_next-botttom');
114 sleep(5);
115 }
116 $this->open($this->sboxPath . "civicrm?reset=1");
117 $this->waitForPageToLoad($this->getTimeoutMsec());
118
119 $this->click("xpath=//div[@id='recently-viewed']/ul/li[1]/a");
120 $this->waitForPageToLoad($this->getTimeoutMsec());
121 $this->waitForElementPresent("_qf_Activity_cancel-bottom");
122 $this->webtestVerifyTabularData(
123 array(
124 'Current Attachment(s)' => 'Financial_Transactions_'
125 )
126 );
127 }
128 }