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' => '',
'expectedHtml' => '',
];
yield [
'case' => 'Not YouTube iframe html',
'html' => '',
'expectedHtml' => '',
];
yield [
'case' => 'YouTube iframe html',
'html' => <<
HTML
,
'expectedHtml' => <<
HTML
];
}
}