diff options
Diffstat (limited to 'modules/system/system.test')
-rw-r--r-- | modules/system/system.test | 105 |
1 files changed, 96 insertions, 9 deletions
diff --git a/modules/system/system.test b/modules/system/system.test index 549df44b0..be4e36698 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -1,5 +1,9 @@ <?php -// $Id$ + +/** + * @file + * Tests for system.module. + */ /** * Helper class for module test cases. @@ -1355,7 +1359,7 @@ class SystemThemeFunctionalTest extends DrupalWebTestCase { function setUp() { parent::setUp(); - $this->admin_user = $this->drupalCreateUser(array('access administration pages', 'view the administration theme', 'administer themes', 'bypass node access')); + $this->admin_user = $this->drupalCreateUser(array('access administration pages', 'view the administration theme', 'administer themes', 'bypass node access', 'administer blocks')); $this->drupalLogin($this->admin_user); $this->node = $this->drupalCreateNode(); } @@ -1439,6 +1443,26 @@ class SystemThemeFunctionalTest extends DrupalWebTestCase { $this->drupalGet('node/add'); $this->assertRaw('themes/bartik', t('Site default theme used on the add content page.')); } + + /** + * Test switching the default theme. + */ + function testSwitchDefaultTheme() { + // Enable "stark" and set it as the default theme. + theme_enable(array('stark')); + $this->drupalGet('admin/appearance'); + $this->clickLink(t('Set default'), 1); + $this->assertTrue(variable_get('theme_default', '') == 'stark', t('Site default theme switched successfully.')); + + // Test the default theme on the secondary links (blocks admin page). + $this->drupalGet('admin/structure/block'); + $this->assertText('Stark(' . t('active tab') . ')', t('Default local task on blocks admin page is the default theme.')); + // Switch back to Bartik and test again to test that the menu cache is cleared. + $this->drupalGet('admin/appearance'); + $this->clickLink(t('Set default'), 0); + $this->drupalGet('admin/structure/block'); + $this->assertText('Bartik(' . t('active tab') . ')', t('Default local task on blocks admin page has changed.')); + } } @@ -1571,13 +1595,13 @@ class TokenReplaceTestCase extends DrupalWebTestCase { // Test that the clear parameter cleans out non-existent tokens. $result = token_replace($source, array('node' => $node), array('language' => $language, 'clear' => TRUE)); - $result = $this->assertFalse(strcmp($target, $result), 'Valid tokens replaced while invalid tokens cleared out.'); + $result = $this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens cleared out.'); // Test without using the clear parameter (non-existant token untouched). $target .= '[user:name]'; $target .= '[bogus:token]'; $result = token_replace($source, array('node' => $node), array('language' => $language)); - $this->assertFalse(strcmp($target, $result), 'Valid tokens replaced while invalid tokens ignored.'); + $this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens ignored.'); // Check that the results of token_generate are sanitized properly. This does NOT // test the cleanliness of every token -- just that the $sanitize flag is being @@ -1585,10 +1609,39 @@ class TokenReplaceTestCase extends DrupalWebTestCase { // token, [node:title]. $raw_tokens = array('title' => '[node:title]'); $generated = token_generate('node', $raw_tokens, array('node' => $node)); - $this->assertFalse(strcmp($generated['[node:title]'], check_plain($node->title)), t('Token sanitized.')); + $this->assertEqual($generated['[node:title]'], check_plain($node->title), t('Token sanitized.')); $generated = token_generate('node', $raw_tokens, array('node' => $node), array('sanitize' => FALSE)); - $this->assertFalse(strcmp($generated['[node:title]'], $node->title), t('Unsanitized token generated properly.')); + $this->assertEqual($generated['[node:title]'], $node->title, t('Unsanitized token generated properly.')); + } + + /** + * Test whether token-replacement works in various contexts. + */ + function testSystemTokenRecognition() { + global $language; + + // Generate prefixes and suffixes for the token context. + $tests = array( + array('prefix' => 'this is the ', 'suffix' => ' site'), + array('prefix' => 'this is the', 'suffix' => 'site'), + array('prefix' => '[', 'suffix' => ']'), + array('prefix' => '', 'suffix' => ']]]'), + array('prefix' => '[[[', 'suffix' => ''), + array('prefix' => ':[:', 'suffix' => '--]'), + array('prefix' => '-[-', 'suffix' => ':]:'), + array('prefix' => '[:', 'suffix' => ']'), + array('prefix' => '[site:', 'suffix' => ':name]'), + array('prefix' => '[site:', 'suffix' => ']'), + ); + + // Check if the token is recognized in each of the contexts. + foreach ($tests as $test) { + $input = $test['prefix'] . '[site:name]' . $test['suffix']; + $expected = $test['prefix'] . 'Drupal' . $test['suffix']; + $output = token_replace($input, array(), array('language' => $language)); + $this->assertTrue($output == $expected, t('Token recognized in string %string', array('%string' => $input))); + } } /** @@ -1620,7 +1673,7 @@ class TokenReplaceTestCase extends DrupalWebTestCase { foreach ($tests as $input => $expected) { $output = token_replace($input, array(), array('language' => $language)); - $this->assertFalse(strcmp($output, $expected), t('Sanitized system site information token %token replaced.', array('%token' => $input))); + $this->assertEqual($output, $expected, t('Sanitized system site information token %token replaced.', array('%token' => $input))); } // Generate and test unsanitized tokens. @@ -1629,7 +1682,7 @@ class TokenReplaceTestCase extends DrupalWebTestCase { foreach ($tests as $input => $expected) { $output = token_replace($input, array(), array('language' => $language, 'sanitize' => FALSE)); - $this->assertFalse(strcmp($output, $expected), t('Unsanitized system site information token %token replaced.', array('%token' => $input))); + $this->assertEqual($output, $expected, t('Unsanitized system site information token %token replaced.', array('%token' => $input))); } } @@ -1656,7 +1709,7 @@ class TokenReplaceTestCase extends DrupalWebTestCase { foreach ($tests as $input => $expected) { $output = token_replace($input, array('date' => $date), array('language' => $language)); - $this->assertFalse(strcmp($output, $expected), t('Date token %token replaced.', array('%token' => $input))); + $this->assertEqual($output, $expected, t('Date token %token replaced.', array('%token' => $input))); } } } @@ -2145,3 +2198,37 @@ class SystemAuthorizeCase extends DrupalWebTestCase { $this->assertText('System Test Username'); } } + +/** + * Test the handling of requests containing 'index.php'. + */ +class SystemIndexPhpTest extends DrupalWebTestCase { + public static function getInfo() { + return array( + 'name' => 'Index.php handling', + 'description' => "Test the handling of requests containing 'index.php'.", + 'group' => 'System', + ); + } + + function setUp() { + parent::setUp(); + } + + /** + * Test index.php handling. + */ + function testIndexPhpHandling() { + $index_php = $GLOBALS['base_url'] . '/index.php'; + + $this->drupalGet($index_php, array('external' => TRUE)); + $this->assertResponse(200, t('Make sure index.php returns a valid page.')); + + $this->drupalGet($index_php, array('external' => TRUE, 'query' => array('q' => 'user'))); + $this->assertResponse(200, t('Make sure index.php?q=user returns a valid page.')); + + $this->drupalGet($index_php .'/user', array('external' => TRUE)); + $this->assertResponse(404, t("Make sure index.php/user returns a 'page not found'.")); + } +} + |