function QuickEditJavascriptTestBase::assertEntityInstanceFieldStates

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

Asserts all FieldModels for 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.)

array $expected_field_states: Must describe the expected state of all in-place editable fields of the given entity instance.

6 calls to QuickEditJavascriptTestBase::assertEntityInstanceFieldStates()
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.
LayoutBuilderQuickEditTest::assertEntityInstanceFieldStates in core/modules/quickedit/tests/src/FunctionalJavascript/LayoutBuilderQuickEditTest.php
Asserts all FieldModels for the given entity instance.

... See full list

1 method overrides QuickEditJavascriptTestBase::assertEntityInstanceFieldStates()
LayoutBuilderQuickEditTest::assertEntityInstanceFieldStates in core/modules/quickedit/tests/src/FunctionalJavascript/LayoutBuilderQuickEditTest.php
Asserts all FieldModels for the given entity instance.

File

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

Class

QuickEditJavascriptTestBase
Base class for testing the QuickEdit.

Namespace

Drupal\Tests\quickedit\FunctionalJavascript

Code

protected function assertEntityInstanceFieldStates($entity_type_id, $entity_id, $entity_instance_id, array $expected_field_states) {
    // Get all FieldModel states for the entity instance being asserted. This
    // ensures that $expected_field_states must describe the state of all fields
    // of the entity instance.
    $entity_page_id = $entity_type_id . '/' . $entity_id . '[' . $entity_instance_id . ']';
    $js_get_all_field_states_for_entity = <<<JS
function () {
  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) {
    result[fieldModel.get('fieldID')] = fieldModel.get('state');
    return result;
  }, {});
}()
JS;
    $this->assertEquals($expected_field_states, $this->getSession()
        ->evaluateScript($js_get_all_field_states_for_entity));
    // Assert that those fields also have the appropriate DOM decorations.
    $expected_field_attributes = [];
    foreach ($expected_field_states as $quickedit_field_id => $expected_field_state) {
        $expected_field_attributes[$quickedit_field_id] = static::$expectedFieldStateAttributes[$expected_field_state];
    }
    $this->assertEntityInstanceFieldMarkup($expected_field_attributes);
}

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