1 path_pattern.test PathPatternUnitTestCase::testCleanString()

Test path_clean_string().

File

core/modules/path/tests/path_pattern.test, line 174
Functionality tests for automatic path generation.

Class

PathPatternUnitTestCase
Unit tests for Path pattern functions.

Code

function testCleanString() {
  $config = config('path.settings');
  $tests = array();
  $config->set('ignore_words', ', a, in, is,that, the  , this, with, ');
  $config->set('max_component_length', 35);
  $config->save();

  // Test the 'ignored words' removal.
  $tests['this'] = 'this';
  $tests['this with that'] = 'this-with-that';
  $tests['this thing with that thing'] = 'thing-thing';

  // Test length truncation and duplicate separator removal.
  $tests[' - Dave – Greg — Freso - Mike'] = 'dave-greg-freso-mike';

  // Test that HTML tags are removed.
  $tests['This <span class="text">text</span> has <br /><a href="http://example.com"><strong>HTML tags</strong></a>.'] = 'text-has-html-tags';
  $tests[check_plain('This <span class="text">text</span> has <br /><a href="http://example.com"><strong>HTML tags</strong></a>.')] = 'text-has-html-tags';

  // Test fancy single and double quotes are removed along with normal ones.
  $tests['"double" “fancy” \'single\' ‘fancy’'] = 'double-fancy-single-fancy';

  foreach ($tests as $input => $expected) {
    $output = path_clean_string($input);
    $this->assertEqual($output, $expected, format_string("path_clean_string('@input') expected '@expected', actual '@output'", array('@input' => $input, '@expected' => $expected, '@output' => $output)));
  }

  // Test transliteration replacements.
  $config->set('transliterate', 1);
  $config->save();
  backdrop_static_reset('path_clean_string');

  // cspell:disable-next-line
  $input = 'ädd ä accènts thè';
  $expected = 'add-accents'; // "a" and "the" is stripped out.
  $output = path_clean_string($input);
  $this->assertEqual($output, $expected, format_string("path_clean_string('@input') expected '@expected', actual '@output'", array('@input' => $input, '@expected' => $expected, '@output' => $output)));

  // German transliteration: "Ä" -> "ae", "ü" -> "ue", "ö" -> "oe".
  // cspell:disable
  $input = 'Ärger im Büro ist möglich';
  $expected = 'aerger-im-buero-ist-moeglich';
  // cspell:enable
  $output = path_clean_string($input, array('langcode' => 'de'));
  $this->assertEqual($output, $expected, format_string("path_clean_string('@input') expected '@expected', actual '@output'", array(
    '@input' => $input,
    '@expected' => $expected,
    '@output' => $output,
  )));
}