You are here

public function InstantArticleRssContentEntityNormalizerTest::testNormalize in Facebook Instant Articles 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/InstantArticleRssContentEntityNormalizerTest.php \Drupal\Tests\fb_instant_articles\Unit\InstantArticleRssContentEntityNormalizerTest::testNormalize()

Tests the normalize() method.

@covers ::normalize

File

tests/src/Unit/InstantArticleRssContentEntityNormalizerTest.php, line 46

Class

InstantArticleRssContentEntityNormalizerTest
Tests the fbia content entity normalizer class.

Namespace

Drupal\Tests\fb_instant_articles\Unit

Code

public function testNormalize() {

  // Test the global settings effect on the output.
  $normalizer = $this
    ->getContentEntityNormalizer([
    'canonical_url_override' => 'http://example.com',
    'analytics_embed_code' => 'analytics embed code',
    'ads.type' => 'source_url',
    'ads.iframe_url' => 'http://example.com',
    'ads.dimensions' => '300x250',
  ], []);
  $now = time();
  $now_date = \DateTime::createFromFormat('U', $now);
  $entity = $this
    ->getContentEntity(NodeInterface::class, '/node/1', 'Test entity', $now, $now, 'Joe Mayo');
  $normalized = $normalizer
    ->normalize($entity, 'fbia_rss');
  $this
    ->assertTrue(is_array($normalized));
  $this
    ->assertEquals('http://example.com/node/1', $normalized['link']);
  $this
    ->assertEquals('Test entity', $normalized['title']);
  $this
    ->assertEquals($now_date
    ->format('c'), $normalized['created']);
  $this
    ->assertEquals($now_date
    ->format('c'), $normalized['modified']);
  $this
    ->assertEquals('Joe Mayo', $normalized['author']);
  $this
    ->assertTrue($normalized['content:encoded'] instanceof InstantArticle);
}