From 0d6a1d4cb83ff2ac49e9c77f0cc3cfb72765ab28 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 24 Jun 2023 14:16:02 -0700 Subject: [PATCH] Fix test to not use brittle xml, remove redundant crud tests --- tests/phpunit/api/v3/UFMatchTest.php | 149 ++++++------------ .../phpunit/api/v3/dataset/uf_group_test.xml | 23 --- 2 files changed, 45 insertions(+), 127 deletions(-) delete mode 100644 tests/phpunit/api/v3/dataset/uf_group_test.xml diff --git a/tests/phpunit/api/v3/UFMatchTest.php b/tests/phpunit/api/v3/UFMatchTest.php index e0671893d0..ac0961cf1a 100644 --- a/tests/phpunit/api/v3/UFMatchTest.php +++ b/tests/phpunit/api/v3/UFMatchTest.php @@ -10,141 +10,80 @@ */ /** - * Test class for UFGroup API - civicrm_uf_* - * @todo Split UFGroup and UFJoin tests + * Test class for UFMatch api. * - * @package CiviCRM + * @package CiviCRM * @group headless */ class api_v3_UFMatchTest extends CiviUnitTestCase { - /** - * ids from the uf_group_test.xml fixture - * @var int - */ - protected $_ufGroupId = 11; - protected $_ufFieldId; - protected $_contactId; - protected $_params = []; - - protected function setUp(): void { - parent::setUp(); - $this->quickCleanup( - [ - 'civicrm_group', - 'civicrm_contact', - 'civicrm_uf_group', - 'civicrm_uf_join', - 'civicrm_uf_match', - ] - ); - $this->_contactId = $this->individualCreate(); - $this->loadXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml'); - - $this->_params = [ - 'contact_id' => $this->_contactId, - 'uf_id' => '2', - 'uf_name' => 'blahdyblah@gmail.com', - 'domain_id' => 1, - ]; - } public function tearDown(): void { - // Truncate the tables - $this->quickCleanup( - [ - 'civicrm_group', - 'civicrm_contact', - 'civicrm_uf_group', - 'civicrm_uf_join', - 'civicrm_uf_match', - ] - ); - } - - /** - * Fetch contact id by uf id. - * @param int $version - * @dataProvider versionThreeAndFour - */ - public function testGetUFMatchID($version) { - $this->_apiversion = $version; - $params = [ - 'uf_id' => 42, - ]; - $result = $this->callAPISuccess('uf_match', 'get', $params); - $this->assertEquals($result['values'][$result['id']]['contact_id'], 69); + $this->quickCleanup([ + 'civicrm_group', + 'civicrm_uf_group', + 'civicrm_uf_join', + 'civicrm_uf_match', + ]); + parent::tearDown(); } /** - * Fetch uf id by contact id. * @param int $version + * * @dataProvider versionThreeAndFour */ - public function testGetUFID($version) { + public function testCreate(int $version): void { $this->_apiversion = $version; $params = [ - 'contact_id' => 69, + 'contact_id' => $this->individualCreate(), + 'uf_id' => '2', + 'uf_name' => 'blahdyblah@gmail.com', + 'domain_id' => 1, ]; - $result = $this->callAPIAndDocument('uf_match', 'get', $params, __FUNCTION__, __FILE__); - $this->assertEquals($result['values'][$result['id']]['uf_id'], 42); - } - - /** - * Test civicrm_activity_create() using example code - * @param int $version - * @dataProvider versionThreeAndFour - */ - public function testUFMatchGetExample($version) { - $this->_apiversion = $version; - require_once 'api/v3/examples/UFMatch/Get.ex.php'; - $result = UF_match_get_example(); - $expectedResult = UF_match_get_expectedresult(); - $this->assertEquals($result, $expectedResult); - } - - /** - * @param int $version - * @dataProvider versionThreeAndFour - */ - public function testCreate($version) { - $this->_apiversion = $version; - $result = $this->callAPISuccess('uf_match', 'create', $this->_params); - $this->getAndCheck($this->_params, $result['id'], 'uf_match'); + $result = $this->callAPISuccess('UFMatch', 'create', $params); + $this->getAndCheck($params, $result['id'], 'uf_match'); } /** * Test Civi to CMS email sync optional + * * @param int $version + * * @dataProvider versionThreeAndFour */ - public function testUFNameMatchSync($version) { + public function testUFNameMatchSync(int $version): void { $this->_apiversion = $version; - $this->callAPISuccess('uf_match', 'create', $this->_params); - $email1 = substr(sha1(rand()), 0, 7) . '@test.com'; - $email2 = substr(sha1(rand()), 0, 7) . '@test.com'; + $this->createTestEntity('UFMatch', [ + 'contact_id' => $this->individualCreate(), + 'uf_id' => '2', + 'uf_name' => 'blahdyblah@gmail.com', + 'domain_id' => 1, + ]); + $email1 = 'a@test.com'; + $email2 = 'b@test.com'; // Case A: Enable CMS integration Civi::settings()->set('syncCMSEmail', TRUE); $this->callAPISuccess('email', 'create', [ - 'contact_id' => $this->_contactId, + 'contact_id' => $this->ids['Contact']['individual_0'], 'email' => $email1, 'is_primary' => 1, ]); - $ufName = $this->callAPISuccess('uf_match', 'getvalue', [ - 'contact_id' => $this->_contactId, + $ufName = $this->callAPISuccess('UFMatch', 'getvalue', [ + 'contact_id' => $this->ids['Contact']['individual_0'], 'return' => 'uf_name', ]); $this->assertEquals($email1, $ufName); // Case B: Disable CMS integration Civi::settings()->set('syncCMSEmail', FALSE); - $this->callAPISuccess('email', 'create', [ - 'contact_id' => $this->_contactId, + $this->callAPISuccess('Email', 'create', [ + 'contact_id' => $this->ids['Contact']['individual_0'], 'email' => $email2, 'is_primary' => 1, ]); - $ufName = $this->callAPISuccess('uf_match', 'getvalue', [ - 'contact_id' => $this->_contactId, + $ufName = $this->callAPISuccess('UFMatch', 'getvalue', [ + 'contact_id' => $this->ids['Contact']['individual_0'], 'return' => 'uf_name', ]); $this->assertNotEquals($email2, $ufName, 'primary email will not match if changed on disabled CMS integration setting'); @@ -153,20 +92,22 @@ class api_v3_UFMatchTest extends CiviUnitTestCase { /** * @param int $version + * * @dataProvider versionThreeAndFour */ - public function testDelete($version) { + public function testDelete(int $version): void { $this->_apiversion = $version; - $result = $this->callAPISuccess('uf_match', 'create', $this->_params); - $this->assertEquals(1, $this->callAPISuccess('uf_match', 'getcount', [ - 'id' => $result['id'], - ])); - $this->callAPISuccess('uf_match', 'delete', [ - 'id' => $result['id'], + $result = $this->callAPISuccess('UFMatch', 'create', [ + 'contact_id' => $this->individualCreate(), + 'uf_id' => '2', + 'uf_name' => 'blahdyblah@gmail.com', + 'domain_id' => 1, ]); - $this->assertEquals(0, $this->callAPISuccess('uf_match', 'getcount', [ + $this->assertEquals(1, $this->callAPISuccess('UFMatch', 'getcount', [ 'id' => $result['id'], ])); + $this->callAPISuccess('UFMatch', 'delete', ['id' => $result['id']]); + $this->callAPISuccessGetCount('UFMatch', ['id' => $result['id']], 0); } } diff --git a/tests/phpunit/api/v3/dataset/uf_group_test.xml b/tests/phpunit/api/v3/dataset/uf_group_test.xml deleted file mode 100644 index 8df3bc85f9..0000000000 --- a/tests/phpunit/api/v3/dataset/uf_group_test.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - -- 2.25.1