Commit 2ff3752a authored by Tino Goratsch's avatar Tino Goratsch

- Added an explicit breadcrumb to the imprint controller action of the contact...

- Added an explicit breadcrumb to the imprint controller action of the contact module, as the imprint is not directly associated with the contact form
- The titles of the programmatically breadcrumb steps now always take precedence over the ones from the database
parent f19644b6
......@@ -119,13 +119,15 @@ class StepsTest extends \PHPUnit_Framework_TestCase
$this->requestMock->expects($this->any())
->method('getModuleAndController')
->willReturn(
($area === AreaEnum::AREA_ADMIN ? 'acp/' : '') . $moduleName . '/' . $controller
($area === AreaEnum::AREA_ADMIN ? 'acp/' : '') . $moduleName . '/' . $controller . '/'
);
$this->requestMock->expects($this->any())
->method('getFullPath')
->willReturn(
($area === AreaEnum::AREA_ADMIN ? 'acp/' : '') . $moduleName . '/' . $controller . '/' . $action
($area === AreaEnum::AREA_ADMIN ? 'acp/' : '') . $moduleName . '/' . $controller . '/' . $action . '/'
);
$parameters .= preg_match('=/$=', $parameters) ? '' : '/';
$this->requestMock->expects($this->any())
->method('getQuery')
->willReturn($moduleName . '/' . $controller . '/' . $action . '/' . $parameters);
......
......@@ -75,12 +75,17 @@ class Steps extends Core\Breadcrumb\Steps
}
if (!empty($this->stepsFromDb)) {
$this->breadcrumbCache = $this->stepsFromDb;
$lastDbStepUri = $this->stepsFromDb[count($this->stepsFromDb) - 1]['uri'];
if ($this->breadcrumbCache[count($this->breadcrumbCache) - 1]['uri'] === $this->steps[0]['uri']) {
$steps = $this->steps;
unset($steps[0]);
$this->breadcrumbCache = array_merge($this->breadcrumbCache, $steps);
if (count($this->steps) === 1 && empty($this->steps[0]['uri'])) {
$this->copyTitleFromFirstStepToLastDbStep();
$this->steps[0]['uri'] = $lastDbStepUri;
}
if ($lastDbStepUri === $this->steps[0]['uri']) {
$this->copyTitleFromFirstStepToLastDbStep();
$this->breadcrumbCache = array_merge($this->stepsFromDb, array_slice($this->steps, 1));
}
}
}
......@@ -90,7 +95,7 @@ class Steps extends Core\Breadcrumb\Steps
*/
private function prePopulate()
{
$items = $this->menuItemRepository->getMenuItemsByUri($this->possibleMatchedRoutes());
$items = $this->menuItemRepository->getMenuItemsByUri($this->getPossiblyMatchingRoutes());
$matches = $this->findRestrictionInRoutes($items);
if (!empty($matches)) {
......@@ -104,7 +109,7 @@ class Steps extends Core\Breadcrumb\Steps
}
}
private function possibleMatchedRoutes() {
private function getPossiblyMatchingRoutes() {
return [
$this->request->getQuery(),
$this->request->getUriWithoutPages(),
......@@ -122,7 +127,7 @@ class Steps extends Core\Breadcrumb\Steps
{
rsort($items);
foreach ($items as $index => $item) {
if (in_array($item['uri'], $this->possibleMatchedRoutes())) {
if (in_array($item['uri'], $this->getPossiblyMatchingRoutes())) {
return [
$item['left_id'],
$item['right_id'],
......@@ -147,4 +152,9 @@ class Steps extends Core\Breadcrumb\Steps
return $this;
}
private function copyTitleFromFirstStepToLastDbStep()
{
$this->stepsFromDb[count($this->stepsFromDb) - 1]['title'] = $this->steps[0]['title'];
}
}
......@@ -69,7 +69,7 @@ class StepsTest extends \ACP3\Core\Test\Breadcrumb\StepsTest
$expected = [
[
'title' => 'News',
'title' => '{NEWS_NEWS}',
'uri' => '/news/',
'last' => true
]
......@@ -108,7 +108,7 @@ class StepsTest extends \ACP3\Core\Test\Breadcrumb\StepsTest
'uri' => '/news/',
],
[
'title' => 'Newsletter',
'title' => '{NEWSLETTER_NEWSLETTER}',
'uri' => '/newsletter/',
'last' => true
],
......@@ -147,7 +147,7 @@ class StepsTest extends \ACP3\Core\Test\Breadcrumb\StepsTest
'uri' => '/news/',
],
[
'title' => 'Newsletter',
'title' => '{NEWSLETTER_NEWSLETTER}',
'uri' => '/newsletter/',
],
[
......@@ -180,7 +180,7 @@ class StepsTest extends \ACP3\Core\Test\Breadcrumb\StepsTest
$this->setUpTranslatorMockExpectations(0);
$this->steps->append('News', 'news');
$this->steps->append('Category', 'news/index/index/cat_' . 1);
$this->steps->append('Category', 'news/index/index/cat_1');
$this->steps->append('News-Title');
$expected = [
......@@ -190,7 +190,7 @@ class StepsTest extends \ACP3\Core\Test\Breadcrumb\StepsTest
],
[
'title' => 'Category',
'uri' => '/news/index/index/cat_' . 1 . '/',
'uri' => '/news/index/index/cat_1/',
],
[
'title' => 'News-Title',
......@@ -201,6 +201,70 @@ class StepsTest extends \ACP3\Core\Test\Breadcrumb\StepsTest
$this->assertEquals($expected, $this->steps->getBreadcrumb());
}
public function testGetBreadcrumbLastStepTitleShouldTakePrecedence()
{
$this->setUpMenuItemRepositoryExpectations([
[
'title' => 'FooBar',
'uri' => 'articles/index/details/id_1/',
'left_id' => 1,
'right_id' => 2
]
]);
$this->setUpRequestMockExpectations(
AreaEnum::AREA_FRONTEND,
'articles',
'index',
'details',
'id_1'
);
$this->setUpRouterMockExpectations();
$this->setUpTranslatorMockExpectations(0);
$this->steps->append('Lorem Ipsum Dolor', 'articles/index/details/id_1');
$expected = [
[
'title' => 'Lorem Ipsum Dolor',
'uri' => '/articles/index/details/id_1/',
'last' => true
],
];
$this->assertEquals($expected, $this->steps->getBreadcrumb());
}
public function testGetBreadcrumbLastStepTitleShouldTakePrecedenceWithEmptyUri()
{
$this->setUpMenuItemRepositoryExpectations([
[
'title' => 'FooBar',
'uri' => 'articles/index/details/id_1/',
'left_id' => 1,
'right_id' => 2
]
]);
$this->setUpRequestMockExpectations(
AreaEnum::AREA_FRONTEND,
'articles',
'index',
'details',
'id_1'
);
$this->setUpRouterMockExpectations();
$this->setUpTranslatorMockExpectations(0);
$this->steps->append('Lorem Ipsum Dolor');
$expected = [
[
'title' => 'Lorem Ipsum Dolor',
'uri' => '/articles/index/details/id_1/',
'last' => true
],
];
$this->assertEquals($expected, $this->steps->getBreadcrumb());
}
public function testGetBreadcrumbForFrontendControllerIndex()
{
$this->setUpMenuItemRepositoryExpectations();
......
......@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [4.x.y] - 2017-xx-yy
### Changed
- Added an explicit breadcrumb to the imprint controller action of the contact module, as the imprint is not directly associated with the contact form
- The titles of the programmatically breadcrumb steps now always take precedence over the ones from the database
## [4.13.1] - 2017-10-21
### Fixed
- Fixed the inability to create a new menu item which should not be displayed
......
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