Chris@18: drupalCreateContentType([ Chris@18: 'type' => 'article', Chris@18: ]); Chris@18: $this->vocabulary = Vocabulary::create([ Chris@18: 'name' => 'quickedit testing tags', Chris@18: 'vid' => 'quickedit_testing_tags', Chris@18: ]); Chris@18: $this->vocabulary->save(); Chris@18: $this->fieldName = 'field_' . $this->vocabulary->id(); Chris@18: Chris@18: $handler_settings = [ Chris@18: 'target_bundles' => [ Chris@18: $this->vocabulary->id() => $this->vocabulary->id(), Chris@18: ], Chris@18: 'auto_create' => TRUE, Chris@18: ]; Chris@18: $this->createEntityReferenceField('node', 'article', $this->fieldName, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); Chris@18: Chris@18: entity_get_form_display('node', 'article', 'default') Chris@18: ->setComponent($this->fieldName, [ Chris@18: 'type' => 'entity_reference_autocomplete_tags', Chris@18: 'weight' => -4, Chris@18: ]) Chris@18: ->save(); Chris@18: Chris@18: entity_get_display('node', 'article', 'default') Chris@18: ->setComponent($this->fieldName, [ Chris@18: 'type' => 'entity_reference_label', Chris@18: 'weight' => 10, Chris@18: ]) Chris@18: ->save(); Chris@18: entity_get_display('node', 'article', 'teaser') Chris@18: ->setComponent($this->fieldName, [ Chris@18: 'type' => 'entity_reference_label', Chris@18: 'weight' => 10, Chris@18: ]) Chris@18: ->save(); Chris@18: Chris@18: $this->term1 = $this->createTerm(); Chris@18: $this->term2 = $this->createTerm(); Chris@18: Chris@18: $node = []; Chris@18: $node['type'] = 'article'; Chris@18: $node[$this->fieldName][]['target_id'] = $this->term1->id(); Chris@18: $node[$this->fieldName][]['target_id'] = $this->term2->id(); Chris@18: $this->node = $this->drupalCreateNode($node); Chris@18: Chris@18: $this->editorUser = $this->drupalCreateUser([ Chris@18: 'access content', Chris@18: 'create article content', Chris@18: 'edit any article content', Chris@18: 'administer nodes', Chris@18: 'access contextual links', Chris@18: 'access in-place editing', Chris@18: ]); Chris@18: } Chris@18: Chris@18: /** Chris@18: * Tests Quick Edit autocomplete term behavior. Chris@18: */ Chris@18: public function testAutocompleteQuickEdit() { Chris@18: $page = $this->getSession()->getPage(); Chris@18: $assert = $this->assertSession(); Chris@18: Chris@18: $this->drupalLogin($this->editorUser); Chris@18: $this->drupalGet('node/' . $this->node->id()); Chris@18: Chris@18: // Wait "Quick edit" button for node. Chris@18: $assert->waitForElement('css', '[data-quickedit-entity-id="node/' . $this->node->id() . '"] .contextual .quickedit'); Chris@18: // Click by "Quick edit". Chris@18: $this->clickContextualLink('[data-quickedit-entity-id="node/' . $this->node->id() . '"]', 'Quick edit'); Chris@18: // Switch to body field. Chris@18: $page->find('css', '[data-quickedit-field-id="node/' . $this->node->id() . '/' . $this->fieldName . '/' . $this->node->language()->getId() . '/full"]')->click(); Chris@18: Chris@18: // Open Quick Edit. Chris@18: $quickedit_field_locator = '[name="field_quickedit_testing_tags[target_id]"]'; Chris@18: $tag_field = $assert->waitForElementVisible('css', $quickedit_field_locator); Chris@18: $tag_field->focus(); Chris@18: $tags = $tag_field->getValue(); Chris@18: Chris@18: // Check existing terms. Chris@18: $this->assertTrue(strpos($tags, $this->term1->label()) !== FALSE); Chris@18: $this->assertTrue(strpos($tags, $this->term2->label()) !== FALSE); Chris@18: Chris@18: // Add new term. Chris@18: $new_tag = $this->randomMachineName(); Chris@18: $tags .= ', ' . $new_tag; Chris@18: $assert->waitForElementVisible('css', $quickedit_field_locator)->setValue($tags); Chris@18: $assert->waitOnAutocomplete(); Chris@18: // Wait and click by "Save" button after body field was changed. Chris@18: $assert->waitForElementVisible('css', '.quickedit-toolgroup.ops [type="submit"][aria-hidden="false"]')->click(); Chris@18: $assert->waitOnAutocomplete(); Chris@18: Chris@18: // Reload the page and check new term. Chris@18: $this->drupalGet('node/' . $this->node->id()); Chris@18: $link = $assert->waitForLink($new_tag); Chris@18: $this->assertNotEmpty($link); Chris@18: } Chris@18: Chris@18: /** Chris@18: * Returns a new term with random name and description in $this->vocabulary. Chris@18: * Chris@18: * @return \Drupal\Core\Entity\EntityInterface|\Drupal\taxonomy\Entity\Term Chris@18: * The created taxonomy term. Chris@18: * Chris@18: * @throws \Drupal\Core\Entity\EntityStorageException Chris@18: */ Chris@18: protected function createTerm() { Chris@18: $filter_formats = filter_formats(); Chris@18: $format = array_pop($filter_formats); Chris@18: $term = Term::create([ Chris@18: 'name' => $this->randomMachineName(), Chris@18: 'description' => $this->randomMachineName(), Chris@18: // Use the first available text format. Chris@18: 'format' => $format->id(), Chris@18: 'vid' => $this->vocabulary->id(), Chris@18: 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, Chris@18: ]); Chris@18: $term->save(); Chris@18: return $term; Chris@18: } Chris@18: Chris@18: }