function TaxonomyViewsFieldAccessTest::testTermFields

Same name in other branches
  1. 9 core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyViewsFieldAccessTest.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyViewsFieldAccessTest::testTermFields()
  2. 8.9.x core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyViewsFieldAccessTest.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyViewsFieldAccessTest::testTermFields()
  3. 10 core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyViewsFieldAccessTest.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyViewsFieldAccessTest::testTermFields()

Check access for taxonomy fields.

File

core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyViewsFieldAccessTest.php, line 35

Class

TaxonomyViewsFieldAccessTest
Tests base field access in Views for the taxonomy entity.

Namespace

Drupal\Tests\taxonomy\Kernel\Views

Code

public function testTermFields() : void {
    $vocab = Vocabulary::create([
        'vid' => 'random',
        'name' => 'Randomness',
    ]);
    $vocab->save();
    $term1 = Term::create([
        'name' => 'Semi random',
        'vid' => $vocab->id(),
    ]);
    $term1->save();
    $term2 = Term::create([
        'name' => 'Majorly random',
        'vid' => $vocab->id(),
    ]);
    $term2->save();
    $term3 = Term::create([
        'name' => 'Not really random',
        'vid' => $vocab->id(),
    ]);
    $term3->save();
    $this->assertFieldAccess('taxonomy_term', 'name', 'Majorly random');
    $this->assertFieldAccess('taxonomy_term', 'name', 'Semi random');
    $this->assertFieldAccess('taxonomy_term', 'name', 'Not really random');
    $this->assertFieldAccess('taxonomy_term', 'tid', $term1->id());
    $this->assertFieldAccess('taxonomy_term', 'tid', $term2->id());
    $this->assertFieldAccess('taxonomy_term', 'tid', $term3->id());
    $this->assertFieldAccess('taxonomy_term', 'uuid', $term1->uuid());
    $this->assertFieldAccess('taxonomy_term', 'uuid', $term2->uuid());
    $this->assertFieldAccess('taxonomy_term', 'uuid', $term3->uuid());
}

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