public function QuickEditIntegrationTest::testQuickEditLinks in Drupal 8
Tests QuickEdit links behavior.
File
- core/
modules/ settings_tray/ tests/ src/ FunctionalJavascript/ QuickEditIntegrationTest.php, line 49
Class
- QuickEditIntegrationTest
- Test Settings Tray and Quick Edit modules integration.
Namespace
Drupal\Tests\settings_tray\FunctionalJavascriptCode
public function testQuickEditLinks() {
$quick_edit_selector = '#quickedit-entity-toolbar';
$node_selector = '[data-quickedit-entity-id="node/1"]';
$body_selector = '[data-quickedit-field-id="node/1/body/en/full"]';
$web_assert = $this
->assertSession();
// Create a Content type and two test nodes.
$this
->createContentType([
'type' => 'page',
]);
$auth_role = Role::load(Role::AUTHENTICATED_ID);
$this
->grantPermissions($auth_role, [
'edit any page content',
'access content',
]);
$node = $this
->createNode([
'title' => 'Page One',
'type' => 'page',
'body' => [
[
'value' => 'Regular NODE body for the test.',
'format' => 'plain_text',
],
],
]);
$page = $this
->getSession()
->getPage();
$block_plugin = 'system_powered_by_block';
foreach ($this
->getTestThemes() as $theme) {
$this
->enableTheme($theme);
$block = $this
->placeBlock($block_plugin);
$block_selector = $this
->getBlockSelector($block);
// Load the same page twice.
foreach ([
1,
2,
] as $page_load_times) {
$this
->drupalGet('node/' . $node
->id());
// The 2nd page load we should already be in edit mode.
if ($page_load_times == 1) {
$this
->enableEditMode();
}
// In Edit mode clicking field should open QuickEdit toolbar.
$page
->find('css', $body_selector)
->click();
$this
->assertElementVisibleAfterWait('css', $quick_edit_selector);
$this
->disableEditMode();
// Exiting Edit mode should close QuickEdit toolbar.
$web_assert
->elementNotExists('css', $quick_edit_selector);
// When not in Edit mode QuickEdit toolbar should not open.
$page
->find('css', $body_selector)
->click();
$web_assert
->elementNotExists('css', $quick_edit_selector);
$this
->enableEditMode();
$this
->openBlockForm($block_selector);
$page
->find('css', $body_selector)
->click();
$this
->assertElementVisibleAfterWait('css', $quick_edit_selector);
// Off-canvas dialog should be closed when opening QuickEdit toolbar.
$this
->waitForOffCanvasToClose();
$this
->openBlockForm($block_selector);
// QuickEdit toolbar should be closed when opening Off-canvas dialog.
$web_assert
->elementNotExists('css', $quick_edit_selector);
}
// Check using contextual links to invoke QuickEdit and open the tray.
$this
->drupalGet('node/' . $node
->id());
$web_assert
->assertWaitOnAjaxRequest();
$this
->disableEditMode();
// Open QuickEdit toolbar before going into Edit mode.
$this
->clickContextualLink($node_selector, "Quick edit");
$this
->assertElementVisibleAfterWait('css', $quick_edit_selector);
// Open off-canvas and enter Edit mode via contextual link.
$this
->clickContextualLink($block_selector, "Quick edit");
$this
->waitForOffCanvasToOpen();
// QuickEdit toolbar should be closed when opening off-canvas dialog.
$web_assert
->elementNotExists('css', $quick_edit_selector);
// Open QuickEdit toolbar via contextual link while in Edit mode.
$this
->clickContextualLink($node_selector, "Quick edit", FALSE);
$this
->waitForOffCanvasToClose();
$this
->assertElementVisibleAfterWait('css', $quick_edit_selector);
$this
->disableEditMode();
}
}