Add in Country and StateProvince APIv4 Entities
[civicrm-core.git] / tests / phpunit / api / v3 / WebsiteTest.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_website_* functions
14 *
15 * @package CiviCRM_APIv3
16 * @subpackage API_Contact
17 * @group headless
18 */
19 class api_v3_WebsiteTest extends CiviUnitTestCase {
20 protected $_apiversion = 3;
21 protected $params;
22 protected $id;
23 protected $_entity;
24
25 public $DBResetRequired = FALSE;
26
27 public function setUp() {
28 parent::setUp();
29 $this->useTransaction();
30
31 $this->_entity = 'website';
32 $this->_contactID = $this->organizationCreate();
33 $this->params = [
34 'contact_id' => $this->_contactID,
35 'url' => 'website.com',
36 'website_type_id' => 1,
37 ];
38 }
39
40 /**
41 * @param int $version
42 * @dataProvider versionThreeAndFour
43 */
44 public function testCreateWebsite($version) {
45 $this->_apiversion = $version;
46 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
47 $this->assertEquals(1, $result['count']);
48 $this->getAndCheck($this->params, $result['id'], $this->_entity);
49 $this->assertNotNull($result['values'][$result['id']]['id']);
50 }
51
52 /**
53 * @param int $version
54 * @dataProvider versionThreeAndFour
55 */
56 public function testGetWebsite($version) {
57 $this->_apiversion = $version;
58 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
59 $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__);
60 $this->assertEquals(1, $result['count']);
61 $this->assertNotNull($result['values'][$result['id']]['id']);
62 $this->callAPISuccess('website', 'delete', ['id' => $result['id']]);
63 }
64
65 /**
66 * @param int $version
67 * @dataProvider versionThreeAndFour
68 */
69 public function testDeleteWebsite($version) {
70 $this->_apiversion = $version;
71 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
72 $deleteParams = ['id' => $result['id']];
73 $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
74 $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
75 $this->assertEquals(0, $checkDeleted['count']);
76 }
77
78 /**
79 * @param int $version
80 * @dataProvider versionThreeAndFour
81 */
82 public function testDeleteWebsiteInvalid($version) {
83 $this->_apiversion = $version;
84 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
85 $deleteParams = ['id' => 600];
86 $result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams);
87 $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
88 $this->assertEquals(1, $checkDeleted['count']);
89 }
90
91 /**
92 * Test retrieval of metadata.
93 */
94 public function testGetMetadata() {
95 $result = $this->callAPIAndDocument($this->_entity, 'get', [
96 'options' => [
97 'metadata' => ['fields'],
98 ],
99 ], __FUNCTION__, __FILE__, 'Demonostrates returning field metadata', 'GetWithMetadata');
100 $this->assertEquals('Website', $result['metadata']['fields']['url']['title']);
101 }
102
103 /**
104 * @param int $version
105 * @dataProvider versionThreeAndFour
106 */
107 public function testGetFields($version) {
108 $this->_apiversion = $version;
109 $result = $this->callAPIAndDocument($this->_entity, 'getfields', ['action' => 'get'], __FUNCTION__, __FILE__);
110 $this->assertArrayKeyExists('url', $result['values']);
111 }
112
113 }