Initial Upload

This commit is contained in:
Matt Batchelder
2025-12-02 10:32:59 -05:00
commit 05ce0da296
2240 changed files with 467811 additions and 0 deletions

105
tests/Xmds/GetDataTest.php Normal file
View File

@@ -0,0 +1,105 @@
<?php
/*
* 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/>.
*/
namespace Xibo\Tests\Xmds;
use DOMDocument;
use DOMXPath;
use Xibo\Tests\XmdsTestCase;
/**
* Get data tests for xmds v7
* @property string $dataSetXml
*/
class GetDataTest extends XmdsTestCase
{
// The widgetId of our expected widget (if we change the default layout this ID will change).
const WIDGET_ID = 7;
use XmdsHelperTrait;
public function setUp(): void
{
parent::setUp();
// to make sure Display is logged in, otherwise WidgetSyncTask will not sync data.
$this->sendRequest(
'POST',
$this->register(
'PHPUnit7',
'phpunitv7',
'android'
),
7
);
}
public function testGetData()
{
// Fresh RF
$this->sendRequest('POST', $this->getRf(7), 7);
// Execute Widget Sync task so we can have data for our Widget
exec('cd /var/www/cms; php bin/run.php 9');
// XMDS GetData with our dataSet Widget
$response = $this->sendRequest('POST', $this->getWidgetData(7, self::WIDGET_ID));
$content = $response->getBody()->getContents();
// expect GetDataResponse
$this->assertStringContainsString(
'<ns1:GetDataResponse><data xsi:type="xsd:string">',
$content,
'GetData received incorrect response'
);
$document = new DOMDocument();
$document->loadXML($content);
$xpath = new DOMXpath($document);
$result = $xpath->evaluate('string(//data)');
$array = json_decode($result, true);
// go through GetData response and see what we have
foreach ($array as $key => $item) {
// data and meta expected to not be empty
if ($key === 'data' || $key === 'meta') {
$this->assertNotEmpty($item);
$this->assertNotEmpty($key);
}
if ($key === 'data') {
$i = 0;
// go through the expected 2 rows in our dataSet data and see if the column/value matches
foreach ($item as $row) {
$this->assertNotEmpty($row);
if ($i === 0) {
$this->assertSame('Example text value', $row['Text']);
$this->assertSame(1, $row['Number']);
} else if ($i === 1) {
$this->assertSame('PHPUnit text', $row['Text']);
$this->assertSame(2, $row['Number']);
}
$i++;
}
}
}
}
}

View File

