function WorkspacePublisherTest::testPublishingChangedTime
Tests that publishing a workspace updates the changed time of its entities.
File
-
core/
modules/ workspaces/ tests/ src/ Kernel/ WorkspacePublisherTest.php, line 78
Class
- WorkspacePublisherTest
- Tests workspace publishing.
Namespace
Drupal\Tests\workspaces\KernelCode
public function testPublishingChangedTime() : void {
// Create an entity in Live.
$entity = $this->createNode([
'status' => TRUE,
]);
$initial_request_time = \Drupal::time()->getRequestTime();
$this->assertEquals($initial_request_time, $entity->getChangedTime());
// Create a new workspace, activate it, and make some changes to the entity.
$workspace = Workspace::create([
'id' => 'test_changed',
'label' => 'Test changed',
]);
$workspace->save();
$this->switchToWorkspace('test_changed');
// Simulate passing time.
TestTime::$offset = 1;
$entity = $this->entityTypeManager
->getStorage('node')
->loadUnchanged($entity->id());
$entity->title = $this->randomString();
$entity->save();
$this->assertEquals($initial_request_time + 1, $entity->getChangedTime());
// Publish the workspace and check that the changed time has been updated.
TestTime::$offset = 2;
$workspace->publish();
$entity = $this->entityTypeManager
->getStorage('node')
->loadUnchanged($entity->id());
$this->assertEquals($initial_request_time + 2, $entity->getChangedTime());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.