You are here

public function PageContextTest::testPopulateHtmlHeadWithNodeAndArrayTitle in Acquia Lift Connector 8.3

Same name and namespace in other branches
  1. 8.4 tests/src/Unit/Service/Context/PageContextTest.php \Drupal\Tests\acquia_lift\Unit\Service\Context\PageContextTest::testPopulateHtmlHeadWithNodeAndArrayTitle()

Tests the populate() method, populateHtmlHead() sub method, with a Node and array title.

@covers ::populate

File

tests/src/Unit/Service/Context/PageContextTest.php, line 363

Class

PageContextTest
PageContextTest Test.

Namespace

Drupal\Tests\acquia_lift\Unit\Service\Context

Code

public function testPopulateHtmlHeadWithNodeAndArrayTitle() {
  $this->requestParameterBag
    ->expects($this
    ->once())
    ->method('has')
    ->with('node')
    ->willReturn(TRUE);
  $this->requestParameterBag
    ->expects($this
    ->once())
    ->method('get')
    ->with('node')
    ->willReturn($this
    ->getNode());
  $this->titleResolver
    ->expects($this
    ->once())
    ->method('getTitle')
    ->with($this->request, $this->route)
    ->willReturn([
    '#markup' => 'My Title from Title Resolver <a><a/><script></script><br />',
    '#allowed_tags' => [
      'br',
    ],
  ]);

  // Language mock
  $this->language
    ->expects($this
    ->any())
    ->method('getCurrentLanguage')
    ->willReturn($this->languageInterface);
  $page_context = new PageContext($this->configFactory, $this->entityTypeManager, $this->requestStack, $this->routeMatch, $this->titleResolver, $this->language);
  $page = [];
  $page_context
    ->populate($page);
  $expected_head = $this
    ->toRenderArray([
    'content_title' => 'My Title from Title Resolver <br />',
    'content_type' => 'article',
    'page_type' => 'node page',
    'context_language' => 'fr',
    'content_section' => '',
    'content_keywords' => '',
    'post_id' => '90210',
    'content_uuid' => 'ecf826eb-3ef0-4aa6-aae2-9f6e5886bbb6',
    'published_date' => 'a_published_time',
    'persona' => '',
    'engagement_score' => PageContext::ENGAGEMENT_SCORE_DEFAULT,
    'account_id' => 'AccountId1',
    'site_id' => 'SiteId1',
    'contentOrigin' => '08c93130-2e45-45f6-af6d-7c02de8cd90c',
    'userAccess' => 'user_access_1',
    'liftAssetsURL' => 'AssetsUrl1',
    'liftDecisionAPIURL' => 'decision_api_url_1',
    'authEndpoint' => 'oauth_url_1',
    'bootstrapMode' => 'manual',
    'contentReplacementMode' => 'customized',
  ], 'AssetsUrl1');
  $this
    ->assertEquals($expected_head, $page['#attached']['html_head']);
}