@@ -0,0 +1,235 @@
<?php
/*
* 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/>.
*/
namespace Xibo\Tests\Xmds;
use DOMDocument;
use DOMXPath;
use PHPUnit\Framework\Attributes\DataProvider;
use Xibo\Tests\XmdsTestCase;
/**
* GetDependency tests, fonts, bundle
*/
class GetDependencyTest extends XmdsTestCase
{
use XmdsHelperTrait;
public function setUp(): void
{
parent::setUp();
}
public static function successCasesBundle(): array
{
return [
[7],
];
}
public static function successCasesFont(): array
{
return [
[7, 'Aileron-Heavy.otf'],
[7, 'fonts.css'],
[6, 'Aileron-Heavy.otf'],
[6, 'fonts.css'],
[5, 'Aileron-Heavy.otf'],
[5, 'fonts.css'],
[4, 'Aileron-Heavy.otf'],
[4, 'fonts.css'],
];
}
public static function successCasesBundleOld(): array
{
return [
[6],
[5],
[4],
];
}
#[DataProvider('successCasesFont')]
public function testGetFont($version, $fileName)
{
$rf = $this->sendRequest('POST', $this->getRf($version), $version);
$response = $rf->getBody()->getContents();
$path = null;
$document = new DOMDocument();
$document->loadXML($response);
$xpath = new DOMXpath($document);
$result = $xpath->evaluate('string(//RequiredFilesXml)');
$array = json_decode(json_encode(simplexml_load_string($result)), true);
foreach ($array as $item) {
foreach ($item as $file) {
if (!empty($file['@attributes'])
&& !empty($file['@attributes']['saveAs'])
&& $file['@attributes']['saveAs'] === $fileName
) {
if ($version === 7) {
$this->assertSame('dependency', $file['@attributes']['type']);
} else {
$this->assertSame('media', $file['@attributes']['type']);
}
$path = strstr($file['@attributes']['path'], '?');
}
}
}
$this->assertNotEmpty($path);
// Font dependency is still http download, try to get it here
$getFile = $this->getFile($path);
$this->assertSame(200, $getFile->getStatusCode());
$this->assertNotEmpty($getFile->getBody()->getContents());
}
#[DataProvider('successCasesBundle')]
public function testGetBundlev7($version)
{
$rf = $this->sendRequest('POST', $this->getRf($version), $version);
$response = $rf->getBody()->getContents();
$size = null;
$id = null;
$type = null;
$document = new DOMDocument();
$document->loadXML($response);
$xpath = new DOMXpath($document);
$result = $xpath->evaluate('string(//RequiredFilesXml)');
$array = json_decode(json_encode(simplexml_load_string($result)), true);
foreach ($array as $item) {
foreach ($item as $file) {
if (!empty($file['@attributes'])
&& !empty($file['@attributes']['saveAs'])
&& $file['@attributes']['saveAs'] === 'bundle.min.js'
) {
$size = $file['@attributes']['size'];
$type = $file['@attributes']['fileType'];
$id = $file['@attributes']['id'];
}
}
}
$this->assertNotEmpty($size);
$this->assertNotEmpty($type);
$this->assertNotEmpty($id);
// construct the xml for GetDependency wsdl request
$bundleXml = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="urn:xmds" xmlns:types="urn:xmds/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<tns:GetDependency>
<serverKey xsi:type="xsd:string">6v4RduQhaw5Q</serverKey>
<hardwareKey xsi:type="xsd:string">PHPUnit'.$version.'</hardwareKey>
<fileType xsi:type="xsd:string">'. $type .'</fileType>
<id xsi:type="xsd:string">'. $id .'</id>
<chunkOffset xsi:type="xsd:double">0</chunkOffset>
<chunkSize xsi:type="xsd:double">'. $size .'</chunkSize>
</tns:GetDependency>
</soap:Body>
</soap:Envelope>';
// try to call GetDependency with our xml
$getBundle = $this->sendRequest('POST', $bundleXml, $version);
$getBundleResponse = $getBundle->getBody()->getContents();
// expect success
$this->assertSame(200, $getBundle->getStatusCode());
// expect not empty body
$this->assertNotEmpty($getBundleResponse);
// expect response format
$this->assertStringContainsString(
'<ns1:GetDependencyResponse><file xsi:type="xsd:base64Binary">',
$getBundleResponse,
'GetDependency getBundle received incorrect response'
);
}
#[DataProvider('successCasesBundleOld')]
public function testGetBundleOld($version)
{
$rf = $this->sendRequest('POST', $this->getRf($version), $version);
$response = $rf->getBody()->getContents();
$size = null;
$id = null;
$type = null;
$document = new DOMDocument();
$document->loadXML($response);
$xpath = new DOMXpath($document);
$result = $xpath->evaluate('string(//RequiredFilesXml)');
$array = json_decode(json_encode(simplexml_load_string($result)), true);
foreach ($array as $item) {
foreach ($item as $file) {
if (!empty($file['@attributes'])
&& !empty($file['@attributes']['saveAs'])
&& $file['@attributes']['saveAs'] === 'bundle.min.js'
) {
$size = $file['@attributes']['size'];
$type = $file['@attributes']['type'];
$id = $file['@attributes']['id'];
}
}
}
$this->assertNotEmpty($size);
$this->assertNotEmpty($type);
$this->assertNotEmpty($id);
// construct the xml for GetDependency wsdl request
$bundleXml = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:xmds" xmlns:types="urn:xmds/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<tns:GetFile>
<serverKey xsi:type="xsd:string">6v4RduQhaw5Q</serverKey>
<hardwareKey xsi:type="xsd:string">PHPUnit'.$version.'</hardwareKey>
<fileId xsi:type="xsd:string">'. $id .'</fileId>
<fileType xsi:type="xsd:string">'. $type .'</fileType>
<chunkOffset xsi:type="xsd:double">0</chunkOffset>
<chuckSize xsi:type="xsd:double">'. $size .'</chuckSize>
</tns:GetFile>
</soap:Body>
</soap:Envelope>';
// try to call GetFile with our xml
$getBundle = $this->sendRequest('POST', $bundleXml, $version);
$getBundleResponse = $getBundle->getBody()->getContents();
// expect success
$this->assertSame(200, $getBundle->getStatusCode());
// expect not empty body
$this->assertNotEmpty($getBundleResponse);
// expect response format
$this->assertStringContainsString(
'<ns1:GetFileResponse><file xsi:type="xsd:base64Binary">',
$getBundleResponse,
'GetDependency getBundle received incorrect response'
);
}
}

