TaxonomyVocabularyArgumentTest.php 1.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
<?php

namespace Drupal\taxonomy\Tests\Views;

use Drupal\taxonomy\Entity\Vocabulary;

/**
 * Tests the vocabulary argument.
 *
 * @group taxonomy
 */
class TaxonomyVocabularyArgumentTest extends TaxonomyTestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = ['taxonomy', 'taxonomy_test_views', 'views'];

  /**
   * {@inheritdoc}
   */
  public static $testViews = ['test_argument_taxonomy_vocabulary'];

  /**
   * @var \Drupal\taxonomy\TermInterface[]
   */
  protected $terms = [];

  /**
   * Vocabularies used for creating terms.
   *
   * @var \Drupal\taxonomy\VocabularyInterface[]
   */
  protected $vocabularies;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    // Add default vocabulary to list of vocabularies.
    $this->vocabularies[] = $this->vocabulary;
    // Create additional vocabulary.
    $vocabulary = Vocabulary::create([
      'name' => 'Views testing category',
      'vid' => 'views_testing_category',
    ]);
    $vocabulary->save();
    $this->vocabularies[] = $vocabulary;

    // Create some terms.
    $this->terms[0] = $this->createTerm([
      'name' => 'First',
      'vid' => $this->vocabularies[0]->id(),
    ]);
    $this->terms[1] = $this->createTerm([
      'name' => 'Second',
      'vid' => $this->vocabularies[1]->id(),
    ]);
  }

  /**
   * Tests the vocabulary argument handler.
   *
   * @see Drupal\taxonomy\Plugin\views\argument\VocabularyVid
   */
  public function testTermWithVocabularyArgument() {
    $this->drupalGet('test_argument_taxonomy_vocabulary/' . $this->vocabularies[0]->id());
    // First term should be present.
    $this->assertText($this->terms[0]->label());
    // Second term should not be present.
    $this->assertNoText($this->terms[1]->label());
  }

}