Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / token / tests / src / Kernel / TaxonomyTest.php
index 73274df0812adae950b622c76d6279715c8918e0..abc99ea4d4fbe381c60afe5cc51a06907a387c68 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace Drupal\Tests\token\Kernel;
 
-use Drupal\Component\Utility\Unicode;
+use Drupal\taxonomy\Entity\Term;
 use Drupal\taxonomy\Entity\Vocabulary;
 use Drupal\language\Entity\ConfigurableLanguage;
 use Drupal\Core\Url;
@@ -13,6 +13,7 @@ use Drupal\Core\Url;
  * @group token
  */
 class TaxonomyTest extends KernelTestBase {
+
   protected $vocab;
 
   /**
@@ -20,7 +21,7 @@ class TaxonomyTest extends KernelTestBase {
    *
    * @var array
    */
-  public static $modules = array('taxonomy', 'text', 'language');
+  public static $modules = ['taxonomy', 'text', 'language'];
 
   /**
    * {@inheritdoc}
@@ -43,31 +44,31 @@ class TaxonomyTest extends KernelTestBase {
    * Test the additional taxonomy term tokens.
    */
   function testTaxonomyTokens() {
-    $root_term = $this->addTerm($this->vocab, array('name' => 'Root term', 'path' => array('alias' => '/root-term')));
-    $tokens = array(
-      'url' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], array('absolute' => TRUE))->toString(),
-      'url:absolute' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], array('absolute' => TRUE))->toString(),
-      'url:relative' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], array('absolute' => FALSE))->toString(),
+    $root_term = $this->addTerm($this->vocab, ['name' => 'Root term', 'path' => ['alias' => '/root-term']]);
+    $tokens = [
+      'url' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], ['absolute' => TRUE])->toString(),
+      'url:absolute' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], ['absolute' => TRUE])->toString(),
+      'url:relative' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $root_term->id()], ['absolute' => FALSE])->toString(),
       'url:path' => '/root-term',
       'url:unaliased:path' => "/taxonomy/term/{$root_term->id()}",
-      'edit-url' => Url::fromRoute('entity.taxonomy_term.edit_form', ['taxonomy_term' => $root_term->id()], array('absolute' => TRUE))->toString(),
+      'edit-url' => Url::fromRoute('entity.taxonomy_term.edit_form', ['taxonomy_term' => $root_term->id()], ['absolute' => TRUE])->toString(),
       'parents' => NULL,
       'parents:count' => NULL,
       'parents:keys' => NULL,
       'root' => NULL,
       // Deprecated tokens
       'url:alias' => '/root-term',
-    );
-    $this->assertTokens('term', array('term' => $root_term), $tokens);
-
-    $parent_term = $this->addTerm($this->vocab, array('name' => 'Parent term', 'parent' => $root_term->id()));
-    $tokens = array(
-      'url' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], array('absolute' => TRUE))->toString(),
-      'url:absolute' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], array('absolute' => TRUE))->toString(),
-      'url:relative' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], array('absolute' => FALSE))->toString(),
+    ];
+    $this->assertTokens('term', ['term' => $root_term], $tokens);
+
+    $parent_term = $this->addTerm($this->vocab, ['name' => 'Parent term', 'parent' => $root_term->id()]);
+    $tokens = [
+      'url' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], ['absolute' => TRUE])->toString(),
+      'url:absolute' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], ['absolute' => TRUE])->toString(),
+      'url:relative' => Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $parent_term->id()], ['absolute' => FALSE])->toString(),
       'url:path' => "/taxonomy/term/{$parent_term->id()}",
       'url:unaliased:path' => "/taxonomy/term/{$parent_term->id()}",
-      'edit-url' => Url::fromRoute('entity.taxonomy_term.edit_form', ['taxonomy_term' => $parent_term->id()], array('absolute' => TRUE))->toString(),
+      'edit-url' => Url::fromRoute('entity.taxonomy_term.edit_form', ['taxonomy_term' => $parent_term->id()], ['absolute' => TRUE])->toString(),
       'parents' => 'Root term',
       'parents:count' => 1,
       'parents:keys' => $root_term->id(),
