function QuickEditAutocompleteTermTest::testAutocompleteQuickEdit

Same name and namespace in other branches
  1. 8.9.x core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditAutocompleteTermTest.php \Drupal\Tests\quickedit\FunctionalJavascript\QuickEditAutocompleteTermTest::testAutocompleteQuickEdit()

Tests Quick Edit autocomplete term behavior.

File

core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditAutocompleteTermTest.php, line 148

Class

QuickEditAutocompleteTermTest
Tests in-place editing of autocomplete tags.

Namespace

Drupal\Tests\quickedit\FunctionalJavascript

Code

public function testAutocompleteQuickEdit() {
    $page = $this->getSession()
        ->getPage();
    $assert = $this->assertSession();
    $this->drupalLogin($this->editorUser);
    $this->drupalGet('node/' . $this->node
        ->id());
    // Wait "Quick edit" button for node.
    $assert->waitForElement('css', '[data-quickedit-entity-id="node/' . $this->node
        ->id() . '"] .contextual .quickedit');
    // Click by "Quick edit".
    $this->clickContextualLink('[data-quickedit-entity-id="node/' . $this->node
        ->id() . '"]', 'Quick edit');
    // Switch to body field.
    $page->find('css', '[data-quickedit-field-id="node/' . $this->node
        ->id() . '/' . $this->fieldName . '/' . $this->node
        ->language()
        ->getId() . '/full"]')
        ->click();
    // Open Quick Edit.
    $quickedit_field_locator = '[name="field_quickedit_testing_tags[target_id]"]';
    $tag_field = $assert->waitForElementVisible('css', $quickedit_field_locator);
    $tag_field->focus();
    $tags = $tag_field->getValue();
    // Check existing terms.
    $this->assertStringContainsString($this->term1
        ->label(), $tags);
    $this->assertStringContainsString($this->term2
        ->label(), $tags);
    // Add new term.
    $new_tag = $this->randomMachineName();
    $tags .= ', ' . $new_tag;
    $assert->waitForElementVisible('css', $quickedit_field_locator)
        ->setValue($tags);
    $assert->waitOnAutocomplete();
    // Wait and click by "Save" button after body field was changed.
    $assert->waitForElementVisible('css', '.quickedit-toolgroup.ops [type="submit"][aria-hidden="false"]')
        ->click();
    $assert->waitOnAutocomplete();
    // Reload the page and check new term.
    $this->drupalGet('node/' . $this->node
        ->id());
    $link = $assert->waitForLink($new_tag);
    $this->assertNotEmpty($link);
}

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