public function InstantArticleContentEntityNormalizerTest::testNormalize in Facebook Instant Articles 3.x
Same name in this branch
- 3.x tests/src/Unit/InstantArticleContentEntityNormalizerTest.php \Drupal\Tests\fb_instant_articles\Unit\InstantArticleContentEntityNormalizerTest::testNormalize()
- 3.x tests/src/Kernel/InstantArticleContentEntityNormalizerTest.php \Drupal\Tests\fb_instant_articles\Kernel\InstantArticleContentEntityNormalizerTest::testNormalize()
Same name and namespace in other branches
- 8.2 tests/src/Unit/InstantArticleContentEntityNormalizerTest.php \Drupal\Tests\fb_instant_articles\Unit\InstantArticleContentEntityNormalizerTest::testNormalize()
Tests the normalize() method.
@covers ::normalize
File
- tests/
src/ Unit/ InstantArticleContentEntityNormalizerTest.php, line 53
Class
- InstantArticleContentEntityNormalizerTest
- Tests the fbia content entity normalizer class.
Namespace
Drupal\Tests\fb_instant_articles\UnitCode
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();
$entity = $this
->getContentEntity(NodeInterface::class, '/node/1', 'Test entity', $now, $now, 'Joe Mayo');
$article = $normalizer
->normalize($entity, 'fbia');
$this
->assertTrue($article instanceof InstantArticle);
$this
->assertEquals('http://example.com/node/1', $article
->getCanonicalURL());
$this
->assertEquals('Test entity', $article
->getHeader()
->getTitle()
->getPlainText());
$this
->assertEquals($now, $article
->getHeader()
->getPublished()
->getDatetime()
->format('U'));
$this
->assertEquals($now, $article
->getHeader()
->getModified()
->getDatetime()
->format('U'));
$this
->assertEquals('Joe Mayo', $article
->getHeader()
->getAuthors()[0]
->getName());
$children = $article
->getChildren();
/** @var \Facebook\InstantArticles\Elements\Analytics $analytics */
$analytics = $children[0];
$this
->assertTrue($analytics instanceof Analytics);
$this
->assertEquals('analytics embed code', $analytics
->getHtml()->ownerDocument
->saveHTML($analytics
->getHtml()));
$ads = $article
->getHeader()
->getAds();
$this
->assertEquals(1, count($ads));
$this
->assertEquals($ads[0]
->getWidth(), 300);
$this
->assertEquals($ads[0]
->getHeight(), 250);
$this
->assertEquals($ads[0]
->getSource(), 'http://example.com');
}