~xibo-maintainers/xibo/release22

« back to all changes in this revision

Viewing changes to tests/integration/Cache/LayoutProofOfPlayXMLMediaOffWidgetOffTest.php

  • Committer: GitHub
  • Author(s): Dan Garner
  • Date: 2019-08-22 11:52:43 UTC
  • mfrom: (698.1.72)
  • Revision ID: git-v1:b39d8fee23eb1dedc2a60d20c85a0d5d4f6e4bff
Tags: 2.1.0
Merge pull request #662 from xibosignage/release21

Release 2.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Copyright (C) 2019 Xibo Signage Ltd
 
4
 *
 
5
 * Xibo - Digital Signage - http://www.xibo.org.uk
 
6
 *
 
7
 * This file is part of Xibo.
 
8
 *
 
9
 * Xibo is free software: you can redistribute it and/or modify
 
10
 * it under the terms of the GNU Affero General Public License as published by
 
11
 * the Free Software Foundation, either version 3 of the License, or
 
12
 * any later version.
 
13
 *
 
14
 * Xibo is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU Affero General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU Affero General Public License
 
20
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
 
21
 */
 
22
 
 
23
namespace Xibo\Tests\integration\Cache;
 
24
 
 
25
use Xibo\Entity\Display;
 
26
use Xibo\OAuth2\Client\Entity\XiboDisplay;
 
27
use Xibo\OAuth2\Client\Entity\XiboImage;
 
28
use Xibo\OAuth2\Client\Entity\XiboLayout;
 
29
use Xibo\OAuth2\Client\Entity\XiboLibrary;
 
30
use Xibo\OAuth2\Client\Entity\XiboPlaylist;
 
31
use Xibo\OAuth2\Client\Entity\XiboRegion;
 
32
use Xibo\OAuth2\Client\Entity\XiboSchedule;
 
33
use Xibo\OAuth2\Client\Entity\XiboText;
 
34
use Xibo\OAuth2\Client\Entity\XiboTicker;
 
35
use Xibo\OAuth2\Client\Entity\XiboVideo;
 
36
use Xibo\Tests\Helper\DisplayHelperTrait;
 
37
use Xibo\Tests\Helper\LayoutHelperTrait;
 
38
use Xibo\Tests\LocalWebTestCase;
 
39
use Xibo\Helper\Random;
 
40
 
 
41
/**
 
42
 * Class LayoutProofOfPlayXMLMediaOffWidgetOffTest
 
43
 * @package Xibo\Tests\integration\Cache
 
44
 */
 
45
class LayoutProofOfPlayXMLMediaOffWidgetOffTest extends LocalWebTestCase
 
