function RevisionUserTest::testRevisionUser
Same name in this branch
- 10 core/modules/block_content/tests/src/Kernel/Views/RevisionUserTest.php \Drupal\Tests\block_content\Kernel\Views\RevisionUserTest::testRevisionUser()
Same name in other branches
- 9 core/modules/media/tests/src/Kernel/Views/RevisionUserTest.php \Drupal\Tests\media\Kernel\Views\RevisionUserTest::testRevisionUser()
- 9 core/modules/block_content/tests/src/Kernel/Views/RevisionUserTest.php \Drupal\Tests\block_content\Kernel\Views\RevisionUserTest::testRevisionUser()
- 11.x core/modules/media/tests/src/Kernel/Views/RevisionUserTest.php \Drupal\Tests\media\Kernel\Views\RevisionUserTest::testRevisionUser()
- 11.x core/modules/block_content/tests/src/Kernel/Views/RevisionUserTest.php \Drupal\Tests\block_content\Kernel\Views\RevisionUserTest::testRevisionUser()
Tests the media_revision_user relationship.
File
-
core/
modules/ media/ tests/ src/ Kernel/ Views/ RevisionUserTest.php, line 89
Class
- RevisionUserTest
- Tests the media_revision_user field.
Namespace
Drupal\Tests\media\Kernel\ViewsCode
public function testRevisionUser() : void {
$primary_author = $this->createUser();
$secondary_author = $this->createUser();
$media = Media::create([
'name' => 'Test media',
'bundle' => $this->testMediaType
->id(),
'uid' => $primary_author->id(),
]);
$media->setRevisionUserId($primary_author->id());
$media->save();
$view = Views::getView('test_media_revision_uid');
$this->executeView($view);
$this->assertIdenticalResultset($view, [
[
'mid' => 1,
'vid' => 1,
'uid' => $primary_author->id(),
'revision_user' => $primary_author->id(),
],
], static::$columnMap);
// Test results shows the original author as well as the revision author.
$media->setRevisionUser($secondary_author);
$media->setNewRevision();
$media->save();
$view = Views::getView('test_media_revision_uid');
$this->executeView($view);
$this->assertIdenticalResultset($view, [
[
'mid' => 1,
'vid' => 2,
'uid' => $primary_author->id(),
'revision_user' => $secondary_author->id(),
],
], static::$columnMap);
// Build a larger dataset to allow filtering.
$media2_name = $this->randomString();
$media2 = Media::create([
'name' => $media2_name,
'bundle' => $this->testMediaType
->id(),
'uid' => $primary_author->id(),
]);
$media2->save();
$media2->setRevisionUser($primary_author);
$media2->setNewRevision();
$media2->save();
$view = Views::getView('test_media_revision_uid');
$this->executeView($view);
$this->assertIdenticalResultset($view, [
[
'mid' => 1,
'vid' => 2,
'uid' => $primary_author->id(),
'revision_user' => $secondary_author->id(),
],
[
'mid' => 2,
'vid' => 4,
'uid' => $primary_author->id(),
'revision_user' => $primary_author->id(),
],
], static::$columnMap);
// Test filter by revision_user.
$view = Views::getView('test_media_revision_uid');
$view->initHandlers();
$view->filter['revision_user']->value = [
$secondary_author->id(),
];
$this->executeView($view);
$this->assertIdenticalResultset($view, [
[
'mid' => 1,
'vid' => 2,
'uid' => $primary_author->id(),
'revision_user' => $secondary_author->id(),
],
], static::$columnMap);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.