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 use Civi\Test\Invasive
;
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',
34 * Financial data used in these tests is invalid - do not validate.
36 * Note ideally it would be fixed and we would always use valid data.
40 protected $isValidateFinancialsOnPostAssert = FALSE;
45 public function dataProvider(): array {
47 'CRM_Report_Form_Contribute_Detail',
56 'total_amount_op' => 'gte',
57 'total_amount_value' => 50,
61 'Contribute/fixtures/dataset-ascii.sql',
62 'Contribute/fixtures/report-ascii.csv',
69 // We repeat the test a second time to
70 // ensure that CiviReportTestCase can
71 // clean up sufficiently to run
79 public function badDataProvider(): array {
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',
93 'total_amount_op' => 'gte',
94 'total_amount_value' => 50,
98 'Contribute/fixtures/dataset-ascii.sql',
99 'Contribute/fixtures/report.csv',
101 // This test-case is bad because the filters check for
102 // an amount >= $100, but the test data includes records
105 'CRM_Report_Form_Contribute_Detail',
114 'total_amount_op' => 'gte',
115 'total_amount_value' => 100,
117 // FIXME: add filters
119 'Contribute/fixtures/dataset-ascii.sql',
120 'Contribute/fixtures/report.csv',
126 * @throws \CRM_Core_Exception
128 public function setUp(): void
{
130 $this->quickCleanup($this->_tablesToTruncate
);
134 * @dataProvider dataProvider
135 * @param $reportClass
136 * @param $inputParams
138 * @param $expectedOutputCsvFile
141 public function testReportOutput($reportClass, $inputParams, $dataSet, $expectedOutputCsvFile): void
{
142 $config = CRM_Core_Config
::singleton();
143 CRM_Utils_File
::sourceSQLFile($config->dsn
, __DIR__
. "/$dataSet");
145 $reportCsvFile = $this->getReportOutputAsCsv($reportClass, $inputParams);
146 $reportCsvArray = $this->getArrayFromCsv($reportCsvFile);
148 $expectedOutputCsvArray = $this->getArrayFromCsv(__DIR__
. "/$expectedOutputCsvFile");
149 $this->assertCsvArraysEqual($expectedOutputCsvArray, $reportCsvArray);
153 * @dataProvider badDataProvider
155 * @param $reportClass
156 * @param $inputParams
158 * @param $expectedOutputCsvFile
160 * @throws \CRM_Core_Exception
162 public function testBadReportOutput($reportClass, $inputParams, $dataSet, $expectedOutputCsvFile): void
{
163 CRM_Utils_File
::sourceSQLFile(CIVICRM_DSN
, __DIR__
. "/$dataSet");
165 $reportCsvFile = $this->getReportOutputAsCsv($reportClass, $inputParams);
166 $reportCsvArray = $this->getArrayFromCsv($reportCsvFile);
168 $expectedOutputCsvArray = $this->getArrayFromCsv(__DIR__
. "/$expectedOutputCsvFile");
169 $this->assertNotEquals($expectedOutputCsvArray[1], $reportCsvArray[1]);
173 * Test processReportMode() Function in Reports
175 public function testOutputMode(): void
{
176 $reportForm = new CRM_Report_Form();
178 Invasive
::set([$reportForm, '_params'], ['groups' => 4]);
179 $reportForm->processReportMode();
180 $this->assertEquals('group', Invasive
::get([$reportForm, '_outputMode']));
182 Invasive
::set([$reportForm, '_params'], ['task' => 'copy']);
183 $reportForm->processReportMode();
184 $this->assertEquals('copy', Invasive
::get([$reportForm, '_outputMode']));
186 Invasive
::set([$reportForm, '_params'], ['task' => 'print']);
187 $reportForm->processReportMode();
188 $this->assertEquals('print', Invasive
::get([$reportForm, '_outputMode']));