You are here

public function SlideshowTest::testSlideshow in Lightning Media 8.4

Same name and namespace in other branches
  1. 8.3 modules/lightning_media_slideshow/tests/src/FunctionalJavascript/SlideshowTest.php \Drupal\Tests\lightning_media_slideshow\FunctionalJavascript\SlideshowTest::testSlideshow()

Tests creating a slideshow block with media items in it.

File

modules/lightning_media_slideshow/tests/src/FunctionalJavascript/SlideshowTest.php, line 80

Class

SlideshowTest
Tests the basic functionality of Lightning Media's slideshow component.

Namespace

Drupal\Tests\lightning_media_slideshow\FunctionalJavascript

Code

public function testSlideshow() {
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $account = $this
    ->drupalCreateUser([
    'access content',
    'access media overview',
    'view media',
    'create media',
    'update media',
    'administer blocks',
  ]);
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('/block/add/media_slideshow');
  $page
    ->fillField('Block description', 'Test Block');

  // This is an amazingly sketchy way to use the media library, but it will
  // suffice for now until there is a trait in core that allows us to write
  // interact with it more cleanly.
  $page
    ->pressButton('Add media');
  $assert_session
    ->waitForText('Add or select media');
  $assert_session
    ->waitForElement('css', '.js-media-library-item')
    ->click();

  // Switch to the other media type.
  $links = $page
    ->findAll('css', '.js-media-library-menu a');
  $this
    ->assertCount(2, $links);
  $links[1]
    ->click();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->waitForElement('css', '.js-media-library-item')
    ->click();
  $assert_session
    ->elementExists('css', '.ui-dialog-buttonpane')
    ->pressButton('Insert selected');

  // Wait for the selected items to actually appear on the page.
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->waitForElement('css', '.js-media-library-selection .js-media-library-item');
  $page
    ->pressButton('Save');
  $page
    ->selectFieldOption('Region', 'Content');
  $page
    ->pressButton('Save block');
  $this
    ->drupalGet('<front>');
  $this
    ->assertNotEmpty($assert_session
    ->waitForElement('css', 'button.slick-prev.slick-arrow'));
  $assert_session
    ->elementExists('css', 'button.slick-next.slick-arrow');
}