~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to tests/integration/DisplayTest.php

  • Committer: Dan Garner
  • Date: 2016-02-18 16:07:16 UTC
  • mfrom: (454.4.137)
  • Revision ID: git-v1:8867f12675bc9e0e67e7e622c80da7471b9f294a
Merge pull request #139 from dasgarner/feature/nested-display-groups

Feature/nested display groups

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Spring Signage Ltd - http://www.springsignage.com
4
 
 * Copyright (C) 2015 Spring Signage Ltd
5
 
 * (DisplayTest.php)
6
 
 */
7
 
namespace Xibo\Tests\Integration;
8
 
use Xibo\Helper\Random;
9
 
use Xibo\OAuth2\Client\Entity\XiboDisplay;
10
 
 
11
 
class DisplayTest extends \Xibo\Tests\LocalWebTestCase
12
 
{
13
 
    protected $startDisplays;
14
 
    /**
15
 
     * setUp - called before every test automatically
16
 
     */
17
 
    public function setup()
18
 
    {
19
 
        parent::setup();
20
 
        $this->startDisplays = (new XiboDisplay($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
21
 
    }
22
 
    /**
23
 
     * tearDown - called after every test automatically
24
 
     */
25
 
    public function tearDown()
26
 
    {
27
 
        // Tear down any displays that weren't there before
28
 
        $finalDisplays = (new XiboDisplay($this->getEntityProvider()))->get(['start' => 0, 'length' => 10000]);
29
 
        
30
 
        # Loop over any remaining displays and nuke them
31
 
        foreach ($finalDisplays as $display) {
32
 
            /** @var XiboDisplay $display */
33
 
            $flag = true;
34
 
            foreach ($this->startDisplays as $startDisplay) {
35
 
               if ($startDisplay->displayId == $display->displayId) {
36
 
                   $flag = false;
37
 
               }
38
 
            }
39
 
            if ($flag) {
40
 
                try {
41
 
                    $display->delete();
42
 
                } catch (\Exception $e) {
43
 
                    fwrite(STDERR, 'Unable to delete ' . $display->displayId . '. E:' . $e->getMessage());
44
 
                }
45
 
            }
46
 
        }
47
 
        parent::tearDown();
48
 
    }
49
 
 
50
 
    /**
51
 
     * Shows list of all displays Test
52
 
     */
53
 
    public function testListAll()
54
 
    {
55
 
        # Get all displays
56
 
        $this->client->get('/display');
57
 
        # Check if successful
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());
62
 
    }
63
 
 
64
 
    /**
65
 
     * Delete Display Test
66
 
     */
67
 
    public function testDelete()
68
 
    {
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());
80
 
    }
81
 
 
82
 
    /**
83
 
     * Edit Display test, expecting success
84
 
     */
85
 
    public function testEditSuccess()
86
 
    {
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);
113
 
    }
114
 
 
115
 
    /**
116
 
     * Edit Display test, expecting failure
117
 
     */
118
 
    public function testEditFailure()
119
 
    {
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,
134
 
            'license' => null,
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());
141
 
    }
142
 
 
143
 
    /**
144
 
     * Request screenshot Test
145
 
     */
146
 
    public function testScreenshot()
147
 
    {
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',
161
 
            'windows',
162
 
            null,
163
 
            null,
164
 
            null,
165
 
            '00:16:D9:C9:AL:69',
166
 
            $xmrChannel,
167
 
            $xmrPubkey
168
 
        );
169
 
 
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());
184
 
    }
185
 
 
186
 
    /**
187
 
     * Wake On Lan Test
188
 
     */
189
 
    public function testWoL()
190
 
    {
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', 
197
 
            'windows', 
198
 
            null, 
199
 
            null, 
200
 
            null, 
201
 
            $macAddress,
202
 
            Random::generateString(50), 
203
 
            Random::generateString(50)
204
 
        );
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, 
219
 
        $display->licensed, 
220
 
        $display->license, 
221
 
        $display->incSchedule, 
222
 
        $display->emailAlert, 
223
 
        $display->wakeOnLanEnabled, 
224
 
        '127.0.0.1',
225
 
        0,
226
 
        0);
227
 
        # Call WOL
228
 
        $this->client->post('/display/wol/' . $display->displayId);
229
 
        $this->assertSame(200, $this->client->response->status(), 'Not successful: ' . $this->client->response->body());
230
 
    }
231
 
}