You are here

protected function SitemapTaxonomyTestBase::createTerms in Sitemap 8

Same name and namespace in other branches
  1. 8.2 src/Tests/SitemapTaxonomyTestBase.php \Drupal\sitemap\Tests\SitemapTaxonomyTestBase::createTerms()
  2. 2.0.x src/Tests/SitemapTaxonomyTestBase.php \Drupal\sitemap\Tests\SitemapTaxonomyTestBase::createTerms()

Create taxonomy terms.

Parameters

\Drupal\taxonomy\Entity\Vocabulary $vocabulary: Taxonomy vocabulary.

Return value

array List of tags.

4 calls to SitemapTaxonomyTestBase::createTerms()
SitemapTaxonomyTermsRssTest::setUp in src/Tests/SitemapTaxonomyTermsRssTest.php
Sets up a Drupal site for running functional and integration tests.
SitemapTaxonomyTermsTest::setUp in src/Tests/SitemapTaxonomyTermsTest.php
Sets up a Drupal site for running functional and integration tests.
SitemapTaxonomyTest::testVocabularyDescription in src/Tests/SitemapTaxonomyTest.php
Tests vocabulary description.
SitemapTaxonomyTestBase::createNodeWithTerms in src/Tests/SitemapTaxonomyTestBase.php
Create node and assign tags to it.

File

src/Tests/SitemapTaxonomyTestBase.php, line 79

Class

SitemapTaxonomyTestBase
Base class for some Sitemap test cases.

Namespace

Drupal\sitemap\Tests

Code

protected function createTerms(Vocabulary $vocabulary) {
  $terms = [
    $this
      ->createTerm($vocabulary),
    $this
      ->createTerm($vocabulary),
    $this
      ->createTerm($vocabulary),
  ];
  $this->terms = $terms;

  // Make term 2 child of term 1, term 3 child of term 2.
  $edit = [
    // Term 1.
    'terms[tid:' . $terms[0]
      ->id() . ':0][term][tid]' => $terms[0]
      ->id(),
    'terms[tid:' . $terms[0]
      ->id() . ':0][term][parent]' => 0,
    'terms[tid:' . $terms[0]
      ->id() . ':0][term][depth]' => 0,
    'terms[tid:' . $terms[0]
      ->id() . ':0][weight]' => 0,
    // Term 2.
    'terms[tid:' . $terms[1]
      ->id() . ':0][term][tid]' => $terms[1]
      ->id(),
    'terms[tid:' . $terms[1]
      ->id() . ':0][term][parent]' => $terms[0]
      ->id(),
    'terms[tid:' . $terms[1]
      ->id() . ':0][term][depth]' => 1,
    'terms[tid:' . $terms[1]
      ->id() . ':0][weight]' => 0,
    // Term 3.
    'terms[tid:' . $terms[2]
      ->id() . ':0][term][tid]' => $terms[2]
      ->id(),
    'terms[tid:' . $terms[2]
      ->id() . ':0][term][parent]' => $terms[1]
      ->id(),
    'terms[tid:' . $terms[2]
      ->id() . ':0][term][depth]' => 2,
    'terms[tid:' . $terms[2]
      ->id() . ':0][weight]' => 0,
  ];
  $this
    ->drupalPostForm('admin/structure/taxonomy/manage/' . $vocabulary
    ->get('vid') . '/overview', $edit, t('Save'));
  return $terms;
}