Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* The content of this file is subject to ("Vtiger Public License 1.2") refer to LIECENSE.md for more details.
* Copyright (c) Vtiger.
* All Rights Reserved.
*/
class RestApiTest extends \PHPUnit\Framework\TestCase {
private $restapi;
private $MOCK_TEST_ACCOUNTNAME = "RestApiTestAccount";
protected function setUp() {
$this->assertNotEmpty($_ENV['CRM_DOMAIN'], "CRM_DOMAIN not configured in phpunit.xml");
$this->assertNotEmpty($_ENV['CRM_USERNAME'], "CRM_USERNAME not configured in phpunit.xml");
$this->assertNotEmpty($_ENV['CRM_ACCESSKEY'], "CRM_ACCESSKEY not configured in phpunit.xml");
$this->restapi = new \Vtiger\Cloud\RestApi(
$_ENV['CRM_DOMAIN'],
$_ENV['CRM_USERNAME'],
$_ENV['CRM_ACCESSKEY']
);
}
protected function fetchMockAccountRecord() {
$records = $this->restapi->query("SELECT * FROM Accounts WHERE accountname='$this->MOCK_TEST_ACCOUNTNAME' LIMIT 1;");
$this->assertNotEmpty($records, "Failed to fetch mock test record.");
return array_shift($records);
}
public function testMe() {
$this->assertNotNull($this->restapi->me());
}
public function testListTypes() {
$this->assertNotNull($this->restapi->list_types());
}
public function testDescribe() {
$this->assertNotNull($this->restapi->describe("Accounts"));
}
public function testCreate() {
$this->assertNotNull($this->restapi->create("Accounts", array(
"accountname" => $this->MOCK_TEST_ACCOUNTNAME,
"assigned_user_id" => $this->restapi->myid()
)));
}
public function testUpdate() {
$record = $this->fetchMockAccountRecord();
$record["website"] = "www.404.com";
$this->assertNotNull($this->restapi->update($record));
}
public function testRevise() {
$record = $this->fetchMockAccountRecord();
$this->assertNotNull($this->restapi->revise(array(
"id" => $record["id"],
"website" => "www.404-rev.com"
)));
}
public function testQuery() {
$this->fetchMockAccountRecord();
}
public function testTagsAdd() {
$record = $this->fetchMockAccountRecord();
$this->assertNotNull(
$this->restapi->tags_add($record["id"], array("test-rest-tag1", "test-rest-tag2"))
);
}
public function testTagsDelete() {
$record = $this->fetchMockAccountRecord();
$this->assertNotEmpty(
$this->restapi->tags_delete($record["id"], array("test-rest-tag1"))
);
}
public function testTagsRetrieve() {
$record = $this->fetchMockAccountRecord();
$this->assertNotEmpty(
$this->restapi->tags_retrieve($record["id"])
);
}
public function testRelatedTypes() {
$this->assertNotNull(
$this->restapi->related_types("Accounts")
);
}
public function xtestDelete() {
$record = $this->fetchMockAccountRecord();
$this->assertNotNull($this->restapi->delete($record["id"]));
}
public function testConvertLead() {
$lead = $this->restapi->create("Leads", array(
"lastname" => "LEAD-".microtime(),
"firstname"=> "RestApiTest",
"company" => "RestApiTestCompany-". microtime(),
"email" => "lead-".microtime()."@404.com",
"assigned_user_id" => $this->restapi->myid()
));
$this->assertNotEmpty($lead["id"]);
$result = $this->restapi->convert_lead($lead["id"], array("closingdate" => date("YYYY-MM-dd")));
$this->assertNotEmpty($result["Potentials"]);
}
}