Commit | Line | Data |
---|---|---|
a219d9b1 TM |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
a219d9b1 | 5 | | | |
7d61e75f TO |
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 | | |
a219d9b1 TM |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
a219d9b1 TM |
12 | /** |
13 | * Test APIv3 civicrm_openid_* functions | |
14 | * | |
15 | * @package CiviCRM_APIv3 | |
16 | * @subpackage API_Contact | |
acb109b7 | 17 | * @group headless |
a219d9b1 TM |
18 | */ |
19 | class api_v3_OpenIDTest extends CiviUnitTestCase { | |
20 | ||
21 | protected $_apiversion = 3; | |
f19fee10 | 22 | protected $_params; |
a219d9b1 TM |
23 | protected $id; |
24 | protected $_entity; | |
25 | ||
26 | public $DBResetRequired = FALSE; | |
27 | ||
28 | public function setUp() { | |
29 | parent::setUp(); | |
30 | $this->useTransaction(TRUE); | |
31 | ||
f2aea45f | 32 | $this->_entity = 'OpenID'; |
a219d9b1 | 33 | $this->_contactID = $this->organizationCreate(); |
f19fee10 | 34 | $this->_params = [ |
a219d9b1 | 35 | 'contact_id' => $this->_contactID, |
f2aea45f | 36 | 'openid' => 'My OpenID handle', |
a219d9b1 | 37 | 'location_type_id' => 1, |
9099cab3 | 38 | ]; |
a219d9b1 TM |
39 | } |
40 | ||
2d932085 CW |
41 | /** |
42 | * @param int $version | |
43 | * @dataProvider versionThreeAndFour | |
44 | */ | |
45 | public function testCreateOpenID($version) { | |
46 | $this->_apiversion = $version; | |
f19fee10 | 47 | $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__); |
a219d9b1 | 48 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); |
f19fee10 | 49 | $this->getAndCheck($this->_params, $result['id'], $this->_entity); |
a219d9b1 TM |
50 | $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); |
51 | } | |
52 | ||
0e70279a AS |
53 | /** |
54 | * If no location is specified when creating a new openid, it should default to | |
55 | * the LocationType default | |
56 | * | |
57 | * @param int $version | |
58 | * @dataProvider versionThreeAndFour | |
59 | */ | |
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']]); | |
67 | } | |
68 | ||
2d932085 CW |
69 | /** |
70 | * @param int $version | |
71 | * @dataProvider versionThreeAndFour | |
72 | */ | |
73 | public function testGetOpenID($version) { | |
74 | $this->_apiversion = $version; | |
f19fee10 AS |
75 | $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); |
76 | $result = $this->callAPIAndDocument($this->_entity, 'get', $this->_params, __FUNCTION__, __FILE__); | |
a219d9b1 TM |
77 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); |
78 | $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); | |
9099cab3 | 79 | $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]); |
a219d9b1 TM |
80 | } |
81 | ||
2d932085 CW |
82 | /** |
83 | * @param int $version | |
84 | * @dataProvider versionThreeAndFour | |
85 | */ | |
86 | public function testDeleteOpenID($version) { | |
87 | $this->_apiversion = $version; | |
f19fee10 | 88 | $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); |
9099cab3 | 89 | $deleteParams = ['id' => $result['id']]; |
a219d9b1 | 90 | $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); |
9099cab3 | 91 | $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); |
a219d9b1 TM |
92 | $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__); |
93 | } | |
94 | ||
2d932085 CW |
95 | /** |
96 | * @param int $version | |
97 | * @dataProvider versionThreeAndFour | |
98 | */ | |
99 | public function testDeleteOpenIDInvalid($version) { | |
100 | $this->_apiversion = $version; | |
f19fee10 | 101 | $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); |
9099cab3 | 102 | $deleteParams = ['id' => 600]; |
a219d9b1 | 103 | $result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams); |
9099cab3 | 104 | $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); |
a219d9b1 TM |
105 | $this->assertEquals(1, $checkDeleted['count'], 'In line ' . __LINE__); |
106 | } | |
107 | ||
108 | } |