View File

@@ -0,0 +1,215 @@
<?php
/*
* 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/>.
*/
namespace Xibo\Tests\Xmds;
use PHPUnit\Framework\Attributes\DataProvider;
use Xibo\Tests\XmdsTestCase;
/**
* Various Notify Status tests
*/
final class NotifyStatusTest extends XmdsTestCase
{
use XmdsHelperTrait;
public function setUp(): void
{
parent::setUp();
}
public static function successCases(): array
{
return [
[7],
[6],
[5],
[4],
];
}
public static function failureCases(): array
{
return [
[3],
];
}
#[DataProvider('successCases')]
public function testCurrentLayout(int $version)
{
$request = $this->sendRequest('POST', $this->notifyStatus($version, '{"currentLayoutId":1}'), $version);
$this->assertStringContainsString(
'<ns1:NotifyStatusResponse><success xsi:type="xsd:boolean">true</success></ns1:NotifyStatusResponse>',
$request->getBody()->getContents(),
'Notify Current Layout received incorrect response'
);
}
#[DataProvider('failureCases')]
public function testCurrentLayoutFailure(int $version)
{
// disable exception on http_error in guzzle, so we can still check the response
$request = $this->sendRequest(
'POST',
$this->notifyStatus($version, '{"currentLayoutId":1}'),
$version,
false
);
$this->assertSame(500, $request->getStatusCode());
// check the fault code
$this->assertStringContainsString(
'<faultcode>SOAP-ENV:Server</faultcode>',
$request->getBody(),
'Notify Current Layout received incorrect response'
);
// check the fault string
$this->assertStringContainsString(
'<faultstring>Procedure \'NotifyStatus\' not present</faultstring>',
$request->getBody(),
'Notify Current Layout received incorrect response'
);
}
#[DataProvider('failureCases')]
public function testCurrentLayoutExceptionFailure(int $version)
{
// we are expecting 500 Server Exception here for xmds 3
$this->expectException('GuzzleHttp\Exception\ServerException');
$this->expectExceptionCode(500);
$request = $this->sendRequest('POST', $this->notifyStatus($version, '{"currentLayoutId":1}'), $version);
}
#[DataProvider('successCases')]
public function testGeoLocation($version)
{
$request = $this->sendRequest(
'POST',
$this->notifyStatus($version, '{"latitude":52.3676, "longitude":4.9041}'),
$version
);
$this->assertStringContainsString(
'<ns1:NotifyStatusResponse><success xsi:type="xsd:boolean">true</success></ns1:NotifyStatusResponse>',
$request->getBody()->getContents(),
'Notify Geo Location received incorrect response'
);
}
#[DataProvider('failureCases')]
public function testGeoLocationFailure(int $version)
{
// disable exception on http_error in guzzle, so we can still check the response
$request = $this->sendRequest(
'POST',
$this->notifyStatus($version, '{"latitude":52.3676, "longitude":4.9041}'),
$version,
false
);
$this->assertSame(500, $request->getStatusCode());
// check the fault code
$this->assertStringContainsString(
'<faultcode>SOAP-ENV:Server</faultcode>',
$request->getBody(),
'Notify Geo Location received incorrect response'
);
// check the fault string
$this->assertStringContainsString(
'<faultstring>Procedure \'NotifyStatus\' not present</faultstring>',
$request->getBody(),
'Notify Geo Location received incorrect response'
);
}
#[DataProvider('failureCases')]
public function testGeoLocationExceptionFailure(int $version)
{
// we are expecting 500 Server Exception here for xmds 3
$this->expectException('GuzzleHttp\Exception\ServerException');
$this->expectExceptionCode(500);
$this->sendRequest(
'POST',
$this->notifyStatus($version, '{"latitude":52.3676, "longitude":4.9041}'),
$version,
);
}
#[DataProvider('successCases')]
public function testOrientation(int $version)
{
$request = $this->sendRequest(
'POST',
$this->notifyStatus($version, '{"width":7680, "height":4320}'),
$version,
);
$this->assertStringContainsString(
'<ns1:NotifyStatusResponse><success xsi:type="xsd:boolean">true</success></ns1:NotifyStatusResponse>',
$request->getBody()->getContents(),
'Notify Orientation received incorrect response'
);
}
#[DataProvider('failureCases')]
public function testOrientationFailure(int $version)
{
// disable exception on http_error in guzzle, so we can still check the response
$request = $this->sendRequest(
'POST',
$this->notifyStatus($version, '{"width":7680, "height":4320}'),
$version,
false
);
$this->assertSame(500, $request->getStatusCode());
// check the fault code
$this->assertStringContainsString(
'<faultcode>SOAP-ENV:Server</faultcode>',
$request->getBody(),
'Notify Orientation received incorrect response'
);
// check the fault string
$this->assertStringContainsString(
'<faultstring>Procedure \'NotifyStatus\' not present</faultstring>',
$request->getBody(),
'Notify Orientation received incorrect response'
);
}
#[DataProvider('failureCases')]
public function testOrientationExceptionFailure(int $version)
{
// we are expecting 500 Server Exception here for xmds 3
$this->expectException('GuzzleHttp\Exception\ServerException');
$this->expectExceptionCode(500);
$this->sendRequest(
'POST',
$this->notifyStatus($version, '{"width":7680, "height":4320}'),
$version,
);
}
}

