Merge pull request #16469 from civicrm/5.22
[civicrm-core.git] / tests / phpunit / api / v3 / WebsiteTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7d61e75f 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035 11
6a488035
TO
12/**
13 * Test APIv3 civicrm_website_* functions
14 *
6c6e6187
TO
15 * @package CiviCRM_APIv3
16 * @subpackage API_Contact
acb109b7 17 * @group headless
6a488035 18 */
6a488035 19class api_v3_WebsiteTest extends CiviUnitTestCase {
e6ff1593 20 protected $_apiversion = 3;
6a488035
TO
21 protected $params;
22 protected $id;
23 protected $_entity;
b7c9bc4c 24
430ae6dd
TO
25 public $DBResetRequired = FALSE;
26
00be9182 27 public function setUp() {
6a488035 28 parent::setUp();
cd5e1cac 29 $this->useTransaction();
6a488035 30
92915c55
TO
31 $this->_entity = 'website';
32 $this->_contactID = $this->organizationCreate();
9099cab3 33 $this->params = [
6a488035
TO
34 'contact_id' => $this->_contactID,
35 'url' => 'website.com',
36 'website_type_id' => 1,
9099cab3 37 ];
6a488035
TO
38 }
39
2d932085
CW
40 /**
41 * @param int $version
42 * @dataProvider versionThreeAndFour
43 */
44 public function testCreateWebsite($version) {
45 $this->_apiversion = $version;
e6ff1593 46 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
ba4a1892 47 $this->assertEquals(1, $result['count']);
6a488035 48 $this->getAndCheck($this->params, $result['id'], $this->_entity);
ba4a1892 49 $this->assertNotNull($result['values'][$result['id']]['id']);
6a488035
TO
50 }
51
2d932085
CW
52 /**
53 * @param int $version
54 * @dataProvider versionThreeAndFour
55 */
56 public function testGetWebsite($version) {
57 $this->_apiversion = $version;
e6ff1593 58 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
59 $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__);
ba4a1892
TM
60 $this->assertEquals(1, $result['count']);
61 $this->assertNotNull($result['values'][$result['id']]['id']);
9099cab3 62 $this->callAPISuccess('website', 'delete', ['id' => $result['id']]);
6a488035
TO
63 }
64
2d932085
CW
65 /**
66 * @param int $version
67 * @dataProvider versionThreeAndFour
68 */
69 public function testDeleteWebsite($version) {
70 $this->_apiversion = $version;
e6ff1593 71 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
9099cab3 72 $deleteParams = ['id' => $result['id']];
e6ff1593 73 $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
9099cab3 74 $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
ba4a1892 75 $this->assertEquals(0, $checkDeleted['count']);
6a488035 76 }
92915c55 77
2d932085
CW
78 /**
79 * @param int $version
80 * @dataProvider versionThreeAndFour
81 */
82 public function testDeleteWebsiteInvalid($version) {
83 $this->_apiversion = $version;
e6ff1593 84 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
9099cab3 85 $deleteParams = ['id' => 600];
e6ff1593 86 $result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams);
9099cab3 87 $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
ba4a1892 88 $this->assertEquals(1, $checkDeleted['count']);
dc5a7701 89 }
92915c55 90
dc5a7701 91 /**
eceb18cc 92 * Test retrieval of metadata.
dc5a7701
E
93 */
94 public function testGetMetadata() {
9099cab3
CW
95 $result = $this->callAPIAndDocument($this->_entity, 'get', [
96 'options' => [
97 'metadata' => ['fields'],
98 ],
99 ], __FUNCTION__, __FILE__, 'Demonostrates returning field metadata', 'GetWithMetadata');
dc5a7701
E
100 $this->assertEquals('Website', $result['metadata']['fields']['url']['title']);
101 }
92915c55 102
dc5a7701 103 /**
2d932085
CW
104 * @param int $version
105 * @dataProvider versionThreeAndFour
dc5a7701 106 */
2d932085
CW
107 public function testGetFields($version) {
108 $this->_apiversion = $version;
9099cab3 109 $result = $this->callAPIAndDocument($this->_entity, 'getfields', ['action' => 'get'], __FUNCTION__, __FILE__);
dc5a7701
E
110 $this->assertArrayKeyExists('url', $result['values']);
111 }
96025800 112
6a488035 113}