You are here

abstract class ContentEntityNormalizerTestBase 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

Base class for Instant Articles content entity normalizers.

Hierarchy

Expanded class hierarchy of ContentEntityNormalizerTestBase

File

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

Namespace

Drupal\Tests\fb_instant_articles\Unit
View source
abstract class ContentEntityNormalizerTestBase extends UnitTestCase {

  /**
   * Mock current language.
   *
   * @var \Drupal\Core\Language\Language
   */
  protected $currentLanguage;

  /**
   * Get a content entity to test with.
   *
   * @param string $class_name
   *   Type of content entity to create.
   * @param string $relative_uri
   *   Relative URI of the created entity, eg. /node/1.
   * @param string $label
   *   Entity label.
   * @param int $created_timestamp
   *   UNIX timestamp for created.
   * @param int $changed_timestamp
   *   UNIX timestamp for changed.
   * @param string $author_name
   *   Display name for the author of the returned entity.
   *
   * @return \Drupal\Core\Entity\ContentEntityInterface
   *   Content entity stub.
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentEntityNormalizerTestBase::$currentLanguage protected property Mock current language.
ContentEntityNormalizerTestBase::getContentEntity protected function Get a content entity to test with.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 308
UnitTestCase::setUpBeforeClass public static function