3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Test APIv3 civicrm_openid_* functions
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contact
35 class api_v3_OpenIDTest
extends CiviUnitTestCase
{
37 protected $_apiversion = 3;
42 public $DBResetRequired = FALSE;
44 public function setUp() {
46 $this->useTransaction(TRUE);
48 $this->_entity
= 'OpenID';
49 $this->_contactID
= $this->organizationCreate();
51 'contact_id' => $this->_contactID
,
52 'openid' => 'My OpenID handle',
53 'location_type_id' => 1,
59 * @dataProvider versionThreeAndFour
61 public function testCreateOpenID($version) {
62 $this->_apiversion
= $version;
63 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
64 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
65 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
66 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
70 * If no location is specified when creating a new openid, it should default to
71 * the LocationType default
74 * @dataProvider versionThreeAndFour
76 public function testCreateOpenIDDefaultLocation($version) {
77 $this->_apiversion
= $version;
78 $params = $this->_params
;
79 unset($params['location_type_id']);
80 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
81 $this->assertEquals(CRM_Core_BAO_LocationType
::getDefault()->id
, $result['values'][$result['id']]['location_type_id']);
82 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $result['id']]);
87 * @dataProvider versionThreeAndFour
89 public function testGetOpenID($version) {
90 $this->_apiversion
= $version;
91 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
92 $result = $this->callAPIAndDocument($this->_entity
, 'get', $this->_params
, __FUNCTION__
, __FILE__
);
93 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
94 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
95 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $result['id']]);
100 * @dataProvider versionThreeAndFour
102 public function testDeleteOpenID($version) {
103 $this->_apiversion
= $version;
104 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
105 $deleteParams = ['id' => $result['id']];
106 $result = $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
107 $checkDeleted = $this->callAPISuccess($this->_entity
, 'get', []);
108 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__
);
112 * @param int $version
113 * @dataProvider versionThreeAndFour
115 public function testDeleteOpenIDInvalid($version) {
116 $this->_apiversion
= $version;
117 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
118 $deleteParams = ['id' => 600];
119 $result = $this->callAPIFailure($this->_entity
, 'delete', $deleteParams);
120 $checkDeleted = $this->callAPISuccess($this->_entity
, 'get', []);
121 $this->assertEquals(1, $checkDeleted['count'], 'In line ' . __LINE__
);