-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForkCmsTest.php
188 lines (169 loc) · 6.46 KB
/
ForkCmsTest.php
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
namespace ForkCMS\Api\tests;
require_once '../vendor/autoload.php';
require_once __DIR__ . '/src/credentials.php';
use \ForkCms\Api\ForkCms;
/**
* Tests for the Wrapper class for any Fork CMS API.
*
* @author Tijs Verkoyen <[email protected]>
* @author Jeroen Desloovere <[email protected]>
*/
class ForkCmsTest extends PHPUnit_Framework_TestCase
{
/**
* @var Api
*/
private $api;
/**
* Prepares the environment before running a test.
*/
protected function setUp()
{
// call parent
parent::setUp();
// create instance
$this->api = new Api(URL, EMAIL, APIKEY);
}
/**
* Cleans up the environment after running a test.
*/
protected function tearDown()
{
// unset instance
$this->api = null;
// call parent
parent::tearDown();
}
/**
* Tests Api->getTimeOut()
*/
public function testGetTimeOut()
{
$this->api->setTimeOut(5);
$this->assertEquals(5, $this->api->getTimeOut());
}
/**
* Tests Api->getUserAgent()
*/
public function testGetUserAgent()
{
$this->api->setUserAgent('testing/1.0.0');
$this->assertEquals(
'PHP ForkAPI/' . Api::VERSION . ' testing/1.0.0',
$this->api->getUserAgent()
);
}
/**
* Tests Api->coreGetAPIKey()
*/
public function testCoreGetAPIKey()
{
$var = $this->api->coreGetAPIKey(EMAIL, PASSWORD);
$this->assertArrayHasKey('api_key', $var);
}
/**
* Tests Api->coreGetInfo()
*/
public function testCoreGetInfo()
{
$var = $this->api->coreGetInfo();
$this->assertArrayHasKey('languages', $var);
foreach ($var['languages'] as $row) {
$this->assertArrayHasKey('language', $row);
$this->assertArrayHasKey('title', $row['language']);
$this->assertArrayHasKey('url', $row['language']);
$this->assertArrayHasKey('@attributes', $row['language']);
$this->assertArrayHasKey('language', $row['language']['@attributes']);
}
}
/**
* Tests Api->coreAppleAddDevice()
*/
public function testCoreAppleAddDevice()
{
$var = $this->api->coreAppleAddDevice(APPLE_DEVICE_TOKEN);
$this->assertNull($var);
}
/**
* Tests Api->coreAppleRemoveDevice()
*/
public function testCoreAppleRemoveDevice()
{
$var = $this->api->coreAppleRemoveDevice(APPLE_DEVICE_TOKEN);
$this->assertNull($var);
}
/**
* tests Api->blogCommentsGet()
*/
public function testBlogCommentsGet()
{
$var = $this->api->blogCommentsGet();
$this->assertArrayHasKey('comments', $var);
foreach ($var['comments'] as $row) {
$this->assertArrayHasKey('comment', $row);
$this->assertArrayHasKey('article', $row['comment']);
$this->assertArrayHasKey('@attributes', $row['comment']['article']);
$this->assertArrayHasKey('id', $row['comment']['article']['@attributes']);
$this->assertArrayHasKey('lang', $row['comment']['article']['@attributes']);
$this->assertArrayHasKey('title', $row['comment']['article']);
$this->assertArrayHasKey('url', $row['comment']['article']);
$this->assertArrayHasKey('@attributes', $row['comment']);
$this->assertArrayHasKey('id', $row['comment']['@attributes']);
$this->assertArrayHasKey('created_on', $row['comment']['@attributes']);
$this->assertArrayHasKey('status', $row['comment']['@attributes']);
$this->assertArrayHasKey('text', $row['comment']);
$this->assertArrayHasKey('url', $row['comment']);
$this->assertArrayHasKey('author', $row['comment']);
$this->assertArrayHasKey('@attributes', $row['comment']['author']);
$this->assertArrayHasKey('email', $row['comment']['author']['@attributes']);
$this->assertArrayHasKey('name', $row['comment']['author']);
$this->assertArrayHasKey('website', $row['comment']['author']);
}
}
/**
* Tests Api->blogCommentsGetById()
*/
public function testBlogCommentsGetById()
{
$var = $this->api->blogCommentsGetById(40);
$this->assertArrayHasKey('comments', $var);
$this->assertArrayHasKey('comment', $var['comments'][0]);
$this->assertArrayHasKey('article', $var['comments'][0]['comment']);
$this->assertArrayHasKey('@attributes', $var['comments'][0]['comment']['article']);
$this->assertArrayHasKey('id', $var['comments'][0]['comment']['article']['@attributes']);
$this->assertArrayHasKey('lang', $var['comments'][0]['comment']['article']['@attributes']);
$this->assertArrayHasKey('title', $var['comments'][0]['comment']['article']);
$this->assertArrayHasKey('url', $var['comments'][0]['comment']['article']);
$this->assertArrayHasKey('@attributes', $var['comments'][0]['comment']);
$this->assertArrayHasKey('id', $var['comments'][0]['comment']['@attributes']);
$this->assertArrayHasKey('created_on', $var['comments'][0]['comment']['@attributes']);
$this->assertArrayHasKey('status', $var['comments'][0]['comment']['@attributes']);
$this->assertArrayHasKey('text', $var['comments'][0]['comment']);
$this->assertArrayHasKey('url', $var['comments'][0]['comment']);
$this->assertArrayHasKey('author', $var['comments'][0]['comment']);
$this->assertArrayHasKey('@attributes', $var['comments'][0]['comment']['author']);
$this->assertArrayHasKey('email', $var['comments'][0]['comment']['author']['@attributes']);
$this->assertArrayHasKey('name', $var['comments'][0]['comment']['author']);
$this->assertArrayHasKey('website', $var['comments'][0]['comment']['author']);
}
/**
* Tests Api->blogCommentsUpdate()
*/
public function testBlogCommentsUpdate()
{
$authorName = 'John Doe';
$var = $this->api->blogCommentsUpdate(40, null, null, $authorName);
$this->assertNull($var);
$var = $this->api->blogCommentsGetById(40);
$this->assertEquals($authorName, $var['comments'][0]['comment']['author']['name']);
}
/**
* Tests Api->blogCommentsUpdateStatus()
*/
public function testBlogCommentsUpdateStatus()
{
$var = $this->api->blogCommentsUpdateStatus(array(39, 40), 'published');
$this->assertNull($var);
}
}