3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 static $_tablesToTruncate = array(
46 'civicrm_contribution',
49 public function dataProvider() {
51 'CRM_Report_Form_Contribute_Detail',
59 'total_amount_op' => 'gte',
60 'total_amount_value' => 50,
64 'Contribute/fixtures/dataset-ascii.sql',
65 'Contribute/fixtures/report-ascii.csv',
72 // We repeat the test a second time to
73 // ensure that CiviReportTestCase can
74 // clean up sufficiently to run
79 public function badDataProvider() {
81 // This test-case is bad because the dataset-ascii.sql does not match the
82 // report.csv (due to differences in international chars)
84 'CRM_Report_Form_Contribute_Detail',
92 'total_amount_op' => 'gte',
93 'total_amount_value' => 50,
97 'Contribute/fixtures/dataset-ascii.sql',
98 'Contribute/fixtures/report.csv',
100 // This test-case is bad because the filters check for
101 // an amount >= $100, but the test data includes records
104 'CRM_Report_Form_Contribute_Detail',
112 'total_amount_op' => 'gte',
113 'total_amount_value' => 100,
115 // FIXME: add filters
117 'Contribute/fixtures/dataset-ascii.sql',
118 'Contribute/fixtures/report.csv',
125 $this->foreignKeyChecksOff();
126 $this->quickCleanup(self
::$_tablesToTruncate);
129 function tearDown() {
131 CRM_Core_DAO
::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp1');
132 CRM_Core_DAO
::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp2');
133 CRM_Core_DAO
::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp3');
137 * @dataProvider dataProvider
139 public function testReportOutput($reportClass, $inputParams, $dataSet, $expectedOutputCsvFile) {
140 $config = CRM_Core_Config
::singleton();
141 CRM_Utils_File
::sourceSQLFile($config->dsn
, dirname(__FILE__
) . "/{$dataSet}");
143 $reportCsvFile = $this->getReportOutputAsCsv($reportClass, $inputParams);
144 $reportCsvArray = $this->getArrayFromCsv($reportCsvFile);
146 $expectedOutputCsvArray = $this->getArrayFromCsv(dirname(__FILE__
) . "/{$expectedOutputCsvFile}");
147 $this->assertCsvArraysEqual($expectedOutputCsvArray, $reportCsvArray);
151 * @expectedException PHPUnit_Framework_AssertionFailedError
152 * @dataProvider badDataProvider
154 public function testBadReportOutput($reportClass, $inputParams, $dataSet, $expectedOutputCsvFile) {
155 $config = CRM_Core_Config
::singleton();
156 CRM_Utils_File
::sourceSQLFile($config->dsn
, dirname(__FILE__
) . "/{$dataSet}");
158 $reportCsvFile = $this->getReportOutputAsCsv($reportClass, $inputParams);
159 $reportCsvArray = $this->getArrayFromCsv($reportCsvFile);
161 $expectedOutputCsvArray = $this->getArrayFromCsv(dirname(__FILE__
) . "/{$expectedOutputCsvFile}");
162 $this->assertCsvArraysEqual($expectedOutputCsvArray, $reportCsvArray);