Skip to content

Commit

Permalink
Rename page controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Jul 10, 2020
1 parent 04f50f1 commit c4b004b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
Expand Up @@ -26,7 +26,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Route;

class RootController extends AbstractController implements PageRouteEnhancerInterface, CompositionAwareInterface
class RootPageController extends AbstractController implements PageRouteEnhancerInterface, CompositionAwareInterface
{
/**
* @var ContaoFramework
Expand Down
Expand Up @@ -139,6 +139,10 @@ private function getPageType(string $className, array $attributes): string
$className = substr($className, 0, -10);
}

if ('Page' === substr($className, -4)) {
$className = substr($className, 0, -4);
}

return Container::underscore($className);
}
}
2 changes: 1 addition & 1 deletion core-bundle/src/Resources/config/controller.yml
Expand Up @@ -3,7 +3,7 @@ services:
autoconfigure: true
public: true

Contao\CoreBundle\Controller\Page\RootController:
Contao\CoreBundle\Controller\Page\RootPageController:
arguments:
- '@contao.framework'
- '@database_connection'
Expand Down
Expand Up @@ -12,7 +12,7 @@

namespace Contao\CoreBundle\Tests\Controller\Page;

use Contao\CoreBundle\Controller\Page\RootController;
use Contao\CoreBundle\Controller\Page\RootPageController;
use Contao\CoreBundle\Exception\NoActivePageFoundException;
use Contao\CoreBundle\Framework\Adapter;
use Contao\CoreBundle\Routing\Page\CompositionAwareInterface;
Expand All @@ -28,7 +28,7 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class RootControllerTest extends TestCase
class RootPageControllerTest extends TestCase
{
/**
* @var PageModel|Adapter|MockObject
Expand All @@ -46,7 +46,7 @@ class RootControllerTest extends TestCase
private $router;

/**
* @var RootController
* @var RootPageController
*/
private $controller;

Expand All @@ -65,7 +65,7 @@ protected function setUp(): void
->willReturn($this->router)
;

$this->controller = new RootController($framework, $this->connection);
$this->controller = new RootPageController($framework, $this->connection);
$this->controller->setContainer($container);
}

Expand Down
Expand Up @@ -13,6 +13,7 @@
namespace Contao\CoreBundle\Tests\DependencyInjection\Compiler;

use Contao\CoreBundle\ContaoCoreBundle;
use Contao\CoreBundle\Controller\FrontendModule\TwoFactorController;
use Contao\CoreBundle\Controller\Page\RootPageController;
use Contao\CoreBundle\DependencyInjection\Compiler\RegisterPagesPass;
use Contao\CoreBundle\Routing\Page\PageRegistry;
Expand Down Expand Up @@ -100,6 +101,33 @@ static function ($arguments) {
}

public function testStripsControllerSuffixOnGetPageTypeFromClass(): void
{
$registry = $this->createMock(Definition::class);
$registry
->expects($this->once())
->method('addMethodCall')
->with(
'add',
$this->callback(
static function ($arguments) {
return 'two_factor' === $arguments[0];
}
)
)
;

$definition = new Definition(TwoFactorController::class);
$definition->addTag('contao.page');

$container = new ContainerBuilder();
$container->setDefinition(PageRegistry::class, $registry);
$container->setDefinition('test.controller', $definition);

$pass = new RegisterPagesPass();
$pass->process($container);
}

public function testStripsPageControllerSuffixOnGetPageTypeFromClass(): void
{
$registry = $this->createMock(Definition::class);
$registry
Expand Down

0 comments on commit c4b004b

Please sign in to comment.