You are here

public function TaxonomyUniqueTest::testEditTerm in Taxonomy unique 8.2

Tests whether terms can be saved using another terms name.

File

tests/src/Kernel/TaxonomyUniqueTest.php, line 89

Class

TaxonomyUniqueTest
Tests for taxonomy unique module.

Namespace

Drupal\Tests\taxonomy_unique\Kernel

Code

public function testEditTerm() {
  $vocabulary = $this
    ->createVocabulary();
  $GLOBALS['config']['taxonomy_unique.settings'] = [
    $vocabulary
      ->id() => TRUE,
  ];
  $t1 = $this
    ->createTerm($vocabulary, [
    'name' => 'Term 1',
  ]);
  $t1_violations = $t1
    ->validate();
  $this
    ->assertEquals(0, $t1_violations
    ->count());
  $t2 = $this
    ->createTerm($vocabulary, [
    'name' => 'Term 2',
  ]);
  $t2_violations = $t2
    ->validate();
  $this
    ->assertEquals(0, $t2_violations
    ->count());
  $t2
    ->setName('Term 1');
  $t2
    ->save();
  $violations = $t2
    ->validate();
  $this
    ->assertEquals(1, $violations
    ->count());
}