3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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',
52 public function dataProvider() {
54 'CRM_Report_Form_Contribute_Detail',
63 'total_amount_op' => 'gte',
64 'total_amount_value' => 50,
68 'Contribute/fixtures/dataset-ascii.sql',
69 'Contribute/fixtures/report-ascii.csv',
76 // We repeat the test a second time to
77 // ensure that CiviReportTestCase can
78 // clean up sufficiently to run
86 public function badDataProvider() {
88 // This test-case is bad because the dataset-ascii.sql does not match the
89 // report.csv (due to differences in international chars)
91 'CRM_Report_Form_Contribute_Detail',
100 'total_amount_op' => 'gte',
101 'total_amount_value' => 50,
103 // FIXME: add filters
105 'Contribute/fixtures/dataset-ascii.sql',
106 'Contribute/fixtures/report.csv',
108 // This test-case is bad because the filters check for
109 // an amount >= $100, but the test data includes records
112 'CRM_Report_Form_Contribute_Detail',
121 'total_amount_op' => 'gte',
122 'total_amount_value' => 100,
124 // FIXME: add filters
126 'Contribute/fixtures/dataset-ascii.sql',
127 'Contribute/fixtures/report.csv',
132 public function setUp() {
134 $this->foreignKeyChecksOff();
135 $this->quickCleanup($this->_tablesToTruncate
);
138 public function tearDown() {
140 CRM_Core_DAO
::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp1');
141 CRM_Core_DAO
::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp2');
142 CRM_Core_DAO
::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp3');
146 * @dataProvider dataProvider
147 * @param $reportClass
148 * @param $inputParams
150 * @param $expectedOutputCsvFile
153 public function testReportOutput($reportClass, $inputParams, $dataSet, $expectedOutputCsvFile) {
154 $config = CRM_Core_Config
::singleton();
155 CRM_Utils_File
::sourceSQLFile($config->dsn
, dirname(__FILE__
) . "/{$dataSet}");
157 $reportCsvFile = $this->getReportOutputAsCsv($reportClass, $inputParams);
158 $reportCsvArray = $this->getArrayFromCsv($reportCsvFile);
160 $expectedOutputCsvArray = $this->getArrayFromCsv(dirname(__FILE__
) . "/{$expectedOutputCsvFile}");
161 $this->assertCsvArraysEqual($expectedOutputCsvArray, $reportCsvArray);
165 * @expectedException PHPUnit_Framework_AssertionFailedError
166 * @dataProvider badDataProvider
167 * @param $reportClass
168 * @param $inputParams
170 * @param $expectedOutputCsvFile
173 public function testBadReportOutput($reportClass, $inputParams, $dataSet, $expectedOutputCsvFile) {
174 $config = CRM_Core_Config
::singleton();
175 CRM_Utils_File
::sourceSQLFile($config->dsn
, dirname(__FILE__
) . "/{$dataSet}");
177 $reportCsvFile = $this->getReportOutputAsCsv($reportClass, $inputParams);
178 $reportCsvArray = $this->getArrayFromCsv($reportCsvFile);
180 $expectedOutputCsvArray = $this->getArrayFromCsv(dirname(__FILE__
) . "/{$expectedOutputCsvFile}");
181 $this->assertCsvArraysEqual($expectedOutputCsvArray, $reportCsvArray);