~xibo-maintainers/xibo/release22

« back to all changes in this revision

Viewing changes to tests/integration/Cache/LayoutProofOfPlayXMLWithoutMediaTest.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\Tests\Helper\DisplayHelperTrait;
 
36
use Xibo\Tests\Helper\LayoutHelperTrait;
 
37
use Xibo\Tests\LocalWebTestCase;
 
38
use Xibo\Helper\Random;
 
39
 
 
40
/**
 
41
 * Class LayoutProofOfPlayXMLWithoutMediaTest
 
42
 * @package Xibo\Tests\integration\Cache
 
43
 */
 
44
class LayoutProofOfPlayXMLWithoutMediaTest extends LocalWebTestCase
 
45
{
 
46
    use LayoutHelperTrait;
 
47
    use DisplayHelperTrait;
 
48
 
 
49
    /** @var XiboLayout */
 
50
    protected $layoutOff;
 
51
 
 
52
    /** @var XiboLayout */
 
53
    protected $layoutOn;
 
54
 
 
55
    /** @var XiboRegion */
 
56
    protected $region;
 
57
 
 
58
    /** @var XiboDisplay */
 
59
    protected $display;
 
60
 
 
61
    /** @var XiboDisplay */
 
62
    protected $display2;
 
63
 
 
64
    /** @var XiboTicker */
 
65
    protected $widget;
 
66
 
 
67
    protected $media;
 
68
 
 
69
    protected $widgetId2;
 
70
 
 
71
    // <editor-fold desc="Init">
 
72
    public function setup()
 
73
    {
 
74
        parent::setup();
 
75
 
 
76
        $this->getLogger()->debug('Setup test for ' . get_class() .' Test');
 
77
 
 
78
        // Create a Layout with enableStat Off (by default)
 
79
        $this->layoutOff = $this->createLayout();
 
80
 
 
81
        // Create a Display
 
82
        $this->display = $this->createDisplay();
 
83
 
 
84
        // Schedule the Layout "always" onto our display
 
85
        //  deleting the layoutOff will remove this at the end
 
86
        $event = (new XiboSchedule($this->getEntityProvider()))->createEventLayout(
 
87
            date('Y-m-d H:i:s', time()+3600),
 
88
            date('Y-m-d H:i:s', time()+7200),
 
89
            $this->layoutOff->campaignId,
 
90
            [$this->display->displayGroupId],
 
91
            0,
 
92
            NULL,
 
93
            NULL,
 
94
            NULL,
 
95
            0,
 
96
            0,
 
97
            0
 
98
        );
 
99
 
 
100
        $this->displaySetStatus($this->display, Display::$STATUS_DONE);
 
101
        $this->displaySetLicensed($this->display);
 
102
 
 
103
        // Create a layout with enableStat On
 
104
        $this->layoutOn = (new XiboLayout($this->getEntityProvider()))->create(
 
105
            Random::generateString(8, 'phpunit'),
 
106
            'phpunit description',
 
107
            '',
 
108
            $this->getResolutionId('landscape'),
 
109
            1
 
110
        );
 
111
 
 
112
        // Create a Display2
 
113
        $this->display2 = $this->createDisplay();
 
114
 
 
115
        // Schedule the LayoutOn "always" onto our display
 
116
        //  deleting the layoutOn will remove this at the end
 
117
        $event2 = (new XiboSchedule($this->getEntityProvider()))->createEventLayout(
 
118
            date('Y-m-d H:i:s', time()+3600),
 
119
            date('Y-m-d H:i:s', time()+7200),
 
120
            $this->layoutOn->campaignId,
 
121
            [$this->display2->displayGroupId],
 
122
            0,
 
123
            NULL,
 
124
            NULL,
 
125
            NULL,
 
126
            0,
 
127
            0,
 
128
            0
 
129
        );
 
130
 
 
131
        $this->displaySetStatus($this->display2, Display::$STATUS_DONE);
 
132
        $this->displaySetLicensed($this->display2);
 
133
 
 
134
        $this->getLogger()->debug('Finished Setup');
 
135
    }
 
136
 
 
137
    public function tearDown()
 
138
    {
 
139
        $this->getLogger()->debug('Tear Down');
 
140
 
 
141
        parent::tearDown();
 
142
 
 
143
        // Delete the LayoutOff
 
144
        $this->deleteLayout($this->layoutOff);
 
145
 
 
146
        // Delete the Display
 
147
        $this->deleteDisplay($this->display);
 
148
 
 
149
        // Delete the LayoutOn
 
150
        $this->deleteLayout($this->layoutOn);
 
151
 
 
152
        // Delete the Display2
 
153
        $this->deleteDisplay($this->display2);
 
154
    }
 
155
    // </editor-fold>
 
156
 
 
157
//                Logic Table
 
158
//
 
159
//                Widget Without Media
 
160
//                LAYOUT        WIDGET          Widget stats collected?
 
161
//                    ON        ON                  YES     Widget takes precedence     // Match - 1
 
162
//                    ON        OFF                 NO      Widget takes precedence     // Match - 2
 
163
//                    ON        INHERIT         YES         Inherited from Layout       // Match - 7
 
164
//                    OFF       ON                  YES     Widget takes precedence     // Match - 1
 
165
//                    OFF       OFF                 NO      Widget takes precedence     // Match - 2
 
166
//                    OFF       INHERIT         NO          Inherited from Layout       // Match - 8
 
167
 
 
168
 
 
169
    /**
 
170
     * Each array is a test run
 
171
     * Format (enableStat)
 
172
     * @return array
 
173
     */
 
174
    public function layoutEnableStatOffCases()
 
175
    {
 
176
        return [
 
177
            // Layout enableStat Off options - for layout and widget and their expected result (Widget stats collected?) in enableStat (media node attribute)
 
178
            'Layout Off Media On' => [0, 'On', 1],
 
179
            'Layout Off Media Off' => [0, 'Off', 0],
 
180
            'Layout Off Media Inherit' => [0, 'Inherit', 0]
 
181
        ];
 
182
    }
 
183
 
 
184
    /**
 
185
     * Each array is a test run
 
186
     * Format (enableStat)
 
187
     * @return array
 
188
     */
 
189
    public function layoutEnableStatOnCases()
 
190
    {
 
191
        return [
 
192
            // Layout enableStat On options - for layout and widget and their expected result (Widget stats collected?) in enableStat (media node attribute)
 
193
            'Layout On Media On' => [1, 'On', 1],
 
194
            'Layout On Media Off' => [1, 'Off', 0],
 
195
            'Layout On Media Inherit' => [1, 'Inherit', 1]
 
196
        ];
 
197
    }
 
198
 
 
199
    /**
 
200
     * Edit
 
201
     * @dataProvider layoutEnableStatOffCases
 
202
     */
 
203
    public function testLayoutOff($layoutEnableStat, $widgetEnableStat, $outputEnableStat)
 
204
    {
 
205
        // Checkout
 
206
        $layoutOff = $this->checkout($this->layoutOff);
 
207
 
 
208
        $response = $this->getEntityProvider()->post('/playlist/widget/text/' . $layoutOff->regions[0]->regionPlaylist->playlistId);
 
209
        $response = $this->getEntityProvider()->put('/playlist/widget/' . $response['widgetId'] , [
 
210
            'text' => 'Widget A',
 
211
            'duration' => 100,
 
212
            'useDuration' => 1,
 
213
            'enableStat' => $widgetEnableStat
 
214
        ]);
 
215
 
 
216
        $this->widget = (new XiboText($this->getEntityProvider()))->hydrate($response);
 
217
 
 
218
        // Publish layout
 
219
        $response = $this->client->put('/layout/publish/' . $this->layoutOff->layoutId, [
 
220
            'publishNow' => 1
 
221
        ], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
 
222
        $response = json_decode($response, true);
 
223
 
 
224
        $this->layoutOff = $this->constructLayoutFromResponse($response['data']);
 
225
        $this->getLogger()->debug($this->layoutOff->enableStat);
 
226
 
 
227
        // Confirm our Layout is in the Schedule
 
228
        $schedule = $this->getXmdsWrapper()->Schedule($this->display->license);
 
229
        $this->assertContains('file="' . $this->layoutOff->layoutId . '"', $schedule, 'Layout not scheduled');
 
230
 
 
231
        // Call Required Files
 
232
        $rf = $this->getXmdsWrapper()->RequiredFiles($this->display->license);
 
233
 
 
234
        // Get XML string for player
 
235
        $xmlString = $this->getXmdsWrapper()->GetFile($this->display->license, $this->layoutOff->layoutId, 'layout', 0, 0);
 
236
        $this->assertContains('<layout width="1920" height="1080" bgcolor="#000" schemaVersion="3" enableStat="'.$layoutEnableStat.'">', $xmlString );
 
237
        $this->assertContains('<media id="'.$this->widget->widgetId.'" type="text" render="native" duration="100" useDuration="1" fromDt="1970-01-01 01:00:00" toDt="2038-01-19 03:14:07" enableStat="'.$outputEnableStat.'">', $xmlString );
 
238
    }
 
239
 
 
240
    /**
 
241
     * Edit
 
242
     * @dataProvider layoutEnableStatOnCases
 
243
     */
 
244
    public function testLayoutOn($layoutEnableStat, $widgetEnableStat, $outputEnableStat)
 
245
    {
 
246
        // Checkout
 
247
        $layoutOn = $this->checkout($this->layoutOn);
 
248
 
 
249
        $response = $this->getEntityProvider()->post('/playlist/widget/text/' . $layoutOn->regions[0]->regionPlaylist->playlistId);
 
250
        $response = $this->getEntityProvider()->put('/playlist/widget/' . $response['widgetId'] , [
 
251
            'text' => 'Widget A',
 
252
            'duration' => 100,
 
253
            'useDuration' => 1,
 
254
            'enableStat' => $widgetEnableStat
 
255
        ]);
 
256
 
 
257
        $this->widget = (new XiboText($this->getEntityProvider()))->hydrate($response);
 
258
 
 
259
        // Publish layout
 
260
        $response = $this->client->put('/layout/publish/' . $this->layoutOn->layoutId, [
 
261
            'publishNow' => 1
 
262
        ], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
 
263
        $response = json_decode($response, true);
 
264
 
 
265
        $this->layoutOn = $this->constructLayoutFromResponse($response['data']);
 
266
        $this->getLogger()->debug($this->layoutOn->enableStat);
 
267
 
 
268
        // Confirm our Layout is in the Schedule
 
269
        $schedule = $this->getXmdsWrapper()->Schedule($this->display2->license);
 
270
        $this->assertContains('file="' . $this->layoutOn->layoutId . '"', $schedule, 'Layout not scheduled');
 
271
 
 
272
        // Call Required Files
 
273
        $rf = $this->getXmdsWrapper()->RequiredFiles($this->display2->license);
 
274
 
 
275
        // Get XML string for player
 
276
        $xmlString = $this->getXmdsWrapper()->GetFile($this->display2->license, $this->layoutOn->layoutId, 'layout', 0, 0);
 
277
        $this->assertContains('<layout width="1920" height="1080" bgcolor="#000" schemaVersion="3" enableStat="'.$layoutEnableStat.'">', $xmlString );
 
278
        $this->assertContains('<media id="'.$this->widget->widgetId.'" type="text" render="native" duration="100" useDuration="1" fromDt="1970-01-01 01:00:00" toDt="2038-01-19 03:14:07" enableStat="'.$outputEnableStat.'">', $xmlString );
 
279
    }
 
280
 
 
281
}
 
 
b'\\ No newline at end of file'