46
{
 
47
    use LayoutHelperTrait;
 
48
    use DisplayHelperTrait;
 
49
 
 
50
    /** @var XiboLayout */
 
51
    protected $layoutOff;
 
52
 
 
53
    /** @var XiboLayout */
 
54
    protected $layoutOn;
 
55
 
 
56
    /** @var XiboRegion */
 
57
    protected $region;
 
58
 
 
59
    /** @var XiboDisplay */
 
60
    protected $display;
 
61
 
 
62
    /** @var XiboDisplay */
 
63
    protected $display2;
 
64
 
 
65
    /** @var XiboTicker */
 
66
    protected $widget;
 
67
 
 
68
    /** @var XiboLibrary */
 
69
    protected $media;
 
70
 
 
71
    /** @var XiboLibrary */
 
72
    protected $mediaOn;
 
73
 
 
74
    protected $widgetId;
 
75
    protected $widgetId2;
 
76
 
 
77
    // <editor-fold desc="Init">
 
78
    public function setup()
 
79
    {
 
80
        parent::setup();
 
81
 
 
82
        $this->getLogger()->debug('Setup test for ' . get_class() .' Test');
 
83
 
 
84
        // Set global widget enable stat set to Off
 
85
        self::$container->configService->changeSetting('WIDGET_STATS_ENABLED_DEFAULT', 'Off');
 
86
        $this->getStore()->commitIfNecessary();
 
87
 
 
88
        // Create a Layout with enableStat Off (by default)
 
89
        $this->layoutOff = $this->createLayout();
 
90
        $layoutOff = $this->checkout($this->layoutOff);
 
91
 
 
92
        // Upload some media - enableStat is Inherit (from global media stat setting)
 
93
        $this->media = (new XiboLibrary($this->getEntityProvider()))->create(
 
94
            Random::generateString(8, 'API Video'),
 
95
            PROJECT_ROOT . '/tests/resources/HLH264.mp4'
 
96
        );
 
97
 
 
98
        // Edit the media to set enableStat On
 
99
        $this->media->edit(
 
100
            $this->media->name,
 
101
            $this->media->duration,
 
102
            $this->media->retired,
 
103
            $this->media->tags,
 
104
            $this->media->updateInLayouts,
 
105
            'Off'
 
106
        );
 
107
 
 
108
        // Assign the media we've edited to our regions playlist- widget with Inherit (from global widget stat setting)
 
109
        $playlist = (new XiboPlaylist($this->getEntityProvider()))
 
110
            ->assign([$this->media->mediaId], 10, $layoutOff->regions[0]->regionPlaylist->playlistId);
 
111
 
 
112
        // Store the widgetId
 
113
        $this->widgetId = $playlist->widgets[0]->widgetId;
 
114
 
 
115
        // Create a Display
 
116
        $this->display = $this->createDisplay();
 
117
 
 
118
        // Schedule the Layout "always" onto our display
 
119
        //  deleting the layout will remove this at the end
 
120
        $event = (new XiboSchedule($this->getEntityProvider()))->createEventLayout(
 
121
            date('Y-m-d H:i:s', time()+3600),
 
122
            date('Y-m-d H:i:s', time()+7200),
 
123
            $this->layoutOff->campaignId,
 
124
            [$this->display->displayGroupId],
 
125
            0,
 
126
            NULL,
 
127
            NULL,
 
128
            NULL,
 
129
            0,
 
130
            0,
 
131
            0
 
132
        );
 
133
 
 
134
        $this->displaySetStatus($this->display, Display::$STATUS_DONE);
 
135
        $this->displaySetLicensed($this->display);
 
136
 
 
137
        // Create a layout with enableStat On
 
138
        $this->layoutOn = (new XiboLayout($this->getEntityProvider()))->create(
 
139
            Random::generateString(8, 'phpunit'),
 
140
            'phpunit description',
 
141
            '',
 
142
            $this->getResolutionId('landscape'),
 
143
            1
 
144
        );
 
145
        $layoutOn = $this->checkout($this->layoutOn);
 
146
 
 
147
        // Assign the media we've created to our regions playlist- widget with Inherit (from global widget stat setting)
 
148
        $playlist2 = (new XiboPlaylist($this->getEntityProvider()))
 
149
            ->assign([$this->media->mediaId], 10, $layoutOn->regions[0]->regionPlaylist->playlistId);
 
150
 
 
151
        // Store the widgetId
 
152
        $this->widgetId2 = $playlist2->widgets[0]->widgetId;
 
153
 
 
154
        // Create a Display2
 
155
        $this->display2 = $this->createDisplay();
 
156
 
 
157
        // Schedule the LayoutOn "always" onto our display
 
158
        //  deleting the layoutOn will remove this at the end
 
159
        $event2 = (new XiboSchedule($this->getEntityProvider()))->createEventLayout(
 
160
            date('Y-m-d H:i:s', time()+3600),
 
161
            date('Y-m-d H:i:s', time()+7200),
 
162
            $this->layoutOn->campaignId,
 
163
            [$this->display2->displayGroupId],
 
164
            0,
 
165
            NULL,
 
166
            NULL,
 
167
            NULL,
 
168
            0,
 
169
            0,
 
170
            0
 
171
        );
 
172
 
 
173
        $this->displaySetStatus($this->display2, Display::$STATUS_DONE);
 
174
        $this->displaySetLicensed($this->display2);
 
175
 
 
176
        $this->getLogger()->debug('Finished Setup');
 
177
    }
 
178
 
 
179
    public function tearDown()
 
180
    {
 
181
        $this->getLogger()->debug('Tear Down');
 
182
 
 
183
        parent::tearDown();
 
184
 
 
185
        // Delete the LayoutOn
 
186
        $this->deleteLayout($this->layoutOff);
 
187
 
 
188
        // Delete the Display2
 
189
        $this->deleteDisplay($this->display);
 
190
 
 
191
        // Delete the LayoutOn
 
192
        $this->deleteLayout($this->layoutOn);
 
193
 
 
194
        // Delete the Display2
 
195
        $this->deleteDisplay($this->display2);
 
196
 
 
197
        // Delete the media record
 
198
        $this->media->deleteAssigned();
 
199
 
 
200
        // Set global widget enable stat set to Inherit
 
201
        self::$container->configService->changeSetting('WIDGET_STATS_ENABLED_DEFAULT', 'Inherit');
 
202
        $this->getStore()->commitIfNecessary();
 
203
 
 
204
    }
 
205
    // </editor-fold>
 
206
 
 
207
//                Logic Table
 
208
//
 
209
//                Widget With Media
 
210
//                LAYOUT        MEDIA   WIDGET  Media stats collected?
 
211
//                    ON        ON          ON      YES     Widget takes precedence     // Match - 1
 
212
//                    ON        OFF         ON      YES     Widget takes precedence     // Match - 1
 
213
//                    ON        INHERIT ON          YES     Widget takes precedence     // Match - 1
 
214
//
 
215
//                    OFF       ON          ON      YES     Widget takes precedence     // Match - 1
 
216
//                    OFF       OFF         ON      YES     Widget takes precedence     // Match - 1
 
217
//                    OFF       INHERIT ON          YES     Widget takes precedence     // Match - 1
 
218
//
 
219
//                    ON        ON          OFF     NO      Widget takes precedence     // Match - 2
 
220
//                    ON        OFF         OFF     NO      Widget takes precedence     // Match - 2
 
221
//                    ON        INHERIT OFF         NO      Widget takes precedence     // Match - 2
 
222
//
 
223
//                    OFF       ON          OFF     NO      Widget takes precedence     // Match - 2
 
224
//                    OFF       OFF         OFF     NO      Widget takes precedence     // Match - 2
 
225
//                    OFF       INHERIT OFF         NO      Widget takes precedence     // Match - 2
 
226
//
 
227
//                    ON        ON          INHERIT     YES     Media takes precedence      // Match - 3
 
228
//                    ON        OFF         INHERIT     NO      Media takes precedence      // Match - 4
 
229
//                    ON        INHERIT INHERIT YES     Media takes precedence and Inherited from Layout        // Match - 5
 
230
//
 
231
//                    OFF       ON          INHERIT     YES     Media takes precedence      // Match - 3
 
232
//                    OFF       OFF         INHERIT     NO      Media takes precedence      // Match - 4
 
233
//                    OFF       INHERIT INHERIT NO      Media takes precedence and Inherited from Layout        // Match - 6
 
234
////
 
235
 
 
236
    public function testLayoutOff()
 
237
    {
 
238
        // Publish layout
 
239
        $response = $this->client->put('/layout/publish/' . $this->layoutOff->layoutId, [
 
240
            'publishNow' => 1
 
241
        ], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
 
242
        $response = json_decode($response, true);
 
243
 
 
244
        $this->layoutOff = $this->constructLayoutFromResponse($response['data']);
 
245
 
 
246
        // Confirm our Layout is in the Schedule
 
247
        $schedule = $this->getXmdsWrapper()->Schedule($this->display->license);
 
248
        $this->assertContains('file="' . $this->layoutOff->layoutId . '"', $schedule, 'Layout not scheduled');
 
249
 
 
250
        // Call Required Files
 
251
        $rf = $this->getXmdsWrapper()->RequiredFiles($this->display->license);
 
252
 
 
253
        // Get XML string for player
 
254
        $xmlString = $this->getXmdsWrapper()->GetFile($this->display->license, $this->layoutOff->layoutId, 'layout', 0, 0);
 
255
 
 
256
        // Layout enable stat 0
 
257
        $this->assertContains('<layout width="1920" height="1080" bgcolor="#000" schemaVersion="3" enableStat="0">', $xmlString );
 
258
 
 
259
        // Layout Off, Media Off, Widget Off, Output => [0, 'Off', 'Off', 0],
 
260
        $this->assertContains('<media id="'.$this->widgetId.'" type="video" render="native" duration="0" useDuration="1" fromDt="1970-01-01 01:00:00" toDt="2038-01-19 03:14:07" enableStat="0" fileId="'.$this->media->mediaId.'">', $xmlString );
 
261
 
 
262
    }
 
263
 
 
264
    public function testLayoutOn()
 
265
    {
 
266
 
 
267
        // Publish layout
 
268
        $response = $this->client->put('/layout/publish/' . $this->layoutOn->layoutId, [
 
269
            'publishNow' => 1
 
270
        ], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
 
271
        $response = json_decode($response, true);
 
272
 
 
273
        $this->layoutOn = $this->constructLayoutFromResponse($response['data']);
 
274
 
 
275
        // Confirm our Layout is in the Schedule
 
276
        $schedule = $this->getXmdsWrapper()->Schedule($this->display2->license);
 
277
        $this->assertContains('file="' . $this->layoutOn->layoutId . '"', $schedule, 'Layout not scheduled');
 
278
 
 
279
        // Call Required Files
 
280
        $rf = $this->getXmdsWrapper()->RequiredFiles($this->display2->license);
 
281
 
 
282
        // Get XML string for player
 
283
        $xmlString = $this->getXmdsWrapper()->GetFile($this->display2->license, $this->layoutOn->layoutId, 'layout', 0, 0);
 
284
 
 
285
        // Layout enable stat 1
 
286
        $this->assertContains('<layout width="1920" height="1080" bgcolor="#000" schemaVersion="3" enableStat="1">', $xmlString );
 
287
 
 
288
        // Layout On, Media Off, Widget Off, Output => [1, 'Off', 'Off', 0],
 
289
        $this->assertContains('<media id="'.$this->widgetId2.'" type="video" render="native" duration="0" useDuration="1" fromDt="1970-01-01 01:00:00" toDt="2038-01-19 03:14:07" enableStat="0" fileId="'.$this->media->mediaId.'">', $xmlString );
 
290
 
 
291
    }
 
292
 
 
293
}
 
 
b'\\ No newline at end of file'