createVocabulary example

protected function setUp(): void {
    parent::setUp();

    $this->installEntitySchema('taxonomy_term');
  }

  /** * Tests loading multiple taxonomy terms by term ID and vocabulary. */
  public function testTaxonomyTermMultipleLoad() {
    // Create a vocabulary.     $vocabulary = $this->createVocabulary();

    // Create five terms in the vocabulary.     $i = 0;
    while ($i < 5) {
      $i++;
      $this->createTerm($vocabulary);
    }
    // Load the terms from the vocabulary.     $term_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
    $terms = $term_storage->loadByProperties(['vid' => $vocabulary->id()]);
    $count = count($terms);
    
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Create an administrative user.     $this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));

    // Create a vocabulary to which the terms will be assigned.     $this->vocabulary = $this->createVocabulary();

    // Add some custom languages.     foreach (['aa', 'bb', 'cc'] as $language_code) {
      ConfigurableLanguage::create([
        'id' => $language_code,
        'label' => $this->randomMachineName(),
      ])->save();
    }
  }

  public function testTermLanguage() {
    
protected $defaultTheme = 'stark';

  protected $vocab;
  protected $commentType;

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

    $this->vocab = $this->createVocabulary();
    $this->commentType = CommentType::create([
      'id' => 'taxonomy_comment',
      'label' => 'Taxonomy comment',
      'description' => '',
      'target_entity_type_id' => 'taxonomy_term',
    ]);
    $this->commentType->save();
    $this->addDefaultCommentField(
      'taxonomy_term',
      $this->vocab->id(),
      'field_comment',
      
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->setupLanguages();
    $this->vocabulary = $this->createVocabulary();
    $this->enableTranslation();
    $this->setUpTerm();
    $this->setUpTermReferenceField();
    $this->setUpNode();
  }

  /** * Tests if the translated taxonomy term is displayed. */
  public function testTranslatedTaxonomyTermReferenceDisplay() {
    $path = 'node/' . $this->node->id();
    
node_access_test_add_field(NodeType::load('article'));
    \Drupal::state()->set('node_access_test.private', TRUE);

    // Create 10 nodes.     for ($i = 1; $i <= 5; $i++) {
      $this->nodes[] = $this->drupalCreateNode(['type' => 'page']);
      // These 5 articles are inaccessible to the admin user doing the uninstalling.       $this->nodes[] = $this->drupalCreateNode(['type' => 'article', 'uid' => 0, 'private' => TRUE]);
    }

    // Create 3 top-level taxonomy terms, each with 11 children.     $vocabulary = $this->createVocabulary();
    for ($i = 1; $i <= 3; $i++) {
      $term = $this->createTerm($vocabulary);
      $this->terms[] = $term;
      for ($j = 1; $j <= 11; $j++) {
        $this->terms[] = $this->createTerm($vocabulary['parent' => ['target_id' => $term->id()]]);
      }
    }
  }

  /** * Tests that Node and Taxonomy can be uninstalled. */


  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Tests contextual links. */
  public function testTermContextualLinks() {
    $vocabulary = $this->createVocabulary();
    $term = $this->createTerm($vocabulary);

    $user = $this->drupalCreateUser([
      'administer taxonomy',
      'access contextual links',
    ]);
    $this->drupalLogin($user);

    $this->drupalGet('taxonomy/term/' . $term->id());
    $this->assertSession()->elementExists('css', 'div[data-contextual-id^="taxonomy_term:taxonomy_term=' . $term->id() . ':"]');
  }

}
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
    $this->vocabulary = $this->createVocabulary();
    $this->drupalPlaceBlock('local_actions_block');
    $this->drupalPlaceBlock('page_title_block');
  }

  /** * Create, edit and delete a vocabulary via the user interface. */
  public function testVocabularyInterface() {
    // Visit the main taxonomy administration page.     $this->drupalGet('admin/structure/taxonomy');

    

  protected function setUp(): void {
    parent::setUp();

    // Create an administrative user.     $this->drupalLogin($this->drupalCreateUser([
      'administer taxonomy',
      'bypass node access',
    ]));

    // Create a vocabulary and add two term reference fields to article nodes.     $this->vocabulary = $this->createVocabulary();

    $this->fieldName1 = mb_strtolower($this->randomMachineName());
    $handler_settings = [
      'target_bundles' => [
        $this->vocabulary->id() => $this->vocabulary->id(),
      ],
      'auto_create' => TRUE,
    ];
    $this->createEntityReferenceField('node', 'article', $this->fieldName1, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);

    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    
/** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE): void {
    parent::setUp($import_test_views);

    $this->installEntitySchema('taxonomy_term');
    $this->installConfig(['filter']);

    /** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary */
    $vocabulary = $this->createVocabulary();
    $this->term1 = $this->createTerm($vocabulary);

    ViewTestData::createTestViews(static::class['taxonomy_test_views']);
  }

  /** * Tests the taxonomy field handler. */
  public function testViewsHandlerTidField() {
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');

    
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->setupLanguages();
    $this->vocabulary = $this->createVocabulary();
    $this->enableTranslation();
    $this->setUpTerms();
    $this->setUpTermReferenceField();
  }

  /** * Tests translated breadcrumbs. */
  public function testTranslatedBreadcrumbs() {
    // Ensure non-translated breadcrumb is correct.     $breadcrumb = [Url::fromRoute('<front>')->toString() => 'Home'];
    

  protected function setUp(): void {
    parent::setUp();
    $this->installConfig(['filter']);
    $this->installEntitySchema('taxonomy_term');
  }

  /** * Tests that a deleted term is no longer in the vocabulary. */
  public function testTermDelete() {
    $vocabulary = $this->createVocabulary();
    $valid_term = $this->createTerm($vocabulary);
    // Delete a valid term.     $valid_term->delete();
    $terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['vid' => $vocabulary->id()]);
    $this->assertEmpty($terms, 'Vocabulary is empty after deletion');
  }

  /** * Deleting a parent of a term with multiple parents does not delete the term. */
  public function testMultipleParentDelete() {
    
'filter',
    'taxonomy',
    'text',
    'user',
  ];

  /** * Tests that a basic taxonomy entity query works. */
  public function testTermEntityQuery() {
    $this->installEntitySchema('taxonomy_term');
    $vocabulary = $this->createVocabulary();

    $terms = [];
    for ($i = 0; $i < 5; $i++) {
      $term = $this->createTerm($vocabulary);
      $terms[$term->id()] = $term;
    }
    $result = \Drupal::entityQuery('taxonomy_term')->accessCheck(FALSE)->execute();
    sort($result);
    $this->assertEquals(array_keys($terms)$result);
    $tid = reset($result);
    $ids = (object) [
      
protected $vocabulary;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->drupalLogin($this->drupalCreateUser([
      'administer taxonomy',
      'bypass node access',
    ]));
    $this->vocabulary = $this->createVocabulary();
  }

  /** * Tests that the pager is displayed properly on the term overview page. */
  public function testTaxonomyTermOverviewPager() {
    // Set limit to 3 terms per page.     $this->config('taxonomy.settings')
      ->set('terms_per_page_admin', '3')
      ->save();

    
    $contexts = $context_repository->getAvailableContexts();
    $this->assertArrayHasKey('@taxonomy_term.taxonomy_term_route_context:taxonomy_term', $contexts);
    $this->assertSame('entity:taxonomy_term', $contexts['@taxonomy_term.taxonomy_term_route_context:taxonomy_term']->getContextDefinition()
      ->getDataType());
  }

  /** * @covers ::getRuntimeContexts */
  public function testGetRuntimeContexts() {
    // Create term.     $vocabulary = $this->createVocabulary();
    $term = $this->createTerm($vocabulary);

    // Create RouteMatch from term entity.     $url = $term->toUrl();
    $route_provider = \Drupal::service('router.route_provider');
    $route = $route_provider->getRouteByName($url->getRouteName());
    $route_match = new RouteMatch($url->getRouteName()$route[
      'taxonomy_term' => $term,
    ]);

    // Initiate TermRouteContext with RouteMatch.
$assert_session->statusCodeEquals(200);
    $assert_session->pageTextContains('Vocabulary name');
    $assert_session->linkNotExists('Add vocabulary');
  }

  /** * Tests the vocabulary overview permission. */
  public function testTaxonomyVocabularyOverviewPermissions() {
    // Create two vocabularies, one with two terms, the other without any term.     /** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary1 , $vocabulary2 */
    $vocabulary1 = $this->createVocabulary();
    $vocabulary2 = $this->createVocabulary();
    $vocabulary1_id = $vocabulary1->id();
    $vocabulary2_id = $vocabulary2->id();
    $this->createTerm($vocabulary1);
    $this->createTerm($vocabulary1);

    // Assert expected help texts on first vocabulary.     $vocabulary1_label = Unicode::ucfirst($vocabulary1->label());
    $edit_help_text = "You can reorganize the terms in $vocabulary1_label using their drag-and-drop handles, and group terms under a parent term by sliding them under and to the right of the parent.";
    $no_edit_help_text = "$vocabulary1_label contains the following terms.";

    
Home | Imprint | This part of the site doesn't use cookies.