Skip to content

Commit

Permalink
XMDS PHPUnit tests and other fixes (xibosignage#1780)
Browse files Browse the repository at this point in the history
* User Group : dynamic libraryQuotaFormatted property fix.
* Tag Factory : fix php warning about trim on null.
* Layout : toXlf omit module properties without id.
* Library : care about oldMedia folder id when replacing Media.
* Maintenance : Fix publishing Layouts with publish date in the future
* Required Files : Fix downloading dependencies for non xmds 7 Players.
* XMDS phpunit tests : phpunit.xml and bootstrap adjustments.
* XMDS phpunit tests : WIP new tests.
* LocalWebTestCase : add return values for functions, to avoid fatal php errors :)
* XmdsTestCase : rename file start with uppercase, remove getPool as we are not using it.
* Required Files : use xmds dependency static variables for offset in getLegacyType function
Change fontsCss legacy id to be equal to the legacy font offset
* XMDS tests : add fonts.css to testGetFont
  • Loading branch information
PeterMis authored May 9, 2023
1 parent 2c4bfca commit c2fa4ac
Show file tree
Hide file tree
Showing 19 changed files with 1,105 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ openooh/
openooh/specification.json

# PHPStorm config
tests/http-client.private.env.json
tests/http-client.private.env.json
/.phpunit.result.cache
2 changes: 1 addition & 1 deletion lib/Controller/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ public function add(Request $request, Response $response)
// Get Valid Extensions
if ($parsedBody->getInt('oldMediaId', ['default' => $options['oldMediaId']]) !== null) {
$media = $this->mediaFactory->getById($parsedBody->getInt('oldMediaId', ['default' => $options['oldMediaId']]));
$oldFolderId = $media->folderId;
$folderId = $media->folderId;
$validExt = $this->moduleFactory->getValidExtensions(['type' => $media->mediaType, 'allowMediaTypeChange' => $options['allowMediaTypeChange']]);
} else {
$validExt = $this->moduleFactory->getValidExtensions();
Expand Down
6 changes: 4 additions & 2 deletions lib/Controller/UserGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Slim\Http\Response as Response;
use Slim\Http\ServerRequest as Request;
use Xibo\Entity\Permission;
use Xibo\Entity\User;
use Xibo\Factory\PermissionFactory;
use Xibo\Factory\UserFactory;
use Xibo\Factory\UserGroupFactory;
Expand Down Expand Up @@ -137,7 +136,10 @@ function grid(Request $request, Response $response)
foreach ($groups as $group) {
/* @var \Xibo\Entity\UserGroup $group */

$group->libraryQuotaFormatted = ByteFormatter::format($group->libraryQuota * 1024);
$group->setUnmatchedProperty(
'libraryQuotaFormatted',
ByteFormatter::format($group->libraryQuota * 1024)
);

if ($this->isApi($request)) {
continue;
Expand Down
6 changes: 4 additions & 2 deletions lib/Entity/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -1653,8 +1653,10 @@ public function toXlf()
continue;
}

$optionNode = $document->createElement($property->id, $property->value ?? '');
$optionsNode->appendChild($optionNode);
if (!empty($property->id)) {
$optionNode = $document->createElement($property->id, $property->value ?? '');
$optionsNode->appendChild($optionNode);
}
}

if ($property->id === 'updateInterval') {
Expand Down
28 changes: 27 additions & 1 deletion lib/Factory/RequiredFileFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Xibo\Entity\RequiredFile;
use Xibo\Event\XmdsDependencyRequestEvent;
use Xibo\Support\Exception\NotFoundException;
use Xibo\Xmds\Entity\Dependency;

/**
* Class RequiredFileFactory
Expand Down Expand Up @@ -129,6 +130,10 @@ public function getByDisplayAndWidget($displayId, $widgetId, $type = 'W')
*/
public function getByDisplayAndDependency($displayId, $fileType, $id, bool $isUseRealId = true)
{
if (!$isUseRealId && $id < 0) {
$fileType = self::getLegacyFileType($id);
}

$result = $this->getStore()->select('
SELECT *
FROM `requiredfile`
Expand All @@ -150,6 +155,22 @@ public function getByDisplayAndDependency($displayId, $fileType, $id, bool $isUs
return $this->createEmpty()->hydrate($result[0], ['stringProperties' => ['realId']]);
}

/**
* Return the fileType depending on the legacyId range
* @param $id
* @return string
*/
private static function getLegacyFileType($id): string
{
return match (true) {
$id < 0 && $id > Dependency::LEGACY_ID_OFFSET_FONT * -1 => 'bundle',
$id === Dependency::LEGACY_ID_OFFSET_FONT * -1 => 'fontCss',
$id < Dependency::LEGACY_ID_OFFSET_FONT * -1 && $id > Dependency::LEGACY_ID_OFFSET_PLAYER_SOFTWARE * -1 => 'font',
$id < Dependency::LEGACY_ID_OFFSET_PLAYER_SOFTWARE * -1 && $id > Dependency::LEGACY_ID_OFFSET_ASSET * -1 => 'playersoftware',
$id < Dependency::LEGACY_ID_OFFSET_PLAYER_SOFTWARE * -1 => 'asset',
};
}

/**
* @param int $displayId
* @param string $path The path of this dependency
Expand Down Expand Up @@ -345,7 +366,12 @@ public function resolveRequiredFileFromRequest($request): RequiredFile
if (empty($fileType)) {
throw new NotFoundException(__('Missing fileType'));
}
$file = $this->getByDisplayAndDependency($displayId, $fileType, $itemId);
$file = $this->getByDisplayAndDependency(
$displayId,
$fileType,
$itemId,
!($fileType == 'media' && $itemId < 0)
);

// Update $file->path with the path on disk (likely /dependencies/$fileType/$itemId)
$event = new XmdsDependencyRequestEvent($file);
Expand Down
2 changes: 1 addition & 1 deletion lib/Factory/TagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function createTagLink($tagId, $tag, $value)
$tagLink = $this->createEmptyLink();
$tagLink->tag = trim($tag);
$tagLink->tagId = $tagId;
$tagLink->value = trim($value);
$tagLink->value = trim($value ?? '');

return $tagLink;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/XTR/MaintenanceRegularTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ private function publishLayouts()
if (count($layouts) > 0) {
foreach ($layouts as $layout) {
// check if the layout should be published now according to the date
if (Carbon::createFromTimestamp($layout->publishedDate)->format('U') < Carbon::now()->format('U')) {
if (Carbon::createFromFormat(DateFormatHelper::getSystemFormat(), $layout->publishedDate)
->isBefore(Carbon::now()->format(DateFormatHelper::getSystemFormat()))
) {
try {
// publish the layout
$layout = $this->layoutFactory->concurrentRequestLock($layout, true);
Expand Down
2 changes: 1 addition & 1 deletion lib/Xmds/Listeners/XmdsFontsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function onDependencyList(XmdsDependencyListEvent $event): void
filesize($fontsCssPath),
md5_file($fontsCssPath),
true,
$this->getLegacyId(1, Dependency::LEGACY_ID_OFFSET_FONT)
$this->getLegacyId(0, Dependency::LEGACY_ID_OFFSET_FONT)
);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/Xmds/Soap.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ protected function doRequiredFiles(
'media' => 'M',
default => 'P',
};

if ($node->getAttribute('id') < 0 && $type === 'M') {
$type = 'P';
}

$newUrl = $this->generateRequiredFileDownloadPath(
$type,
$node->getAttribute('id'),
Expand Down Expand Up @@ -2755,6 +2760,7 @@ private function addDependency(
$file->setAttribute('path', $dependencyBasePath);
}
$file->setAttribute('id', $dependency->legacyId);
$file->setAttribute('fileType', 'media');
}

// Add our node
Expand Down
2 changes: 2 additions & 0 deletions lib/Xmds/Soap5.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ public function RegisterDisplay(
}

$display->commercialLicence = $commercialLicence;
$node = $return->createElement('commercialLicence', $commercialLicenceString);
$displayElement->appendChild($node);
}

// commercial licence not applicable for Windows and Linux players.
Expand Down
39 changes: 30 additions & 9 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
<!--
~ Copyright (C) 2023 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/>.
-->

<phpunit bootstrap="tests/Bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true">
colors="true">
<testsuites>
<testsuite name="Xibo Integration Test Suite">
<directory suffix="Test.php">tests/integration/</directory>
Expand All @@ -12,19 +30,22 @@
<testsuite name="Xibo Unit-Test Suite">
<directory suffix="Test.php">tests/Widget/</directory>
</testsuite>
<testsuite name="Xibo XMDS Test Suite">
<directory suffix="Test.php">tests/xmds/</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>broken</group>
</exclude>
</groups>
<filter>
<whitelist>
<coverage>
<include>
<directory>lib</directory>
</whitelist>
</filter>
</include>
</coverage>
<logging>
<log type="junit" target="results.xml" logIncompleteSkipped="true"/>
<junit outputFile="results.xml"/>
</logging>
<php>
<ini name="memory_limit" value="-1" />
Expand Down
8 changes: 5 additions & 3 deletions tests/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php
/*
* Xibo - Digital Signage - http://www.xibo.org.uk
* Copyright (C) 2015 Spring Signage Ltd
* Copyright (C) 2023 Xibo Signage Ltd
*
* This file (UserFactory.php) is part of Xibo.
* 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
Expand All @@ -27,6 +28,7 @@

require_once PROJECT_ROOT . '/vendor/autoload.php';
require_once PROJECT_ROOT . '/tests/LocalWebTestCase.php';
require_once PROJECT_ROOT . '/tests/XmdsTestCase.php';

if (!file_exists(PROJECT_ROOT . '/web/settings.php'))
die('Not configured');
Expand Down
10 changes: 5 additions & 5 deletions tests/LocalWebTestCase.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/*
* Copyright (c) 2022 Xibo Signage Ltd
* Copyright (C) 2022-2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
Expand Down Expand Up @@ -226,7 +226,7 @@ protected function createRequest(string $method, string $path, $body = null, arr
* Create a global container for all tests to share.
* @throws \Exception
*/
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();

Expand Down Expand Up @@ -516,7 +516,7 @@ protected static function installModuleIfNecessary($name, $class)
* @inheritDoc
* @throws \Exception
*/
public function setUp()
public function setUp(): void
{
self::getLogger()->debug('LocalWebTestCase: setUp');
parent::setUp();
Expand All @@ -529,7 +529,7 @@ public function setUp()
* @inheritDoc
* @throws \Exception
*/
public function tearDown()
public function tearDown(): void
{
self::getLogger()->debug('LocalWebTestCase: tearDown');

Expand Down
Loading

0 comments on commit c2fa4ac

Please sign in to comment.