.../QuickEditIntegrationTest.php | 108 +++++++++++++++------ 1 file changed, 77 insertions(+), 31 deletions(-) diff --git a/core/modules/quickedit/tests/src/FunctionalJavaScript/QuickEditIntegrationTest.php b/core/modules/quickedit/tests/src/FunctionalJavaScript/QuickEditIntegrationTest.php index a59a657..e1dda2b 100644 --- a/core/modules/quickedit/tests/src/FunctionalJavaScript/QuickEditIntegrationTest.php +++ b/core/modules/quickedit/tests/src/FunctionalJavaScript/QuickEditIntegrationTest.php @@ -135,10 +135,10 @@ public function testArticleNode() { // Initial state. $this->awaitQuickEditForEntity('node', 1); - $this->assertEntityStates([ + $this->assertEntityInstanceStates([ 'node/1[0]' => 'closed', ]); - $this->assertEntityFieldStates('node', 1, 0, [ + $this->assertEntityInstanceFieldStates('node', 1, 0, [ 'node/1/title/en/full' => 'inactive', 'node/1/uid/en/full' => 'inactive', 'node/1/created/en/full' => 'inactive', @@ -147,12 +147,12 @@ public function testArticleNode() { ]); // Start in-place editing of the article node. - $this->startQuickEditViaToolbar('node', 1); - $this->assertEntityStates([ + $this->startQuickEditViaToolbar('node', 1, 0); + $this->assertEntityInstanceStates([ 'node/1[0]' => 'opened', ]); $this->assertQuickEditEntityToolbar((string) $node->label(), NULL); - $this->assertEntityFieldStates('node', 1, 0, [ + $this->assertEntityInstanceFieldStates('node', 1, 0, [ 'node/1/title/en/full' => 'candidate', 'node/1/uid/en/full' => 'candidate', 'node/1/created/en/full' => 'candidate', @@ -163,14 +163,14 @@ public function testArticleNode() { // Click the title field. $this->click('h1.js-quickedit-page-title > span'); $this->assertQuickEditEntityToolbar((string) $node->label(), 'Title'); - $this->assertEntityFieldStates('node', 1, 0, [ + $this->assertEntityInstanceFieldStates('node', 1, 0, [ 'node/1/title/en/full' => 'active', 'node/1/uid/en/full' => 'candidate', 'node/1/created/en/full' => 'candidate', 'node/1/body/en/full' => 'candidate', 'node/1/field_tags/en/full' => 'candidate', ]); - $this->assertEntityFieldMarkup('node', 1, 0, [ + $this->assertEntityInstanceFieldMarkup('node', 1, 0, [ 'node/1/title/en/full' => '[contenteditable="true"]', ]); @@ -190,7 +190,7 @@ function () { }() JS; $this->getSession()->evaluateScript($js_simulate_user_typing); - $this->assertEntityFieldStates('node', 1, 0, [ + $this->assertEntityInstanceFieldStates('node', 1, 0, [ 'node/1/title/en/full' => 'changed', 'node/1/uid/en/full' => 'candidate', 'node/1/created/en/full' => 'candidate', @@ -201,7 +201,7 @@ function () { // Click the body field. $this->click('[data-quickedit-entity-id="node/1"] .field--name-body'); $this->assertQuickEditEntityToolbar((string) $node->label(), 'Body'); - $this->assertEntityFieldStates('node', 1, 0, [ + $this->assertEntityInstanceFieldStates('node', 1, 0, [ 'node/1/title/en/full' => 'saving', 'node/1/uid/en/full' => 'candidate', 'node/1/created/en/full' => 'candidate', @@ -211,7 +211,7 @@ function () { // Wait for CKEditor to load, then verify it has. $this->assertJsCondition('CKEDITOR.status === "loaded"'); - $this->assertEntityFieldMarkup('node', 1, 0, [ + $this->assertEntityInstanceFieldMarkup('node', 1, 0, [ 'node/1/body/en/full' => '.cke_editable_inline', 'node/1/field_tags/en/full' => ':not(.quickedit-editor-is-popup)', ]); @@ -223,14 +223,14 @@ function () { // Click the tags field. $this->click('.field--name-field-tags'); $this->assertQuickEditEntityToolbar((string) $node->label(), 'Tags'); - $this->assertEntityFieldStates('node', 1, 0, [ + $this->assertEntityInstanceFieldStates('node', 1, 0, [ 'node/1/uid/en/full' => 'candidate', 'node/1/created/en/full' => 'candidate', 'node/1/body/en/full' => 'candidate', 'node/1/field_tags/en/full' => 'activating', 'node/1/title/en/full' => 'candidate', ]); - $this->assertEntityFieldMarkup('node', 1, 0, [ + $this->assertEntityInstanceFieldMarkup('node', 1, 0, [ 'node/1/title/en/full' => '.quickedit-changed', 'node/1/field_tags/en/full' => '.quickedit-editor-is-popup', ]); @@ -238,7 +238,7 @@ function () { $this->assertSession()->elementExists('css', '.quickedit-form-container > .quickedit-form[role="dialog"] > .placeholder'); // Wait for the form to load. $this->assertJsCondition('document.querySelector(\'.quickedit-form-container > .quickedit-form[role="dialog"] > .placeholder\') === null'); - $this->assertEntityFieldStates('node', 1, 0, [ + $this->assertEntityInstanceFieldStates('node', 1, 0, [ 'node/1/uid/en/full' => 'candidate', 'node/1/created/en/full' => 'candidate', 'node/1/body/en/full' => 'candidate', @@ -256,7 +256,7 @@ function () { }() JS; $this->getSession()->evaluateScript($js_simulate_user_typing); - $this->assertEntityFieldStates('node', 1, 0, [ + $this->assertEntityInstanceFieldStates('node', 1, 0, [ 'node/1/uid/en/full' => 'candidate', 'node/1/created/en/full' => 'candidate', 'node/1/body/en/full' => 'candidate', @@ -269,35 +269,45 @@ function () { $save_button = $quickedit_entity_toolbar->find('css', 'button.action-save'); $save_button->press(); $this->assertSame('Saving', $save_button->getText()); - $this->assertEntityStates([ + $this->assertEntityInstanceStates([ 'node/1[0]' => 'committing', ]); - $this->assertEntityFieldStates('node', 1, 0, [ + $this->assertEntityInstanceFieldStates('node', 1, 0, [ 'node/1/uid/en/full' => 'candidate', 'node/1/created/en/full' => 'candidate', 'node/1/body/en/full' => 'candidate', 'node/1/field_tags/en/full' => 'saving', 'node/1/title/en/full' => 'candidate', ]); - $this->assertEntityFieldMarkup('node', 1, 0, [ + $this->assertEntityInstanceFieldMarkup('node', 1, 0, [ 'node/1/title/en/full' => '.quickedit-changed', 'node/1/field_tags/en/full' => '.quickedit-changed', ]); // Wait for the saving of the tags field to complete. $this->assertJsCondition("Drupal.quickedit.collections.entities.get('node/1[0]').get('state') === 'closed'"); - $this->assertEntityStates([ + $this->assertEntityInstanceStates([ 'node/1[0]' => 'closed', ]); } // @todo test custom block - protected function startQuickEditViaToolbar($entity_type_id, $entity_id) { + /** + * Starts in-place editing of the given entity instance. + * + * @param $entity_type_id + * The entity type ID. + * @param $entity_id + * The entity ID. + * @param $entity_instance_id + * The entity instance ID. (Instance on the page.) + */ + 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_selector = '[data-quickedit-entity-id="' . $entity_type_id . '/' . $entity_id . '"]'; + $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 @@ -331,20 +341,20 @@ protected function startQuickEditViaToolbar($entity_type_id, $entity_id) { // 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_selector) + $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_selector . ' ' . $contextual_links_trigger_selector); + $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_selector . ' [data-contextual-id] ul.contextual-links li.quickedit a'); + $this->click($entity_instance_selector . ' [data-contextual-id] ul.contextual-links li.quickedit a'); // Assert the Quick Edit internal state is correct. $js_condition = << 0"; + $condition = "document.querySelectorAll('" . $entity_selector . "').length === document.querySelectorAll('" . $entity_selector . " .quickedit').length"; $this->assertJsCondition($condition, 10000); } /** + * Asserts the state of the Quick Edit entity toolbar. + * * @param string $expected_entity_label * The expected label in the Quick Edit Entity Toolbar. */ @@ -379,15 +399,15 @@ protected function assertQuickEditEntityToolbar($expected_entity_label, $expecte } /** - * Asserts all EntityModels for the page. + * Asserts all EntityModels (entity instances) on the page. * * @see Drupal.quickedit.EntityModel * * @param array $expected_entity_states - * Must describe the expected state of all in-place editable entities on the - * page. + * Must describe the expected state of all in-place editable entity + * instances on the page. */ - protected function assertEntityStates(array $expected_entity_states) { + protected function assertEntityInstanceStates(array $expected_entity_states) { $js_get_all_field_states_for_entity = <<assertSame($expected_entity_states, $this->getSession()->evaluateScript($js_get_all_field_states_for_entity)); } - protected function assertEntityFieldStates($entity_type_id, $entity_id, $entity_instance_id, array $expected_field_states) { + /** + * Asserts all FieldModels for the given entity instance. + * + * @param $entity_type_id + * The entity type ID. + * @param $entity_id + * The entity ID. + * @param $entity_instance_id + * The entity instance ID. (Instance on the page.) + * @param array $expected_field_states + * Must describe the expected state of all in-place editable fields of the + * given entity instance. + */ + 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. @@ -423,10 +456,23 @@ function () { foreach ($expected_field_states as $quickedit_field_id => $expected_field_state) { $expected_field_attributes[$quickedit_field_id] = static::$expectedFieldStateAttributes[$expected_field_state]; } - $this->assertEntityFieldMarkup($entity_type_id, $entity_id, $entity_instance_id, $expected_field_attributes); + $this->assertEntityInstanceFieldMarkup($entity_type_id, $entity_id, $entity_instance_id, $expected_field_attributes); } - protected function assertEntityFieldMarkup($entity_type_id, $entity_id, $entity_instance_id, array $expected_field_attributes) { + /** + * Asserts all in-place editable fields with markup expectations. + * + * @param $entity_type_id + * The entity type ID. + * @param $entity_id + * The entity ID. + * @param $entity_instance_id + * The entity instance ID. (Instance on the page.) + * @param array $expected_field_attributes + * Must describe the expected markup attributes for all given in-place + * editable fields. + */ + 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 = <<