Commit fe974e07 authored by Tino Goratsch's avatar Tino Goratsch

- covered the PageCssClasses Smarty filter with unit tests

- removed an unused dependency from the \ACP3\Core\Assets\PageCssClasses class
parent 88545164
......@@ -9,10 +9,6 @@ use ACP3\Core;
*/
class PageCssClasses
{
/**
* @var \ACP3\Core\Breadcrumb\Steps
*/
protected $breadcrumb;
/**
* @var \ACP3\Core\Breadcrumb\Title
*/
......@@ -28,16 +24,13 @@ class PageCssClasses
protected $details;
/**
* @param \ACP3\Core\Breadcrumb\Steps $breadcrumb
* @param \ACP3\Core\Breadcrumb\Title $title
* @param \ACP3\Core\Http\RequestInterface $request
*/
public function __construct(
Core\Breadcrumb\Steps $breadcrumb,
Core\Breadcrumb\Title $title,
Core\Http\RequestInterface $request
) {
$this->breadcrumb = $breadcrumb;
$this->title = $title;
$this->request = $request;
}
......
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Test\View\Renderer\Smarty\Filters;
use ACP3\Core\Controller\AreaEnum;
use ACP3\Core\Http\Request;
use ACP3\Core\Test\View\Renderer\Smarty\AbstractPluginTest;
use ACP3\Core\View\Renderer\Smarty\Filters\PageCssClasses;
class PageCssClassesTest extends AbstractPluginTest
{
/**
* @var PageCssClasses
*/
protected $plugin;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $pageCssClassesMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $requestMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $smartyInternalTemplateMock;
protected function setUp()
{
$this->setUpMockObjects();
$this->plugin = new PageCssClasses(
$this->pageCssClassesMock,
$this->requestMock
);
}
private function setUpMockObjects()
{
$this->pageCssClassesMock = $this->getMockBuilder(\ACP3\Core\Assets\PageCssClasses::class)
->disableOriginalConstructor()
->getMock();
$this->requestMock = $this->getMockBuilder(Request::class)
->disableOriginalConstructor()
->getMock();
$this->smartyInternalTemplateMock = $this->getMockBuilder(\Smarty_Internal_Template::class)
->disableOriginalConstructor()
->getMock();
}
/**
* @return string
*/
protected function getExpectedExtensionName()
{
return 'output';
}
public function testProcessInFrontend()
{
$this->setUpPageCssClassesMockExpectations();
$this->setUpRequestMockExpectations();
$expected = <<<HTML
<html>
<head>
<title>Foobar</title>
</head>
<body class="foo foo-bar-baz foo-bar-pagetitle">
<p>Baz</p>
</body>
</html>
HTML;
$this->assertEquals(
$expected,
$this->plugin->process($this->getTemplateContent(), $this->smartyInternalTemplateMock)
);
}
/**
* @param int $getDetailsCalls
*/
private function setUpPageCssClassesMockExpectations($getDetailsCalls = 1)
{
$this->pageCssClassesMock
->expects($this->once())
->method('getModule')
->willReturn('foo');
$this->pageCssClassesMock
->expects($this->once())
->method('getControllerAction')
->willReturn('foo-bar-baz');
$this->pageCssClassesMock
->expects($this->exactly($getDetailsCalls))
->method('getDetails')
->willReturn('foo-bar-pagetitle');
}
/**
* @param bool $isHomepage
* @param string $area
*/
private function setUpRequestMockExpectations($isHomepage = false, $area = AreaEnum::AREA_FRONTEND)
{
$this->requestMock->expects($area === AreaEnum::AREA_FRONTEND ? $this->once() : $this->never())
->method('isHomepage')
->willReturn($isHomepage);
$this->requestMock->expects($this->once())
->method('getArea')
->willReturn($area);
}
/**
* @return string
*/
private function getTemplateContent()
{
return <<<HTML
<html>
<head>
<title>Foobar</title>
</head>
<body>
<p>Baz</p>
</body>
</html>
HTML;
}
public function testProcessIsHomepage()
{
$this->setUpPageCssClassesMockExpectations(0);
$this->setUpRequestMockExpectations(true);
$expected = <<<HTML
<html>
<head>
<title>Foobar</title>
</head>
<body class="foo foo-bar-baz is-homepage">
<p>Baz</p>
</body>
</html>
HTML;
$this->assertEquals(
$expected,
$this->plugin->process($this->getTemplateContent(), $this->smartyInternalTemplateMock)
);
}
public function testProcessInAdmin()
{
$this->setUpPageCssClassesMockExpectations(0);
$this->setUpRequestMockExpectations(false, AreaEnum::AREA_ADMIN);
$expected = <<<HTML
<html>
<head>
<title>Foobar</title>
</head>
<body class="foo foo-bar-baz in-admin">
<p>Baz</p>
</body>
</html>
HTML;
$this->assertEquals(
$expected,
$this->plugin->process($this->getTemplateContent(), $this->smartyInternalTemplateMock)
);
}
public function testProcessWithNoHtmlBodyTag()
{
$templateContent = <<<HTML
<p>Baz</p>
HTML;
$this->assertEquals(
$templateContent,
$this->plugin->process($templateContent, $this->smartyInternalTemplateMock)
);
}
}
......@@ -45,6 +45,5 @@ services:
core.assets.page_css_classes:
class: ACP3\Core\Assets\PageCssClasses
arguments:
- '@core.breadcrumb'
- '@core.breadcrumb.title'
- '@core.http.request'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment