Merge pull request #14673 from eileenmcnaughton/payment_create
[civicrm-core.git] / tests / phpunit / api / v3 / OpenIDTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Test APIv3 civicrm_openid_* functions
30 *
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contact
33 * @group headless
34 */
35 class api_v3_OpenIDTest extends CiviUnitTestCase {
36
37 protected $_apiversion = 3;
38 protected $_params;
39 protected $id;
40 protected $_entity;
41
42 public $DBResetRequired = FALSE;
43
44 public function setUp() {
45 parent::setUp();
46 $this->useTransaction(TRUE);
47
48 $this->_entity = 'OpenID';
49 $this->_contactID = $this->organizationCreate();
50 $this->_params = [
51 'contact_id' => $this->_contactID,
52 'openid' => 'My OpenID handle',
53 'location_type_id' => 1,
54 ];
55 }
56
57 /**
58 * @param int $version
59 * @dataProvider versionThreeAndFour
60 */
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__);
67 }
68
69 /**
70 * If no location is specified when creating a new openid, it should default to
71 * the LocationType default
72 *
73 * @param int $version
74 * @dataProvider versionThreeAndFour
75 */
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']]);
83 }
84
85 /**
86 * @param int $version
87 * @dataProvider versionThreeAndFour
88 */
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']]);
96 }
97
98 /**
99 * @param int $version
100 * @dataProvider versionThreeAndFour
101 */
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__);
109 }
110
111 /**
112 * @param int $version
113 * @dataProvider versionThreeAndFour
114 */
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__);
122 }
123
124 }