class InstantArticleRssContentEntityNormalizerTest in Facebook Instant Articles 3.x
Same name and namespace in other branches
- 8.2 tests/src/Unit/InstantArticleRssContentEntityNormalizerTest.php \Drupal\Tests\fb_instant_articles\Unit\InstantArticleRssContentEntityNormalizerTest
Tests the fbia content entity normalizer class.
@coversDefaultClass \Drupal\fb_instant_articles\Normalizer\InstantArticleRssContentEntityNormalizer
@group fb_instant_articles
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\fb_instant_articles\Unit\ContentEntityNormalizerTestBase
- class \Drupal\Tests\fb_instant_articles\Unit\InstantArticleRssContentEntityNormalizerTest
- class \Drupal\Tests\fb_instant_articles\Unit\ContentEntityNormalizerTestBase
Expanded class hierarchy of InstantArticleRssContentEntityNormalizerTest
File
- tests/
src/ Unit/ InstantArticleRssContentEntityNormalizerTest.php, line 19
Namespace
Drupal\Tests\fb_instant_articles\UnitView source
class InstantArticleRssContentEntityNormalizerTest extends ContentEntityNormalizerTestBase {
/**
* Tests the supportsNormalization() method.
*
* @covers ::supportsNormalization
*/
public function testSupportsNormalization() {
$content_entity = $this
->getMockBuilder(ContentEntityInterface::class)
->disableOriginalConstructor()
->getMock();
$config_entity = $this
->getMockBuilder(ConfigEntityInterface::class)
->disableOriginalConstructor()
->getMock();
$normalizer = $this
->getContentEntityNormalizer();
$this
->assertFalse($normalizer
->supportsNormalization($content_entity, 'fbia'));
$this
->assertTrue($normalizer
->supportsNormalization($content_entity, 'fbia_rss'));
$this
->assertFalse($normalizer
->supportsNormalization($content_entity, 'json'));
$this
->assertFalse($normalizer
->supportsNormalization($config_entity, 'fbia'));
}
/**
* Tests the normalize() method.
*
* @covers ::normalize
*/
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);
}
/**
* Helper function to create a new FBIA RSS normalizer for testing.
*
* @param array $settings
* Global config settings.
* @param array $components
* Entity view display components.
*
* @return \Drupal\fb_instant_articles\Normalizer\InstantArticleContentEntityNormalizer
* Content entity normalizer object to test against.
*/
protected function getContentEntityNormalizer(array $settings = [], array $components = []) {
$config_factory = $this
->getConfigFactoryStub([
'fb_instant_articles.settings' => $settings,
]);
$content_entity_normalizer = $this
->getMockBuilder(InstantArticleRssContentEntityNormalizer::class)
->setConstructorArgs([
$config_factory,
])
->addMethods([
'getApplicableComponents',
'getApplicationVersion',
])
->getMock();
$content_entity_normalizer
->method('getApplicableComponents')
->willReturn($components);
$content_entity_normalizer
->method('getApplicationVersion')
->willReturn('8.x-2.x');
$serializer = $this
->createMock(Serializer::class);
$serializer
->method('normalize')
->willReturn(InstantArticle::create());
$content_entity_normalizer
->setSerializer($serializer);
return $content_entity_normalizer;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentEntityNormalizerTestBase:: |
protected | property | Mock current language. | |
ContentEntityNormalizerTestBase:: |
protected | function | Get a content entity to test with. | |
InstantArticleRssContentEntityNormalizerTest:: |
protected | function | Helper function to create a new FBIA RSS normalizer for testing. | |
InstantArticleRssContentEntityNormalizerTest:: |
public | function | Tests the normalize() method. | |
InstantArticleRssContentEntityNormalizerTest:: |
public | function | Tests the supportsNormalization() method. | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 308 | |
UnitTestCase:: |
public static | function |