View source
<?php
namespace Drupal\Tests\media_library\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Drupal\views\Views;
class MediaLibraryUpdateViewTableDisplayTest extends UpdatePathTestBase {
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.4.0.bare.standard.php.gz',
__DIR__ . '/../../../../../media/tests/fixtures/update/drupal-8.4.0-media_installed.php',
__DIR__ . '/../../../fixtures/update/drupal-8.media_library-update-view-table-display-2981044.php',
];
}
public function testMediaLibraryViewTableDisplay() {
$grid_prefix = 'display.widget';
$table_prefix = 'display.widget_table';
$config = $this
->config('views.view.media_library');
$this
->assertNull($config
->get("{$grid_prefix}.display_options.defaults.css_class"));
$this
->assertNull($config
->get("{$grid_prefix}.display_options.css_class"));
$this
->assertNull($config
->get($table_prefix));
$this
->runUpdates();
$config = $this
->config('views.view.media_library');
$this
->assertFalse($config
->get("{$grid_prefix}.display_options.defaults.css_class"));
$this
->assertSame('media-library-view js-media-library-view media-library-view--widget', $config
->get("{$grid_prefix}.display_options.css_class"));
$this
->assertSame('media-library-item media-library-item--grid js-media-library-item js-click-to-select', $config
->get('display.default.display_options.style.options.row_class'));
$this
->assertSame('table', $config
->get("{$table_prefix}.display_options.style.type"));
$this
->assertSame('media-library-item media-library-item--table js-media-library-item js-click-to-select', $config
->get("{$table_prefix}.display_options.style.options.row_class"));
$this
->assertSame('fields', $config
->get("{$table_prefix}.display_options.row.type"));
$this
->assertSame([
'media_library_select_form',
'thumbnail__target_id',
'name',
'uid',
'changed',
], array_keys($config
->get("{$table_prefix}.display_options.fields")));
$this
->assertFalse($config
->get("{$table_prefix}.display_options.defaults.css_class"));
$this
->assertSame('media-library-view js-media-library-view media-library-view--widget', $config
->get("{$table_prefix}.display_options.css_class"));
$this
->assertSame($config
->get("{$grid_prefix}.display_options.filters"), $config
->get("{$table_prefix}.display_options.filters"));
$this
->assertSame($config
->get("{$grid_prefix}.display_options.access"), $config
->get("{$table_prefix}.display_options.access"));
$this
->assertSame($config
->get("{$grid_prefix}.display_options.sorts"), $config
->get("{$table_prefix}.display_options.sorts"));
$this
->assertSame($config
->get("{$grid_prefix}.display_options.pager"), $config
->get("{$table_prefix}.display_options.pager"));
$this
->assertSame($config
->get("{$grid_prefix}.display_options.arguments"), $config
->get("{$table_prefix}.display_options.arguments"));
$this
->assertSame('display_link', $config
->get("{$grid_prefix}.display_options.header.display_link_grid.plugin_id"));
$this
->assertSame('display_link', $config
->get("{$grid_prefix}.display_options.header.display_link_table.plugin_id"));
$this
->assertSame('display_link', $config
->get("{$table_prefix}.display_options.header.display_link_grid.plugin_id"));
$this
->assertSame('display_link', $config
->get("{$table_prefix}.display_options.header.display_link_table.plugin_id"));
$this
->assertSame('widget', $config
->get("{$grid_prefix}.display_options.header.display_link_grid.display_id"));
$this
->assertSame('widget_table', $config
->get("{$grid_prefix}.display_options.header.display_link_table.display_id"));
$this
->assertSame('widget', $config
->get("{$table_prefix}.display_options.header.display_link_grid.display_id"));
$this
->assertSame('widget_table', $config
->get("{$table_prefix}.display_options.header.display_link_table.display_id"));
}
public function testMediaLibraryChangedViewTableDisplay() {
$grid_prefix = 'display.widget';
$table_prefix = 'display.widget_table';
$view = Views::getView('media_library');
$view
->setDisplay('widget');
$grid_display = $view
->getDisplay('widget');
$grid_display
->overrideOption('filters', [
'uid' => [
'id' => 'uid',
'table' => 'media_field_data',
'field' => 'uid',
'relationship' => 'none',
'operator' => '=',
'exposed' => TRUE,
],
]);
$grid_display
->overrideOption('sorts', [
'name' => [
'id' => 'name',
'table' => 'media_field_data',
'field' => 'name',
'relationship' => 'none',
'order' => 'ASC',
],
]);
$grid_display
->overrideOption('pager', [
'type' => 'full',
'options' => [
'items_per_page' => 10,
],
]);
$view
->save();
$this
->runUpdates();
$config = $this
->config('views.view.media_library');
$this
->assertFalse($config
->get("{$grid_prefix}.display_options.defaults.css_class"));
$this
->assertSame('media-library-view js-media-library-view media-library-view--widget', $config
->get("{$grid_prefix}.display_options.css_class"));
$this
->assertSame('media-library-item media-library-item--grid js-media-library-item js-click-to-select', $config
->get('display.default.display_options.style.options.row_class'));
$this
->assertSame('table', $config
->get("{$table_prefix}.display_options.style.type"));
$this
->assertSame('media-library-item media-library-item--table js-media-library-item js-click-to-select', $config
->get("{$table_prefix}.display_options.style.options.row_class"));
$this
->assertSame('fields', $config
->get("{$table_prefix}.display_options.row.type"));
$this
->assertSame([
'media_library_select_form',
'thumbnail__target_id',
'name',
'uid',
'changed',
], array_keys($config
->get("{$table_prefix}.display_options.fields")));
$this
->assertFalse($config
->get("{$table_prefix}.display_options.defaults.css_class"));
$this
->assertSame('media-library-view js-media-library-view media-library-view--widget', $config
->get("{$table_prefix}.display_options.css_class"));
$this
->assertSame($config
->get("{$grid_prefix}.display_options.filters"), $config
->get("{$table_prefix}.display_options.filters"));
$this
->assertSame($config
->get("{$grid_prefix}.display_options.access"), $config
->get("{$table_prefix}.display_options.access"));
$this
->assertSame($config
->get("{$grid_prefix}.display_options.sorts"), $config
->get("{$table_prefix}.display_options.sorts"));
$this
->assertSame($config
->get("{$grid_prefix}.display_options.pager"), $config
->get("{$table_prefix}.display_options.pager"));
$this
->assertSame($config
->get("{$grid_prefix}.display_options.arguments"), $config
->get("{$table_prefix}.display_options.arguments"));
$this
->assertSame('display_link', $config
->get("{$grid_prefix}.display_options.header.display_link_grid.plugin_id"));
$this
->assertSame('display_link', $config
->get("{$grid_prefix}.display_options.header.display_link_table.plugin_id"));
$this
->assertSame('display_link', $config
->get("{$table_prefix}.display_options.header.display_link_grid.plugin_id"));
$this
->assertSame('display_link', $config
->get("{$table_prefix}.display_options.header.display_link_table.plugin_id"));
$this
->assertSame('widget', $config
->get("{$grid_prefix}.display_options.header.display_link_grid.display_id"));
$this
->assertSame('widget_table', $config
->get("{$grid_prefix}.display_options.header.display_link_table.display_id"));
$this
->assertSame('widget', $config
->get("{$table_prefix}.display_options.header.display_link_grid.display_id"));
$this
->assertSame('widget_table', $config
->get("{$table_prefix}.display_options.header.display_link_table.display_id"));
}
}