From: Tim Otten Date: Tue, 30 Jul 2013 03:33:49 +0000 (-0700) Subject: CRM-12622 - Extract assertCsvArraysEqual X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3b608e05ae8f8822263e4ebb9bc4aff0617bd1a4;p=civicrm-core.git CRM-12622 - Extract assertCsvArraysEqual ---------------------------------------- * CRM-12622: Create framework for example report data files http://issues.civicrm.org/jira/browse/CRM-12622 --- diff --git a/tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php b/tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php index a941b9caf4..c3f587440f 100644 --- a/tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php +++ b/tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php @@ -84,11 +84,7 @@ class CRM_Report_Form_Contribute_DetailTest extends CiviReportTestCase { $reportCsvArray = $this->getArrayFromCsv($reportCsvFile); $expectedOutputCsvArray = $this->getArrayFromCsv(dirname(__FILE__) . "/{$expectedOutputCsvFile}"); - $this->assertEquals(count($reportCsvArray[0]), count($expectedOutputCsvArray[0]), 'In line ' . __LINE__); - - foreach($reportCsvArray as $intKey => $strVal) { - $this->assertNotNull($expectedOutputCsvArray[$intKey], 'In line ' . __LINE__); - $this->assertEquals($expectedOutputCsvArray[$intKey], $strVal); - } + $this->assertCsvArraysEqual($expectedOutputCsvArray, $reportCsvArray); } + } diff --git a/tests/phpunit/CiviTest/CiviReportTestCase.php b/tests/phpunit/CiviTest/CiviReportTestCase.php index 9a4c7b8530..297f91e66e 100644 --- a/tests/phpunit/CiviTest/CiviReportTestCase.php +++ b/tests/phpunit/CiviTest/CiviReportTestCase.php @@ -85,4 +85,28 @@ class CiviReportTestCase extends CiviUnitTestCase { } return $arrFile; } + + /** + * @param array $expectedCsvArray two-dimensional array representing a CSV table + * @param array $actualCsvArray two-dimensional array representing a CSV table + */ + public function assertCsvArraysEqual($expectedCsvArray, $actualCsvArray) { + // TODO provide better debug output + + $this->assertEquals( + count($actualCsvArray), + count($expectedCsvArray), + 'Arrays have different number of rows; in line ' . __LINE__ + ); + + foreach ($actualCsvArray as $intKey => $strVal) { + $this->assertNotNull($expectedCsvArray[$intKey], 'In line ' . __LINE__); + $this->assertEquals( + count($actualCsvArray[$intKey]), + count($expectedCsvArray[$intKey]), + 'Arrays have different number of columns at row ' . $intKey . '; in line ' . __LINE__ + ); + $this->assertEquals($expectedCsvArray[$intKey], $strVal); + } + } }