You are here

public function AddLayoutTest::testAddLayout in Layout builder library 8

Tests adding a layout to the library.

File

tests/src/Functional/AddLayoutTest.php, line 51

Class

AddLayoutTest
Tests adding a layout to the library.

Namespace

Drupal\Tests\layout_library\Functional

Code

public function testAddLayout() {
  $session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->drupalGet('admin/structure/layouts');
  $this
    ->clickLink('Add layout');
  $page
    ->fillField('label', 'Archaeopteryx');
  $page
    ->fillField('id', 'archaeopteryx');
  $page
    ->selectFieldOption('_entity_type', 'node:my_little_dinosaur');
  $page
    ->pressButton('Save');
  $session
    ->pageTextContains('Edit layout for Archaeopteryx');

  // Add three sections: a header, a two-column content area, and a footer.
  $page
    ->clickLink('Add section');
  $page
    ->clickLink('One column');
  $page
    ->fillField('Administrative label', 'Header');
  $page
    ->pressButton('Add section');
  $session
    ->linkExists('Configure Header');
  $this
    ->addSectionAfter(1);
  $page
    ->clickLink('Two column');
  $page
    ->selectFieldOption('Column widths', '67%/33%');
  $page
    ->fillField('Administrative label', 'Main content');
  $page
    ->pressButton('Add section');
  $session
    ->linkExists('Configure Main content');
  $this
    ->addSectionAfter(2);
  $page
    ->clickLink('One column');
  $page
    ->fillField('Administrative label', 'Footer');
  $page
    ->pressButton('Add section');
  $session
    ->linkExists('Configure Footer');

  // Try to remove the Header section.
  $page
    ->clickLink('Remove Header');
  $page
    ->pressButton('Remove');
  $session
    ->statusCodeEquals(200);
  $session
    ->linkNotExists('Configure Header');
  $this
    ->drupalGet('admin/structure/types/manage/my_little_dinosaur/display');
  $page
    ->checkField('layout[enabled]');
  $page
    ->checkField('layout[library]');
  $page
    ->pressButton('Save');
  $page
    ->checkField('layout[allow_custom]');
  $page
    ->pressButton('Save');
  $this
    ->drupalGet('node/add/my_little_dinosaur');
  $session
    ->optionExists('Layout', 'Archaeopteryx');
  $this
    ->drupalGet('admin/structure/types/manage/my_little_dinosaur/display');
  $page
    ->uncheckField('layout[allow_custom]');
  $page
    ->uncheckField('layout[library]');
  $page
    ->pressButton('Save');
  $this
    ->drupalGet('node/add/my_little_dinosaur');
  $session
    ->fieldNotExists('Layout');
}