@@ -75,16 +76,16 @@ class TaxonomyTest extends KernelTestBase {
       'root:tid' => $root_term->id(),
       // Deprecated tokens
       'url:alias' => "/taxonomy/term/{$parent_term->id()}",
-    );
-    $this->assertTokens('term', array('term' => $parent_term), $tokens);
+    ];
+    $this->assertTokens('term', ['term' => $parent_term], $tokens);
 
-    $term = $this->addTerm($this->vocab, array('name' => 'Test term', 'parent' => $parent_term->id()));
-    $tokens = array(
+    $term = $this->addTerm($this->vocab, ['name' => 'Test term', 'parent' => $parent_term->id()]);
+    $tokens = [
       'parents' => 'Root term, Parent term',
       'parents:count' => 2,
-      'parents:keys' => implode(', ', array($root_term->id(), $parent_term->id())),
-    );
-    $this->assertTokens('term', array('term' => $term), $tokens);
+      'parents:keys' => implode(', ', [$root_term->id(), $parent_term->id()]),
+    ];
+    $this->assertTokens('term', ['term' => $term], $tokens);
   }
 
   /**
@@ -92,28 +93,28 @@ class TaxonomyTest extends KernelTestBase {
    */
   function testVocabularyTokens() {
     $vocabulary = $this->vocab;
-    $tokens = array(
+    $tokens = [
       'machine-name' => 'tags',
-      'edit-url' => Url::fromRoute('entity.taxonomy_vocabulary.edit_form', ['taxonomy_vocabulary' => $vocabulary->id()], array('absolute' => TRUE))->toString(),
-    );
-    $this->assertTokens('vocabulary', array('vocabulary' => $vocabulary), $tokens);
+      'edit-url' => Url::fromRoute('entity.taxonomy_vocabulary.edit_form', ['taxonomy_vocabulary' => $vocabulary->id()], ['absolute' => TRUE])->toString(),
+    ];
+    $this->assertTokens('vocabulary', ['vocabulary' => $vocabulary], $tokens);
   }
 
-  function addVocabulary(array $vocabulary = array()) {
-    $vocabulary += array(
-      'name' => Unicode::strtolower($this->randomMachineName(5)),
-      'nodes' => array('article' => 'article'),
-    );
-    $vocabulary = entity_create('taxonomy_vocabulary', $vocabulary)->save();
+  function addVocabulary(array $vocabulary = []) {
+    $vocabulary += [
+      'name' => mb_strtolower($this->randomMachineName(5)),
+      'nodes' => ['article' => 'article'],
+    ];
+    $vocabulary = Vocabulary::create($vocabulary)->save();
     return $vocabulary;
   }
 
-  function addTerm($vocabulary, array $term = array()) {
-    $term += array(
-      'name' => Unicode::strtolower($this->randomMachineName(5)),
+  function addTerm($vocabulary, array $term = []) {
+    $term += [
+      'name' => mb_strtolower($this->randomMachineName(5)),
       'vid' => $vocabulary->id(),
-    );
-    $term = entity_create('taxonomy_term', $term);
+    ];
+    $term = Term::create($term);
     $term->save();
     return $term;
   }
@@ -146,6 +147,8 @@ class TaxonomyTest extends KernelTestBase {
     ])->save();
 
     // Expect the parent term to be in the specified language.
-    $this->assertTokens('term', array('term' => $child_term), ['parents' => 'german-parent-term'], ['langcode' => 'de']);
+    $this->assertTokens('term', ['term' => $child_term], ['parents' => 'german-parent-term'], ['langcode' => 'de']);
+    $this->assertTokens('term', ['term' => $child_term], ['root' => 'german-parent-term'], ['langcode' => 'de']);
   }
+
 }