Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test to not use brittle xml, remove redundant crud tests #26648

Merged
merged 1 commit into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 45 additions & 104 deletions tests/phpunit/api/v3/UFMatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -153,20 +92,22 @@ public function testUFNameMatchSync($version) {

/**
* @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);
}

}
23 changes: 0 additions & 23 deletions tests/phpunit/api/v3/dataset/uf_group_test.xml

This file was deleted.