Skip to content

Commit

Permalink
Review from @dmolineus
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Jul 17, 2020
1 parent fba7c23 commit a1d0532
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 6 deletions.
4 changes: 2 additions & 2 deletions core-bundle/src/DependencyInjection/Configuration.php
Expand Up @@ -73,7 +73,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->booleanNode('prepend_locale')
->info('Whether or not to add the page language to the URL.')
->setDeprecated('The language prefix is configured per root page since Contao 4.10')
->setDeprecated('The language prefix is configured per root page since Contao 4.10. Enabling this option will activate legacy routing.')
->end()
->booleanNode('pretty_error_screens')
->info('Show customizable, pretty error screens instead of the default PHP error messages.')
Expand Down Expand Up @@ -108,7 +108,7 @@ static function (string $v): int {
->defaultValue('css,csv,html,ini,js,json,less,md,scss,svg,svgz,txt,xliff,xml,yml,yaml')
->end()
->scalarNode('url_suffix')
->setDeprecated('The URL suffix is configured per root page since Contao 4.10')
->setDeprecated('The URL suffix is configured per root page since Contao 4.10. Enabling this option will activate legacy routing.')
->end()
->scalarNode('web_dir')
->info('Absolute path to the web directory. Defaults to %kernel.project_dir%/web.')
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Event/FilterPageTypeEvent.php
Expand Up @@ -39,7 +39,7 @@ public function getDataContainer(): DataContainer

public function getOptions(): array
{
return $this->options;
return array_values($this->options);
}

public function setOptions(array $options): self
Expand Down
15 changes: 12 additions & 3 deletions core-bundle/src/Exception/ContentRouteNotFoundException.php
Expand Up @@ -18,12 +18,21 @@

class ContentRouteNotFoundException extends RouteNotFoundException
{
private $content;

public function __construct($content, $code = 0, \Throwable $previous = null)
{
parent::__construct('No route found for '.static::getRouteDebugMessage($content), $code, $previous);
parent::__construct('No route found for '.$this->getRouteDebugMessage($content), $code, $previous);

$this->content = $content;
}

public function getContent()
{
return $this->content;
}

public static function getRouteDebugMessage($content): string
private function getRouteDebugMessage($content): string
{
if (is_scalar($content)) {
return $content;
Expand All @@ -45,6 +54,6 @@ public static function getRouteDebugMessage($content): string
return \get_class($content);
}

return 'null route';
return 'unknown route';
}
}
6 changes: 6 additions & 0 deletions core-bundle/src/Resources/contao/languages/en/tl_page.xlf
Expand Up @@ -14,6 +14,12 @@
<trans-unit id="tl_page.alias.1">
<source>The page alias is a unique reference to the page which can be called instead of its numeric ID.</source>
</trans-unit>
<trans-unit id="tl_page.alias.0">
<source>URL parameters</source>
</trans-unit>
<trans-unit id="tl_page.alias.1">
<source>URL parameters are placeholders for the current reader page item, e.g. a news alias. Refer to the current page type for available parameters.</source>
</trans-unit>
<trans-unit id="tl_page.type.0">
<source>Page type</source>
</trans-unit>
Expand Down
93 changes: 93 additions & 0 deletions core-bundle/tests/Event/FilterPageTypeEventTest.php
@@ -0,0 +1,93 @@
<?php

namespace Contao\CoreBundle\Tests\Event;

use Contao\CoreBundle\Event\FilterPageTypeEvent;
use Contao\DataContainer;
use PHPUnit\Framework\TestCase;

class FilterPageTypeEventTest extends TestCase
{
public function testReturnsDataContainer(): void
{
$dc = $this->createMock(DataContainer::class);

$event = new FilterPageTypeEvent([], $dc);

$this->assertSame($dc, $event->getDataContainer());
}

public function testReturnsOptionsWithNumericKeys(): void
{
$dc = $this->createMock(DataContainer::class);

$event = new FilterPageTypeEvent(['foo' => 'bar'], $dc);

$this->assertSame(['bar'], $event->getOptions());
}

public function testCanAddOption(): void
{
$dc = $this->createMock(DataContainer::class);

$event = new FilterPageTypeEvent([], $dc);

$this->assertSame([], $event->getOptions());

$event->addOption('foo');

$this->assertSame(['foo'], $event->getOptions());
}

public function testDoesNotAddDuplicateOptions(): void
{
$dc = $this->createMock(DataContainer::class);

$event = new FilterPageTypeEvent(['foo'], $dc);

$this->assertSame(['foo'], $event->getOptions());

$event->addOption('foo');

$this->assertSame(['foo'], $event->getOptions());
}

public function testCanSetOptions(): void
{
$dc = $this->createMock(DataContainer::class);

$event = new FilterPageTypeEvent(['foo'], $dc);

$this->assertSame(['foo'], $event->getOptions());

$event->setOptions(['foo' => 'bar']);

$this->assertSame(['bar'], $event->getOptions());
}

public function testCanRemoveOption(): void
{
$dc = $this->createMock(DataContainer::class);

$event = new FilterPageTypeEvent(['foo'], $dc);

$this->assertSame(['foo'], $event->getOptions());

$event->removeOption('foo');

$this->assertSame([], $event->getOptions());
}

public function testIgnoresMissingWhenRemovingOptions(): void
{
$dc = $this->createMock(DataContainer::class);

$event = new FilterPageTypeEvent(['foo'], $dc);

$this->assertSame(['foo'], $event->getOptions());

$event->removeOption('bar');

$this->assertSame(['foo'], $event->getOptions());
}
}

0 comments on commit a1d0532

Please sign in to comment.