Commit 29223699 authored by catch's avatar catch

Issue #1598600 by c31ck, Rob Loach: Convert path.test to PSR-0.

parent 03e6f03a
<?php
/**
* @file
* Definition of Drupal\system\Tests\Path\LookupTest.
*/
namespace Drupal\system\Tests\Path;
use Drupal\simpletest\WebTestBase;
/**
* Unit test for drupal_lookup_path().
*/
class LookupTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => t('Path lookup'),
'description' => t('Tests that drupal_lookup_path() returns correct paths.'),
'group' => t('Path API'),
);
}
/**
* Test that drupal_lookup_path() returns the correct path.
*/
function testDrupalLookupPath() {
$account = $this->drupalCreateUser();
$uid = $account->uid;
$name = $account->name;
// Test the situation where the source is the same for multiple aliases.
// Start with a language-neutral alias, which we will override.
$path = array(
'source' => "user/$uid",
'alias' => 'foo',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('Basic alias lookup works.'));
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Basic source lookup works.'));
// Create a language specific alias for the default language (English).
$path = array(
'source' => "user/$uid",
'alias' => "users/$name",
'langcode' => 'en',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('English alias overrides language-neutral alias.'));
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('English source overrides language-neutral source.'));
// Create a language-neutral alias for the same path, again.
$path = array(
'source' => "user/$uid",
'alias' => 'bar',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), "users/$name", t('English alias still returned after entering a language-neutral alias.'));
// Create a language-specific (xx-lolspeak) alias for the same path.
$path = array(
'source' => "user/$uid",
'alias' => 'LOL',
'langcode' => 'xx-lolspeak',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), "users/$name", t('English alias still returned after entering a LOLspeak alias.'));
// The LOLspeak alias should be returned if we really want LOLspeak.
$this->assertEqual(drupal_lookup_path('alias', $path['source'], 'xx-lolspeak'), 'LOL', t('LOLspeak alias returned if we specify xx-lolspeak to drupal_lookup_path().'));
// Create a new alias for this path in English, which should override the
// previous alias for "user/$uid".
$path = array(
'source' => "user/$uid",
'alias' => 'users/my-new-path',
'langcode' => 'en',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('Recently created English alias returned.'));
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Recently created English source returned.'));
// Remove the English aliases, which should cause a fallback to the most
// recently created language-neutral alias, 'bar'.
db_delete('url_alias')
->condition('langcode', 'en')
->execute();
drupal_clear_path_cache();
$this->assertEqual(drupal_lookup_path('alias', $path['source']), 'bar', t('Path lookup falls back to recently created language-neutral alias.'));
// Test the situation where the alias and language are the same, but
// the source differs. The newer alias record should be returned.
$account2 = $this->drupalCreateUser();
$path = array(
'source' => 'user/' . $account2->uid,
'alias' => 'bar',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Newer alias record is returned when comparing two LANGUAGE_NOT_SPECIFIED paths with the same alias.'));
}
}
<?php
/**
* @file
* Definition of Drupal\system\Tests\Path\MatchPathTest.
*/
namespace Drupal\system\Tests\Path;
use Drupal\simpletest\WebTestBase;
/**
* Unit tests for the drupal_match_path() function in path.inc.
*
* @see drupal_match_path().
*/
class MatchPathTest extends WebTestBase {
protected $front;
public static function getInfo() {
return array(
'name' => 'Drupal match path',
'description' => 'Tests the drupal_match_path() function to make sure it works properly.',
'group' => 'Path API',
);
}
function setUp() {
// Set up the database and testing environment.
parent::setUp();
// Set up a random site front page to test the '<front>' placeholder.
$this->front = $this->randomName();
variable_set('site_frontpage', $this->front);
// Refresh our static variables from the database.
$this->refreshVariables();
}
/**
* Run through our test cases, making sure each one works as expected.
*/
function testDrupalMatchPath() {
// Set up our test cases.
$tests = $this->drupalMatchPathTests();
foreach ($tests as $patterns => $cases) {
foreach ($cases as $path => $expected_result) {
$actual_result = drupal_match_path($path, $patterns);
$this->assertIdentical($actual_result, $expected_result, t('Tried matching the path <code>@path</code> to the pattern <pre>@patterns</pre> - expected @expected, got @actual.', array('@path' => $path, '@patterns' => $patterns, '@expected' => var_export($expected_result, TRUE), '@actual' => var_export($actual_result, TRUE))));
}
}
}
/**
* Helper function for testDrupalMatchPath(): set up an array of test cases.
*
* @return
* An array of test cases to cycle through.
*/
private function drupalMatchPathTests() {
return array(
// Single absolute paths.
'example/1' => array(
'example/1' => TRUE,
'example/2' => FALSE,
'test' => FALSE,
),
// Single paths with wildcards.
'example/*' => array(
'example/1' => TRUE,
'example/2' => TRUE,
'example/3/edit' => TRUE,
'example/' => TRUE,
'example' => FALSE,
'test' => FALSE,
),
// Single paths with multiple wildcards.
'node/*/revisions/*' => array(
'node/1/revisions/3' => TRUE,
'node/345/revisions/test' => TRUE,
'node/23/edit' => FALSE,
'test' => FALSE,
),
// Single paths with '<front>'.
'<front>' => array(
$this->front => TRUE,
"$this->front/" => FALSE,
"$this->front/edit" => FALSE,
'node' => FALSE,
'' => FALSE,
),
// Paths with both '<front>' and wildcards (should not work).
'<front>/*' => array(
$this->front => FALSE,
"$this->front/" => FALSE,
"$this->front/edit" => FALSE,
'node/12' => FALSE,
'' => FALSE,
),
// Multiple paths with the \n delimiter.
"node/*\nnode/*/edit" => array(
'node/1' => TRUE,
'node/view' => TRUE,
'node/32/edit' => TRUE,
'node/delete/edit' => TRUE,
'node/50/delete' => TRUE,
'test/example' => FALSE,
),
// Multiple paths with the \r delimiter.
"user/*\rexample/*" => array(
'user/1' => TRUE,
'example/1' => TRUE,
'user/1/example/1' => TRUE,
'user/example' => TRUE,
'test/example' => FALSE,
'user' => FALSE,
'example' => FALSE,
),
// Multiple paths with the \r\n delimiter.
"test\r\n<front>" => array(
'test' => TRUE,
$this->front => TRUE,
'example' => FALSE,
),
// Test existing regular expressions (should be escaped).
'[^/]+?/[0-9]' => array(
'test/1' => FALSE,
'[^/]+?/[0-9]' => TRUE,
),
);
}
}
<?php
/**
* @file
* Definition of Drupal\system\Tests\Path\SaveTest.
*/
namespace Drupal\system\Tests\Path;
use Drupal\simpletest\WebTestBase;
/**
* Tests the path_save() function.
*/
class SaveTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => t('Path save'),
'description' => t('Tests that path_save() exposes the previous alias value.'),
'group' => t('Path API'),
);
}
function setUp() {
// Enable a helper module that implements hook_path_update().
parent::setUp('path_test');
path_test_reset();
}
/**
* Tests that path_save() makes the original path available to modules.
*/
function testDrupalSaveOriginalPath() {
$account = $this->drupalCreateUser();
$uid = $account->uid;
$name = $account->name;
// Create a language-neutral alias.
$path = array(
'source' => "user/$uid",
'alias' => 'foo',
);
$path_original = $path;
path_save($path);
// Alter the path.
$path['alias'] = 'bar';
path_save($path);
// Test to see if the original alias is available to modules during
// hook_path_update().
$results = variable_get('path_test_results', array());
$this->assertIdentical($results['hook_path_update']['original']['alias'], $path_original['alias'], t('Old path alias available to modules during hook_path_update.'));
$this->assertIdentical($results['hook_path_update']['original']['source'], $path_original['source'], t('Old path alias available to modules during hook_path_update.'));
}
}
......@@ -2,131 +2,12 @@
/**
* @file
* Tests for path.inc.
* Definition of Drupal\system\Tests\Path\UrlAlterFunctionalTest.
*/
use Drupal\simpletest\WebTestBase;
/**
* Unit tests for the drupal_match_path() function in path.inc.
*
* @see drupal_match_path().
*/
class DrupalMatchPathTestCase extends WebTestBase {
protected $front;
public static function getInfo() {
return array(
'name' => 'Drupal match path',
'description' => 'Tests the drupal_match_path() function to make sure it works properly.',
'group' => 'Path API',
);
}
function setUp() {
// Set up the database and testing environment.
parent::setUp();
namespace Drupal\system\Tests\Path;
// Set up a random site front page to test the '<front>' placeholder.
$this->front = $this->randomName();
variable_set('site_frontpage', $this->front);
// Refresh our static variables from the database.
$this->refreshVariables();
}
/**
* Run through our test cases, making sure each one works as expected.
*/
function testDrupalMatchPath() {
// Set up our test cases.
$tests = $this->drupalMatchPathTests();
foreach ($tests as $patterns => $cases) {
foreach ($cases as $path => $expected_result) {
$actual_result = drupal_match_path($path, $patterns);
$this->assertIdentical($actual_result, $expected_result, t('Tried matching the path <code>@path</code> to the pattern <pre>@patterns</pre> - expected @expected, got @actual.', array('@path' => $path, '@patterns' => $patterns, '@expected' => var_export($expected_result, TRUE), '@actual' => var_export($actual_result, TRUE))));
}
}
}
/**
* Helper function for testDrupalMatchPath(): set up an array of test cases.
*
* @return
* An array of test cases to cycle through.
*/
private function drupalMatchPathTests() {
return array(
// Single absolute paths.
'example/1' => array(
'example/1' => TRUE,
'example/2' => FALSE,
'test' => FALSE,
),
// Single paths with wildcards.
'example/*' => array(
'example/1' => TRUE,
'example/2' => TRUE,
'example/3/edit' => TRUE,
'example/' => TRUE,
'example' => FALSE,
'test' => FALSE,
),
// Single paths with multiple wildcards.
'node/*/revisions/*' => array(
'node/1/revisions/3' => TRUE,
'node/345/revisions/test' => TRUE,
'node/23/edit' => FALSE,
'test' => FALSE,
),
// Single paths with '<front>'.
'<front>' => array(
$this->front => TRUE,
"$this->front/" => FALSE,
"$this->front/edit" => FALSE,
'node' => FALSE,
'' => FALSE,
),
// Paths with both '<front>' and wildcards (should not work).
'<front>/*' => array(
$this->front => FALSE,
"$this->front/" => FALSE,
"$this->front/edit" => FALSE,
'node/12' => FALSE,
'' => FALSE,
),
// Multiple paths with the \n delimiter.
"node/*\nnode/*/edit" => array(
'node/1' => TRUE,
'node/view' => TRUE,
'node/32/edit' => TRUE,
'node/delete/edit' => TRUE,
'node/50/delete' => TRUE,
'test/example' => FALSE,
),
// Multiple paths with the \r delimiter.
"user/*\rexample/*" => array(
'user/1' => TRUE,
'example/1' => TRUE,
'user/1/example/1' => TRUE,
'user/example' => TRUE,
'test/example' => FALSE,
'user' => FALSE,
'example' => FALSE,
),
// Multiple paths with the \r\n delimiter.
"test\r\n<front>" => array(
'test' => TRUE,
$this->front => TRUE,
'example' => FALSE,
),
// Test existing regular expressions (should be escaped).
'[^/]+?/[0-9]' => array(
'test/1' => FALSE,
'[^/]+?/[0-9]' => TRUE,
),
);
}
}
use Drupal\simpletest\WebTestBase;
/**
* Tests hook_url_alter functions.
......@@ -245,139 +126,3 @@ protected function assertUrlInboundAlter($original, $final) {
$this->assertIdentical($result, $final, t('Altered inbound URL %original, expected %final, and got %result.', array('%original' => $original, '%final' => $final, '%result' => $result)));
}
}
/**
* Unit test for drupal_lookup_path().
*/
class PathLookupTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => t('Path lookup'),
'description' => t('Tests that drupal_lookup_path() returns correct paths.'),
'group' => t('Path API'),
);
}
/**
* Test that drupal_lookup_path() returns the correct path.
*/
function testDrupalLookupPath() {
$account = $this->drupalCreateUser();
$uid = $account->uid;
$name = $account->name;
// Test the situation where the source is the same for multiple aliases.
// Start with a language-neutral alias, which we will override.
$path = array(
'source' => "user/$uid",
'alias' => 'foo',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('Basic alias lookup works.'));
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Basic source lookup works.'));
// Create a language specific alias for the default language (English).
$path = array(
'source' => "user/$uid",
'alias' => "users/$name",
'langcode' => 'en',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('English alias overrides language-neutral alias.'));
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('English source overrides language-neutral source.'));
// Create a language-neutral alias for the same path, again.
$path = array(
'source' => "user/$uid",
'alias' => 'bar',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), "users/$name", t('English alias still returned after entering a language-neutral alias.'));
// Create a language-specific (xx-lolspeak) alias for the same path.
$path = array(
'source' => "user/$uid",
'alias' => 'LOL',
'langcode' => 'xx-lolspeak',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), "users/$name", t('English alias still returned after entering a LOLspeak alias.'));
// The LOLspeak alias should be returned if we really want LOLspeak.
$this->assertEqual(drupal_lookup_path('alias', $path['source'], 'xx-lolspeak'), 'LOL', t('LOLspeak alias returned if we specify xx-lolspeak to drupal_lookup_path().'));
// Create a new alias for this path in English, which should override the
// previous alias for "user/$uid".
$path = array(
'source' => "user/$uid",
'alias' => 'users/my-new-path',
'langcode' => 'en',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('Recently created English alias returned.'));
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Recently created English source returned.'));
// Remove the English aliases, which should cause a fallback to the most
// recently created language-neutral alias, 'bar'.
db_delete('url_alias')
->condition('langcode', 'en')
->execute();
drupal_clear_path_cache();
$this->assertEqual(drupal_lookup_path('alias', $path['source']), 'bar', t('Path lookup falls back to recently created language-neutral alias.'));
// Test the situation where the alias and language are the same, but
// the source differs. The newer alias record should be returned.
$account2 = $this->drupalCreateUser();
$path = array(
'source' => 'user/' . $account2->uid,
'alias' => 'bar',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Newer alias record is returned when comparing two LANGUAGE_NOT_SPECIFIED paths with the same alias.'));
}
}
/**
* Tests the path_save() function.
*/
class PathSaveTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => t('Path save'),
'description' => t('Tests that path_save() exposes the previous alias value.'),
'group' => t('Path API'),
);
}
function setUp() {
// Enable a helper module that implements hook_path_update().
parent::setUp('path_test');
path_test_reset();
}
/**
* Tests that path_save() makes the original path available to modules.
*/
function testDrupalSaveOriginalPath() {
$account = $this->drupalCreateUser();
$uid = $account->uid;
$name = $account->name;
// Create a language-neutral alias.
$path = array(
'source' => "user/$uid",
'alias' => 'foo',
);
$path_original = $path;
path_save($path);
// Alter the path.
$path['alias'] = 'bar';
path_save($path);
// Test to see if the original alias is available to modules during
// hook_path_update().
$results = variable_get('path_test_results', array());
$this->assertIdentical($results['hook_path_update']['original']['alias'], $path_original['alias'], t('Old path alias available to modules during hook_path_update.'));
$this->assertIdentical($results['hook_path_update']['original']['source'], $path_original['source'], t('Old path alias available to modules during hook_path_update.'));
}
}
......@@ -20,7 +20,6 @@ files[] = tests/installer.test
files[] = tests/menu.test
files[] = tests/module.test
files[] = tests/pager.test
files[] = tests/path.test
files[] = tests/registry.test
files[] = tests/schema.test
files[] = tests/symfony.test
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment