Fix token subscriber to format the display of the custom tokens
[civicrm-core.git] / tests / phpunit / api / v3 / OpenIDTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Test APIv3 civicrm_openid_* functions
14 *
15 * @package CiviCRM_APIv3
16 * @subpackage API_Contact
17 * @group headless
18 */
19 class api_v3_OpenIDTest extends CiviUnitTestCase {
20
21 /**
22 * Should location types be checked to ensure primary addresses are correctly assigned after each test.
23 *
24 * @var bool
25 */
26 protected $isLocationTypesOnPostAssert = TRUE;
27
28 protected $_params;
29 protected $id;
30 protected $_entity;
31
32 public $DBResetRequired = FALSE;
33
34 public function setUp() {
35 parent::setUp();
36 $this->useTransaction();
37
38 $this->_entity = 'OpenID';
39 $this->_params = [
40 'contact_id' => $this->organizationCreate(),
41 'openid' => 'My OpenID handle',
42 'location_type_id' => 1,
43 'sequential' => 1,
44 ];
45 }
46
47 /**
48 * @param int $version
49 *
50 * @dataProvider versionThreeAndFour
51 * @throws \CRM_Core_Exception
52 */
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);
59 }
60
61 /**
62 * If no location is specified when creating a new openid, it should default to
63 * the LocationType default
64 *
65 * @param int $version
66 *
67 * @dataProvider versionThreeAndFour
68 * @throws \CRM_Core_Exception
69 */
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']]);
77 }
78
79 /**
80 * @param int $version
81 *
82 * @dataProvider versionThreeAndFour
83 * @throws \CRM_Core_Exception
84 */
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']]);
92 }
93
94 /**
95 * @param int $version
96 *
97 * @dataProvider versionThreeAndFour
98 * @throws \CRM_Core_Exception
99 */
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']);
107 }
108
109 /**
110 * @param int $version
111 *
112 * @dataProvider versionThreeAndFour
113 * @throws \CRM_Core_Exception
114 */
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']);
122 }
123
124 }