--- modules/simpletest/tests/custom_rewrite_url_inbound.inc 2008-11-06 13:53:29.000000000 +0100 +++ modules/simpletest/tests/custom_rewrite_url_inbound.test 2008-11-06 13:52:09.000000000 +0100 @@ -1,11 +1,62 @@ - t('Custom url rewrite inbound test'), + 'description' => t('Test for custom_url_rewrite_inbound function.'), + 'group' => t('Path'), + ); + } + + /** + * Tests the drupal_get_normal_path function without having included the custom_url_rewrite_inbound function. + */ + function testCustomUrlRewriteInboundWithoutFunction() { + $id = $this->randomName(); + $inbound_path = 'foobar/' . $id; + $real_path = 'node/' . $id; + + $found_path = drupal_get_normal_path($inbound_path); + $this->assertNotEqual($found_path, $real_path, t('Inbound path does not get rewritten because the function is not yet included.')); + } + + /** + * Tests a successful rewrite by the drupal_get_normal_path function. + */ + function testCustomUrlRewriteInbound() { + // This function would normally be in settings.php, so we're simulating that by including it here. + include(drupal_get_path('module', 'simpletest') . '/tests/custom_rewrite_url_inbound.inc'); -function custom_url_rewrite_inbound(&$result, $path, $path_language) { - global $user; - if (preg_match('|^foobar(/.*)|', $path, $matches)) { - $result = 'node' . $matches[1]; + $id = $this->randomName(); + $inbound_path = 'foobar/' . $id; + $real_path = 'node/' . $id; + + $found_path = drupal_get_normal_path($inbound_path); + $this->assertEqual($found_path, $real_path, t('Inbound path gets rewritten when function is defined.')); } -} \ No newline at end of file + /** + * Tests the output of the drupal_get_normal_path function with a path that can't be rewritten. + */ + function testCustomUrlRewriteInboundNoMatch() { + + include(drupal_get_path('module', 'simpletest') . '/tests/custom_rewrite_url_inbound.inc'); + + $id = $this->randomName(); + $inbound_path = 'no_match/' . $id; + $real_path = 'node/' . $id; + + $found_path = drupal_get_normal_path($inbound_path); + $this->assertNotEqual($found_path, $real_path, t('Inbound path does not match any of the patterns defined in the custom_url_rewrite_inbound function')); + } +}