3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * Test APIv3 civicrm_website_* functions
15 * @package CiviCRM_APIv3
16 * @subpackage API_Contact
19 class api_v3_WebsiteTest
extends CiviUnitTestCase
{
20 protected $_apiversion = 3;
25 public $DBResetRequired = FALSE;
27 public function setUp() {
29 $this->useTransaction();
31 $this->_entity
= 'website';
32 $this->_contactID
= $this->organizationCreate();
34 'contact_id' => $this->_contactID
,
35 'url' => 'website.com',
36 'website_type_id' => 1,
42 * @dataProvider versionThreeAndFour
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']);
54 * @dataProvider versionThreeAndFour
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']]);
67 * @dataProvider versionThreeAndFour
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']);
80 * @dataProvider versionThreeAndFour
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']);
92 * Test retrieval of metadata.
94 public function testGetMetadata() {
95 $result = $this->callAPIAndDocument($this->_entity
, 'get', [
97 'metadata' => ['fields'],
99 ], __FUNCTION__
, __FILE__
, 'Demonostrates returning field metadata', 'GetWithMetadata');
100 $this->assertEquals('Website', $result['metadata']['fields']['url']['title']);
104 * @param int $version
105 * @dataProvider versionThreeAndFour
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']);