From 1df3cfffefefc93ed2d29041d148938d08bb9d4e Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Fri, 29 Jan 2010 22:40:41 +0000 Subject: - Patch #284899 by c960657, voxpelli, mattconnolly: fixed Drupal url problem with clean urls. --- modules/path/path.test | 12 +++-- modules/simpletest/tests/file.test | 66 ++++++++++++++++++++++++++ modules/simpletest/tests/menu.test | 11 +++++ modules/simpletest/tests/menu_test.module | 11 ++++- modules/simpletest/tests/path.test | 9 ++++ modules/simpletest/tests/url_alter_test.module | 25 ++++++++++ 6 files changed, 129 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/path/path.test b/modules/path/path.test index baba8e864..66b5c1344 100644 --- a/modules/path/path.test +++ b/modules/path/path.test @@ -66,11 +66,13 @@ class PathTestCase extends DrupalWebTestCase { $this->assertText($node1->title, 'Alias works.'); $this->assertResponse(200); - // Change alias. + // Change alias to one containing "exotic" characters. $pid = $this->getPID($edit['alias']); $previous = $edit['alias']; - $edit['alias'] = $this->randomName(8); + $edit['alias'] = "- ._~!$'\"()*@[]?&+%#,;=:" . // "Special" ASCII characters. + "%23%25%26%2B%2F%3F" . // Characters that look like a percent-escaped string. + "éøïвβ中國書۞"; // Characters from various non-ASCII alphabets. $this->drupalPost('admin/config/search/path/edit/' . $pid, $edit, t('Save')); // Confirm that the alias works. @@ -122,9 +124,11 @@ class PathTestCase extends DrupalWebTestCase { $this->assertText($node1->title, 'Alias works.'); $this->assertResponse(200); - // Change alias. + // Change alias to one containing "exotic" characters. $previous = $edit['path[alias]']; - $edit['path[alias]'] = $this->randomName(8); + $edit['path[alias]'] = "- ._~!$'\"()*@[]?&+%#,;=:" . // "Special" ASCII characters. + "%23%25%26%2B%2F%3F" . // Characters that look like a percent-escaped string. + "éøïвβ中國書۞"; // Characters from various non-ASCII alphabets. $this->drupalPost('node/' . $node1->nid . '/edit', $edit, t('Save')); // Confirm that the alias works. diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test index 46931e69b..cf7c8f1ca 100644 --- a/modules/simpletest/tests/file.test +++ b/modules/simpletest/tests/file.test @@ -1888,6 +1888,8 @@ class FileDownloadTest extends FileTestCase { function setUp() { parent::setUp('file_test'); + // Clear out any hook calls. + file_test_reset(); } /** @@ -1937,6 +1939,70 @@ class FileDownloadTest extends FileTestCase { $this->drupalHead($url); $this->assertResponse(404, t('Correctly returned 404 response for a non-existent file.')); } + + /** + * Test file_create_url(). + */ + function testFileCreateUrl() { + global $base_url; + + $basename = " -._~!$'\"()*@[]?&+%#,;=:\n\x00" . // "Special" ASCII characters. + "%23%25%26%2B%2F%3F" . // Characters that look like a percent-escaped string. + "éøïвβ中國書۞"; // Characters from various non-ASCII alphabets. + $basename_encoded = '%20-._%7E%21%24%27%22%28%29%2A%40%5B%5D%3F%26%2B%25%23%2C%3B%3D%3A__' . + '%2523%2525%2526%252B%252F%253F' . + '%C3%A9%C3%B8%C3%AF%D0%B2%CE%B2%E4%B8%AD%E5%9C%8B%E6%9B%B8%DB%9E'; + + $this->checkUrl('public', '', $basename, $base_url . '/' . file_directory_path() . '/' . $basename_encoded); + $this->checkUrl('private', '', $basename, $base_url . '/system/files/' . $basename_encoded); + $this->checkUrl('private', '', $basename, $base_url . '/?q=system/files/' . $basename_encoded, '0'); + } + + /** + * Download a file from the URL generated by file_create_url(). + * + * Create a file with the specified scheme, directory and filename; check that + * the URL generated by file_create_url() for the specified file equals the + * specified URL; fetch the URL and then compare the contents to the file. + * + * @param $scheme + * A scheme, e.g. "public" + * @param $directory + * A directory, possibly "" + * @param $filename + * A filename + * @param $expected_url + * The expected URL + * @param $clean_url + * The value of the clean_url setting + */ + private function checkUrl($scheme, $directory, $filename, $expected_url, $clean_url = '1') { + variable_set('clean_url', $clean_url); + + // Convert $filename to a valid filename, i.e. strip characters not + // supported by the filesystem, and create the file in the specified + // directory. + $filepath = file_create_filename($filename, $directory); + $directory_uri = $scheme . '://' . dirname($filepath); + file_prepare_directory($directory_uri, FILE_CREATE_DIRECTORY); + $file = $this->createFile($filepath, NULL, $scheme); + + $url = file_create_url($file->uri); + $this->assertEqual($url, $expected_url, t('Generated URL matches expected URL.')); + + if ($scheme == 'private') { + // Tell the implementation of hook_file_download() in file_test.module + // that this file may be downloaded. + file_test_set_return('download', array('x-foo' => 'Bar')); + } + + $this->drupalGet($url); + if ($this->assertResponse(200) == 'pass') { + $this->assertRaw(file_get_contents($file->uri), t('Contents of the file are correct.')); + } + + file_delete($file); + } } /** diff --git a/modules/simpletest/tests/menu.test b/modules/simpletest/tests/menu.test index 4a34369fe..c98014b06 100644 --- a/modules/simpletest/tests/menu.test +++ b/modules/simpletest/tests/menu.test @@ -51,6 +51,17 @@ class MenuRouterTestCase extends DrupalWebTestCase { $this->assertRaw('seven/style.css', t("The administrative theme's CSS appears on the page.")); } + /** + * Test path containing "exotic" characters. + */ + function testExoticPath() { + $path = "menu-test/ -._~!$'\"()*@[]?&+%#,;=:" . // "Special" ASCII characters. + "%23%25%26%2B%2F%3F" . // Characters that look like a percent-escaped string. + "éøïвβ中國書۞"; // Characters from various non-ASCII alphabets. + $this->drupalGet($path); + $this->assertRaw('This is menu_test_callback().'); + } + /** * Test the theme callback when the site is in maintenance mode. */ diff --git a/modules/simpletest/tests/menu_test.module b/modules/simpletest/tests/menu_test.module index 264861240..194fe8006 100644 --- a/modules/simpletest/tests/menu_test.module +++ b/modules/simpletest/tests/menu_test.module @@ -58,6 +58,15 @@ function menu_test_menu() { 'page arguments' => array(TRUE), 'access arguments' => array('access content'), ); + // Path containing "exotic" characters. + $path = "menu-test/ -._~!$'\"()*@[]?&+%#,;=:" . // "Special" ASCII characters. + "%23%25%26%2B%2F%3F" . // Characters that look like a percent-escaped string. + "éøïвβ中國書۞"; // Characters from various non-ASCII alphabets. + $items[$path] = array( + 'title' => '"Exotic" path', + 'page callback' => 'menu_test_callback', + 'access arguments' => array('access content'), + ); // Hidden tests; base parents. // Same structure as in Menu and Block modules. Since those structures can @@ -174,7 +183,7 @@ function menu_test_menu() { * A random string. */ function menu_test_callback() { - return $this->randomName(); + return 'This is menu_test_callback().'; } /** diff --git a/modules/simpletest/tests/path.test b/modules/simpletest/tests/path.test index 567731421..676c709cb 100644 --- a/modules/simpletest/tests/path.test +++ b/modules/simpletest/tests/path.test @@ -200,6 +200,15 @@ class UrlAlterFunctionalTest extends DrupalWebTestCase { $this->assertUrlOutboundAlter("taxonomy/term/$tid", "taxonomy/term/$tid"); } + /** + * Test current_path() and request_path(). + */ + function testCurrentUrlRequestedPath() { + $this->drupalGet('url-alter-test/bar'); + $this->assertRaw('request_path=url-alter-test/bar', t('request_path() returns the requested path.')); + $this->assertRaw('current_path=url-alter-test/foo', t('current_path() returns the internal path.')); + } + /** * Assert that an outbound path is altered to an expected value. * diff --git a/modules/simpletest/tests/url_alter_test.module b/modules/simpletest/tests/url_alter_test.module index 2734d8caa..da6cd635b 100644 --- a/modules/simpletest/tests/url_alter_test.module +++ b/modules/simpletest/tests/url_alter_test.module @@ -6,6 +6,27 @@ * Module to help test hook_url_inbound_alter() and hook_url_outbound_alter(). */ +/** + * Implements hook_menu(). + */ +function url_alter_test_menu() { + $items['url-alter-test/foo'] = array( + 'title' => 'Foo', + 'page callback' => 'url_alter_test_foo', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); + return $items; +} + +/** + * Menu callback. + */ +function url_alter_test_foo() { + print 'current_path=' . current_path() . ' request_path=' . request_path(); + exit; +} + /** * Implements hook_url_inbound_alter(). */ @@ -22,6 +43,10 @@ function url_alter_test_url_inbound_alter(&$path, $original_path, $path_language if ($path == 'community' || strpos($path, 'community/') === 0) { $path = 'forum' . substr($path, 9); } + + if ($path == 'url-alter-test/bar') { + $path = 'url-alter-test/foo'; + } } /** -- cgit v1.2.3