PanelizerWizardTest.php in Lightning Layout 8
File
tests/src/FunctionalJavascript/PanelizerWizardTest.php
View source
<?php
namespace Drupal\Tests\lightning_layout\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\lightning_layout\Traits\PanelsIPETrait;
class PanelizerWizardTest extends WebDriverTestBase {
use PanelsIPETrait;
protected static $modules = [
'lightning_landing_page',
'lightning_roles',
'views',
];
public function testBlockPlacement() {
$user = $this
->createUser([], NULL, TRUE);
$page = $this
->createNode([
'type' => 'landing_page',
'uid' => $user
->id(),
]);
$this
->drupalLogin($user);
$this
->drupalGet($page
->toUrl());
$this
->getBlockForm('views_block:who_s_online-who_s_online_block', 'Lists (Views)')
->pressButton('Add');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->saveLayout();
$this
->assertSession()
->elementExists('css', '[data-block-plugin-id="views_block:who_s_online-who_s_online_block"]');
$this
->drupalGet($page
->toUrl('edit-form'));
$this
->assertSession()
->buttonExists('Save')
->click();
$this
->assertSession()
->elementExists('css', '[data-block-plugin-id="views_block:who_s_online-who_s_online_block"]');
}
public function testChangeLayouts() {
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$account = $this
->drupalCreateUser();
$account
->addRole('landing_page_creator');
$account
->addRole('layout_manager');
$account
->save();
$this
->drupalLogin($account);
$this
->drupalGet('/admin/structure/panelizer/edit/node__landing_page__full__two_column/content');
$page
->clickLink('Add new block');
$this
->waitForLink('Authored by')
->click();
$this
->waitForField('region')
->selectOption('first');
$this
->waitForButton('Add block')
->press();
$this
->assertBlockExistsInRegion('Authored by', 'first');
$page
->pressButton('Update and save');
$edit_form = $this
->drupalCreateNode([
'type' => 'landing_page',
])
->toUrl('edit-form');
$this
->drupalGet($edit_form);
$page
->selectFieldOption('Full content', 'Two Column');
$page
->pressButton('Save');
$assert_session
->pageTextContains('Authored by');
$this
->drupalGet($edit_form);
$page
->selectFieldOption('Full content', 'Single Column');
$page
->pressButton('Save');
$assert_session
->pageTextNotContains('Authored by');
}
private function assertBlockExistsInRegion($block_label, $region) {
$page = $this
->getSession()
->getPage();
$rows = [];
foreach ($page
->findAll('css', ".block-region-select option[value='{$region}'][selected]") as $element) {
$rows[] = $element
->getParent()
->getParent()
->getParent()
->getParent();
}
foreach ($rows as $row) {
$row_label = $row
->find('css', 'td')
->getText();
if (trim($row_label) == $block_label) {
return;
}
}
$this
->fail("Expected block '{$block_label}' to be present in '{$region}' region.");
}
private function waitForButton($locator) {
$button = $this
->assertSession()
->waitForButton($locator);
$this
->assertNotEmpty($button);
return $button;
}
private function waitForField($locator) {
$field = $this
->assertSession()
->waitForField($locator);
$this
->assertNotEmpty($field);
return $field;
}
private function waitForLink($locator) {
$link = $this
->assertSession()
->waitForLink($locator);
$this
->assertNotEmpty($link);
return $link;
}
}