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,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\Unit\DataObjects;
use OxidProfessionalServices\Usercentrics\DataObject\Configuration;
use OxidProfessionalServices\Usercentrics\DataObject\Script;
use OxidProfessionalServices\Usercentrics\DataObject\ScriptSnippet;
use OxidProfessionalServices\Usercentrics\DataObject\Service;
use PHPUnit\Framework\TestCase;
/**
* Class ServiceTest
* @package OxidProfessionalServices\Usercentrics\Tests\Unit
* @covers \OxidProfessionalServices\Usercentrics\DataObject\Configuration
*/
class ConfigurationTest extends TestCase
{
public function testHasService(): void
{
$service = new Service('name', 'id');
$configuration = new Configuration(
[$service],
[],
[]
);
$services = $configuration->getServices();
$this->assertCount(1, $services);
$this->assertSame($service, $services[0]);
}
public function testHasScript(): void
{
$script = new Script('path', 'id');
$configuration = new Configuration(
[],
[$script],
[]
);
$scripts = $configuration->getScripts();
$this->assertCount(1, $scripts);
$this->assertSame($script, $scripts[0]);
}
public function testHasScriptSnippets(): void
{
$scriptSnippet = new ScriptSnippet('123', 'id');
$configuration = new Configuration(
[],
[],
[$scriptSnippet]
);
$scripts = $configuration->getScriptSnippets();
$this->assertCount(1, $scripts);
$this->assertSame($scriptSnippet, $scripts[0]);
}
}

View File

@@ -0,0 +1,45 @@
<?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\Unit\DataObjects;
use OxidProfessionalServices\Usercentrics\DataObject\ScriptSnippet;
use PHPUnit\Framework\TestCase;
/**
* Class ServiceTest
* @package OxidProfessionalServices\Usercentrics\Tests\Unit
* @covers \OxidProfessionalServices\Usercentrics\DataObject\ScriptSnippet
*/
class ScriptSnippetTest extends TestCase
{
public function testHasId(): void
{
$service = new ScriptSnippet('123ABC', 'testServiceId');
$this->assertSame('123ABC', $service->getId());
}
public function testHasServiceId(): void
{
$service = new ScriptSnippet('123ABC', 'testServiceId');
$this->assertSame('testServiceId', $service->getServiceId());
}
}

View File

@@ -0,0 +1,45 @@
<?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\Unit\DataObjects;
use OxidProfessionalServices\Usercentrics\DataObject\Script;
use PHPUnit\Framework\TestCase;
/**
* Class ServiceTest
* @package OxidProfessionalServices\Usercentrics\Tests\Unit
* @covers \OxidProfessionalServices\Usercentrics\DataObject\Script
*/
class ScriptTest extends TestCase
{
public function testHasPath(): void
{
$service = new Script('test/path', 'testServiceId');
$this->assertSame('test/path', $service->getPath());
}
public function testHasServiceId(): void
{
$service = new Script('test/path', 'testServiceId');
$this->assertSame('testServiceId', $service->getServiceId());
}
}

View File

@@ -0,0 +1,45 @@
<?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\Unit\DataObjects;
use OxidProfessionalServices\Usercentrics\DataObject\Service;
use PHPUnit\Framework\TestCase;
/**
* Class ServiceTest
* @package OxidProfessionalServices\Usercentrics\Tests\Unit
* @covers \OxidProfessionalServices\Usercentrics\DataObject\Service
*/
class ServiceTest extends TestCase
{
public function testHasName(): void
{
$service = new Service('testName', 'testId');
$this->assertSame('testName', $service->getName());
}
public function testHasId(): void
{
$service = new Service('testName', 'testId');
$this->assertSame('testId', $service->getId());
}
}

View File

@@ -0,0 +1,52 @@
<?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\Unit\Service\Integration;
use OxidProfessionalServices\Usercentrics\Service\Integration;
use OxidProfessionalServices\Usercentrics\Tests\Unit\UnitTestCase;
/**
* @covers \OxidProfessionalServices\Usercentrics\Service\Integration\IntegrationScriptBuilder
*/
class IntegrationScriptBuilderTest extends UnitTestCase
{
public function testGetIntegrationScript(): void
{
$builder = new Integration\IntegrationScriptBuilder(
new Integration\IntegrationVersionFactory()
);
$versionName = Integration\Pattern\CmpV1::VERSION_NAME;
$params = [
'{USERCENTRICS_CLIENT_ID}' => 'ABC123'
];
$result = $builder->getIntegrationScript($versionName, $params);
$this->assertHtmlEquals(
'<script type="application/javascript"
src="https://app.usercentrics.eu/latest/main.js"
id="ABC123" ></script>',
$result
);
}
}

View File

