3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Test APIv3 civicrm_openid_* functions
15 * @package CiviCRM_APIv3
16 * @subpackage API_Contact
19 class api_v3_OpenIDTest
extends CiviUnitTestCase
{
22 * Should location types be checked to ensure primary addresses are correctly assigned after each test.
26 protected $isLocationTypesOnPostAssert = TRUE;
32 public $DBResetRequired = FALSE;
34 public function setUp() {
36 $this->useTransaction();
38 $this->_entity
= 'OpenID';
40 'contact_id' => $this->organizationCreate(),
41 'openid' => 'My OpenID handle',
42 'location_type_id' => 1,
50 * @dataProvider versionThreeAndFour
51 * @throws \CRM_Core_Exception
53 public function testCreateOpenID($version) {
54 $this->_apiversion
= $version;
55 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
)['values'];
56 $this->assertCount(1, $result);
57 unset($this->_params
['sequential']);
58 $this->getAndCheck($this->_params
, $result[0]['id'], $this->_entity
);
62 * If no location is specified when creating a new openid, it should default to
63 * the LocationType default
67 * @dataProvider versionThreeAndFour
68 * @throws \CRM_Core_Exception
70 public function testCreateOpenIDDefaultLocation($version) {
71 $this->_apiversion
= $version;
72 $params = $this->_params
;
73 unset($params['location_type_id']);
74 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
)['values'];
75 $this->assertEquals(CRM_Core_BAO_LocationType
::getDefault()->id
, $result[0]['location_type_id']);
76 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $result[0]['id']]);
82 * @dataProvider versionThreeAndFour
83 * @throws \CRM_Core_Exception
85 public function testGetOpenID($version) {
86 $this->_apiversion
= $version;
87 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
88 $result = $this->callAPIAndDocument($this->_entity
, 'get', $this->_params
, __FUNCTION__
, __FILE__
)['values'];
89 $this->assertCount(1, $result);
90 $this->assertNotNull($result[0]['id']);
91 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $result[0]['id']]);
97 * @dataProvider versionThreeAndFour
98 * @throws \CRM_Core_Exception
100 public function testDeleteOpenID($version) {
101 $this->_apiversion
= $version;
102 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
103 $deleteParams = ['id' => $result['id']];
104 $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
105 $checkDeleted = $this->callAPISuccess($this->_entity
, 'get');
106 $this->assertEquals(0, $checkDeleted['count']);
110 * @param int $version
112 * @dataProvider versionThreeAndFour
113 * @throws \CRM_Core_Exception
115 public function testDeleteOpenIDInvalid($version) {
116 $this->_apiversion
= $version;
117 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
118 $deleteParams = ['id' => 600];
119 $this->callAPIFailure($this->_entity
, 'delete', $deleteParams);
120 $checkDeleted = $this->callAPISuccess($this->_entity
, 'get');
121 $this->assertEquals(1, $checkDeleted['count']);