168 lines
5.5 KiB
PHP
168 lines
5.5 KiB
PHP
<?php
|
|
/*
|
|
* Copyright (C) 2025 Xibo Signage Ltd
|
|
*
|
|
* Xibo - Digital Signage - https://xibosignage.com
|
|
*
|
|
* This file is part of Xibo.
|
|
*
|
|
* Xibo is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* any later version.
|
|
*
|
|
* Xibo is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
|
|
namespace Xibo\Tests\integration\Cache;
|
|
|
|
use Carbon\Carbon;
|
|
use Xibo\Entity\Display;
|
|
use Xibo\Helper\DateFormatHelper;
|
|
use Xibo\Helper\Random;
|
|
use Xibo\OAuth2\Client\Entity\XiboCampaign;
|
|
use Xibo\OAuth2\Client\Entity\XiboDisplay;
|
|
use Xibo\OAuth2\Client\Entity\XiboLayout;
|
|
use Xibo\OAuth2\Client\Entity\XiboRegion;
|
|
use Xibo\OAuth2\Client\Entity\XiboSchedule;
|
|
use Xibo\OAuth2\Client\Entity\XiboText;
|
|
use Xibo\OAuth2\Client\Entity\XiboTicker;
|
|
use Xibo\Tests\Helper\DisplayHelperTrait;
|
|
use Xibo\Tests\Helper\LayoutHelperTrait;
|
|
use Xibo\Tests\LocalWebTestCase;
|
|
|
|
/**
|
|
* Class LayoutInCampaignStatusTest
|
|
* @package Xibo\Tests\integration\Cache
|
|
*/
|
|
class LayoutInCampaignStatusTest extends LocalWebTestCase
|
|
{
|
|
use LayoutHelperTrait;
|
|
use DisplayHelperTrait;
|
|
|
|
/** @var XiboCampaign */
|
|
protected $campaign;
|
|
|
|
/** @var XiboLayout */
|
|
protected $layout;
|
|
|
|
/** @var XiboRegion */
|
|
protected $region;
|
|
|
|
/** @var XiboDisplay */
|
|
protected $display;
|
|
|
|
/** @var XiboTicker */
|
|
protected $widget;
|
|
|
|
// <editor-fold desc="Init">
|
|
public function setup()
|
|
{
|
|
parent::setup();
|
|
|
|
$this->getLogger()->debug('Setup test for Cache ' . get_class($this) .' Test');
|
|
|
|
// Create a Campaign
|
|
$this->campaign = (new XiboCampaign($this->getEntityProvider()))->create(Random::generateString());
|
|
|
|
// Create a Layout
|
|
$this->layout = $this->createLayout();
|
|
|
|
// Checkout
|
|
$layout = $this->getDraft($this->layout);
|
|
|
|
$response = $this->getEntityProvider()->post('/playlist/widget/text/' . $layout->regions[0]->regionPlaylist->playlistId);
|
|
$response = $this->getEntityProvider()->put('/playlist/widget/' . $response['widgetId'], [
|
|
'text' => 'Widget A',
|
|
'duration' => 100,
|
|
'useDuration' => 1
|
|
]);
|
|
|
|
$this->widget = (new XiboText($this->getEntityProvider()))->hydrate($response);
|
|
|
|
// Assign the layout to our campaign
|
|
$this->getEntityProvider()->post('/campaign/layout/assign/' . $this->campaign->campaignId, [
|
|
'layoutId' => $this->layout->layoutId
|
|
]);
|
|
|
|
// Create a Display
|
|
$this->display = $this->createDisplay();
|
|
|
|
// Schedule the Campaign "always" onto our display
|
|
// deleting the layout will remove this at the end
|
|
$event = (new XiboSchedule($this->getEntityProvider()))->createEventLayout(
|
|
Carbon::now()->format(DateFormatHelper::getSystemFormat()),
|
|
Carbon::now()->addSeconds(7200)->format(DateFormatHelper::getSystemFormat()),
|
|
$this->campaign->campaignId,
|
|
[$this->display->displayGroupId],
|
|
0,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
0,
|
|
0,
|
|
0
|
|
);
|
|
|
|
$this->displaySetStatus($this->display, Display::$STATUS_DONE);
|
|
$this->displaySetLicensed($this->display);
|
|
|
|
$this->getLogger()->debug('Finished Setup');
|
|
}
|
|
|
|
public function tearDown()
|
|
{
|
|
$this->getLogger()->debug('Tear Down');
|
|
|
|
parent::tearDown();
|
|
|
|
// Delete the Layout we've been working with
|
|
$this->deleteLayout($this->layout);
|
|
|
|
// Delete the Display
|
|
$this->deleteDisplay($this->display);
|
|
|
|
// Delete the Campaign
|
|
$this->campaign->delete();
|
|
}
|
|
// </editor-fold>
|
|
|
|
/**
|
|
* @group cacheInvalidateTests
|
|
*/
|
|
public function testInvalidateCache()
|
|
{
|
|
// Make sure our Layout is already status 1
|
|
$this->assertTrue($this->layoutStatusEquals($this->layout, 3), 'Pre-Layout Status isnt as expected');
|
|
|
|
// Make sure our Display is already DONE
|
|
$this->assertTrue($this->displayStatusEquals($this->display, Display::$STATUS_DONE), 'Pre-Display Status isnt as expected');
|
|
|
|
// Publish (which builds)
|
|
$response = $this->sendRequest('PUT','/layout/publish/' . $this->layout->layoutId, [
|
|
'publishNow' => 1
|
|
], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
|
|
|
|
$this->assertSame(200, $response->getStatusCode(), "Not successful: " . $response->getStatusCode() . $response->getBody()->getContents());
|
|
|
|
$response = json_decode($response->getBody(), true);
|
|
$this->layout = $this->constructLayoutFromResponse($response['data']);
|
|
|
|
// Check the Layout Status
|
|
// Validate the layout status afterwards
|
|
$this->assertTrue($this->layoutStatusEquals($this->layout, 1), 'Layout Status isnt as expected');
|
|
|
|
// Validate the display status afterwards
|
|
$this->assertTrue($this->displayStatusEquals($this->display, Display::$STATUS_PENDING), 'Display Status isnt as expected');
|
|
|
|
// Validate that XMR has been called.
|
|
$this->assertTrue(in_array($this->display->displayId, $this->getPlayerActionQueue()), 'Player action not present');
|
|
}
|
|
} |