.
*/
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 = '
6v4RduQhaw5Q
PHPUnit'.$version.'
'. $type .'
'. $id .'
0
'. $size .'
';
// 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(
'',
$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 = '
6v4RduQhaw5Q
PHPUnit'.$version.'
'. $id .'
'. $type .'
0
'. $size .'
';
// 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(
'',
$getBundleResponse,
'GetDependency getBundle received incorrect response'
);
}
}