View source
<?php
namespace Drupal\Tests\media_library\FunctionalJavascript;
class MediaOverviewTest extends MediaLibraryTestBase {
protected static $modules = [
'block',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->createMediaItems([
'type_one' => [
'Horse',
'Bear',
'Cat',
'Dog',
],
'type_two' => [
'Crocodile',
'Lizard',
'Snake',
'Turtle',
],
]);
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalPlaceBlock('local_actions_block');
$user = $this
->drupalCreateUser([
'access media overview',
'create media',
'delete any media',
'update any media',
]);
$this
->drupalLogin($user);
}
public function testAdministrationPage() {
$session = $this
->getSession();
$page = $session
->getPage();
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/content/media');
$assert_session
->linkExists('Grid');
$assert_session
->linkExists('Table');
$assert_session
->elementExists('css', '[data-drupal-selector="views-form-media-media-page-list"] table');
$assert_session
->linkExists('Add media');
$page
->clickLink('Grid');
$assert_session
->addressEquals('admin/content/media-grid');
$assert_session
->linkExists('Add media');
$assert_session
->pageTextContains('Dog');
$assert_session
->pageTextContains('Turtle');
$assert_session
->elementExists('css', '.js-media-library-item-preview + div:contains("Dog")');
$assert_session
->elementExists('css', '.js-media-library-item-preview + div:contains("Turtle")');
$assert_session
->elementNotExists('css', '.js-media-library-item-preview + div a');
$assert_session
->linkExists('Edit Dog');
$assert_session
->linkExists('Delete Turtle');
$page
->selectFieldOption('Media type', 'Type One');
$page
->pressButton('Apply filters');
$this
->waitForNoText('Turtle');
$assert_session
->pageTextContains('Dog');
$page
->selectFieldOption('Media type', 'Type Two');
$page
->pressButton('Apply filters');
$this
->waitForText('Turtle');
$assert_session
->pageTextNotContains('Dog');
$page
->selectFieldOption('Media type', '- Any -');
$assert_session
->elementExists('css', '#views-exposed-form-media-library-page')
->submit();
$this
->waitForText('Dog');
$this
->getSession()
->executeScript('jQuery(".js-click-to-select-trigger a")[4].click()');
$this
->submitForm([], 'Apply to selected items');
$assert_session
->pageTextContains('Dog');
$assert_session
->pageTextNotContains('Cat');
$assert_session
->elementExists('css', 'form')
->submit();
$assert_session
->pageTextNotContains('Dog');
$assert_session
->pageTextContains('Cat');
$select_all = $this
->waitForFieldExists('Select all media');
$select_all
->check();
$this
->waitForText('All 7 items selected');
$select_all
->uncheck();
$this
->waitForText('Zero items selected');
$select_all
->check();
$page
->selectFieldOption('Action', 'media_delete_action');
$this
->submitForm([], 'Apply to selected items');
$assert_session
->elementExists('css', 'form')
->submit();
$assert_session
->pageTextNotContains('Cat');
$assert_session
->pageTextNotContains('Turtle');
$assert_session
->pageTextNotContains('Snake');
$assert_session
->pageTextContains('No media available.');
}
}