Unverified Commit 18623b27 authored by alexpott's avatar alexpott

Issue #3113986 by acbramley, msuthars: Can't show 'revision author' on Media views

(cherry picked from commit ca0f252c4c4f4294ce5d8d3c1d9a7ac02ad9bca6)
parent 017dbaa2
......@@ -18,6 +18,13 @@ public function getViewsData() {
$data['media_field_data']['table']['wizard_id'] = 'media';
$data['media_field_revision']['table']['wizard_id'] = 'media_revision';
$data['media_revision']['revision_user']['help'] = $this->t('The user who created the revision.');
$data['media_revision']['revision_user']['relationship']['label'] = $this->t('revision user');
$data['media_revision']['revision_user']['filter']['id'] = 'user_name';
$data['media_revision']['table']['join']['media_field_data']['left_field'] = 'vid';
$data['media_revision']['table']['join']['media_field_data']['field'] = 'vid';
$data['media_field_data']['status_extra'] = [
'title' => $this->t('Published status or admin user'),
'help' => $this->t('Filters out unpublished media if the current user cannot view it.'),
......
<?php
namespace Drupal\Tests\media\Kernel\Views;
use Drupal\media\Entity\Media;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewResultAssertionTrait;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
/**
* Tests the media_revision_user field.
*
* @group media
*/
class RevisionUserTest extends ViewsKernelTestBase {
use UserCreationTrait;
use ViewResultAssertionTrait;
use MediaTypeCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'media',
'media_test_views',
'media_test_source',
'system',
'user',
'views',
'image',
'field',
'file',
];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_media_revision_uid'];
/**
* The test media type.
*
* @var \Drupal\media\MediaTypeInterface
*/
protected $testMediaType;
/**
* Map column names.
*
* @var array
*/
public static $columnMap = [
'mid' => 'mid',
'vid' => 'vid',
'uid' => 'uid',
'revision_user' => 'revision_user',
];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE): void {
parent::setUp($import_test_views);
$this->installEntitySchema('media');
$this->installEntitySchema('file');
$this->installSchema('file', 'file_usage');
$this->installEntitySchema('user');
$this->installConfig(['field', 'system', 'image', 'file', 'media']);
if ($import_test_views) {
ViewTestData::createTestViews(get_class($this), ['media_test_views']);
}
$this->testMediaType = $this->createMediaType('test');
}
/**
* Tests the media_revision_user relationship.
*/
public function testRevisionUser() {
$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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment