function QuickEditJavascriptTestBase::assertEntityInstanceFieldMarkup

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

Asserts all in-place editable fields with markup expectations.

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.)

array $expected_field_attributes: Must describe the expected markup attributes for all given in-place editable fields.

5 calls to QuickEditJavascriptTestBase::assertEntityInstanceFieldMarkup()
LayoutBuilderQuickEditTest::assertEntityInstanceFieldMarkup in core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderQuickEditTest.php
Asserts all in-place editable fields with markup expectations.
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.
QuickEditJavascriptTestBase::assertEntityInstanceFieldStates in core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditJavascriptTestBase.php
Asserts all FieldModels for the given entity instance.
1 method overrides QuickEditJavascriptTestBase::assertEntityInstanceFieldMarkup()
LayoutBuilderQuickEditTest::assertEntityInstanceFieldMarkup in core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderQuickEditTest.php
Asserts all in-place editable fields with markup expectations.

File

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

Class

QuickEditJavascriptTestBase
Base class for testing the QuickEdit.

Namespace

Drupal\Tests\quickedit\FunctionalJavascript

Code

protected function assertEntityInstanceFieldMarkup($entity_type_id, $entity_id, $entity_instance_id, array $expected_field_attributes) {
    $entity_page_id = $entity_type_id . '/' . $entity_id . '[' . $entity_instance_id . ']';
    $expected_field_attributes_json = json_encode($expected_field_attributes);
    $js_match_field_element_attributes = <<<JS
function () {
  var expectations = {<span class="php-variable">$expected_field_attributes_json</span>};
  var entityCollection = Drupal.quickedit.collections.entities;
  var entityModel = entityCollection.get('{<span class="php-variable">$entity_page_id</span>}');
  return entityModel.get('fields').reduce(function (result, fieldModel) {
    var fieldID = fieldModel.get('fieldID');
    var element = fieldModel.get('el');
    var matches = element.webkitMatchesSelector(expectations[fieldID]);
    result[fieldID] = matches ? matches : element.outerHTML;
    return result;
  }, {});
}()
JS;
    $result = $this->getSession()
        ->evaluateScript($js_match_field_element_attributes);
    foreach ($expected_field_attributes as $quickedit_field_id => $expectation) {
        $this->assertSame(TRUE, $result[$quickedit_field_id], 'Field ' . $quickedit_field_id . ' did not match its expectation selector (' . $expectation . '), actual HTML: ' . $result[$quickedit_field_id]);
    }
}

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