abstract class ContentEntityNormalizerTestBase in Facebook Instant Articles 8.2
Same name and namespace in other branches
- 3.x tests/src/Unit/ContentEntityNormalizerTestBase.php \Drupal\Tests\fb_instant_articles\Unit\ContentEntityNormalizerTestBase
Base class for Instant Articles content entity normalizers.
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\fb_instant_articles\Unit\ContentEntityNormalizerTestBase
Expanded class hierarchy of ContentEntityNormalizerTestBase
File
- tests/
src/ Unit/ ContentEntityNormalizerTestBase.php, line 13
Namespace
Drupal\Tests\fb_instant_articles\UnitView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentEntityNormalizerTestBase:: |
protected | property | Mock current language. | |
ContentEntityNormalizerTestBase:: |
protected | function | Get a content entity to test with. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
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 | Mocks a block with a block plugin. | 1 |
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 | 340 |