You are here

protected function QuickEditJavascriptTestBase::assertEntityInstanceFieldStates in Drupal 8

Same name and namespace in other branches
  1. 9 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.

4 calls to QuickEditJavascriptTestBase::assertEntityInstanceFieldStates()
LayoutBuilderQuickEditTest::assertEntityInstanceFieldStates in core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderQuickEditTest.php
Asserts all FieldModels for the given entity instance.
QuickEditImageTest::testImageInPlaceEditor in core/modules/image/tests/src/FunctionalJavascript/QuickEditImageTest.php
Test 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.
1 method overrides QuickEditJavascriptTestBase::assertEntityInstanceFieldStates()
LayoutBuilderQuickEditTest::assertEntityInstanceFieldStates in core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderQuickEditTest.php
Asserts all FieldModels for the given entity instance.

File

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

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($entity_type_id, $entity_id, $entity_instance_id, $expected_field_attributes);
}