Commit d9650568 authored by Tino Goratsch's avatar Tino Goratsch

unit tests

parent 4ed1d563
<?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\Breadcrumb;
use ACP3\Core\Breadcrumb\Steps;
use ACP3\Core\Controller\AreaEnum;
use ACP3\Core\Http\Request;
use ACP3\Core\I18n\Translator;
use ACP3\Core\Router;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\EventDispatcher\EventDispatcher;
class StepsTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $containerMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $translatorMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $requestMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $routerMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $eventDispatcherMock;
/**
* @var \ACP3\Core\Breadcrumb\Steps
*/
private $steps;
protected function setUp()
{
$this->initializeMockObjects();
$this->steps = new Steps(
$this->containerMock,
$this->translatorMock,
$this->requestMock,
$this->routerMock,
$this->eventDispatcherMock
);
}
protected function initializeMockObjects()
{
$this->containerMock = $this->getMockBuilder(Container::class)
->disableOriginalConstructor()
->getMock();
$this->translatorMock = $this->getMockBuilder(Translator::class)
->disableOriginalConstructor()
->getMock();
$this->requestMock = $this->getMockBuilder(Request::class)
->disableOriginalConstructor()
->getMock();
$this->routerMock = $this->getMockBuilder(Router::class)
->disableOriginalConstructor()
->getMock();
$this->eventDispatcherMock = $this->getMockBuilder(EventDispatcher::class)
->disableOriginalConstructor()
->getMock();
}
public function testGetBreadcrumbForAdminControllerIndex()
{
$this->setUpRequestMockExpectations(
AreaEnum::AREA_ADMIN,
'foo',
'index',
'index'
);
$this->setUpRouterMockExpectations('acp/foo');
$this->setUpTranslatorMockExpectations('foo', 'foo');
$expected = [
[
'title' => '{FOO_FOO}',
'uri' => '/acp/foo',
'last' => true
]
];
$this->assertEquals($expected, $this->steps->getBreadcrumb());
}
private function setUpRequestMockExpectations($area, $moduleName, $controller, $action)
{
$this->requestMock->expects($this->atLeastOnce())
->method('getArea')
->willReturn($area);
$this->requestMock->expects($this->atLeastOnce())
->method('getModule')
->willReturn($moduleName);
$this->requestMock->expects($this->atLeastOnce())
->method('getController')
->willReturn($controller);
$this->requestMock->expects($this->atLeastOnce())
->method('getAction')
->willReturn($action);
}
/**
* @param string $serviceId
* @param bool $serviceExists
*/
private function setUpContainerMockExpectations($serviceId, $serviceExists)
{
$this->containerMock->expects($this->once())
->method('has')
->with($serviceId)
->willReturn($serviceExists);
}
private function setUpRouterMockExpectations($path)
{
$this->routerMock->expects($this->atLeastOnce())
->method('route')
->with($path)
->willReturn('/' . $path);
}
private function setUpTranslatorMockExpectations($moduleName, $phrase)
{
$this->translatorMock->expects($this->atLeastOnce())
->method('t')
->with($moduleName, $phrase)
->willReturn(strtoupper('{' . $moduleName . '_' . $phrase . '}'));
}
}
......@@ -16,15 +16,15 @@ class TitleTest extends \PHPUnit_Framework_TestCase
/**
* @var \ACP3\Core\Breadcrumb\Title
*/
private $title;
protected $title;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $stepsMock;
protected $stepsMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $eventDispatcherMock;
protected $eventDispatcherMock;
protected function setUp()
{
......@@ -36,7 +36,7 @@ class TitleTest extends \PHPUnit_Framework_TestCase
);
}
private function initializeMockObjects()
protected function initializeMockObjects()
{
$this->stepsMock = $this->getMockBuilder(Steps::class)
->disableOriginalConstructor()
......@@ -46,14 +46,14 @@ class TitleTest extends \PHPUnit_Framework_TestCase
->getMock();
}
public function testGetSiteAndPageTitleWithEmptySiteTitle()
public function testGetSiteAndPageTitleWithNoCustomSiteTitle()
{
$this->setUpStepsExpectations(1);
$this->assertEquals('Foo', $this->title->getSiteAndPageTitle());
}
private function setUpStepsExpectations($callCount)
protected function setUpStepsExpectations($callCount)
{
$steps = [
[
......@@ -67,7 +67,7 @@ class TitleTest extends \PHPUnit_Framework_TestCase
->willReturn($steps);
}
public function testGetSiteAndPageTitleWithNotEmptySiteTitle()
public function testGetSiteAndPageTitleWithCustomSiteTitle()
{
$this->setUpStepsExpectations(1);
......
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Modules\ACP3\Seo\Test\Core\Breadcrumb;
use ACP3\Core\Config;
use ACP3\Modules\ACP3\Seo\Core\Breadcrumb\Title;
class TitleTest extends \ACP3\Core\Test\Breadcrumb\TitleTest
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $configMock;
protected function setUp()
{
$this->initializeMockObjects();
$this->title = new Title(
$this->stepsMock,
$this->eventDispatcherMock,
$this->configMock
);
}
protected function initializeMockObjects()
{
parent::initializeMockObjects();
$this->configMock = $this->getMockBuilder(Config::class)
->disableOriginalConstructor()
->getMock();
$this->configMock->expects($this->once())
->method('getSettings')
->with('seo')
->willReturn([
'title' => 'SEO Title'
]);
}
public function testGetSiteAndPageTitleWithNoCustomSiteTitle()
{
$this->setUpStepsExpectations(1);
$this->assertEquals('Foo | SEO Title', $this->title->getSiteAndPageTitle());
}
}
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