View File

@@ -0,0 +1,134 @@
<?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\Xmds;
use DOMDocument;
use DOMXPath;
use Xibo\Tests\XmdsTestCase;
/**
* Register Displays tests
*/
class RegisterDisplayTest extends XmdsTestCase
{
use XmdsHelperTrait;
public function setUp(): void
{
parent::setUp();
}
public function testRegisterDisplayAuthed()
{
$request = $this->sendRequest(
'POST',
$this->register(
'PHPUnit7',
'phpunitv7',
'android'
),
7
);
$response = $request->getBody()->getContents();
$document = new DOMDocument();
$document->loadXML($response);
$xpath = new DOMXpath($document);
$result = $xpath->evaluate('string(//ActivationMessage)');
$innerDocument = new DOMDocument();
$innerDocument->loadXML($result);
$this->assertSame('READY', $innerDocument->documentElement->getAttribute('code'));
$this->assertSame(
'Display is active and ready to start.',
$innerDocument->documentElement->getAttribute('message')
);
}
public function testRegisterDisplayNoAuth()
{
$request = $this->sendRequest(
'POST',
$this->register(
'PHPUnitWaiting',
'phpunitwaiting',
'android'
),
7
);
$response = $request->getBody()->getContents();
$document = new DOMDocument();
$document->loadXML($response);
$xpath = new DOMXpath($document);
$result = $xpath->evaluate('string(//ActivationMessage)');
$innerDocument = new DOMDocument();
$innerDocument->loadXML($result);
$this->assertSame('WAITING', $innerDocument->documentElement->getAttribute('code'));
$this->assertSame(
'Display is Registered and awaiting Authorisation from an Administrator in the CMS',
$innerDocument->documentElement->getAttribute('message')
);
$array = json_decode(json_encode(simplexml_load_string($result)), true);
foreach ($array as $key => $value) {
if ($key === 'commercialLicence') {
$this->assertSame('trial', $value);
}
}
}
public function testRegisterNewDisplay()
{
$request = $this->sendRequest(
'POST',
$this->register(
'PHPUnitAddedTest' . mt_rand(1, 10),
'phpunitaddedtest',
'android'
),
7
);
$response = $request->getBody()->getContents();
$document = new DOMDocument();
$document->loadXML($response);
$xpath = new DOMXpath($document);
$result = $xpath->evaluate('string(//ActivationMessage)');
$innerDocument = new DOMDocument();
$innerDocument->loadXML($result);
$this->assertSame('ADDED', $innerDocument->documentElement->getAttribute('code'));
$this->assertSame(
'Display is now Registered and awaiting Authorisation from an Administrator in the CMS',
$innerDocument->documentElement->getAttribute('message')
);
}
}

View File

@@ -0,0 +1,98 @@
<?php
/*
* 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/>.
*/
namespace Xibo\Tests\Xmds;
use PHPUnit\Framework\Attributes\DataProvider;
use Xibo\Tests\XmdsTestCase;
/**
* Report fault tests
*/
final class ReportFaultsTest extends XmdsTestCase
{
use XmdsHelperTrait;
public function setUp(): void
{
parent::setUp();
}
public static function successCases(): array
{
return [
[7],
[6],
];
}
public static function failureCases(): array
{
return [
[5],
[4],
[3],
];
}
#[DataProvider('successCases')]
public function testSendFaultSuccess(int $version)
{
$request = $this->sendRequest('POST', $this->reportFault($version), $version);
$this->assertStringContainsString(
'<ns1:ReportFaultsResponse><success xsi:type="xsd:boolean">true</success>',
$request->getBody()->getContents(),
'Send fault received incorrect response'
);
}
#[DataProvider('failureCases')]
public function testSendFaultFailure(int $version)
{
// disable exception on http_error in guzzle, so we can still check the response
$request = $this->sendRequest('POST', $this->reportFault($version), $version, false);
// check the fault code
$this->assertStringContainsString(
'<faultcode>SOAP-ENV:Server</faultcode>',
$request->getBody(),
'Send fault received incorrect response'
);
// check the fault string
$this->assertStringContainsString(
'<faultstring>Procedure \'ReportFaults\' not present</faultstring>',
$request->getBody(),
'Send fault received incorrect response'
);
}
#[DataProvider('failureCases')]
public function testSendFaultExceptionFailure(int $version)
{
// we are expecting 500 Server Exception here for xmds 3,4 and 5
$this->expectException('GuzzleHttp\Exception\ServerException');
$this->expectExceptionCode(500);
$this->sendRequest('POST', $this->reportFault($version), $version);
}
}

View File

@@ -0,0 +1,56 @@
<?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\Xmds;
use GuzzleHttp\Exception\GuzzleException;
use Xibo\Tests\xmdsTestCase;
class SubmitLogTest extends XmdsTestCase
{
use XmdsHelperTrait;
public function setUp(): void
{
parent::setUp();
}
/**
* Submit log with category event
* @return void
* @throws GuzzleException
*/
public function testSubmitEventLog()
{
$request = $this->sendRequest(
'POST',
$this->submitEventLog('7'),
7
);
$this->assertStringContainsString(
'<ns1:SubmitLogResponse><success xsi:type="xsd:boolean">true</success>',
$request->getBody()->getContents(),
'Submit Log received incorrect response'
);
}
}

124
tests/Xmds/SyncTest.php Normal file
View File

@@ -0,0 +1,124 @@
<?php
/*
* 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/>.
*/
namespace Xibo\Tests\Xmds;
use DOMDocument;
use DOMXPath;
use PHPUnit\Framework\Attributes\DataProvider;
use Xibo\Tests\xmdsTestCase;
/**
* Sync Schedule and Register tests
*/
class SyncTest extends XmdsTestCase
{
use XmdsHelperTrait;
public function setUp(): void
{
parent::setUp();
}
public static function registerSuccessCases(): array
{
return [
[7],
[6],
];
}
public function testScheduleSyncEvent()
{
$request = $this->sendRequest('POST', $this->getSchedule('PHPUnit7'), 7);
$response = $request->getBody()->getContents();
$document = new DOMDocument();
$document->loadXML($response);
$xpath = new DOMXpath($document);
$result = $xpath->evaluate('string(//ScheduleXml)');
$innerDocument = new DOMDocument();
$innerDocument->loadXML($result);
$layouts = $innerDocument->documentElement->getElementsByTagName('layout');
$i = 0;
foreach ($layouts as $layout) {
if ($i === 0) {
$this->assertSame('8', $layout->getAttribute('file'));
$this->assertSame('1', $layout->getAttribute('syncEvent'));
$this->assertSame('2', $layout->getAttribute('scheduleid'));
} else if ($i === 1) {
$this->assertSame('6', $layout->getAttribute('file'));
$this->assertSame('0', $layout->getAttribute('syncEvent'));
$this->assertSame('1', $layout->getAttribute('scheduleid'));
}
$i++;
}
}
#[DataProvider('registerSuccessCases')]
public function testRegisterDisplay($version)
{
if ($version === 7) {
$this->sendRequest('POST', $this->notifyStatus($version, '{"lanIpAddress":"192.168.0.3"}'), $version);
$xml = $this->register(
'PHPUnit7',
'phpunitv7',
'android'
);
} else {
$xml = $this->register(
'PHPUnit6',
'phpunitv6',
'android'
);
}
$request = $this->sendRequest('POST', $xml, $version);
$response = $request->getBody()->getContents();
$document = new DOMDocument();
$document->loadXML($response);
$xpath = new DOMXpath($document);
$result = $xpath->evaluate('string(//ActivationMessage)');
$innerDocument = new DOMDocument();
$innerDocument->loadXML($result);
$this->assertSame('READY', $innerDocument->documentElement->getAttribute('code'));
$this->assertSame(
'Display is active and ready to start.',
$innerDocument->documentElement->getAttribute('message')
);
$syncNodes = $innerDocument->getElementsByTagName('syncGroup');
$this->assertSame(1, count($syncNodes));
if ($version === 7) {
$this->assertSame('lead', $syncNodes->item(0)->textContent);
} else {
$this->assertSame('192.168.0.3', $syncNodes->item(0)->textContent);
}
}
}

