Skip to content
Snippets Groups Projects
Commit ea9d3b67 authored by eileen's avatar eileen
Browse files

[NFC] Code cleanup in test class

parent ffb8bad4
Branches
Tags
No related merge requests found
......@@ -18,7 +18,6 @@
*/
class api_v3_OpenIDTest extends CiviUnitTestCase {
protected $_apiversion = 3;
protected $_params;
protected $id;
protected $_entity;
......@@ -27,27 +26,29 @@ class api_v3_OpenIDTest extends CiviUnitTestCase {
public function setUp() {
parent::setUp();
$this->useTransaction(TRUE);
$this->useTransaction();
$this->_entity = 'OpenID';
$this->_contactID = $this->organizationCreate();
$this->_params = [
'contact_id' => $this->_contactID,
'contact_id' => $this->organizationCreate(),
'openid' => 'My OpenID handle',
'location_type_id' => 1,
'sequential' => 1,
];
}
/**
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testCreateOpenID($version) {
$this->_apiversion = $version;
$result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
$this->getAndCheck($this->_params, $result['id'], $this->_entity);
$this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
$result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__)['values'];
$this->assertCount(1, $result);
unset($this->_params['sequential']);
$this->getAndCheck($this->_params, $result[0]['id'], $this->_entity);
}
/**
......@@ -55,54 +56,62 @@ class api_v3_OpenIDTest extends CiviUnitTestCase {
* the LocationType default
*
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testCreateOpenIDDefaultLocation($version) {
$this->_apiversion = $version;
$params = $this->_params;
unset($params['location_type_id']);
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals(CRM_Core_BAO_LocationType::getDefault()->id, $result['values'][$result['id']]['location_type_id']);
$this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__)['values'];
$this->assertEquals(CRM_Core_BAO_LocationType::getDefault()->id, $result[0]['location_type_id']);
$this->callAPISuccess($this->_entity, 'delete', ['id' => $result[0]['id']]);
}
/**
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testGetOpenID($version) {
$this->_apiversion = $version;
$result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
$result = $this->callAPIAndDocument($this->_entity, 'get', $this->_params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
$this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
$this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
$this->callAPISuccess($this->_entity, 'create', $this->_params);
$result = $this->callAPIAndDocument($this->_entity, 'get', $this->_params, __FUNCTION__, __FILE__)['values'];
$this->assertCount(1, $result);
$this->assertNotNull($result[0]['id']);
$this->callAPISuccess($this->_entity, 'delete', ['id' => $result[0]['id']]);
}
/**
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testDeleteOpenID($version) {
$this->_apiversion = $version;
$result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
$deleteParams = ['id' => $result['id']];
$result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
$checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
$this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
$checkDeleted = $this->callAPISuccess($this->_entity, 'get');
$this->assertEquals(0, $checkDeleted['count']);
}
/**
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testDeleteOpenIDInvalid($version) {
$this->_apiversion = $version;
$result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
$this->callAPISuccess($this->_entity, 'create', $this->_params);
$deleteParams = ['id' => 600];
$result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams);
$checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(1, $checkDeleted['count'], 'In line ' . __LINE__);
$this->callAPIFailure($this->_entity, 'delete', $deleteParams);
$checkDeleted = $this->callAPISuccess($this->_entity, 'get');
$this->assertEquals(1, $checkDeleted['count']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment