class RevisionViewTest
Same name in this branch
- main core/tests/Drupal/FunctionalTests/Entity/RevisionViewTest.php \Drupal\FunctionalTests\Entity\RevisionViewTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/FunctionalTests/Entity/RevisionViewTest.php \Drupal\FunctionalTests\Entity\RevisionViewTest
- 10 core/tests/Drupal/FunctionalTests/Entity/RevisionViewTest.php \Drupal\FunctionalTests\Entity\RevisionViewTest
Tests revision view page.
Attributes
#[CoversClass(EntityRevisionViewController::class)]
#[Group('Entity')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\Tests\BrowserHtmlDebugTrait, \Drupal\Tests\HttpKernelUiHelperTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Entity\RevisionViewTest uses \Drupal\Tests\block\Traits\BlockCreationTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of RevisionViewTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ RevisionViewTest.php, line 22
Namespace
Drupal\KernelTests\Core\EntityView source
class RevisionViewTest extends KernelTestBase {
use BlockCreationTrait {
placeBlock as drupalPlaceBlock;
}
/**
* {@inheritdoc}
*/
protected static $modules = [
'block',
'entity_test',
'entity_test_revlog',
'field',
'system',
'user',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installConfig('system');
$this->installEntitySchema('entity_test_rev');
$this->installEntitySchema('entity_test_revlog');
\Drupal::service(ThemeInstallerInterface::class)->install([
'stark',
]);
$this->drupalPlaceBlock('page_title_block');
}
/**
* Tests revision page.
*
* @param string $entityTypeId
* Entity type to test.
* @param string $expectedPageTitle
* Expected page title.
*
* @legacy-covers ::__invoke
*/
public function testRevisionPage(string $entityTypeId, string $expectedPageTitle) : void {
/** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
$storage = \Drupal::entityTypeManager()->getStorage($entityTypeId);
// Add a field to test revision page output.
$fieldStorage = FieldStorageConfig::create([
'entity_type' => $entityTypeId,
'field_name' => 'foo',
'type' => 'string',
]);
$fieldStorage->save();
FieldConfig::create([
'field_storage' => $fieldStorage,
'bundle' => $entityTypeId,
])->save();
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $displayRepository */
$displayRepository = \Drupal::service('entity_display.repository');
$displayRepository->getViewDisplay($entityTypeId, $entityTypeId)
->setComponent('foo', [
'type' => 'string',
])
->save();
$entity = $storage->create([
'type' => $entityTypeId,
]);
$entity->setName('revision 1, view revision');
$revision1Body = $this->randomMachineName();
$entity->foo = $revision1Body;
$entity->setNewRevision();
if ($entity instanceof RevisionLogInterface) {
$date = new \DateTime('11 January 2009 4:00:00pm');
$entity->setRevisionCreationTime($date->getTimestamp());
}
$entity->save();
$revisionId = $entity->getRevisionId();
$entity->setName('revision 2, view revision');
$revision2Body = $this->randomMachineName();
$entity->foo = $revision2Body;
if ($entity instanceof RevisionLogInterface) {
$entity->setRevisionCreationTime($date->modify('+1 hour')
->getTimestamp());
}
$entity->setNewRevision();
$entity->save();
$revision = $storage->loadRevision($revisionId);
$this->drupalGet($revision->toUrl('revision'));
$this->assertSession()
->pageTextContains($expectedPageTitle);
$this->assertSession()
->pageTextContains($revision1Body);
$this->assertSession()
->pageTextNotContains($revision2Body);
}
/**
* Data provider for testRevisionPage.
*/
public static function providerRevisionPage() : array {
return [
[
'entity_test_rev',
'Revision of revision 1, view revision',
],
[
'entity_test_revlog',
'Revision of revision 1, view revision from Sun, 11 Jan 2009 - 16:00',
],
];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.