You are here

protected function ContentEntityNormalizerTestBase::getContentEntity in Facebook Instant Articles 3.x

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

Get a content entity to test with.

Parameters

string $class_name: Type of content entity to create.

string $relative_uri: Relative URI of the created entity, eg. /node/1.

string $label: Entity label.

int $created_timestamp: UNIX timestamp for created.

int $changed_timestamp: UNIX timestamp for changed.

string $author_name: Display name for the author of the returned entity.

Return value

\Drupal\Core\Entity\ContentEntityInterface Content entity stub.

3 calls to ContentEntityNormalizerTestBase::getContentEntity()
InstantArticleContentEntityNormalizerTest::testNormalize in tests/src/Unit/InstantArticleContentEntityNormalizerTest.php
Tests the normalize() method.
InstantArticleContentEntityNormalizerTest::testNormalizeRtl in tests/src/Unit/InstantArticleContentEntityNormalizerTest.php
Tests the normalize method on an RTL site.
InstantArticleRssContentEntityNormalizerTest::testNormalize in tests/src/Unit/InstantArticleRssContentEntityNormalizerTest.php
Tests the normalize() method.

File

tests/src/Unit/ContentEntityNormalizerTestBase.php, line 41

Class

ContentEntityNormalizerTestBase
Base class for Instant Articles content entity normalizers.

Namespace

Drupal\Tests\fb_instant_articles\Unit

Code

protected function getContentEntity($class_name, $relative_uri, $label, $created_timestamp, $changed_timestamp, $author_name) {

  // Mock a URL object for getUrl method to return.
  $url = $this
    ->getMockBuilder(Url::class)
    ->disableOriginalConstructor()
    ->getMock();
  $url
    ->method('toString')
    ->willReturn($relative_uri);

  // Mock an entity according to the given class name. For some tests, we want
  // to be more specific than ContentEntityInterface.
  $entity = $this
    ->createMock($class_name);
  $entity
    ->method('toUrl')
    ->willReturn($url);
  $entity
    ->method('label')
    ->willReturn($label);

  // Mock created timestamp return.
  $created = $this
    ->createMock(FieldItemListInterface::class);
  $created
    ->method('__get')
    ->willReturnMap([
    [
      'value',
      $created_timestamp,
    ],
  ]);
  $entity
    ->method('get')
    ->willReturnMap([
    [
      'created',
      $created,
    ],
  ]);
  $entity
    ->method('getChangedTime')
    ->willReturn($changed_timestamp);
  $author = $this
    ->createMock(UserInterface::class);
  $author
    ->method('getDisplayName')
    ->willReturn($author_name);
  $entity
    ->method('getOwner')
    ->willReturn($author);
  return $entity;
}