View File

@@ -0,0 +1,136 @@
<?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\Xmds;
trait XmdsHelperTrait
{
public function getRf(string $version)
{
return '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="urn:xmds" xmlns:types="urn:xmds/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<tns:RequiredFiles>
<serverKey xsi:type="xsd:string">6v4RduQhaw5Q</serverKey>
<hardwareKey xsi:type="xsd:string">PHPUnit'.$version.'</hardwareKey>
</tns:RequiredFiles>
</soap:Body>
</soap:Envelope>';
}
public function notifyStatus(string $version, string $status)
{
return '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:xmds" xmlns:types="urn:xmds/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<tns:NotifyStatus>
<serverKey xsi:type="xsd:string">6v4RduQhaw5Q</serverKey>
<hardwareKey xsi:type="xsd:string">PHPUnit'.$version.'</hardwareKey>
<status xsi:type-="xsd:string">'.$status.'</status>
</tns:NotifyStatus>
</soap:Body>
</soap:Envelope>';
}
public function register(
$hardwareKey,
$displayName,
$clientType,
$clientVersion = '4',
$clientCode = '400',
$macAddress = 'CC:40:D0:46:3C:A8'
) {
return '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:xmds" xmlns:types="urn:xmds/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<tns:RegisterDisplay>
<serverKey xsi:type="xsd:string">6v4RduQhaw5Q</serverKey>
<hardwareKey xsi:type="xsd:string">' . $hardwareKey . '</hardwareKey>
<displayName xsi:type="xsd:string">' . $displayName . '</displayName>
<clientType xsi:type="xsd:string">' . $clientType . '</clientType>
<clientVersion xsi:type="xsd:string">' . $clientVersion . '</clientVersion>
<clientCode xsi:type="xsd:int">' . $clientCode . '</clientCode>
<macAddress xsi:type="xsd:string">' . $macAddress . '</macAddress>
</tns:RegisterDisplay>
</soap:Body>
</soap:Envelope>';
}
public function getSchedule($hardwareKey)
{
return '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:xmds" xmlns:types="urn:xmds/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<tns:Schedule>
<serverKey xsi:type="xsd:string">6v4RduQhaw5Q</serverKey>
<hardwareKey xsi:type="xsd:string">' . $hardwareKey . '</hardwareKey>
</tns:Schedule>
</soap:Body>
</soap:Envelope>';
}
public function reportFault($version)
{
return '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:xmds" xmlns:types="urn:xmds/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<tns:ReportFaults>
<serverKey xsi:type="xsd:string">6v4RduQhaw5Q</serverKey>
<hardwareKey xsi:type="xsd:string">PHPUnit'.$version.'</hardwareKey>
<fault xsi:type="xsd:string">[{"date":"2023-04-20 17:03:52","expires":"2023-04-21 17:03:52","code":"10001","reason":"Test","scheduleId":"0","layoutId":0,"regionId":"0","mediaId":"0","widgetId":"0"}]</fault>
</tns:ReportFaults>
</soap:Body>
</soap:Envelope>';
}
public function getWidgetData($version, $widgetId)
{
return '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="urn:xmds" xmlns:types="urn:xmds/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<tns:GetData>
<serverKey xsi:type="xsd:string">6v4RduQhaw5Q</serverKey>
<hardwareKey xsi:type="xsd:string">PHPUnit'. $version .'</hardwareKey>
<widgetId xsi:type="xsd:int">'.$widgetId.'</widgetId>
</tns:GetData>
</soap:Body>
</soap:Envelope>';
}
public function submitEventLog($version): string
{
return '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="urn:xmds" xmlns:types="urn:xmds/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<tns:SubmitLog>
<serverKey xsi:type="xsd:string">6v4RduQhaw5Q</serverKey>
<hardwareKey xsi:type="xsd:string">PHPUnit'. $version .'</hardwareKey>
<logXml xsi:type="xsd:string">&lt;log&gt;&lt;event date=&quot;2024-04-10 12:45:55&quot; category=&quot;event&quot;&gt;&lt;eventType&gt;App Start&lt;/eventType&gt;&lt;message&gt;Detailed message about this event&lt;/message&gt;&lt;alertType&gt;both&lt;/alertType&gt;&lt;refId&gt;&lt;/refId&gt;&lt;/event&gt;&lt;/log&gt;</logXml>
</tns:SubmitLog>
</soap:Body>
</soap:Envelope>';
}
}

