From 1d291c60a25985fae65435303ffcc917fd5021fc Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 24 May 2019 14:13:34 +1200 Subject: [PATCH] [dbunit] remove dependencies on discontinued dbunit test package --- .../phpunit/CRM/Activity/BAO/ActivityTest.php | 7 +--- .../Contact/Form/Search/Custom/GroupTest.php | 29 +++------------ .../Contact/Form/Search/Custom/SampleTest.php | 36 ++++--------------- tests/phpunit/CRM/Core/BAO/IMTest.php | 6 +--- tests/phpunit/CRM/Mailing/BAO/QueryTest.php | 21 ++--------- .../CRM/Member/Form/MembershipTest.php | 10 ++---- tests/phpunit/CiviTest/CiviUnitTestCase.php | 8 +++-- tests/phpunit/api/v3/ReportTemplateTest.php | 7 +--- tests/phpunit/api/v3/UFFieldTest.php | 8 +---- tests/phpunit/api/v3/UFJoinTest.php | 8 +---- tests/phpunit/api/v3/UFMatchTest.php | 8 +---- 11 files changed, 28 insertions(+), 120 deletions(-) diff --git a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php index bbf70d73f6..e540f1f760 100644 --- a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php @@ -1284,12 +1284,7 @@ $text } protected function createTestActivities() { - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - $this->createFlatXMLDataSet( - dirname(__FILE__) . '/activities_for_dashboard_count.xml' - ) - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/activities_for_dashboard_count.xml'); // Make changes to improve variation in php since the xml method is brittle & relies on option values being unchanged. $this->callAPISuccess('Activity', 'create', ['id' => 12, 'activity_type_id' => 'Bulk Email']); } diff --git a/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTest.php b/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTest.php index 943847df99..bd10b66d8a 100644 --- a/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTest.php +++ b/tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTest.php @@ -92,13 +92,7 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { public function testCount($fv, $count, $ids, $full) { $this->quickCleanup($this->_tablesToTruncate); - // echo "testCount\n"; - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - $this->createFlatXMLDataSet( - dirname(__FILE__) . '/datasets/group-dataset.xml' - ) - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/datasets/group-dataset.xml'); $obj = new CRM_Contact_Form_Search_Custom_Group($fv); @@ -111,9 +105,7 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { * echo "{$dao->contact_id}, {$dao->contact_type}, {$dao->sort_name}, {$dao->group_names}\n"; * } **/ - $this->assertEquals($count, $obj->count(), - 'In line ' . __LINE__ - ); + $this->assertEquals($count, $obj->count()); } /** @@ -128,14 +120,8 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { public function testAll($fv, $count, $ids, $full) { // Truncate affected tables $this->quickCleanup($this->_tablesToTruncate); + $this->loadXMLDataSet(dirname(__FILE__) . '/datasets/group-dataset.xml'); - // echo "testAll\n"; - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - $this->createFlatXMLDataSet( - dirname(__FILE__) . '/datasets/group-dataset.xml' - ) - ); $obj = new CRM_Contact_Form_Search_Custom_Group($fv); $sql = $obj->all(); $this->assertTrue(is_string($sql)); @@ -165,13 +151,8 @@ class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase { // Truncate affected tables $this->quickCleanup($this->_tablesToTruncate); - // echo "testContactIDs\n"; - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - $this->createFlatXMLDataSet( - dirname(__FILE__) . '/datasets/group-dataset.xml' - ) - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/datasets/group-dataset.xml'); + $obj = new CRM_Contact_Form_Search_Custom_Group($fv); $sql = $obj->contactIDs(); $this->assertTrue(is_string($sql)); diff --git a/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTest.php b/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTest.php index 8f49152e88..cedcff81e5 100644 --- a/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTest.php +++ b/tests/phpunit/CRM/Contact/Form/Search/Custom/SampleTest.php @@ -86,19 +86,11 @@ class CRM_Contact_Form_Search_Custom_SampleTest extends CiviUnitTestCase { public function testCount($fv, $count, $ids, $full) { $this->quickCleanup($this->_tablesToTruncate); - // echo "testCount\n"; - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - $this->createFlatXMLDataSet( - dirname(__FILE__) . '/datasets/sample-dataset.xml' - ) - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/datasets/sample-dataset.xml'); $obj = new CRM_Contact_Form_Search_Custom_Sample($fv); - $this->assertEquals($count, $obj->count(), - 'In line ' . __LINE__ - ); + $this->assertEquals($count, $obj->count()); } /** @@ -114,13 +106,8 @@ class CRM_Contact_Form_Search_Custom_SampleTest extends CiviUnitTestCase { // Truncate affected tables $this->quickCleanup($this->_tablesToTruncate); - // echo "testAll\n"; - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - $this->createFlatXMLDataSet( - dirname(__FILE__) . '/datasets/sample-dataset.xml' - ) - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/datasets/sample-dataset.xml'); + $obj = new CRM_Contact_Form_Search_Custom_Sample($fv); $sql = $obj->all(0, 0, 'contact_id'); $this->assertTrue(is_string($sql)); @@ -150,13 +137,7 @@ class CRM_Contact_Form_Search_Custom_SampleTest extends CiviUnitTestCase { // Truncate affected tables $this->quickCleanup($this->_tablesToTruncate); - // echo "testContactIDs\n"; - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - $this->createFlatXMLDataSet( - dirname(__FILE__) . '/datasets/sample-dataset.xml' - ) - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/datasets/sample-dataset.xml'); $obj = new CRM_Contact_Form_Search_Custom_Sample($fv); $sql = $obj->contactIDs(); $this->assertTrue(is_string($sql)); @@ -222,12 +203,7 @@ class CRM_Contact_Form_Search_Custom_SampleTest extends CiviUnitTestCase { public function testSavedSearch() { $this->quickCleanup($this->_tablesToTruncate); - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - $this->createFlatXMLDataSet( - dirname(__FILE__) . '/datasets/sample-dataset.xml' - ) - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/datasets/sample-dataset.xml'); $dataset[1] = array('id' => array(12)); $dataset[2] = array('id' => array(10, 11)); diff --git a/tests/phpunit/CRM/Core/BAO/IMTest.php b/tests/phpunit/CRM/Core/BAO/IMTest.php index c5700282ae..6c766ceeed 100644 --- a/tests/phpunit/CRM/Core/BAO/IMTest.php +++ b/tests/phpunit/CRM/Core/BAO/IMTest.php @@ -55,11 +55,7 @@ class CRM_Core_BAO_IMTest extends CiviUnitTestCase { * AllIMs() method - get all IMs for our contact, with primary IM first */ public function testAllIMs() { - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute( - $this->_dbconn, - $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/im_test.xml') - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/dataset/im_test.xml'); $contactId = 69; $IMs = CRM_Core_BAO_IM::allIMs($contactId); diff --git a/tests/phpunit/CRM/Mailing/BAO/QueryTest.php b/tests/phpunit/CRM/Mailing/BAO/QueryTest.php index 72d1edf654..9dc0ede1f2 100644 --- a/tests/phpunit/CRM/Mailing/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Mailing/BAO/QueryTest.php @@ -44,12 +44,7 @@ class CRM_Mailing_BAO_QueryTest extends CiviUnitTestCase { * @param $full */ public function testSearch($fv, $count, $ids, $full) { - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - $this->createFlatXMLDataSet( - dirname(__FILE__) . '/queryDataset.xml' - ) - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/queryDataset.xml'); $params = CRM_Contact_BAO_Query::convertFormValues($fv); $obj = new CRM_Contact_BAO_Query($params); @@ -73,13 +68,8 @@ class CRM_Mailing_BAO_QueryTest extends CiviUnitTestCase { * CRM-20412: Test accurate count for unique open details */ public function testOpenedMailingQuery() { - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - $this->createFlatXMLDataSet( - dirname(__FILE__) . '/queryDataset.xml' - ) - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/queryDataset.xml'); // ensure that total unique opened mail count is same while // fetching rows and row count for mailing_id = 14 $totalOpenedMailCount = CRM_Mailing_Event_BAO_Opened::getTotalCount(14, NULL, TRUE); @@ -93,12 +83,7 @@ class CRM_Mailing_BAO_QueryTest extends CiviUnitTestCase { * CRM-21194: Test accurate count for unique trackable URLs */ public function testTrackableUrlMailingQuery() { - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - $this->createFlatXMLDataSet( - dirname(__FILE__) . '/queryDataset.xml' - ) - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/queryDataset.xml'); // ensure that total unique clicked mail count is same while // fetching rows and row count for mailing_id = 14 and diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index 0ac9a2803e..d9db47e38c 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -95,13 +95,9 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $this->_individualId = $this->individualCreate(); $this->_paymentProcessorID = $this->processorCreate(); - // Insert test data. - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - $this->createFlatXMLDataSet( - dirname(__FILE__) . '/dataset/data.xml' - ) - ); + + $this->loadXMLDataSet(dirname(__FILE__) . '/dataset/data.xml'); + $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', array( 'domain_id' => 1, 'name' => "AnnualFixed", diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 257ce52f96..e973a1ba45 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -405,7 +405,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { $values[] = is_numeric($value) ? $value : "'{$value}'"; } } - else { + elseif (!empty($row)) { // cos we copied it & it is inconsistent.... foreach ($row as $key => $value) { $keys[] = $key; @@ -413,9 +413,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } } - CRM_Core_DAO::executeQuery(" + if (!empty($values)) { + CRM_Core_DAO::executeQuery(" INSERT INTO $tableName (" . implode(',', $keys) . ') VALUES(' . implode(',', $values) . ')' - ); + ); + } } } } diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index 912c566e32..d02d7d4b12 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -218,12 +218,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { */ public function testReportTemplateGetRowsMailingUniqueOpened() { $description = "Retrieve rows from a mailing opened report template."; - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - $this->createFlatXMLDataSet( - dirname(__FILE__) . '/../../CRM/Mailing/BAO/queryDataset.xml' - ) - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/../../CRM/Mailing/BAO/queryDataset.xml'); // Check total rows without distinct global $_REQUEST; diff --git a/tests/phpunit/api/v3/UFFieldTest.php b/tests/phpunit/api/v3/UFFieldTest.php index a422c8ebd8..68e5610824 100644 --- a/tests/phpunit/api/v3/UFFieldTest.php +++ b/tests/phpunit/api/v3/UFFieldTest.php @@ -46,8 +46,6 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { protected $_contactId = 69; - protected $_apiversion = 3; - protected $_params; protected $_entity = 'uf_field'; @@ -70,11 +68,7 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { ] ); - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute( - $this->_dbconn, - $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml') - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml'); $this->callAPISuccess('uf_field', 'getfields', ['cache_clear' => 1]); diff --git a/tests/phpunit/api/v3/UFJoinTest.php b/tests/phpunit/api/v3/UFJoinTest.php index 381c5e281e..d2e1e4adce 100644 --- a/tests/phpunit/api/v3/UFJoinTest.php +++ b/tests/phpunit/api/v3/UFJoinTest.php @@ -40,7 +40,6 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { protected $_ufGroupId = 11; protected $_ufFieldId; protected $_contactId = 69; - protected $_apiversion; protected function setUp() { parent::setUp(); @@ -54,12 +53,7 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { 'civicrm_uf_match', ) ); - $this->_apiversion = 3; - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute( - $this->_dbconn, - $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml') - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml'); } public function tearDown() { diff --git a/tests/phpunit/api/v3/UFMatchTest.php b/tests/phpunit/api/v3/UFMatchTest.php index b7c4ee776a..d5c8a4e305 100644 --- a/tests/phpunit/api/v3/UFMatchTest.php +++ b/tests/phpunit/api/v3/UFMatchTest.php @@ -40,12 +40,10 @@ class api_v3_UFMatchTest extends CiviUnitTestCase { protected $_ufGroupId = 11; protected $_ufFieldId; protected $_contactId; - protected $_apiversion; protected $_params = array(); protected function setUp() { parent::setUp(); - $this->_apiversion = 3; $this->quickCleanup( array( 'civicrm_group', @@ -56,11 +54,7 @@ class api_v3_UFMatchTest extends CiviUnitTestCase { ) ); $this->_contactId = $this->individualCreate(); - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute( - $this->_dbconn, - $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml') - ); + $this->loadXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml'); $this->_params = array( 'contact_id' => $this->_contactId, -- 2.25.1