1 path_pattern.test PathPatternUnitTestCase::testPatternLoadByEntity()

Test path_get_pattern_by_entity_type().

File

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

Class

PathPatternUnitTestCase
Unit tests for Path pattern functions.

Code

function testPatternLoadByEntity() {
  $config = config('path.settings');
  $config->set('node_story_en_pattern', 'story/en/[node:title] ');
  $config->set('node_story_pattern', 'story/[node:title]');
  $config->set('node_pattern', 'content/[node:title]');
  $config->set('user_pattern', 'users/[user:name]');
  $config->save();

  $tests = array(
    array('entity' => 'node', 'bundle' => 'story', 'langcode' => 'fr', 'expected' => 'story/[node:title]'),
    array('entity' => 'node', 'bundle' => 'story', 'langcode' => 'en', 'expected' => 'story/en/[node:title]'),
    array('entity' => 'node', 'bundle' => 'story', 'langcode' => LANGUAGE_NONE, 'expected' => 'story/[node:title]'),
    array('entity' => 'node', 'bundle' => 'page', 'langcode' => 'en', 'expected' => '[node:title]'),
    array('entity' => 'user', 'bundle' => 'user', 'langcode' => LANGUAGE_NONE, 'expected' => 'users/[user:name]'),
    array('entity' => 'invalid-entity', 'bundle' => '', 'langcode' => LANGUAGE_NONE, 'expected' => ''),
  );
  foreach ($tests as $test) {
    $actual = path_get_pattern_by_entity_type($test['entity'], $test['bundle'], $test['langcode']);
    $this->assertIdentical($actual, $test['expected'], format_string("path_get_pattern_by_entity_type('@entity', '@bundle', '@language') returned '@actual', expected '@expected'", array('@entity' => $test['entity'], '@bundle' => $test['bundle'], '@language' => $test['langcode'], '@actual' => $actual, '@expected' => $test['expected'])));
  }
}