Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into 3.x-into-4.x

� Conflicts:
�	composer.json
�	tests/Page/TemplateManagerTest.php
  • Loading branch information
eerison committed Aug 18, 2022
2 parents 4d2c5c1 + 728cc5b commit af3f022
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Resources/views/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ file that was distributed with this source code.
</div>

{% block sonata_page_breadcrumb %}
<div class="row">
<div class="row page-breadcrumb">
{{ sonata_block_render_event('breadcrumb', { 'context': 'page', 'current_uri': app.request.requestUri }) }}
</div>
{% endblock %}
Expand Down
50 changes: 48 additions & 2 deletions tests/Page/TemplateManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

namespace Sonata\PageBundle\Tests\Page;

use PHPUnit\Framework\TestCase;
use Sonata\PageBundle\Model\Template;
use Sonata\PageBundle\Page\TemplateManager;
use Sonata\PageBundle\Tests\App\AppKernel;
use Twig\Environment;

final class TemplateManagerTest extends TestCase
final class TemplateManagerTest extends KernelTestCase
{
public function testAddSingleTemplate(): void
{
Expand Down Expand Up @@ -136,6 +136,52 @@ public function testRenderResponseWithDefaultParameters(): void
);
}

/**
* NEXT_MAJOR: Remove the legacy group.
*
* @group legacy
*/
public function testTemplateShowingBreadcrumbIntoThePage(): void
{
$kernel = self::bootKernel();
$container = $kernel->getContainer();

$requestStack = new RequestStack();
$requestStack->push(new Request());
$container->set('request_stack', $requestStack);

//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);
$container->set('sonata.page.cms.snapshot', $cmsSnapshotManagerMock);

//NEXT_MAJOR: change for twig
$templating = $container->get('templating');

$manager = new TemplateManager($templating, []);
$response = $manager->renderResponse('test');
$crawler = new Crawler($response->getContent());

static::assertCount(1, $crawler->filter('.page-breadcrumb'));

$breadcrumbFoo = $crawler->filter('.page-breadcrumb')->filter('a');
static::assertSame('/', $breadcrumbFoo->attr('href'));
static::assertStringContainsString('Foo', $breadcrumbFoo->text());
}

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);
Expand Down

0 comments on commit af3f022

Please sign in to comment.