From 9de96f20c08385b9139a7c70bdf4c4fa8d1dc253 Mon Sep 17 00:00:00 2001 From: Erison Silva Date: Thu, 18 Aug 2022 08:16:22 +0200 Subject: [PATCH] Fix TemplateManagerTest --- src/Resources/views/layout.html.twig | 2 +- tests/Page/TemplateManagerTest.php | 30 +++++++++++++++------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Resources/views/layout.html.twig b/src/Resources/views/layout.html.twig index 9ecd607ca..93f949b81 100644 --- a/src/Resources/views/layout.html.twig +++ b/src/Resources/views/layout.html.twig @@ -19,7 +19,7 @@ file that was distributed with this source code. {% block sonata_page_breadcrumb %} {% endblock %} diff --git a/tests/Page/TemplateManagerTest.php b/tests/Page/TemplateManagerTest.php index d4ae4a6ec..da8440259 100644 --- a/tests/Page/TemplateManagerTest.php +++ b/tests/Page/TemplateManagerTest.php @@ -13,9 +13,17 @@ namespace Sonata\PageBundle\Tests\Page; +use Sonata\PageBundle\CmsManager\CmsSnapshotManager; +use Sonata\PageBundle\Model\PageInterface; +use Sonata\PageBundle\Model\SnapshotManagerInterface; use Sonata\PageBundle\Model\Template; +use Sonata\PageBundle\Model\TransformerInterface; use Sonata\PageBundle\Page\TemplateManager; use Sonata\PageBundle\Tests\App\AppKernel; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Symfony\Component\DomCrawler\Crawler; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Twig\Environment; final class TemplateManagerTest extends KernelTestCase @@ -136,11 +144,6 @@ public function testRenderResponseWithDefaultParameters(): void ); } - /** - * NEXT_MAJOR: Remove the legacy group. - * - * @group legacy - */ public function testTemplateShowingBreadcrumbIntoThePage(): void { $kernel = self::bootKernel(); @@ -150,20 +153,22 @@ public function testTemplateShowingBreadcrumbIntoThePage(): void $requestStack->push(new Request()); $container->set('request_stack', $requestStack); - //Mocking snapshot + // Mocking snapshot $pageMock = $this->createMock(PageInterface::class); $pageMock->method('getName')->willReturn('Foo'); $pageMock->method('getParents')->willReturn([]); $pageMock->method('getUrl')->willReturn('/'); - $cmsSnapshotManagerMock = $this->createMock(CmsSnapshotManager::class); - $cmsSnapshotManagerMock->method('getCurrentPage')->willReturn($pageMock); + // Mock Snapshot manager + $snapshotManagerMock = $this->createMock(SnapshotManagerInterface::class); + $transformerMock = $this->createMock(TransformerInterface::class); + $cmsSnapshotManagerMock = new CmsSnapshotManager($snapshotManagerMock, $transformerMock); + $cmsSnapshotManagerMock->setCurrentPage($pageMock); $container->set('sonata.page.cms.snapshot', $cmsSnapshotManagerMock); - //NEXT_MAJOR: change for twig - $templating = $container->get('templating'); + $twig = $container->get('twig'); - $manager = new TemplateManager($templating, []); + $manager = new TemplateManager($twig, []); $response = $manager->renderResponse('test'); $crawler = new Crawler($response->getContent()); @@ -179,9 +184,6 @@ protected static function getKernelClass(): string return AppKernel::class; } - /** - * Returns the mock template. - */ private function getTemplate(string $name, string $path = 'path/to/file'): Template { return new Template($name, $path);