3
* Spring Signage Ltd - http://www.springsignage.com
4
* Copyright (C) 2015 Spring Signage Ltd
7
namespace Xibo\Tests\Integration;
8
use Xibo\Helper\Random;
9
use Xibo\OAuth2\Client\Entity\XiboDisplay;
11
class DisplayTest extends \Xibo\Tests\LocalWebTestCase
13
protected $startDisplays;
15
* setUp - called before every test automatically
17
public function setup()
20
$this->startDisplays = (new XiboDisplay($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
23
* tearDown - called after every test automatically
25
public function tearDown()
27
// Tear down any displays that weren't there before
28
$finalDisplays = (new XiboDisplay($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
30
# Loop over any remaining displays and nuke them
31
foreach ($finalDisplays as $display) {
32
/** @var XiboDisplay $display */
34
foreach ($this->startDisplays as $startDisplay) {
35
if ($startDisplay->displayId == $display->displayId) {
42
} catch (\Exception $e) {
43
fwrite(STDERR, 'Unable to delete ' . $display->displayId . '. E:' . $e->getMessage());
51
* Shows list of all displays Test
53
public function testListAll()
56
$this->client->get('/display');
58
$this->assertSame(200, $this->client->response->status());
59
$this->assertNotEmpty($this->client->response->body());
60
$object = json_decode($this->client->response->body());
61
$this->assertObjectHasAttribute('data', $object, $this->client->response->body());
67
public function testDelete()
69
# Create a Display in the system
70
$hardwareId = Random::generateString(12, 'phpunit');
71
$this->getXmdsWrapper()->RegisterDisplay($hardwareId, 'PHPUnit Test Display');
72
# Now find the Id of that Display
73
$displays = (new XiboDisplay($this->getEntityProvider()))->get(['hardwareKey' => $hardwareId]);
74
if (count($displays) != 1)
75
$this->fail('Display was not added correctly');
76
/** @var XiboDisplay $display */
77
$display = $displays[0];
78
$this->client->delete('/display/' . $display->displayId);
79
$this->assertSame(200, $this->client->response->status(), $this->client->response->body());
83
* Edit Display test, expecting success
85
public function testEditSuccess()
87
# Create a Display in the system
88
$hardwareId = Random::generateString(12, 'phpunit');
89
$this->getXmdsWrapper()->RegisterDisplay($hardwareId, 'PHPUnit Test Display');
90
# Now find the Id of that Display
91
$displays = (new XiboDisplay($this->getEntityProvider()))->get(['hardwareKey' => $hardwareId]);
92
if (count($displays) != 1)
93
$this->fail('Display was not added correctly');
94
/** @var XiboDisplay $display */
95
$display = $displays[0];
96
$auditingTime = time()+3600;
97
# Edit display and change its name
98
$this->client->put('/display/' . $display->displayId, [
99
'display' => 'API EDITED',
100
'defaultLayoutId' => $display->defaultLayoutId,
101
'auditingUntil' => date('Y-m-d H:i:s', $auditingTime),
102
'licensed' => $display->licensed,
103
'license' => $display->license,
104
'incSchedule' => $display->incSchedule,
105
'emailAlert' => $display->emailAlert,
106
'wakeOnLanEnabled' => $display->wakeOnLanEnabled,
107
], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
108
# Check if call was successful
109
$this->assertSame(200, $this->client->response->status(), 'Not successful: ' . $this->client->response->body());
110
$object = json_decode($this->client->response->body());
111
# Check if display has new edited name
112
$this->assertSame('API EDITED', $object->data->display);
116
* Edit Display test, expecting failure
118
public function testEditFailure()
120
# Create a Display in the system
121
$hardwareId = Random::generateString(12, 'phpunit');
122
$this->getXmdsWrapper()->RegisterDisplay($hardwareId, 'PHPUnit Test Display');
123
# Now find the Id of that Display
124
$displays = (new XiboDisplay($this->getEntityProvider()))->get(['hardwareKey' => $hardwareId]);
125
if (count($displays) != 1)
126
$this->fail('Display was not added correctly');
127
/** @var XiboDisplay $display */
128
$display = $displays[0];
129
# Edit display and change its hardwareKey
130
$this->client->put('/display/' . $display->displayId, [
131
'display' => 'API EDITED',
132
'defaultLayoutId' => $display->defaultLayoutId,
133
'licensed' => $display->licensed,
135
'incSchedule' => $display->incSchedule,
136
'emailAlert' => $display->emailAlert,
137
'wakeOnLanEnabled' => $display->wakeOnLanEnabled,
138
], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
139
# Check if call failed as expected (license cannot be null)
140
$this->assertSame(500, $this->client->response->status(), 'Expecting failure, received ' . $this->client->response->status());
144
* Request screenshot Test
146
public function testScreenshot()
148
# Generate names for display and xmr channel
149
$hardwareId = Random::generateString(12, 'phpunit');
150
$xmrChannel = Random::generateString(50);
151
# This is a dummy pubKey and isn't used by anything important
152
$xmrPubkey = '-----BEGIN PUBLIC KEY-----
153
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDmdnXL4gGg3yJfmqVkU1xsGSQI
154
3b6YaeAKtWuuknIF1XAHAHtl3vNhQN+SmqcNPOydhK38OOfrdb09gX7OxyDh4+JZ
155
inxW8YFkqU0zTqWaD+WcOM68wTQ9FCOEqIrbwWxLQzdjSS1euizKy+2GcFXRKoGM
156
pbBhRgkIdydXoZZdjQIDAQAB
157
-----END PUBLIC KEY-----';
158
# Register our display
159
$this->getXmdsWrapper()->RegisterDisplay($hardwareId,
160
'PHPUnit Test Display',
170
# Now find the Id of that Display
171
$displays = (new XiboDisplay($this->getEntityProvider()))->get(['hardwareKey' => $hardwareId]);
172
if (count($displays) != 1)
173
$this->fail('Display was not added correctly');
174
/** @var XiboDisplay $display */
175
$display = $displays[0];
176
# Check if xmr channel and pubkey were registered correctly
177
$this->assertSame($xmrChannel, $display->xmrChannel, 'XMR Channel not set correctly by XMDS Register Display');
178
$this->assertSame($xmrPubkey, $display->xmrPubKey, 'XMR PubKey not set correctly by XMDS Register Display');
179
# Call request screenshot
180
$this->client->put('/display/requestscreenshot/' . $display->displayId);
181
# Check if successful
182
$this->assertSame(200, $this->client->response->status(), 'Not successful: ' . $this->client->response->body());
183
$object = json_decode($this->client->response->body());
189
public function testWoL()
191
# Create dummy hardware key and mac address
192
$hardwareId = Random::generateString(12, 'phpunit');
193
$macAddress = '00-16-D9-C9-AE-69';
194
# Register our display
195
$this->getXmdsWrapper()->RegisterDisplay($hardwareId,
196
'PHPUnit Test Display',
202
Random::generateString(50),
203
Random::generateString(50)
205
# Now find the Id of that Display
206
$displays = (new XiboDisplay($this->getEntityProvider()))->get(['hardwareKey' => $hardwareId]);
207
if (count($displays) != 1)
208
$this->fail('Display was not added correctly');
209
/** @var XiboDisplay $display */
210
$display = $displays[0];
211
# Check if mac address was added correctly
212
$this->assertSame($macAddress, $display->macAddress, 'Mac Address not set correctly by XMDS Register Display');
213
$auditingTime = time()+3600;
214
# Edit display and add broadcast channel
215
$display->edit($display->display,
216
$display->description,
217
date('Y-m-d H:i:s', $auditingTime),
218
$display->defaultLayoutId,
221
$display->incSchedule,
222
$display->emailAlert,
223
$display->wakeOnLanEnabled,
228
$this->client->post('/display/wol/' . $display->displayId);
229
$this->assertSame(200, $this->client->response->status(), 'Not successful: ' . $this->client->response->body());