function TermTest::testReSavingTags

Same name and namespace in other branches
  1. 8.9.x core/modules/taxonomy/tests/src/Functional/TermTest.php \Drupal\Tests\taxonomy\Functional\TermTest::testReSavingTags()
  2. 10 core/modules/taxonomy/tests/src/Functional/TermTest.php \Drupal\Tests\taxonomy\Functional\TermTest::testReSavingTags()
  3. 11.x core/modules/taxonomy/tests/src/Functional/TermTest.php \Drupal\Tests\taxonomy\Functional\TermTest::testReSavingTags()

Tests that editing and saving a node with no changes works correctly.

File

core/modules/taxonomy/tests/src/Functional/TermTest.php, line 708

Class

TermTest
Tests load, save and delete for taxonomy terms.

Namespace

Drupal\Tests\taxonomy\Functional

Code

public function testReSavingTags() {
    // Enable tags in the vocabulary.
    $field = $this->field;
    \Drupal::service('entity_display.repository')->getFormDisplay($field->getTargetEntityTypeId(), $field->getTargetBundle())
        ->setComponent($field->getName(), [
        'type' => 'entity_reference_autocomplete_tags',
    ])
        ->save();
    // Create a term and a node using it.
    $term = $this->createTerm($this->vocabulary);
    $edit = [];
    $edit['title[0][value]'] = $this->randomMachineName(8);
    $edit['body[0][value]'] = $this->randomMachineName(16);
    $edit[$this->field
        ->getName() . '[target_id]'] = $term->getName();
    $this->drupalGet('node/add/article');
    $this->submitForm($edit, 'Save');
    // Check that the term is displayed when editing and saving the node with no
    // changes.
    $this->clickLink('Edit');
    $this->assertSession()
        ->responseContains($term->getName());
    $this->submitForm([], 'Save');
    $this->assertSession()
        ->responseContains($term->getName());
}

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