@@ -0,0 +1,51 @@
<?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\Unit\Service\Integration;
use OxidProfessionalServices\Usercentrics\Exception\PatternNotFound;
use OxidProfessionalServices\Usercentrics\Service\Integration\IntegrationVersionFactory;
use OxidProfessionalServices\Usercentrics\Service\Integration\Pattern\CmpV1;
use OxidProfessionalServices\Usercentrics\Tests\Unit\UnitTestCase;
/**
* @covers \OxidProfessionalServices\Usercentrics\Service\Integration\IntegrationVersionFactory
*/
class IntegrationVersionFactoryTest extends UnitTestCase
{
public function testGetIntegrationScriptPattern(): void
{
$versionName = CmpV1::VERSION_NAME;
$factory = new IntegrationVersionFactory();
$patternObject = $factory->getPatternByVersion($versionName);
$this->assertInstanceOf(CmpV1::class, $patternObject);
}
public function testGetNotExistingIntegrationScriptPattern(): void
{
$this->expectException(PatternNotFound::class);
$versionName = 'NotExisting';
$factory = new IntegrationVersionFactory();
$patternObject = $factory->getPatternByVersion($versionName);
}
}

View File

@@ -0,0 +1,43 @@
<?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\Unit\Service\Integration\Pattern;
use OxidProfessionalServices\Usercentrics\Service\Integration\Pattern\CmpV1;
use OxidProfessionalServices\Usercentrics\Tests\Unit\UnitTestCase;
/**
* @covers \OxidProfessionalServices\Usercentrics\Service\Integration\Pattern\CmpV1
*/
class CmpV1Test extends UnitTestCase
{
public function testGetIntegrationScriptPattern(): void
{
$version = new CmpV1();
$scriptPattern = $version->getIntegrationScriptPattern();
$this->assertHtmlEquals(
'<script type="application/javascript"
src="https://app.usercentrics.eu/latest/main.js"
id="{USERCENTRICS_CLIENT_ID}"></script>',
$scriptPattern
);
}
}

View File

@@ -0,0 +1,45 @@
<?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\Unit\Service\Integration\Pattern;
use OxidProfessionalServices\Usercentrics\Service\Integration\Pattern\CmpV2Tcf;
use OxidProfessionalServices\Usercentrics\Tests\Unit\UnitTestCase;
/**
* @covers \OxidProfessionalServices\Usercentrics\Service\Integration\Pattern\CmpV2Tcf
*/
class CmpV2TcfTest extends UnitTestCase
{
public function testGetIntegrationScriptPattern(): void
{
$version = new CmpV2Tcf();
$scriptPattern = $version->getIntegrationScriptPattern();
$this->assertHtmlEquals(
'<script id="usercentrics-cmp"
data-settings-id="{USERCENTRICS_CLIENT_ID}"
src="https://app.usercentrics.eu/browser-ui/latest/bundle.js"
data-tcf-enabled
defer></script>',
$scriptPattern
);
}
}

View File

@@ -0,0 +1,44 @@
<?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\Unit\Service\Integration\Pattern;
use OxidProfessionalServices\Usercentrics\Service\Integration\Pattern\CmpV2;
use OxidProfessionalServices\Usercentrics\Tests\Unit\UnitTestCase;
/**
* @covers \OxidProfessionalServices\Usercentrics\Service\Integration\Pattern\CmpV2
*/
class CmpV2Test extends UnitTestCase
{
public function testGetIntegrationScriptPattern(): void
{
$version = new CmpV2();
$scriptPattern = $version->getIntegrationScriptPattern();
$this->assertHtmlEquals(
'<script id="usercentrics-cmp"
data-settings-id="{USERCENTRICS_CLIENT_ID}"
src="https://app.usercentrics.eu/browser-ui/latest/bundle.js"
defer></script>',
$scriptPattern
);
}
}

View File

@@ -0,0 +1,38 @@
<?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\Unit\Service\Integration\Pattern;
use OxidProfessionalServices\Usercentrics\Service\Integration\Pattern\Custom;
use OxidProfessionalServices\Usercentrics\Tests\Unit\UnitTestCase;
/**
* @covers \OxidProfessionalServices\Usercentrics\Service\Integration\Pattern\Custom
*/
class CustomTest extends UnitTestCase
{
public function testGetIntegrationScriptPattern(): void
{
$version = new Custom();
$scriptPattern = $version->getIntegrationScriptPattern();
$this->assertSame('', $scriptPattern);
}
}

View File

@@ -0,0 +1,63 @@
<?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\Unit;
use DOMDocument;
use org\bovigo\vfs\vfsStream;
use OxidProfessionalServices\Usercentrics\Service\Configuration\StorageInterface;
use OxidProfessionalServices\Usercentrics\Service\Configuration\YamlStorage;
use PHPUnit\Framework\TestCase;
/**
* Helper methods for tests
*/
class UnitTestCase extends TestCase
{
/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
protected function getVirtualStructurePath(array $structure = []): string
{
$baseDir = vfsStream::setup('root', 444);
vfsStream::create($structure, $baseDir);
return vfsStream::url('root');
}
protected function getStorage(string $file, string $directory = ''): StorageInterface
{
return new YamlStorage(
$directory,
$file
);
}
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);
}
}