3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviReportTestCase.php';
31 * Verify that the CiviReportTestCase provides a working set of
32 * primitives for tests. Do this by running various scenarios
33 * that should yield positive and negative results.
35 * Note: We need some report class to use as an example.
36 * CRM_Report_Form_Contribute_DetailTest is chosen arbitrarily.
40 class CRM_Report_Form_TestCaseTest
extends CiviReportTestCase
{
41 protected $_tablesToTruncate = array(
46 'civicrm_contribution',
49 public function dataProvider() {
51 'CRM_Report_Form_Contribute_Detail',
60 'total_amount_op' => 'gte',
61 'total_amount_value' => 50,
65 'Contribute/fixtures/dataset-ascii.sql',
66 'Contribute/fixtures/report-ascii.csv',
73 // We repeat the test a second time to
74 // ensure that CiviReportTestCase can
75 // clean up sufficiently to run
80 public function badDataProvider() {
82 // This test-case is bad because the dataset-ascii.sql does not match the
83 // report.csv (due to differences in international chars)
85 'CRM_Report_Form_Contribute_Detail',
94 'total_amount_op' => 'gte',
95 'total_amount_value' => 50,
99 'Contribute/fixtures/dataset-ascii.sql',
100 'Contribute/fixtures/report.csv',
102 // This test-case is bad because the filters check for
103 // an amount >= $100, but the test data includes records
106 'CRM_Report_Form_Contribute_Detail',
115 'total_amount_op' => 'gte',
116 'total_amount_value' => 100,
118 // FIXME: add filters
120 'Contribute/fixtures/dataset-ascii.sql',
121 'Contribute/fixtures/report.csv',
128 $this->foreignKeyChecksOff();
129 $this->quickCleanup($this->_tablesToTruncate
);
132 function tearDown() {
134 CRM_Core_DAO
::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp1');
135 CRM_Core_DAO
::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp2');
136 CRM_Core_DAO
::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp3');
140 * @dataProvider dataProvider
142 public function testReportOutput($reportClass, $inputParams, $dataSet, $expectedOutputCsvFile) {
143 $config = CRM_Core_Config
::singleton();
144 CRM_Utils_File
::sourceSQLFile($config->dsn
, dirname(__FILE__
) . "/{$dataSet}");
146 $reportCsvFile = $this->getReportOutputAsCsv($reportClass, $inputParams);
147 $reportCsvArray = $this->getArrayFromCsv($reportCsvFile);
149 $expectedOutputCsvArray = $this->getArrayFromCsv(dirname(__FILE__
) . "/{$expectedOutputCsvFile}");
150 $this->assertCsvArraysEqual($expectedOutputCsvArray, $reportCsvArray);
154 * @expectedException PHPUnit_Framework_AssertionFailedError
155 * @dataProvider badDataProvider
157 public function testBadReportOutput($reportClass, $inputParams, $dataSet, $expectedOutputCsvFile) {
158 $config = CRM_Core_Config
::singleton();
159 CRM_Utils_File
::sourceSQLFile($config->dsn
, dirname(__FILE__
) . "/{$dataSet}");
161 $reportCsvFile = $this->getReportOutputAsCsv($reportClass, $inputParams);
162 $reportCsvArray = $this->getArrayFromCsv($reportCsvFile);
164 $expectedOutputCsvArray = $this->getArrayFromCsv(dirname(__FILE__
) . "/{$expectedOutputCsvFile}");
165 $this->assertCsvArraysEqual($expectedOutputCsvArray, $reportCsvArray);