First upload

This commit is contained in:
Nikolai Fesenko
2025-02-02 13:37:56 +01:00
commit 8d227c9191
3281 changed files with 362319 additions and 0 deletions

View File

@@ -0,0 +1,164 @@
<?php
/**
* This file is part of O3-Shop Usercentrics Cookie Compliance module.
*
* O3-Shop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* O3-Shop 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
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
namespace OxidProfessionalServices\Usercentrics\Tests\Integration\Core;
use DOMDocument;
use OxidEsales\Eshop\Core\Registry;
use OxidProfessionalServices\Usercentrics\Core\ViewConfig;
use OxidProfessionalServices\Usercentrics\Service\Integration\Pattern;
/**
* Class ViewConfigTest
* @covers \OxidProfessionalServices\Usercentrics\Core\ViewConfig
*/
class ViewConfigTest extends \OxidEsales\TestingLibrary\UnitTestCase
{
/**
* @dataProvider booleanProvider
*/
public function testSmartDataProtectorActive(bool $setting): void
{
$config = Registry::getConfig();
/** @psalm-suppress InvalidScalarArgument fails because of wrong typehint in used oxid version */
$config->saveShopConfVar(
'bool',
'smartDataProtectorActive',
$setting,
1,
'module:oxps_usercentrics'
);
/** @var ViewConfig $viewConfig */
$viewConfig = Registry::get(\OxidEsales\Eshop\Core\ViewConfig::class);
// $this->assertInstanceOf(JavaScriptRenderer::class, $viewConfig);
$enabled = $viewConfig->isSmartDataProtectorActive();
$this->assertSame($setting, $enabled);
}
/**
* @dataProvider dataProviderTestOutputPerMode
*/
public function testOutputPerMode(string $mode, string $expected): void
{
$config = Registry::getConfig();
/** @psalm-suppress InvalidScalarArgument fails because of wrong typehint in used oxid version */
$config->saveShopConfVar(
'string',
'usercentricsMode',
$mode,
1,
'module:oxps_usercentrics'
);
$config->saveShopConfVar(
'string',
'usercentricsId',
'ABC123',
1,
'module:oxps_usercentrics'
);
/** @var ViewConfig $viewConfig */
$viewConfig = Registry::get(\OxidEsales\Eshop\Core\ViewConfig::class);
$html = $viewConfig->getUsercentricsScript();
$this->assertHtmlEquals($expected, $html);
}
public function dataProviderTestOutputPerMode(): array
{
return [
[
Pattern\CmpV2Tcf::VERSION_NAME,
'<script id="usercentrics-cmp"
data-settings-id="ABC123"
src="https://app.usercentrics.eu/browser-ui/latest/bundle.js"
data-tcf-enabled
defer></script>'
],
[
Pattern\CmpV2TcfLegacy::VERSION_NAME,
'<script id="usercentrics-cmp"
data-settings-id="ABC123"
src="https://app.usercentrics.eu/browser-ui/latest/bundle_legacy.js"
data-tcf-enabled
defer></script>'
],
[
Pattern\CmpV2Legacy::VERSION_NAME,
'<script id="usercentrics-cmp"
data-settings-id="ABC123"
src="https://app.usercentrics.eu/browser-ui/latest/bundle_legacy.js"
defer></script>'
],
[
Pattern\CmpV2::VERSION_NAME,
'<script id="usercentrics-cmp"
data-settings-id="ABC123"
src="https://app.usercentrics.eu/browser-ui/latest/bundle.js"
defer></script>'
],
[
Pattern\CmpV1::VERSION_NAME,
'<script type="application/javascript"
src="https://app.usercentrics.eu/latest/main.js"
id="ABC123" ></script>'
]
];
}
public function assertHtmlEquals(string $expected, string $actual): void
{
$eDom = new DOMDocument();
$eDom->loadHTML($expected, LIBXML_HTML_NOIMPLIED);
$aDom = new DOMDocument();
$aDom->loadHTML($actual, LIBXML_HTML_NOIMPLIED);
$this->assertXmlStringEqualsXmlString($eDom, $aDom);
}
public function testNoUsercentricsScriptInCustomMode(): void
{
$config = Registry::getConfig();
/** @psalm-suppress InvalidScalarArgument fails because of wrong typehint in used oxid version */
$config->saveShopConfVar(
'string',
'usercentricsMode',
Pattern\Custom::VERSION_NAME,
1,
'module:oxps_usercentrics'
);
/** @var ViewConfig $viewConfig */
$viewConfig = Registry::get(\OxidEsales\Eshop\Core\ViewConfig::class);
$html = $viewConfig->getUsercentricsScript();
$this->assertEmpty($html);
}
public function booleanProvider(): array
{
return [
[true],
[false]
];
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* This file is part of O3-Shop Usercentrics Cookie Compliance module.
*
* O3-Shop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* O3-Shop 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
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
namespace OxidProfessionalServices\Usercentrics\Tests\Integration\Service;
use OxidProfessionalServices\Usercentrics\DataObject\ScriptSnippet;
use OxidProfessionalServices\Usercentrics\Service\Configuration\ConfigurationDao;
use OxidProfessionalServices\Usercentrics\DataObject\Configuration;
use OxidProfessionalServices\Usercentrics\DataObject\Script;
use OxidProfessionalServices\Usercentrics\DataObject\Service;
use OxidProfessionalServices\Usercentrics\Tests\Unit\UnitTestCase;
/**
* Class ConfigTest
* @package OxidProfessionalServices\Usercentrics\Tests\Integration\Service
* @psalm-suppress PropertyNotSetInConstructor
* @covers \OxidProfessionalServices\Usercentrics\Service\Configuration\ConfigurationDao
*/
class ConfigTest extends UnitTestCase
{
public function testConfigPut(): void
{
$directory = $this->getVirtualStructurePath();
$file = 'ConfigPutTest.yaml';
$sut = new ConfigurationDao($this->getStorage($file, $directory));
$services = [new Service('name', 'TestServiceId')];
$scripts = [new Script('test.js', 'TestServiceId')];
$snippets = [new ScriptSnippet('123', 'TestServiceId')];
$configuration = new Configuration($services, $scripts, $snippets);
$sut->putConfiguration($configuration);
$this->assertFileEquals(
__DIR__ . '/ConfigTestData/ConfigPutTest.yaml',
$directory . DIRECTORY_SEPARATOR . $file
);
}
public function testConfigGet(): void
{
$file = 'ConfigReadTest.yaml';
$sut = new ConfigurationDao($this->getStorage($file, __DIR__ . '/ConfigTestData/'));
$configuration = $sut->getConfiguration();
$oneService = $configuration->getServices()['TestService1Id'];
$this->assertEquals("TestService1Id", $oneService->getId());
$this->assertEquals("name1", $oneService->getName());
$oneScript = $configuration->getScripts()[0];
$this->assertEquals("test1.js", $oneScript->getPath());
$this->assertEquals("TestService1Id", $oneScript->getServiceId());
}
}

View File

@@ -0,0 +1,6 @@
scripts:
- { service: TestServiceId, path: test.js }
services:
- { name: name, id: TestServiceId }
scriptSnippets:
- { service: TestServiceId, id: '123' }

View File

@@ -0,0 +1,4 @@
scripts:
- { service: TestService1Id, path: test1.js }
services:
- { name: name1, id: TestService1Id }

View File

@@ -0,0 +1,2 @@
scripts:
services:

View File

@@ -0,0 +1,5 @@
scripts:
- { service: TestService1Id, path: test1.js }
- { service: TestService1Id, path: path/test2.js }
services:
- { name: name1, id: TestService1Id }

View File

@@ -0,0 +1,6 @@
scripts:
- { service: TestService1Id, path: test1.js }
services:
- { name: name1, id: TestService1Id }
scriptSnippets:
- { service: TestService1Id, id: '7bfef2a19ce3ab042f05792ac47bca23' }

View File

@@ -0,0 +1,68 @@
<?php
/**
* This file is part of O3-Shop Usercentrics Cookie Compliance module.
*
* O3-Shop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* O3-Shop 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
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
namespace OxidProfessionalServices\Usercentrics\Tests\Integration\Service;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Tests\Integration\Internal\ContainerTrait;
use OxidProfessionalServices\Usercentrics\Service\Integration\Pattern\CmpV1;
use OxidProfessionalServices\Usercentrics\Service\IntegrationScriptInterface;
use OxidProfessionalServices\Usercentrics\Tests\Unit\UnitTestCase;
/**
* Class RendererTest
* @covers \OxidProfessionalServices\Usercentrics\Service\IntegrationScript
*/
class IntegrationScriptTest extends UnitTestCase
{
use ContainerTrait;
public function testWhiteListedScript(): void
{
$config = Registry::getConfig();
/** @psalm-suppress InvalidScalarArgument fails because of wrong typehint in used oxid version */
$config->saveShopConfVar(
'string',
'usercentricsId',
'SomeId',
1,
'module:oxps_usercentrics'
);
$config->saveShopConfVar(
'string',
'usercentricsMode',
CmpV1::VERSION_NAME,
1,
'module:oxps_usercentrics'
);
/** @var IntegrationScriptInterface $integrationScript */
$integrationScript = $this->get(IntegrationScriptInterface::class);
$script = $integrationScript->getIntegrationScript();
$this->assertHtmlEquals(
'<script type="application/javascript"
src="https://app.usercentrics.eu/latest/main.js"
id="SomeId"></script>',
$script
);
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* This file is part of O3-Shop Usercentrics Cookie Compliance module.
*
* O3-Shop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* O3-Shop 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
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
namespace OxidProfessionalServices\Usercentrics\Tests\Integration\Service;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Tests\Integration\Internal\ContainerTrait;
use OxidProfessionalServices\Usercentrics\Service\ModuleSettingsInterface;
use OxidProfessionalServices\Usercentrics\Tests\Unit\UnitTestCase;
/**
* Class RendererTest
* @covers \OxidProfessionalServices\Usercentrics\Service\ModuleSettings
*/
class ModuleSettingsTest extends UnitTestCase
{
use ContainerTrait;
public function testGetSettingValue(): void
{
$config = Registry::getConfig();
$config->saveShopConfVar(
'str',
'specialVarName',
'someValue',
1,
'module:oxps_usercentrics'
);
/** @var ModuleSettingsInterface $integrationScript */
$moduleSettings = $this->get(ModuleSettingsInterface::class);
$value = $moduleSettings->getSettingValue('specialVarName');
$this->assertEquals('someValue', $value);
}
public function testGetSettingValueGivesNullOnMissingSetting(): void
{
/** @var ModuleSettingsInterface $integrationScript */
$moduleSettings = $this->get(ModuleSettingsInterface::class);
$value = $moduleSettings->getSettingValue('missingSetting');
$this->assertNull($value);
}
public function testGetSettingValueGivesSpecificDefaultOnFail(): void
{
/** @var ModuleSettingsInterface $integrationScript */
$moduleSettings = $this->get(ModuleSettingsInterface::class);
$value = $moduleSettings->getSettingValue('missingSetting', 'special');
$this->assertSame('special', $value);
}
}

View File

@@ -0,0 +1,130 @@
<?php
/**
* This file is part of O3-Shop Usercentrics Cookie Compliance module.
*
* O3-Shop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* O3-Shop 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
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
namespace OxidProfessionalServices\Usercentrics\Tests\Integration\Service;
use OxidProfessionalServices\Usercentrics\Exception\WidgetsNotSupported;
use OxidProfessionalServices\Usercentrics\Service\Configuration\ConfigurationDao;
use OxidProfessionalServices\Usercentrics\Service\Renderer;
use OxidProfessionalServices\Usercentrics\Service\ScriptServiceMapper;
use OxidProfessionalServices\Usercentrics\Tests\Unit\UnitTestCase;
/**
* Class RendererTest
* @package OxidProfessionalServices\Usercentrics\Tests\Integration\Service
* @psalm-suppress PropertyNotSetInConstructor
* @covers \OxidProfessionalServices\Usercentrics\Service\Renderer
*/
class RendererTest extends UnitTestCase
{
public function testWhiteListedScript(): void
{
$file = 'Service1.yaml';
$sut = $this->createRenderer($file);
$rendered = $sut->formFilesOutput([0 => ["http://shop.de/out/theme/js/test.js"]], "");
$this->doAssertStringContainsString('<script type="text/javascript" src="http://shop.de/out/theme/js/test.js"></script>', $rendered);
}
public function testServiceNamedScript(): void
{
$file = 'Service1.yaml';
$sut = $this->createRenderer($file);
$rendered = $sut->formFilesOutput([0 => ["https://shop.de/out/theme/js/test1.js"]], "");
$this->doAssertStringContainsString(
'<script type="text/plain" data-usercentrics="name1" src="https://shop.de/out/theme/js/test1.js"></script>',
$rendered
);
}
public function testNoScript(): void
{
$file = 'Service1.yaml';
$sut = $this->createRenderer($file);
$rendered = $sut->formFilesOutput([], "");
$this->assertEmpty($rendered);
}
public function testServiceNamedSnippet(): void
{
$file = 'Snippets.yaml';
$sut = $this->createRenderer($file);
$rendered = $sut->encloseScriptSnippet("alert('Service2')", "", false);
$expectedResult = <<<'HTML'
<script type="text/plain" data-usercentrics="name1" data-oxid="7bfef2a19ce3ab042f05792ac47bca23">
alert('Service2')
</script>
HTML;
$expectedResult = str_replace("\n", '', $expectedResult);
$this->doAssertStringContainsString($expectedResult, $rendered);
}
public function testNoSnippet(): void
{
$file = 'Snippets.yaml';
$sut = $this->createRenderer($file);
$rendered = $sut->encloseScriptSnippet("", "", false);
$this->assertEmpty($rendered);
}
public function testFormFilesOutputDoesNotSupportWidgets(): void
{
$this->expectException(WidgetsNotSupported::class);
$file = 'Snippets.yaml';
$sut = $this->createRenderer($file);
$sut->formFilesOutput([], "widgetName");
}
public function testEncloseScriptSnippetDoesNotSupportWidgets(): void
{
$this->expectException(WidgetsNotSupported::class);
$file = 'Snippets.yaml';
$sut = $this->createRenderer($file);
$sut->encloseScriptSnippet("", "widgetName", false);
}
protected function createRenderer(string $file): Renderer
{
$config = new ConfigurationDao($this->getStorage($file, __DIR__ . '/ConfigTestData'));
$scriptServiceMapper = new ScriptServiceMapper($config);
return new Renderer($scriptServiceMapper);
}
/**
* @param string $needle
* @param string $haystack
* @param string $message
*/
protected function doAssertStringContainsString($needle, $haystack, $message = ''): void
{
if (method_exists($this, 'assertStringContainsString')) {
parent::assertStringContainsString($needle, $haystack, $message);
} else {
parent::assertContains($needle, $haystack, $message);
}
}
}

View File

@@ -0,0 +1,146 @@
<?php
/**
* This file is part of O3-Shop Usercentrics Cookie Compliance module.
*
* O3-Shop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* O3-Shop 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
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
namespace OxidProfessionalServices\Usercentrics\Tests\Integration\Service;
use OxidProfessionalServices\Usercentrics\DataObject\Service;
use OxidProfessionalServices\Usercentrics\Service\Configuration\ConfigurationDao;
use OxidProfessionalServices\Usercentrics\Service\ScriptServiceMapper;
use OxidProfessionalServices\Usercentrics\Tests\Unit\UnitTestCase;
/**
* Class RepositoryTest
* @package OxidProfessionalServices\Usercentrics\Tests\Integration\Service
* @psalm-suppress PropertyNotSetInConstructor
* @covers \OxidProfessionalServices\Usercentrics\Service\ScriptServiceMapper
*/
class ScriptServiceMapperTest extends UnitTestCase
{
/**
* @dataProvider notMatchingScriptUrls
*/
public function testScriptNoNameConfigured(string $scriptUrl): void
{
$scriptServiceMapper = $this->createScriptMapper('Service1.yaml');
$service = $scriptServiceMapper->getServiceByScriptUrl($scriptUrl);
$this->assertNull(
$service,
"test.js should not return a service name as its not configured"
);
}
/**
* @dataProvider matchingScriptUrls
*/
public function testScriptNameConfigured(string $scriptUrl): void
{
$scriptServiceMapper = $this->createScriptMapper('Service1.yaml');
/** @var Service $service */
$service = $scriptServiceMapper->getServiceByScriptUrl($scriptUrl);
$this->assertNotNull($service);
$this->assertEquals("name1", $service->getName());
}
public function matchingScriptUrls(): array
{
return [
["http://someurl/path/test1.js"],
["http://someurl/path/test1.js?123456"],
["http://someurl/path/test1.js?123456#abc"],
["http://someurl/path/test1.js#abc"],
["https://someurl/path/test2.js#abc"],
["https://someurl/1/test/js/path/test2.js?123456"],
];
}
public function notMatchingScriptUrls(): array
{
return [
["http://someurl/path/test.js"],
["http://someurl/path/test.js?123456"],
["http://someurl/path/test.js?123456#abc"],
["http://someurl/path/test.js#abc"],
["https://someurl/test2.js#abc"],
["https://someurl/js/test2.js"],
["https://someurl/path/js/test2.js?123456"],
];
}
public function testCalculateSnippetIdIsNotEmpty(): void
{
$scriptServiceMapper = $this->createScriptMapper('Snippets.yaml');
$snippet = "alert('Service1')";
$id = $scriptServiceMapper->calculateSnippetId($snippet);
$this->assertNotEmpty($id);
}
public function testCalculateSnippetIdIsUnique(): void
{
$scriptServiceMapper = $this->createScriptMapper('Snippets.yaml');
$snippet = "alert('Service1')";
$id = $scriptServiceMapper->calculateSnippetId($snippet);
$snippet2 = "alert('Service2')";
$id2 = $scriptServiceMapper->calculateSnippetId($snippet2);
$this->assertNotEquals($id, $id2);
}
public function testCalculateSnippetIdIsStable(): void
{
$scriptServiceMapper = $this->createScriptMapper('Snippets.yaml');
$snippet = "alert('Service1')";
$id = $scriptServiceMapper->calculateSnippetId($snippet);
$id3 = $scriptServiceMapper->calculateSnippetId($snippet);
$this->assertEquals($id, $id3);
}
public function testGetServiceBySnippetId(): void
{
$scriptServiceMapper = $this->createScriptMapper('Snippets.yaml');
$id = $scriptServiceMapper->calculateSnippetId("alert('Service2')");
$service = $scriptServiceMapper->getServiceBySnippetId($id);
$this->assertNotNull($service);
/** @psalm-suppress PossiblyNullReference */
$this->assertEquals("name1", $service->getName());
}
public function testGetServiceByNotExistingSnippetId(): void
{
$scriptServiceMapper = $this->createScriptMapper('Snippets.yaml');
$id = $scriptServiceMapper->calculateSnippetId("alert('NoService')");
$service = $scriptServiceMapper->getServiceBySnippetId($id);
$this->assertNull($service);
}
/**
* @return ScriptServiceMapper
*/
private function createScriptMapper(string $file): ScriptServiceMapper
{
$config = new ConfigurationDao($this->getStorage($file, __DIR__ . '/ConfigTestData'));
return new ScriptServiceMapper($config);
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* This file is part of O3-Shop Usercentrics Cookie Compliance module.
*
* O3-Shop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* O3-Shop 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
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
namespace OxidProfessionalServices\Usercentrics\Tests\Integration\Service;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidProfessionalServices\Usercentrics\Service\Configuration\StorageInterface;
use OxidProfessionalServices\Usercentrics\Service\Configuration\YamlStorage;
use OxidProfessionalServices\Usercentrics\Tests\Unit\UnitTestCase;
/**
* YamlStorageTest Yaml
* @package OxidProfessionalServices\Usercentrics\Tests\Integration\Service
* @covers \OxidProfessionalServices\Usercentrics\Service\Configuration\YamlStorage
*/
class YamlStorageTest extends UnitTestCase
{
public function testIntegration(): void
{
$container = ContainerFactory::getInstance()->getContainer();
/** @var StorageInterface $storage */
$storage = $container->get(StorageInterface::class);
$this->assertInstanceOf(YamlStorage::class, $storage);
}
public function testGetData(): void
{
$path = $this->getVirtualStructurePath([
'ConfigReadTest.yaml' => 'test: value'
]);
$sut = new YamlStorage(
$path,
'ConfigReadTest.yaml'
);
$this->assertEquals(["test" => "value"], $sut->getData());
}
public function testGetNotExistingFileDataGivesEmptyArray(): void
{
$path = $this->getVirtualStructurePath([]);
$file = 'ConfigReadTest.yaml';
$sut = new YamlStorage(
$path,
'ConfigReadTest.yaml'
);
$this->assertFileNotExists($path . DIRECTORY_SEPARATOR . $file);
$this->assertEquals([], $sut->getData());
}
public function testPutData(): void
{
$path = $this->getVirtualStructurePath([
'ConfigReadTest.yaml' => 'test: wrongValue'
]);
$sut = new YamlStorage(
$path,
'ConfigReadTest.yaml'
);
$sut->putData(["test" => "correctValue"]);
$this->assertEquals(["test" => "correctValue"], $sut->getData());
}
}