Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Toflar committed Oct 26, 2021
1 parent 902d705 commit 72b18be
Showing 1 changed file with 32 additions and 0 deletions.
Expand Up @@ -12,15 +12,19 @@

namespace Contao\CoreBundle\Tests\Routing\ResponseContext;

use Contao\Controller;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\Routing\ResponseContext\CoreResponseContextFactory;
use Contao\CoreBundle\Routing\ResponseContext\HtmlHeadBag\HtmlHeadBag;
use Contao\CoreBundle\Routing\ResponseContext\JsonLd\ContaoPageSchema;
use Contao\CoreBundle\Routing\ResponseContext\JsonLd\JsonLdManager;
use Contao\CoreBundle\Routing\ResponseContext\ResponseContextAccessor;
use Contao\CoreBundle\Security\Authentication\Token\TokenChecker;
use Contao\Environment;
use Contao\PageModel;
use Contao\System;
use Contao\TestCase\ContaoTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

Expand All @@ -38,6 +42,7 @@ public function testResponseContext(): void
$responseAccessor,
$this->createMock(EventDispatcherInterface::class),
$this->createMock(TokenChecker::class),
$this->createMock(ContaoFramework::class),
);

$responseContext = $factory->createResponseContext();
Expand All @@ -57,6 +62,7 @@ public function testWebpageResponseContext(): void
$responseAccessor,
$this->createMock(EventDispatcherInterface::class),
$this->createMock(TokenChecker::class),
$this->createMock(ContaoFramework::class),
);

$responseContext = $factory->createWebpageResponseContext();
Expand Down Expand Up @@ -93,16 +99,40 @@ public function testContaoWebpageResponseContext(): void
->method('setResponseContext')
;

$controllerAdapter = $this->mockAdapter(['replaceInsertTags']);
$controllerAdapter
->expects($this->once())
->method('replaceInsertTags')
->with('{{link_url::42}}')
->willReturn('de/foobar.html')
;

$environmentAdapter = $this->mockAdapter(['get']);
$environmentAdapter
->expects($this->once())
->method('get')
->with('base')
->willReturn('https://example.com/')
;

$contaoFramework = $this->mockContaoFramework([
Controller::class => $controllerAdapter,
Environment::class => $environmentAdapter,
]);

/** @var PageModel $pageModel */
$pageModel = $this->mockClassWithProperties(PageModel::class);
$pageModel->title = 'My title';
$pageModel->description = 'My description';
$pageModel->robots = 'noindex,nofollow';
$pageModel->enableCanonical = true;
$pageModel->canonicalLink = '{{link_url::42}}';

$factory = new CoreResponseContextFactory(
$responseAccessor,
$this->createMock(EventDispatcherInterface::class),
$this->createMock(TokenChecker::class),
$contaoFramework
);

$responseContext = $factory->createContaoWebpageResponseContext($pageModel);
Expand All @@ -111,6 +141,7 @@ public function testContaoWebpageResponseContext(): void
$this->assertSame('My title', $responseContext->get(HtmlHeadBag::class)->getTitle());
$this->assertSame('My description', $responseContext->get(HtmlHeadBag::class)->getMetaDescription());
$this->assertSame('noindex,nofollow', $responseContext->get(HtmlHeadBag::class)->getMetaRobots());
$this->assertSame('https://example.com/de/foobar.html', $responseContext->get(HtmlHeadBag::class)->getCanonicalUri(new Request()));

$this->assertTrue($responseContext->has(JsonLdManager::class));
$this->assertTrue($responseContext->isInitialized(JsonLdManager::class));
Expand Down Expand Up @@ -146,6 +177,7 @@ public function testDecodingAndCleanupOnContaoResponseContext(): void
$this->createMock(ResponseContextAccessor::class),
$this->createMock(EventDispatcherInterface::class),
$this->createMock(TokenChecker::class),
$this->createMock(ContaoFramework::class),
);

$responseContext = $factory->createContaoWebpageResponseContext($pageModel);
Expand Down

0 comments on commit 72b18be

Please sign in to comment.