Initial Upload
This commit is contained in:
148
tests/Helper/DisplayHelperTrait.php
Normal file
148
tests/Helper/DisplayHelperTrait.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/*
|
||||
* Spring Signage Ltd - http://www.springsignage.com
|
||||
* Copyright (C) 2017 Spring Signage Ltd
|
||||
* (DisplayHelperTrait.php)
|
||||
*/
|
||||
|
||||
|
||||
namespace Xibo\Tests\Helper;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Xibo\Helper\Random;
|
||||
use Xibo\OAuth2\Client\Entity\XiboDisplay;
|
||||
use Xibo\OAuth2\Client\Exception\XiboApiException;
|
||||
|
||||
/**
|
||||
* Trait DisplayHelperTrait
|
||||
* @package Helper
|
||||
*/
|
||||
trait DisplayHelperTrait
|
||||
{
|
||||
/**
|
||||
* @param int $status
|
||||
* @param string $type
|
||||
* @return XiboDisplay
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function createDisplay($status = null, $type = 'windows')
|
||||
{
|
||||
// Generate names for display and xmr channel
|
||||
$hardwareId = Random::generateString(12, 'phpunit');
|
||||
$xmrChannel = Random::generateString(50);
|
||||
|
||||
$this->getLogger()->debug('Creating Display called ' . $hardwareId);
|
||||
|
||||
// This is a dummy pubKey and isn't used by anything important
|
||||
$xmrPubkey = '-----BEGIN PUBLIC KEY-----
|
||||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDmdnXL4gGg3yJfmqVkU1xsGSQI
|
||||
3b6YaeAKtWuuknIF1XAHAHtl3vNhQN+SmqcNPOydhK38OOfrdb09gX7OxyDh4+JZ
|
||||
inxW8YFkqU0zTqWaD+WcOM68wTQ9FCOEqIrbwWxLQzdjSS1euizKy+2GcFXRKoGM
|
||||
pbBhRgkIdydXoZZdjQIDAQAB
|
||||
-----END PUBLIC KEY-----';
|
||||
|
||||
// Register our display
|
||||
$this->getXmdsWrapper()->RegisterDisplay($hardwareId,
|
||||
$hardwareId,
|
||||
$type,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
'00:16:D9:C9:AL:69',
|
||||
$xmrChannel,
|
||||
$xmrPubkey
|
||||
);
|
||||
|
||||
// Now find the Id of that Display
|
||||
$displays = (new XiboDisplay($this->getEntityProvider()))->get(['hardwareKey' => $hardwareId]);
|
||||
|
||||
if (count($displays) != 1)
|
||||
$this->fail('Display was not added correctly');
|
||||
|
||||
/** @var XiboDisplay $display */
|
||||
$display = $displays[0];
|
||||
|
||||
// Set the initial status
|
||||
if ($status !== null)
|
||||
$this->displaySetStatus($display, $status);
|
||||
|
||||
return $display;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param XiboDisplay $display
|
||||
* @param int $status
|
||||
*/
|
||||
protected function displaySetStatus($display, $status)
|
||||
{
|
||||
$display->mediaInventoryStatus = $status;
|
||||
|
||||
$this->getStore()->update('UPDATE `display` SET MediaInventoryStatus = :status, auditingUntil = :auditingUntil WHERE displayId = :displayId', [
|
||||
'displayId' => $display->displayId,
|
||||
'auditingUntil' => Carbon::now()->addSeconds(86400)->format('U'),
|
||||
'status' => $status
|
||||
]);
|
||||
$this->getStore()->commitIfNecessary();
|
||||
$this->getStore()->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param XiboDisplay $display
|
||||
*/
|
||||
protected function displaySetLicensed($display)
|
||||
{
|
||||
$display->licensed = 1;
|
||||
|
||||
$this->getStore()->update('UPDATE `display` SET licensed = 1, auditingUntil = :auditingUntil WHERE displayId = :displayId', [
|
||||
'displayId' => $display->displayId,
|
||||
'auditingUntil' => Carbon::now()->addSeconds(86400)->format('U')
|
||||
]);
|
||||
$this->getStore()->commitIfNecessary();
|
||||
$this->getStore()->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param XiboDisplay $display
|
||||
* @param string $timeZone
|
||||
*/
|
||||
protected function displaySetTimezone($display, $timeZone)
|
||||
{
|
||||
$this->getStore()->update('UPDATE `display` SET timeZone = :timeZone WHERE displayId = :displayId', [
|
||||
'displayId' => $display->displayId,
|
||||
'timeZone' => $timeZone
|
||||
]);
|
||||
$this->getStore()->commitIfNecessary();
|
||||
$this->getStore()->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param XiboDisplay $display
|
||||
*/
|
||||
protected function deleteDisplay($display)
|
||||
{
|
||||
$display->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param XiboDisplay $display
|
||||
* @param int $status
|
||||
* @return bool
|
||||
*/
|
||||
protected function displayStatusEquals($display, $status)
|
||||
{
|
||||
// Requery the Display
|
||||
try {
|
||||
$check = (new XiboDisplay($this->getEntityProvider()))->getById($display->displayId);
|
||||
|
||||
$this->getLogger()->debug('Tested Display ' . $display->display . '. Status returned is ' . $check->mediaInventoryStatus);
|
||||
|
||||
return $check->mediaInventoryStatus === $status;
|
||||
|
||||
} catch (XiboApiException $xiboApiException) {
|
||||
$this->getLogger()->error('API exception for ' . $display->displayId. ': ' . $xiboApiException->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
287
tests/Helper/LayoutHelperTrait.php
Normal file
287
tests/Helper/LayoutHelperTrait.php
Normal file
@@ -0,0 +1,287 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2022 Xibo Signage Ltd
|
||||
*
|
||||
* Xibo - Digital Signage - http://www.xibo.org.uk
|
||||
*
|
||||
* 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\Helper;
|
||||
|
||||
|
||||
use Xibo\Helper\Random;
|
||||
use Xibo\OAuth2\Client\Entity\XiboLayout;
|
||||
use Xibo\OAuth2\Client\Entity\XiboPlaylist;
|
||||
use Xibo\OAuth2\Client\Entity\XiboRegion;
|
||||
use Xibo\OAuth2\Client\Entity\XiboResolution;
|
||||
use Xibo\OAuth2\Client\Entity\XiboWidget;
|
||||
use Xibo\OAuth2\Client\Exception\XiboApiException;
|
||||
|
||||
/**
|
||||
* Trait LayoutHelperTrait
|
||||
* @package Helper
|
||||
*/
|
||||
trait LayoutHelperTrait
|
||||
{
|
||||
/**
|
||||
* @param int|null $status
|
||||
* @return XiboLayout
|
||||
*/
|
||||
protected function createLayout($status = null)
|
||||
{
|
||||
// Create a Layout for us to work with.
|
||||
$layout = (new XiboLayout($this->getEntityProvider()))
|
||||
->create(
|
||||
Random::generateString(),
|
||||
'PHPUnit Created Layout for Automated Integration Testing',
|
||||
'',
|
||||
$this->getResolutionId('landscape')
|
||||
);
|
||||
|
||||
$this->getLogger()->debug('Layout created with name ' . $layout->layout);
|
||||
|
||||
if ($status !== null) {
|
||||
// Set the initial status of this Layout to Built
|
||||
$this->setLayoutStatus($layout, $status);
|
||||
}
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param XiboLayout $layout
|
||||
* @param int $status
|
||||
* @return $this
|
||||
*/
|
||||
protected function setLayoutStatus($layout, $status)
|
||||
{
|
||||
$layout->status = $status;
|
||||
$this->getStore()->update('UPDATE `layout` SET `status` = :status WHERE layoutId = :layoutId', ['layoutId' => $layout->layoutId, 'status' => $status]);
|
||||
$this->getStore()->commitIfNecessary();
|
||||
$this->getStore()->close();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the Layout ready for XMDS
|
||||
* @param XiboLayout $layout
|
||||
* @return $this
|
||||
*/
|
||||
protected function buildLayout($layout)
|
||||
{
|
||||
// Call the status route
|
||||
$this->getEntityProvider()->get('/layout/status/' . $layout->layoutId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param XiboLayout $layout
|
||||
*/
|
||||
protected function deleteLayout($layout)
|
||||
{
|
||||
$layout->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param XiboLayout $layout
|
||||
* @param int $status
|
||||
* @return bool
|
||||
*/
|
||||
protected function layoutStatusEquals($layout, $status)
|
||||
{
|
||||
// Requery the Display
|
||||
try {
|
||||
$check = (new XiboLayout($this->getEntityProvider()))->getById($layout->layoutId);
|
||||
|
||||
$this->getLogger()->debug('Tested Layout ' . $layout->layout . '. Status returned is ' . $check->status);
|
||||
|
||||
return $check->status === $status;
|
||||
|
||||
} catch (XiboApiException $xiboApiException) {
|
||||
$this->getLogger()->error('API exception for ' . $layout->layoutId . ': ' . $xiboApiException->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
* @return int
|
||||
*/
|
||||
protected function getResolutionId($type)
|
||||
{
|
||||
if ($type === 'landscape') {
|
||||
$width = 1920;
|
||||
$height = 1080;
|
||||
} else if ($type === 'portrait') {
|
||||
$width = 1080;
|
||||
$height = 1920;
|
||||
} else {
|
||||
return -10;
|
||||
}
|
||||
|
||||
//$this->getLogger()->debug('Querying for ' . $width . ', ' . $height);
|
||||
|
||||
$resolutions = (new XiboResolution($this->getEntityProvider()))->get(['width' => $width, 'height' => $height]);
|
||||
|
||||
if (count($resolutions) <= 0)
|
||||
return -10;
|
||||
|
||||
return $resolutions[0]->resolutionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param XiboLayout $layout
|
||||
* @return XiboLayout
|
||||
*/
|
||||
protected function checkout($layout)
|
||||
{
|
||||
$this->getLogger()->debug('Checkout ' . $layout->layoutId);
|
||||
|
||||
$response = $this->getEntityProvider()->put('/layout/checkout/' . $layout->layoutId);
|
||||
|
||||
// Swap the Layout object to use the one returned.
|
||||
/** @var XiboLayout $layout */
|
||||
$layout = $this->constructLayoutFromResponse($response);
|
||||
|
||||
$this->getLogger()->debug('LayoutId is now: ' . $layout->layoutId);
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param XiboLayout $layout
|
||||
* @return XiboLayout
|
||||
*/
|
||||
protected function publish($layout)
|
||||
{
|
||||
$this->getLogger()->debug('Publish ' . $layout->layoutId);
|
||||
|
||||
$response = $this->getEntityProvider()->put('/layout/publish/' . $layout->layoutId , [
|
||||
'publishNow' => 1
|
||||
], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']);
|
||||
|
||||
// Swap the Layout object to use the one returned.
|
||||
/** @var XiboLayout $layout */
|
||||
$layout = $this->constructLayoutFromResponse($response);
|
||||
|
||||
$this->getLogger()->debug('LayoutId is now: ' . $layout->layoutId);
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param XiboLayout $layout
|
||||
* @return XiboLayout
|
||||
*/
|
||||
protected function discard($layout)
|
||||
{
|
||||
$this->getLogger()->debug('Discard ' . $layout->layoutId);
|
||||
|
||||
$response = $this->getEntityProvider()->put('/layout/discard/' . $layout->layoutId);
|
||||
|
||||
// Swap the Layout object to use the one returned.
|
||||
/** @var XiboLayout $layout */
|
||||
$layout = $this->constructLayoutFromResponse($response);
|
||||
|
||||
$this->getLogger()->debug('LayoutId is now: ' . $layout->layoutId);
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $layout
|
||||
* @return $this
|
||||
*/
|
||||
protected function addSimpleWidget($layout)
|
||||
{
|
||||
$this->getEntityProvider()->post('/playlist/widget/clock/' . $layout->regions[0]->regionPlaylist->playlistId, [
|
||||
'duration' => 100,
|
||||
'useDuration' => 1
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $layout
|
||||
* @return $this
|
||||
*/
|
||||
protected function addSimpleTextWidget($layout)
|
||||
{
|
||||
$this->getEntityProvider()->post('/playlist/widget/text/' . $layout->regions[0]->regionPlaylist->playlistId, [
|
||||
'text' => 'PHPUNIT TEST TEXT',
|
||||
'duration' => 100,
|
||||
'useDuration' => 1
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $response
|
||||
* @return \Xibo\OAuth2\Client\Entity\XiboEntity|XiboLayout
|
||||
*/
|
||||
private function constructLayoutFromResponse($response)
|
||||
{
|
||||
$hydratedRegions = [];
|
||||
$hydratedWidgets = [];
|
||||
/** @var XiboLayout $layout */
|
||||
$layout = new XiboLayout($this->getEntityProvider());
|
||||
$layout = $layout->hydrate($response);
|
||||
|
||||
$this->getLogger()->debug('Constructing Layout from Response: ' . $layout->layoutId);
|
||||
|
||||
if (isset($response['regions'])) {
|
||||
foreach ($response['regions'] as $item) {
|
||||
/** @var XiboRegion $region */
|
||||
$region = new XiboRegion($this->getEntityProvider());
|
||||
$region->hydrate($item);
|
||||
/** @var XiboPlaylist $playlist */
|
||||
$playlist = new XiboPlaylist($this->getEntityProvider());
|
||||
$playlist->hydrate($item['regionPlaylist']);
|
||||
foreach ($playlist->widgets as $widget) {
|
||||
/** @var XiboWidget $widgetObject */
|
||||
$widgetObject = new XiboWidget($this->getEntityProvider());
|
||||
$widgetObject->hydrate($widget);
|
||||
$hydratedWidgets[] = $widgetObject;
|
||||
}
|
||||
$playlist->widgets = $hydratedWidgets;
|
||||
$region->regionPlaylist = $playlist;
|
||||
$hydratedRegions[] = $region;
|
||||
}
|
||||
$layout->regions = $hydratedRegions;
|
||||
} else {
|
||||
$this->getLogger()->debug('No regions returned with Layout object');
|
||||
}
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $layout
|
||||
* @return XiboLayout
|
||||
*/
|
||||
protected function getDraft($layout)
|
||||
{
|
||||
$draft = (new XiboLayout($this->getEntityProvider()))->get(['parentId' => $layout->layoutId, 'showDrafts' => 1, 'embed' => 'regions,playlists,widgets']);
|
||||
|
||||
return $draft[0];
|
||||
}
|
||||
}
|
||||
78
tests/Helper/MockPlayerActionService.php
Normal file
78
tests/Helper/MockPlayerActionService.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2024 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\Helper;
|
||||
|
||||
use Xibo\Service\ConfigServiceInterface;
|
||||
use Xibo\Service\PlayerActionServiceInterface;
|
||||
|
||||
/**
|
||||
* Class MockPlayerActionService
|
||||
* @package Helper
|
||||
*/
|
||||
class MockPlayerActionService implements PlayerActionServiceInterface
|
||||
{
|
||||
/** @var \Xibo\Service\LogServiceInterface */
|
||||
private $log;
|
||||
|
||||
private $displays = [];
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __construct(ConfigServiceInterface $config, $log, $triggerPlayerActions)
|
||||
{
|
||||
$this->log = $log;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function sendAction($displays, $action): void
|
||||
{
|
||||
$this->log->debug('MockPlayerActionService: sendAction');
|
||||
|
||||
if (!is_array($displays)) {
|
||||
$displays = [$displays];
|
||||
}
|
||||
|
||||
foreach ($displays as $display) {
|
||||
$this->displays[] = $display->displayId;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getQueue(): array
|
||||
{
|
||||
$this->log->debug('MockPlayerActionService: getQueue');
|
||||
return $this->displays;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function processQueue(): void
|
||||
{
|
||||
$this->log->debug('MockPlayerActionService: processQueue');
|
||||
}
|
||||
}
|
||||
68
tests/Helper/NullPlayerActionService.php
Normal file
68
tests/Helper/NullPlayerActionService.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2024 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\Helper;
|
||||
|
||||
use Xibo\Service\ConfigServiceInterface;
|
||||
use Xibo\Service\PlayerActionServiceInterface;
|
||||
|
||||
/**
|
||||
* Class NullPlayerActionService
|
||||
* @package Helper
|
||||
*/
|
||||
class NullPlayerActionService implements PlayerActionServiceInterface
|
||||
{
|
||||
/** @var \Xibo\Service\LogServiceInterface */
|
||||
private $log;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __construct(ConfigServiceInterface $config, $log, $triggerPlayerActions)
|
||||
{
|
||||
$this->log = $log;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function sendAction($displays, $action): void
|
||||
{
|
||||
$this->log->debug('NullPlayerActionService: sendAction');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getQueue(): array
|
||||
{
|
||||
$this->log->debug('NullPlayerActionService: getQueue');
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function processQueue(): void
|
||||
{
|
||||
$this->log->debug('NullPlayerActionService: processQueue');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user