Skip to content

Commit

Permalink
Clean up test class - remove ref to internal tplParams
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Oct 11, 2023
1 parent 9272ab1 commit b9a47d8
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public function setUp(): void {
* @param $expectedOutputCsvFile
* @throws \Exception
*/
public function testReportOutput($reportClass, $inputParams, $dataSet, $expectedOutputCsvFile) {
public function testReportOutput($reportClass, $inputParams, $dataSet, $expectedOutputCsvFile): void {
$config = CRM_Core_Config::singleton();
CRM_Utils_File::sourceSQLFile($config->dsn, dirname(__FILE__) . "/{$dataSet}");
CRM_Utils_File::sourceSQLFile($config->dsn, __DIR__ . "/{$dataSet}");

$reportCsvFile = $this->getReportOutputAsCsv($reportClass, $inputParams);
$reportCsvArray = $this->getArrayFromCsv($reportCsvFile);

$expectedOutputCsvArray = $this->getArrayFromCsv(dirname(__FILE__) . "/{$expectedOutputCsvFile}");
$expectedOutputCsvArray = $this->getArrayFromCsv(__DIR__ . "/{$expectedOutputCsvFile}");
$this->assertCsvArraysEqual($expectedOutputCsvArray, $reportCsvArray);
}

Expand All @@ -88,20 +88,20 @@ public function testReportOutput($reportClass, $inputParams, $dataSet, $expected
* @param $inputParams
* @throws \Exception
*/
public function testPager($reportClass, $inputParams) {
public function testPager($reportClass, $inputParams): void {
$contactID = $this->individualCreate();
for ($i = 1; $i <= 51; $i++) {
$this->contributionCreate(['contact_id' => $contactID, 'total_amount' => 50 + $i]);
}
$reportObj = $this->getReportObject($reportClass, $inputParams);
$pager = $reportObj->getTemplate()->_tpl_vars['pager'];
$this->assertEquals($pager->_response['numPages'], 2, "Pages in Pager");
$pager = $reportObj::getTemplate()->getTemplateVars('pager');
$this->assertEquals(2, $pager->_response['numPages'], 'Pages in Pager');
}

/**
* @return array
*/
public function postalCodeDataProvider() {
public function postalCodeDataProvider(): array {
return [
[
'CRM_Report_Form_Contribute_Detail',
Expand All @@ -126,20 +126,22 @@ public function postalCodeDataProvider() {

/**
* @dataProvider postalCodeDataProvider
* @param $reportClass
* @param $inputParams
* @param $dataSet
* @param $expectedOutputCsvFile
* @throws \Exception
*
* @param string $reportClass
* @param array $inputParams
* @param string $dataSet
* @param string $expectedOutputCsvFile
*
* @throws \CRM_Core_Exception
*/
public function testPostalCodeSearchReportOutput($reportClass, $inputParams, $dataSet, $expectedOutputCsvFile) {
public function testPostalCodeSearchReportOutput(string $reportClass, array $inputParams, string $dataSet, string $expectedOutputCsvFile): void {
$config = CRM_Core_Config::singleton();
CRM_Utils_File::sourceSQLFile($config->dsn, dirname(__FILE__) . "/{$dataSet}");
CRM_Utils_File::sourceSQLFile($config->dsn, __DIR__ . "/{$dataSet}");

$reportCsvFile = $this->getReportOutputAsCsv($reportClass, $inputParams);
$reportCsvArray = $this->getArrayFromCsv($reportCsvFile);

$expectedOutputCsvArray = $this->getArrayFromCsv(dirname(__FILE__) . "/{$expectedOutputCsvFile}");
$expectedOutputCsvArray = $this->getArrayFromCsv(__DIR__ . "/{$expectedOutputCsvFile}");
$this->assertCsvArraysEqual($expectedOutputCsvArray, $reportCsvArray);
}

Expand Down Expand Up @@ -262,7 +264,10 @@ public function testMultipleSoftCredits(): void {
}

/**
* Make sure the civicrm_alterReportVar hook for contribute detail report work well.
* Make sure the civicrm_alterReportVar hook for contribute detail report
* work well.
*
* @throws \Civi\Core\Exception\DBQueryException|\CRM_Core_Exception
*/
public function testContributeDetailReportWithNewColumnFromCustomTable(): void {
$this->quickCleanup($this->_tablesToTruncate);
Expand All @@ -272,9 +277,9 @@ public function testContributeDetailReportWithNewColumnFromCustomTable(): void {
'last_name' => 'User ' . rand(),
'contact_type' => 'Individual',
];
$solicitor1Id = $this->individualCreate($solParams);
$this->individualCreate($solParams);
$solParams['first_name'] = 'Solicitor 2';
$solicitor2Id = $this->individualCreate($solParams);
$this->individualCreate($solParams);
$solParams['first_name'] = 'Donor';
$donorId = $this->individualCreate($solParams);

Expand All @@ -288,22 +293,22 @@ public function testContributeDetailReportWithNewColumnFromCustomTable(): void {
$contribId = $this->contributionCreate($contribParams);

$config = CRM_Core_Config::singleton();
CRM_Utils_File::sourceSQLFile($config->dsn, dirname(__FILE__) . "/fixtures/value_extension_tng55_table.sql");
CRM_Utils_File::sourceSQLFile($config->dsn, __DIR__ . '/fixtures/value_extension_tng55_table.sql');
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_value_extension_tng55 (`entity_id`, `title`) VALUES (%1, 'some_title')", [1 => [$contribId, 'Positive']]);

CRM_Utils_Hook::singleton()->setHook('civicrm_alterReportVar', function ($varType, &$var, &$reportForm) {
CRM_Utils_Hook::singleton()->setHook('civicrm_alterReportVar', function ($varType, &$var) {
if ($varType === 'columns') {
$var['civicrm_value_extension_tng55'] = [
'fields' => [
'extension_tng55_title' => [
'title' => ts('Extension Title'),
'dbAlias' => "civicrm_value_extension_tng55.title",
'dbAlias' => 'civicrm_value_extension_tng55.title',
],
],
'filters' => [
'extension_tng55_title' => [
'title' => ts('Extension Title'),
'dbAlias' => "civicrm_value_extension_tng55.title",
'dbAlias' => 'civicrm_value_extension_tng55.title',
'type' => CRM_Utils_Type::T_INT,
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
'options' => [],
Expand All @@ -313,10 +318,10 @@ public function testContributeDetailReportWithNewColumnFromCustomTable(): void {
}
if ($varType === 'sql') {
$from = $var->getVar('_from');
$from .= "
$from .= '
LEFT JOIN civicrm_value_extension_tng55
ON (civicrm_value_extension_tng55.entity_id = contribution_civireport.id)
";
';
$var->setVar('_from', $from);
}
});
Expand Down

0 comments on commit b9a47d8

Please sign in to comment.