function QuickEditJavascriptTestBase::assertQuickEditEntityToolbar

Same name in other branches
  1. 8.9.x core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditJavascriptTestBase.php \Drupal\Tests\quickedit\FunctionalJavascript\QuickEditJavascriptTestBase::assertQuickEditEntityToolbar()

Asserts the state of the Quick Edit entity toolbar.

Parameters

string $expected_entity_label: The expected entity label in the Quick Edit Entity Toolbar.

string|null $expected_field_label: The expected field label in the Quick Edit Entity Toolbar, or NULL if no field label is expected.

5 calls to QuickEditJavascriptTestBase::assertQuickEditEntityToolbar()
CKEditor5IntegrationTest::testArticleNode in core/modules/quickedit/tests/src/FunctionalJavascript/CKEditor5IntegrationTest.php
Tests if an article node can be in-place edited with Quick Edit.
CKEditor5IntegrationTest::testDiscard in core/modules/quickedit/tests/src/FunctionalJavascript/CKEditor5IntegrationTest.php
Tests that changes can be discarded.
LayoutBuilderIntegrationTest::testArticleNode in core/modules/quickedit/tests/src/FunctionalJavascript/LayoutBuilderIntegrationTest.php
Tests if an article node can be in-place edited with Quick Edit.
LayoutBuilderIntegrationTest::testCustomBlock in core/modules/quickedit/tests/src/FunctionalJavascript/LayoutBuilderIntegrationTest.php
Tests if a custom can be in-place edited with Quick Edit.
QuickEditImageTest::testImageInPlaceEditor in core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditImageTest.php
Tests that quick editor works correctly with images.

File

core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditJavascriptTestBase.php, line 164

Class

QuickEditJavascriptTestBase
Base class for testing the QuickEdit.

Namespace

Drupal\Tests\quickedit\FunctionalJavascript

Code

protected function assertQuickEditEntityToolbar($expected_entity_label, $expected_field_label) {
    $quickedit_entity_toolbar = $this->getSession()
        ->getPage()
        ->findById('quickedit-entity-toolbar');
    // We cannot use ->getText() because it also returns the text of all child
    // nodes. We also cannot use XPath to select text node in Selenium. So we
    // use JS expression to select only the text node.
    $this->assertSame($expected_entity_label, $this->getSession()
        ->evaluateScript("return window.jQuery('#quickedit-entity-toolbar .quickedit-toolbar-label').clone().children().remove().end().text();"));
    if ($expected_field_label !== NULL) {
        $field_label = $quickedit_entity_toolbar->find('css', '.quickedit-toolbar-label > .field');
        // Only try to find the text content of the element if it was actually
        // found; otherwise use the returned value for assertion. This helps
        // us find a more useful stack/error message from testbot instead of the
        // trimmed partial exception stack.
        if ($field_label) {
            $field_label = $field_label->getText();
        }
        $this->assertSame($expected_field_label, $field_label);
    }
    else {
        $this->assertEmpty($quickedit_entity_toolbar->find('css', '.quickedit-toolbar-label > .field'));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.