Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / pathauto / tests / src / Kernel / PathautoTokenTest.php
index 30c5ad1d25a7308e64c64e58210c857fea3e4bd4..1a05007f6e7faaaba7fe0165a4da78b3130293ed 100644 (file)
@@ -39,6 +39,42 @@ class PathautoTokenTest extends KernelTestBase {
     $alias_cleaner = \Drupal::service('pathauto.alias_cleaner');
     $alias_cleaner->cleanTokenValues($replacements, $data, array());
     $this->assertEqual($replacements['[array:join-path]'], 'test-first-arg/array-value');
+
+    // Test additional token cleaning and its configuration.
+    $safe_tokens = $this->config('pathauto.settings')->get('safe_tokens');
+    $safe_tokens[] = 'safe';
+    $this->config('pathauto.settings')
+      ->set('safe_tokens', $safe_tokens)
+      ->save();
+
+    $safe_tokens = [
+      '[example:path]',
+      '[example:url]',
+      '[example:url-brief]',
+      '[example:login-url]',
+      '[example:login-url:relative]',
+      '[example:url:relative]',
+      '[example:safe]',
+    ];
+    $unsafe_tokens = [
+      '[example:path_part]',
+      '[example:something_url]',
+      '[example:unsafe]',
+    ];
+    foreach ($safe_tokens as $token) {
+      $replacements = [
+        $token => 'this/is/a/path',
+      ];
+      $alias_cleaner->cleanTokenValues($replacements);
+      $this->assertEquals('this/is/a/path', $replacements[$token], "Token $token cleaned.");
+    }
+    foreach ($unsafe_tokens as $token) {
+      $replacements = [
+        $token => 'This is not a / path',
+      ];
+      $alias_cleaner->cleanTokenValues($replacements);
+      $this->assertEquals('not-path', $replacements[$token], "Token $token not cleaned.");
+    }
   }
 
   /**