ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Test\Unit\Model\Category;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Plumrocket\CookieConsent\Api\CanManageCookieInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface;
|
||||
use Plumrocket\CookieConsent\Api\GetUserConsentInterface;
|
||||
use Plumrocket\CookieConsent\Api\IsUserOptInInterface;
|
||||
use Plumrocket\CookieConsent\Helper\Config;
|
||||
use Plumrocket\CookieConsent\Model\Category\IsAllowed;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class IsAllowedTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\Category\IsAllowed
|
||||
*/
|
||||
private $isAllowedModel;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\CookieConsent\Api\CanManageCookieInterface
|
||||
*/
|
||||
private $canManageCookieMock;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\CookieConsent\Helper\Config
|
||||
*/
|
||||
private $configMock;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\CookieConsent\Api\IsUserOptInInterface
|
||||
*/
|
||||
private $isUserOptInMock;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\CookieConsent\Api\GetUserConsentInterface
|
||||
*/
|
||||
private $getUserConsentMock;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface
|
||||
*/
|
||||
private $getEssentialCategoryKeysMock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->canManageCookieMock = $this->createMock(CanManageCookieInterface::class);
|
||||
$this->configMock = $this->createMock(Config::class);
|
||||
$this->isUserOptInMock = $this->createMock(IsUserOptInInterface::class);
|
||||
$this->getUserConsentMock = $this->createMock(GetUserConsentInterface::class);
|
||||
$this->getEssentialCategoryKeysMock = $this->createMock(GetEssentialCategoryKeysInterface::class);
|
||||
|
||||
$this->isAllowedModel = new IsAllowed(
|
||||
$this->canManageCookieMock,
|
||||
$this->getUserConsentMock,
|
||||
$this->isUserOptInMock,
|
||||
$this->configMock,
|
||||
$this->getEssentialCategoryKeysMock
|
||||
);
|
||||
}
|
||||
|
||||
public function testCannotManageCookie()
|
||||
{
|
||||
$this->canManageCookieMock
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->willReturn(false);
|
||||
|
||||
$this->assertTrue($this->isAllowedModel->execute('test_category_key'));
|
||||
}
|
||||
|
||||
public function testEssentialCategories()
|
||||
{
|
||||
$this->canManageCookieMock
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->willReturn(true);
|
||||
|
||||
$this->getEssentialCategoryKeysMock
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->willReturn(['test_essential_category_key_1']);
|
||||
|
||||
$this->isUserOptInMock->expects($this->never())->method('execute');
|
||||
$this->getUserConsentMock->expects($this->never())->method('execute');
|
||||
|
||||
$this->assertTrue($this->isAllowedModel->execute('test_essential_category_key_1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider canUseCookieBeforeOptInProvider
|
||||
*
|
||||
* @param bool $canUseCookieBeforeOptIn
|
||||
* @param bool $result
|
||||
*/
|
||||
public function testNotOptIn(bool $canUseCookieBeforeOptIn, bool $result)
|
||||
{
|
||||
$this->canManageCookieMock
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->willReturn(true);
|
||||
|
||||
$this->getEssentialCategoryKeysMock
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->willReturn(['test_essential_category_key_1']);
|
||||
|
||||
$this->isUserOptInMock
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->willReturn(false);
|
||||
|
||||
$this->configMock
|
||||
->expects($this->once())
|
||||
->method('canUseCookieBeforeOptIn')
|
||||
->willReturn($canUseCookieBeforeOptIn);
|
||||
|
||||
$this->assertSame($this->isAllowedModel->execute('test_category_key'), $result);
|
||||
}
|
||||
|
||||
public function canUseCookieBeforeOptInProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'canUseCookieBeforeOptIn' => true,
|
||||
'result' => true,
|
||||
],
|
||||
[
|
||||
'canUseCookieBeforeOptIn' => false,
|
||||
'result' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider consentProvider
|
||||
*
|
||||
* @param array $consent
|
||||
* @param bool $result
|
||||
*/
|
||||
public function testConsent(array $consent, bool $result)
|
||||
{
|
||||
$this->canManageCookieMock
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->willReturn(true);
|
||||
|
||||
$this->getEssentialCategoryKeysMock
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->willReturn(['test_essential_category_key_1']);
|
||||
|
||||
$this->isUserOptInMock
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->willReturn(true);
|
||||
|
||||
$this->getUserConsentMock
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->willReturn($consent);
|
||||
|
||||
$this->assertSame($this->isAllowedModel->execute('test_category_key'), $result);
|
||||
}
|
||||
|
||||
public function consentProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'consent' => ['test_category_key'],
|
||||
'result' => true,
|
||||
],
|
||||
[
|
||||
'consent' => [],
|
||||
'result' => false,
|
||||
],
|
||||
[
|
||||
'consent' => ['test_category_key_1'],
|
||||
'result' => false,
|
||||
],
|
||||
[
|
||||
'consent' => [CategoryInterface::ALL_CATEGORIES],
|
||||
'result' => true,
|
||||
],
|
||||
[
|
||||
'consent' => ['test_category_key_1', 'test_category_key_2'],
|
||||
'result' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_GeoIPLookup
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Test\Unit\Model\Cookie;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Plumrocket\CookieConsent\Api\CanManageCookieInterface;
|
||||
use Plumrocket\CookieConsent\Api\IsAllowedCategoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\IsUserOptInInterface;
|
||||
use Plumrocket\CookieConsent\Helper\Config;
|
||||
use Plumrocket\CookieConsent\Model\Cookie\IsAllowed;
|
||||
use Plumrocket\CookieConsent\Model\Cookie\Name\GetTrueName;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetCategoryKey;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie\IsKnown;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class IsAllowedTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\Cookie\IsAllowed
|
||||
*/
|
||||
private $isAllowedModel;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\CookieConsent\Api\CanManageCookieInterface
|
||||
*/
|
||||
private $canManageCookieMock;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\CookieConsent\Helper\Config
|
||||
*/
|
||||
private $configMock;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\CookieConsent\Api\IsUserOptInInterface
|
||||
*/
|
||||
private $isUserOptInMock;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetCategoryKey
|
||||
*/
|
||||
private $getCategoryKeyMock;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\CookieConsent\Api\IsAllowedCategoryInterface
|
||||
*/
|
||||
private $isAllowedCategoryMock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->canManageCookieMock = $this->createMock(CanManageCookieInterface::class);
|
||||
$this->configMock = $this->createMock(Config::class);
|
||||
$this->isUserOptInMock = $this->createMock(IsUserOptInInterface::class);
|
||||
$this->getCategoryKeyMock = $this->createMock(GetCategoryKey::class);
|
||||
$this->isAllowedCategoryMock = $this->createMock(IsAllowedCategoryInterface::class);
|
||||
$getTrueNameMock = $this->createMock(GetTrueName::class);
|
||||
$getTrueNameMock->method('execute')->willReturnArgument(0);
|
||||
|
||||
$isKnown = new IsKnown($this->getCategoryKeyMock);
|
||||
|
||||
$this->isAllowedModel = new IsAllowed(
|
||||
$this->canManageCookieMock,
|
||||
$this->configMock,
|
||||
$this->isUserOptInMock,
|
||||
$this->getCategoryKeyMock,
|
||||
$this->isAllowedCategoryMock,
|
||||
$isKnown,
|
||||
$getTrueNameMock,
|
||||
['test-key' => 'TEST_SYSTEM_COOKIE_NAME']
|
||||
);
|
||||
}
|
||||
|
||||
public function testSystemCookie()
|
||||
{
|
||||
self::assertTrue($this->isAllowedModel->execute('TEST_SYSTEM_COOKIE_NAME'));
|
||||
}
|
||||
|
||||
public function testCannotManageCookie()
|
||||
{
|
||||
$this->canManageCookieMock
|
||||
->expects(self::once())
|
||||
->method('execute')
|
||||
->willReturn(false);
|
||||
|
||||
$this->getCategoryKeyMock
|
||||
->expects(self::never())
|
||||
->method('execute');
|
||||
|
||||
$this->isAllowedCategoryMock
|
||||
->expects(self::never())
|
||||
->method('execute');
|
||||
|
||||
self::assertTrue($this->isAllowedModel->execute('test_cookie_name'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider canUseCookieBeforeOptInProvider
|
||||
*
|
||||
* @param bool $canUseCookieBeforeOptIn
|
||||
* @param bool $isKnown
|
||||
* @param bool $isAllowedCategory
|
||||
* @param bool $result
|
||||
*/
|
||||
public function testNotOptInUser(
|
||||
bool $canUseCookieBeforeOptIn,
|
||||
bool $isKnown,
|
||||
bool $isAllowedCategory,
|
||||
bool $result
|
||||
) {
|
||||
$this->canManageCookieMock
|
||||
->expects(self::once())
|
||||
->method('execute')
|
||||
->willReturn(true);
|
||||
|
||||
$this->isUserOptInMock
|
||||
->expects(self::once())
|
||||
->method('execute')
|
||||
->willReturn(false);
|
||||
|
||||
$this->configMock
|
||||
->expects(self::once())
|
||||
->method('canUseCookieBeforeOptIn')
|
||||
->willReturn($canUseCookieBeforeOptIn);
|
||||
|
||||
$this->getCategoryKeyMock
|
||||
->method('execute')
|
||||
->willReturn($isKnown ? 'test_category' : '');
|
||||
|
||||
$this->isAllowedCategoryMock
|
||||
->method('execute')
|
||||
->willReturn($isAllowedCategory);
|
||||
|
||||
$this->configMock->expects(self::never())->method('canBlockUnknownCookie');
|
||||
|
||||
self::assertSame($result, $this->isAllowedModel->execute('test_cookie_name'));
|
||||
}
|
||||
|
||||
public function canUseCookieBeforeOptInProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'canUseCookieBeforeOptIn' => true,
|
||||
'isKnown' => false,
|
||||
'isAllowedCategory' => false,
|
||||
'result' => true,
|
||||
],
|
||||
[
|
||||
'canUseCookieBeforeOptIn' => false,
|
||||
'isKnown' => false,
|
||||
'isAllowedCategory' => false,
|
||||
'result' => false,
|
||||
],
|
||||
[
|
||||
'canUseCookieBeforeOptIn' => false,
|
||||
'isKnown' => true,
|
||||
'isAllowedCategory' => false,
|
||||
'result' => false,
|
||||
],
|
||||
[
|
||||
'canUseCookieBeforeOptIn' => false,
|
||||
'isKnown' => true,
|
||||
'isAllowedCategory' => true,
|
||||
'result' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider canBlockUnknownCookieProvider
|
||||
*
|
||||
* @param bool $canBlockUnknownCookie
|
||||
* @param bool $result
|
||||
*/
|
||||
public function testUnknownCookie(bool $canBlockUnknownCookie, bool $result)
|
||||
{
|
||||
$this->canManageCookieMock
|
||||
->expects(self::once())
|
||||
->method('execute')
|
||||
->willReturn(true);
|
||||
|
||||
$this->isUserOptInMock
|
||||
->expects(self::once())
|
||||
->method('execute')
|
||||
->willReturn(true);
|
||||
|
||||
$this->getCategoryKeyMock
|
||||
->expects(self::once())
|
||||
->method('execute')
|
||||
->willReturn('');
|
||||
|
||||
$this->configMock
|
||||
->expects(self::once())
|
||||
->method('canBlockUnknownCookie')
|
||||
->willReturn($canBlockUnknownCookie);
|
||||
|
||||
$this->isAllowedCategoryMock
|
||||
->expects(self::never())
|
||||
->method('execute');
|
||||
|
||||
self::assertSame($result, $this->isAllowedModel->execute('test_cookie_name'));
|
||||
}
|
||||
|
||||
public function canBlockUnknownCookieProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'canBlockUnknownCookie' => true,
|
||||
'result' => false,
|
||||
],
|
||||
[
|
||||
'canBlockUnknownCookie' => false,
|
||||
'result' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider isAllowedCategoryProvider
|
||||
*
|
||||
* @param bool $isAllowedCategory
|
||||
* @param bool $result
|
||||
*/
|
||||
public function testCookieCategoryValidation(bool $isAllowedCategory, bool $result)
|
||||
{
|
||||
$this->canManageCookieMock
|
||||
->expects(self::once())
|
||||
->method('execute')
|
||||
->willReturn(true);
|
||||
|
||||
$this->isUserOptInMock
|
||||
->expects(self::once())
|
||||
->method('execute')
|
||||
->willReturn(true);
|
||||
|
||||
$this->getCategoryKeyMock
|
||||
->expects(self::exactly(2))
|
||||
->method('execute')
|
||||
->willReturn('test_category');
|
||||
|
||||
$this->configMock
|
||||
->expects(self::never())
|
||||
->method('canBlockUnknownCookie');
|
||||
|
||||
$this->isAllowedCategoryMock
|
||||
->expects(self::once())
|
||||
->method('execute')
|
||||
->willReturn($isAllowedCategory);
|
||||
|
||||
self::assertSame($result, $this->isAllowedModel->execute('test_cookie_name'));
|
||||
}
|
||||
|
||||
public function isAllowedCategoryProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'isAllowedCategory' => true,
|
||||
'result' => true,
|
||||
],
|
||||
[
|
||||
'isAllowedCategory' => false,
|
||||
'result' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2022 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
namespace Plumrocket\CookieConsent\Test\Unit\Model\Cookie;
|
||||
|
||||
use Plumrocket\CookieConsent\Model\Cookie\ParentDomain;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParentDomainTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\Cookie\ParentDomain
|
||||
*/
|
||||
private $parentDomain;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->parentDomain = new ParentDomain();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getDomain
|
||||
*
|
||||
* @param string $domain
|
||||
* @param string $expectedDomain
|
||||
* @return void
|
||||
*/
|
||||
public function testResolve(string $domain, string $expectedDomain): void
|
||||
{
|
||||
$parentDomain = $this->parentDomain->resolve($domain);
|
||||
self::assertSame($expectedDomain, $parentDomain);
|
||||
}
|
||||
|
||||
public function getDomain()
|
||||
{
|
||||
yield [
|
||||
'domain' => 'www.plumrocket.com',
|
||||
'parentDomain' => '.plumrocket.com'
|
||||
];
|
||||
|
||||
yield [
|
||||
'domain' => 'blog.magento.com',
|
||||
'parentDomain' => '.magento.com'
|
||||
];
|
||||
|
||||
yield [
|
||||
'domain' => 'magento.com',
|
||||
'parentDomain' => ''
|
||||
];
|
||||
|
||||
yield [
|
||||
'domain' => 'magento.te.ua',
|
||||
'parentDomain' => ''
|
||||
];
|
||||
|
||||
yield [
|
||||
'domain' => 'www.test.magento.com',
|
||||
'parentDomain' => '.test.magento.com'
|
||||
];
|
||||
|
||||
yield [
|
||||
'domain' => 'www.magento.te.ua',
|
||||
'parentDomain' => '.magento.te.ua'
|
||||
];
|
||||
|
||||
yield [
|
||||
'domain' => 'www.magento.xxx',
|
||||
'parentDomain' => '.magento.xxx'
|
||||
];
|
||||
}
|
||||
}
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2022 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Test\Unit\Model\Integration;
|
||||
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Plumrocket\Base\Model\Utils\Config;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Model\CategoryRepository;
|
||||
use Plumrocket\CookieConsent\Model\Integration\NoCookieYoutube;
|
||||
|
||||
/**
|
||||
* @since 1.9.0
|
||||
*/
|
||||
class NoCookieYoutubeTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\IsUserOptInInterface
|
||||
*/
|
||||
private $noCookieYoutube;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\CookieConsent\Helper\Config
|
||||
*/
|
||||
private $configMock;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\CookieConsent\Model\CategoryRepository
|
||||
*/
|
||||
private $categoryRepositoryMock;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\Base\Model\Utils\Config
|
||||
*/
|
||||
private $configUtilsMock;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\CookieConsent\Api\Data\CategoryInterface
|
||||
*/
|
||||
private $cookieCategoryMock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->configMock = $this->createMock(\Plumrocket\CookieConsent\Helper\Config::class);
|
||||
$this->categoryRepositoryMock = $this->createMock(CategoryRepository::class);
|
||||
$this->configUtilsMock = $this->createMock(Config::class);
|
||||
$this->cookieCategoryMock = $this->getMockForAbstractClass(CategoryInterface::class);
|
||||
|
||||
$this->noCookieYoutube = new NoCookieYoutube(
|
||||
$this->configMock,
|
||||
$this->categoryRepositoryMock,
|
||||
$this->configUtilsMock
|
||||
);
|
||||
}
|
||||
|
||||
public function testDisabledExtension(): void
|
||||
{
|
||||
$this->configMock->method('isModuleEnabled')->willReturn(false);
|
||||
$this->assertFalse($this->noCookieYoutube->isEnabled());
|
||||
}
|
||||
|
||||
public function testNotConfiguredCategory(): void
|
||||
{
|
||||
$this->configMock->method('isModuleEnabled')->willReturn(true);
|
||||
$this->configUtilsMock
|
||||
->method('getStoreConfig')
|
||||
->with(NoCookieYoutube::XML_PATH_CATEGORY_KEY)
|
||||
->willReturn(null);
|
||||
$this->assertFalse($this->noCookieYoutube->isEnabled());
|
||||
}
|
||||
|
||||
public function testNotExistingCategory(): void
|
||||
{
|
||||
$this->configMock->method('isModuleEnabled')->willReturn(true);
|
||||
$this->configUtilsMock
|
||||
->method('getStoreConfig')
|
||||
->with(NoCookieYoutube::XML_PATH_CATEGORY_KEY)
|
||||
->willReturn('test');
|
||||
$this->categoryRepositoryMock->method('get')->willThrowException(new NoSuchEntityException(__('')));
|
||||
$this->assertFalse($this->noCookieYoutube->isEnabled());
|
||||
}
|
||||
|
||||
public function testDisabledCategory(): void
|
||||
{
|
||||
$this->configMock->method('isModuleEnabled')->willReturn(true);
|
||||
$this->configUtilsMock
|
||||
->method('getStoreConfig')
|
||||
->with(NoCookieYoutube::XML_PATH_CATEGORY_KEY)
|
||||
->willReturn('test');
|
||||
$this->cookieCategoryMock->method('isEnabled')->willReturn(false);
|
||||
$this->categoryRepositoryMock->method('get')->willReturn($this->cookieCategoryMock);
|
||||
$this->assertFalse($this->noCookieYoutube->isEnabled());
|
||||
}
|
||||
|
||||
public function testEssentialCategory(): void
|
||||
{
|
||||
$this->configMock->method('isModuleEnabled')->willReturn(true);
|
||||
$this->configUtilsMock
|
||||
->method('getStoreConfig')
|
||||
->with(NoCookieYoutube::XML_PATH_CATEGORY_KEY)
|
||||
->willReturn('test');
|
||||
$this->cookieCategoryMock->method('isEnabled')->willReturn(true);
|
||||
$this->cookieCategoryMock->method('isEssential')->willReturn(true);
|
||||
$this->categoryRepositoryMock->method('get')->willReturn($this->cookieCategoryMock);
|
||||
$this->assertFalse($this->noCookieYoutube->isEnabled());
|
||||
}
|
||||
|
||||
public function testCorrectSettingsCategory(): void
|
||||
{
|
||||
$this->configMock->method('isModuleEnabled')->willReturn(true);
|
||||
$this->configUtilsMock
|
||||
->method('getStoreConfig')
|
||||
->with(NoCookieYoutube::XML_PATH_CATEGORY_KEY)
|
||||
->willReturn('test');
|
||||
$this->cookieCategoryMock->method('isEnabled')->willReturn(true);
|
||||
$this->cookieCategoryMock->method('isEssential')->willReturn(false);
|
||||
$this->categoryRepositoryMock->method('get')->willReturn($this->cookieCategoryMock);
|
||||
$this->assertTrue($this->noCookieYoutube->isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider iframeHtml
|
||||
*
|
||||
* @param string $case
|
||||
* @param string $html
|
||||
* @param string $expectedHtml
|
||||
* @return void
|
||||
*/
|
||||
public function testConvertHtml(string $case, string $html, string $expectedHtml): void
|
||||
{
|
||||
$this->configMock->method('isModuleEnabled')->willReturn(true);
|
||||
$this->configUtilsMock
|
||||
->method('getStoreConfig')
|
||||
->with(NoCookieYoutube::XML_PATH_CATEGORY_KEY)
|
||||
->willReturn('test');
|
||||
$this->cookieCategoryMock->method('isEnabled')->willReturn(true);
|
||||
$this->cookieCategoryMock->method('isEssential')->willReturn(false);
|
||||
$this->categoryRepositoryMock->method('get')->willReturn($this->cookieCategoryMock);
|
||||
$this->assertSame($expectedHtml, $this->noCookieYoutube->convertHtml($html), $case);
|
||||
}
|
||||
|
||||
public function iframeHtml(): \Generator
|
||||
{
|
||||
yield [
|
||||
'case' => 'Empty html',
|
||||
'html' => '',
|
||||
'expectedHtml' => '',
|
||||
];
|
||||
yield [
|
||||
'case' => 'YouTube iframe html',
|
||||
'html' => '<iframe width="560" height="315" src="https://www.youtube.com/embed/aaaaaaaaaaa" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
|
||||
'expectedHtml' => '<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/aaaaaaaaaaa" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
|
||||
];
|
||||
yield [
|
||||
'case' => 'Not YouTube iframe html',
|
||||
'html' => '<iframe width="560" height="315" src="https://www.test.com/embed/aaaaaaaaaaa"></iframe>',
|
||||
'expectedHtml' => '<iframe width="560" height="315" src="https://www.test.com/embed/aaaaaaaaaaa"></iframe>',
|
||||
];
|
||||
yield [
|
||||
'case' => 'YouTube iframe html',
|
||||
'html' => <<<HTML
|
||||
<iframe width="560" height="315"
|
||||
src="https://www.youtube.com/embed/aaaaaaaaaaa"
|
||||
title="YouTube video player"
|
||||
frameborder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allowfullscreen>
|
||||
</iframe>
|
||||
HTML
|
||||
,
|
||||
'expectedHtml' => <<<HTML
|
||||
<iframe width="560" height="315"
|
||||
src="https://www.youtube-nocookie.com/embed/aaaaaaaaaaa"
|
||||
title="YouTube video player"
|
||||
frameborder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allowfullscreen>
|
||||
</iframe>
|
||||
HTML
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Test\Unit\Model\User;
|
||||
|
||||
use Magento\Framework\Exception\NotFoundException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\GetUserConsentInterface;
|
||||
use Plumrocket\CookieConsent\Model\User\IsOptIn;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class IsOptInTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|\Plumrocket\CookieConsent\Api\GetUserConsentInterface
|
||||
*/
|
||||
private $getUserConsentMock;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\IsUserOptInInterface
|
||||
*/
|
||||
private $isOptInModel;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->getUserConsentMock = $this->createMock(GetUserConsentInterface::class);
|
||||
|
||||
$this->isOptInModel = new IsOptIn($this->getUserConsentMock);
|
||||
}
|
||||
|
||||
public function testNotHaveConsent()
|
||||
{
|
||||
$this->getUserConsentMock
|
||||
->method('execute')
|
||||
->willThrowException(new NotFoundException(__('User didnt make any consents.')));
|
||||
|
||||
$this->assertFalse($this->isOptInModel->execute());
|
||||
}
|
||||
|
||||
public function testHaveConsent()
|
||||
{
|
||||
$this->getUserConsentMock
|
||||
->method('execute')
|
||||
->willReturn(['test_essential', 'test_marketing']);
|
||||
|
||||
$this->assertTrue($this->isOptInModel->execute());
|
||||
}
|
||||
|
||||
public function testHaveAllConsent()
|
||||
{
|
||||
$this->getUserConsentMock
|
||||
->method('execute')
|
||||
->willReturn([CategoryInterface::ALL_CATEGORIES]);
|
||||
|
||||
$this->assertTrue($this->isOptInModel->execute());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user