function QuickEditJavascriptTestBase::startQuickEditViaToolbar
Same name in other branches
- 9 core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditJavascriptTestBase.php \Drupal\Tests\quickedit\FunctionalJavascript\QuickEditJavascriptTestBase::startQuickEditViaToolbar()
Starts in-place editing of the given entity instance.
Parameters
string $entity_type_id: The entity type ID.
int $entity_id: The entity ID.
int $entity_instance_id: The entity instance ID. (Instance on the page.)
4 calls to QuickEditJavascriptTestBase::startQuickEditViaToolbar()
- QuickEditFileTest::testRemove in core/
modules/ quickedit/ tests/ src/ FunctionalJavascript/ QuickEditFileTest.php - Tests if a file can be in-place removed with Quick Edit.
- QuickEditImageTest::testImageInPlaceEditor in core/
modules/ image/ tests/ src/ FunctionalJavascript/ QuickEditImageTest.php - Tests that quick editor works correctly with images.
- QuickEditIntegrationTest::testArticleNode in core/
modules/ quickedit/ tests/ src/ FunctionalJavascript/ QuickEditIntegrationTest.php - Tests if an article node can be in-place edited with Quick Edit.
- QuickEditIntegrationTest::testCustomBlock in core/
modules/ quickedit/ tests/ src/ FunctionalJavascript/ QuickEditIntegrationTest.php - Tests if a custom can be in-place edited with Quick Edit.
File
-
core/
modules/ quickedit/ tests/ src/ FunctionalJavascript/ QuickEditJavascriptTestBase.php, line 49
Class
- QuickEditJavascriptTestBase
- Base class for testing the QuickEdit.
Namespace
Drupal\Tests\quickedit\FunctionalJavascriptCode
protected function startQuickEditViaToolbar($entity_type_id, $entity_id, $entity_instance_id) {
$page = $this->getSession()
->getPage();
$toolbar_edit_button_selector = '#toolbar-bar .contextual-toolbar-tab button';
$entity_instance_selector = '[data-quickedit-entity-id="' . $entity_type_id . '/' . $entity_id . '"][data-quickedit-entity-instance-id="' . $entity_instance_id . '"]';
$contextual_links_trigger_selector = '[data-contextual-id] > .trigger';
// Assert the original page state does not have the toolbar's "Edit" button
// pressed/activated, and hence none of the contextual link triggers should
// be visible.
$toolbar_edit_button = $page->find('css', $toolbar_edit_button_selector);
$this->assertSame('false', $toolbar_edit_button->getAttribute('aria-pressed'), 'The "Edit" button in the toolbar is not yet pressed.');
$this->assertFalse($toolbar_edit_button->hasClass('is-active'), 'The "Edit" button in the toolbar is not yet marked as active.');
foreach ($page->findAll('css', $contextual_links_trigger_selector) as $dom_node) {
/** @var \Behat\Mink\Element\NodeElement $dom_node */
$this->assertTrue($dom_node->hasClass('visually-hidden'), 'The contextual links trigger "' . $dom_node->getParent()
->getAttribute('data-contextual-id') . '" is hidden.');
}
$this->assertTrue(TRUE, 'All contextual links triggers are hidden.');
// Click the "Edit" button in the toolbar.
$this->click($toolbar_edit_button_selector);
// Assert the toolbar's "Edit" button is now pressed/activated, and hence
// all of the contextual link triggers should be visible.
$this->assertSame('true', $toolbar_edit_button->getAttribute('aria-pressed'), 'The "Edit" button in the toolbar is pressed.');
$this->assertTrue($toolbar_edit_button->hasClass('is-active'), 'The "Edit" button in the toolbar is marked as active.');
foreach ($page->findAll('css', $contextual_links_trigger_selector) as $dom_node) {
/** @var \Behat\Mink\Element\NodeElement $dom_node */
$this->assertFalse($dom_node->hasClass('visually-hidden'), 'The contextual links trigger "' . $dom_node->getParent()
->getAttribute('data-contextual-id') . '" is visible.');
}
$this->assertTrue(TRUE, 'All contextual links triggers are visible.');
// @todo Press tab key to verify that tabbing is now contrained to only
// contextual links triggers: https://www.drupal.org/node/2834776
// Assert that the contextual links associated with the entity's contextual
// links trigger are not visible.
/** @var \Behat\Mink\Element\NodeElement $entity_contextual_links_container */
$entity_contextual_links_container = $page->find('css', $entity_instance_selector)
->find('css', $contextual_links_trigger_selector)
->getParent();
$this->assertFalse($entity_contextual_links_container->hasClass('open'));
$this->assertTrue($entity_contextual_links_container->find('css', 'ul.contextual-links')
->hasAttribute('hidden'));
// Click the contextual link trigger for the entity we want to Quick Edit.
$this->click($entity_instance_selector . ' ' . $contextual_links_trigger_selector);
$this->assertTrue($entity_contextual_links_container->hasClass('open'));
$this->assertFalse($entity_contextual_links_container->find('css', 'ul.contextual-links')
->hasAttribute('hidden'));
// Click the "Quick edit" contextual link.
$this->click($entity_instance_selector . ' [data-contextual-id] ul.contextual-links li.quickedit a');
// Assert the Quick Edit internal state is correct.
$js_condition = <<<JS
Drupal.quickedit.collections.entities.where({isActive: true}).length === 1 && Drupal.quickedit.collections.entities.where({isActive: true})[0].get('entityID') === '{<span class="php-variable">$entity_type_id</span>}/{<span class="php-variable">$entity_id</span>}';
JS;
$this->assertJsCondition($js_condition);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.