3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
12 require_once 'CiviTest/CiviReportTestCase.php';
15 * Verify that the CiviReportTestCase provides a working set of
16 * primitives for tests. Do this by running various scenarios
17 * that should yield positive and negative results.
19 * Note: We need some report class to use as an example.
20 * CRM_Report_Form_Contribute_DetailTest is chosen arbitrarily.
24 class CRM_Report_Form_TestCaseTest
extends CiviReportTestCase
{
25 protected $_tablesToTruncate = [
30 'civicrm_contribution',
36 public function dataProvider() {
38 'CRM_Report_Form_Contribute_Detail',
47 'total_amount_op' => 'gte',
48 'total_amount_value' => 50,
52 'Contribute/fixtures/dataset-ascii.sql',
53 'Contribute/fixtures/report-ascii.csv',
60 // We repeat the test a second time to
61 // ensure that CiviReportTestCase can
62 // clean up sufficiently to run
70 public function badDataProvider() {
72 // This test-case is bad because the dataset-ascii.sql does not match the
73 // report.csv (due to differences in international chars)
75 'CRM_Report_Form_Contribute_Detail',
84 'total_amount_op' => 'gte',
85 'total_amount_value' => 50,
89 'Contribute/fixtures/dataset-ascii.sql',
90 'Contribute/fixtures/report.csv',
92 // This test-case is bad because the filters check for
93 // an amount >= $100, but the test data includes records
96 'CRM_Report_Form_Contribute_Detail',
105 'total_amount_op' => 'gte',
106 'total_amount_value' => 100,
108 // FIXME: add filters
110 'Contribute/fixtures/dataset-ascii.sql',
111 'Contribute/fixtures/report.csv',
116 public function setUp() {
118 $this->quickCleanup($this->_tablesToTruncate
);
122 * @dataProvider dataProvider
123 * @param $reportClass
124 * @param $inputParams
126 * @param $expectedOutputCsvFile
129 public function testReportOutput($reportClass, $inputParams, $dataSet, $expectedOutputCsvFile) {
130 $config = CRM_Core_Config
::singleton();
131 CRM_Utils_File
::sourceSQLFile($config->dsn
, dirname(__FILE__
) . "/{$dataSet}");
133 $reportCsvFile = $this->getReportOutputAsCsv($reportClass, $inputParams);
134 $reportCsvArray = $this->getArrayFromCsv($reportCsvFile);
136 $expectedOutputCsvArray = $this->getArrayFromCsv(dirname(__FILE__
) . "/{$expectedOutputCsvFile}");
137 $this->assertCsvArraysEqual($expectedOutputCsvArray, $reportCsvArray);
141 * @dataProvider badDataProvider
142 * @param $reportClass
143 * @param $inputParams
145 * @param $expectedOutputCsvFile
148 public function testBadReportOutput($reportClass, $inputParams, $dataSet, $expectedOutputCsvFile) {
149 $config = CRM_Core_Config
::singleton();
150 CRM_Utils_File
::sourceSQLFile($config->dsn
, dirname(__FILE__
) . "/{$dataSet}");
152 $reportCsvFile = $this->getReportOutputAsCsv($reportClass, $inputParams);
153 $reportCsvArray = $this->getArrayFromCsv($reportCsvFile);
155 $expectedOutputCsvArray = $this->getArrayFromCsv(dirname(__FILE__
) . "/{$expectedOutputCsvFile}");
157 $this->assertCsvArraysEqual($expectedOutputCsvArray, $reportCsvArray);
159 catch (PHPUnit\Framework\AssertionFailedError
$e) {
162 catch (PHPUnit_Framework_AssertionFailedError
$e) {
168 * Test processReportMode() Function in Reports
170 public function testOutputMode() {
171 $clazz = new ReflectionClass('CRM_Report_Form');
172 $reportForm = new CRM_Report_Form();
174 $params = $clazz->getProperty('_params');
175 $params->setAccessible(TRUE);
176 $outputMode = $clazz->getProperty('_outputMode');
177 $outputMode->setAccessible(TRUE);
179 $params->setValue($reportForm, ['groups' => 4]);
180 $reportForm->processReportMode();
181 $this->assertEquals('group', $outputMode->getValue($reportForm));
183 $params->setValue($reportForm, ['task' => 'copy']);
184 $reportForm->processReportMode();
185 $this->assertEquals('copy', $outputMode->getValue($reportForm));
187 $params->setValue($reportForm, ['task' => 'print']);
188 $reportForm->processReportMode();
189 $this->assertEquals('print', $outputMode->getValue($reportForm));