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
{
21 protected $_apiversion = 3;
26 public $DBResetRequired = FALSE;
28 public function setUp() {
30 $this->useTransaction(TRUE);
32 $this->_entity
= 'OpenID';
33 $this->_contactID
= $this->organizationCreate();
35 'contact_id' => $this->_contactID
,
36 'openid' => 'My OpenID handle',
37 'location_type_id' => 1,
43 * @dataProvider versionThreeAndFour
45 public function testCreateOpenID($version) {
46 $this->_apiversion
= $version;
47 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
48 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
49 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
50 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
54 * If no location is specified when creating a new openid, it should default to
55 * the LocationType default
58 * @dataProvider versionThreeAndFour
60 public function testCreateOpenIDDefaultLocation($version) {
61 $this->_apiversion
= $version;
62 $params = $this->_params
;
63 unset($params['location_type_id']);
64 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
65 $this->assertEquals(CRM_Core_BAO_LocationType
::getDefault()->id
, $result['values'][$result['id']]['location_type_id']);
66 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $result['id']]);
71 * @dataProvider versionThreeAndFour
73 public function testGetOpenID($version) {
74 $this->_apiversion
= $version;
75 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
76 $result = $this->callAPIAndDocument($this->_entity
, 'get', $this->_params
, __FUNCTION__
, __FILE__
);
77 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
78 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
79 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $result['id']]);
84 * @dataProvider versionThreeAndFour
86 public function testDeleteOpenID($version) {
87 $this->_apiversion
= $version;
88 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
89 $deleteParams = ['id' => $result['id']];
90 $result = $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
91 $checkDeleted = $this->callAPISuccess($this->_entity
, 'get', []);
92 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__
);
97 * @dataProvider versionThreeAndFour
99 public function testDeleteOpenIDInvalid($version) {
100 $this->_apiversion
= $version;
101 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
102 $deleteParams = ['id' => 600];
103 $result = $this->callAPIFailure($this->_entity
, 'delete', $deleteParams);
104 $checkDeleted = $this->callAPISuccess($this->_entity
, 'get', []);
105 $this->assertEquals(1, $checkDeleted['count'], 'In line ' . __LINE__
);