189
tests/Xmds/XmdsWrapper.php Normal file
View File

@@ -0,0 +1,189 @@
<?php
/**
* Copyright (C) 2020 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\Xmds;
/**
* Class XmdsWrapper
* @package Xibo\Tests\Xmds
*/
class XmdsWrapper
{
private $URL;
private $KEY;
private $version;
protected $client;
/**
* XmdsWrapper constructor.
* @param string $URL
* @param string $KEY
* @param string $version
* @throws \SoapFault
*/
public function __construct($URL = 'http://localhost/xmds.php', $KEY = 'test', $version = '7')
{
$this->URL = $URL;
$this->KEY = $KEY;
$this->version = $version;
ini_set('soap.wsdl_cache_enabled', 0);
ini_set('soap.wsdl_cache_ttl', 900);
ini_set('default_socket_timeout', 15);
$options = [
'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
'style'=>SOAP_RPC,
'use'=>SOAP_ENCODED,
'soap_version'=>SOAP_1_1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'connection_timeout'=>15,
'trace'=>true,
'encoding'=>'UTF-8',
'exceptions'=>true,
];
$this->client = new \SoapClient($this->URL . '?wsdl&v=' . $this->version, $options);
}
/**
* @param $hardwareKey
* @param $displayName
* @param string $clientType
* @param string $clientVersion
* @param string $clientCode
* @param string $operatingSystem
* @param string $macAddress
* @param string $xmrChannel
* @param string $xmrPubKey
* @return mixed
* @throws \SoapFault
*/
function RegisterDisplay($hardwareKey, $displayName, $clientType='windows', $clientVersion='', $clientCode='', $operatingSystem='', $macAddress='', $xmrChannel='', $xmrPubKey='')
{
return $this->client->RegisterDisplay($this->KEY,
$hardwareKey,
$displayName,
$clientType,
$clientVersion,
$clientCode,
$operatingSystem,
$macAddress,
$xmrChannel,
$xmrPubKey
);
}
/**
* Request Required Files
* @param $hardwareKey
* @return mixed
* @throws \SoapFault
*/
function RequiredFiles($hardwareKey)
{
return $this->client->RequiredFiles($this->KEY, $hardwareKey);
}
/**
* Request a file
* @param $hardwareKey
* @param $fileId
* @param $fileType
* @param $chunkOffset
* @param $chunkSize
* @return mixed
* @throws \SoapFault
*/
function GetFile($hardwareKey, $fileId, $fileType, $chunkOffset, $chunkSize)
{
return $this->client->GetFile($this->KEY,
$hardwareKey,
$fileId,
$fileType,
$chunkOffset,
$chunkSize
);
}
/**
* Request Schedule
* @param $hardwareKey
* @return mixed
* @throws \SoapFault
*/
function Schedule($hardwareKey)
{
return $this->client->Schedule($this->KEY, $hardwareKey);
}
function BlackList()
{
}
function SubmitLog()
{
}
/**
* Submit Stats
* @param $hardwareKey
* @param $statXml
* @return mixed
* @throws \SoapFault
*/
function SubmitStats($hardwareKey, $statXml)
{
return $this->client->SubmitStats($this->KEY, $hardwareKey, $statXml);
}
function MediaInventory()
{
}
/**
* @param string $hardwareKey
* @param int $layoutId
* @param int $regionId
* @param string $mediaId
* @return string
* @throws \SoapFault
*/
function GetResource($hardwareKey, $layoutId, $regionId, $mediaId)
{
return $this->client->GetResource($this->KEY, $hardwareKey, $layoutId, $regionId, $mediaId);
}
function NotifyStatus()
{
}
function SubmitScreenShot()
{
}
}