summaryrefslogtreecommitdiff
path: root/modules/system/system.test
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-04-20 09:48:06 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-04-20 09:48:06 +0000
commit7bb6753e9fc8d89472ecc2b6d5ab670dde27b935 (patch)
tree79eae1caf8b93351560fa36202d46913ac06e1ef /modules/system/system.test
parent8e94b5d6d400d33c0f840a7ae97ff8a715272a79 (diff)
downloadbrdo-7bb6753e9fc8d89472ecc2b6d5ab670dde27b935.tar.gz
brdo-7bb6753e9fc8d89472ecc2b6d5ab670dde27b935.tar.bz2
#701818 by mcarbone: Test coverage of every core token, and bug fixes to make them work. AWESOME! :D
Diffstat (limited to 'modules/system/system.test')
-rw-r--r--modules/system/system.test71
1 files changed, 71 insertions, 0 deletions
diff --git a/modules/system/system.test b/modules/system/system.test
index e20fd769e..d94f114a2 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -1490,6 +1490,77 @@ class TokenReplaceTestCase extends DrupalWebTestCase {
$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.'));
}
+
+ /**
+ * Tests the generation of all system site information tokens.
+ */
+ function testSystemSiteTokenReplacement() {
+ global $language;
+ $url_options = array(
+ 'absolute' => TRUE,
+ 'language' => $language,
+ );
+
+ // Set a few site variables.
+ variable_set('site_name', '<strong>Drupal<strong>');
+ variable_set('site_slogan', '<blink>Slogan</blink>');
+ variable_set('site_mission', '<em>Mission</em>');
+
+ // Generate and test sanitized tokens.
+ $tests = array();
+ $tests['[site:name]'] = check_plain(variable_get('site_name', 'Drupal'));
+ $tests['[site:slogan]'] = check_plain(variable_get('site_slogan', ''));
+ $tests['[site:mission]'] = filter_xss(variable_get('site_mission', ''));
+ $tests['[site:mail]'] = 'simpletest@example.com';
+ $tests['[site:url]'] = url('<front>', $url_options);
+ $tests['[site:url-brief]'] = preg_replace('!^https?://!', '', url('<front>', $url_options));
+ $tests['[site:login-url]'] = url('user', $url_options);
+
+ // Test to make sure that we generated something for each token.
+ $this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
+
+ 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)));
+ }
+
+ // Generate and test unsanitized tokens.
+ $tests['[site:name]'] = variable_get('site_name', 'Drupal');
+ $tests['[site:slogan]'] = variable_get('site_slogan', '');
+ $tests['[site:mission]'] = variable_get('site_mission', '');
+
+ 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)));
+ }
+ }
+
+ /**
+ * Tests the generation of all system date tokens.
+ */
+ function testSystemDateTokenReplacement() {
+ global $language;
+
+ // Set time to one hour before request.
+ $date = REQUEST_TIME - 3600;
+
+ // Generate and test tokens.
+ $tests = array();
+ $tests['[date:short]'] = format_date($date, 'short', '', NULL, $language->language);
+ $tests['[date:medium]'] = format_date($date, 'medium', '', NULL, $language->language);
+ $tests['[date:long]'] = format_date($date, 'long', '', NULL, $language->language);
+ $tests['[date:custom:m/j/Y]'] = format_date($date, 'custom', 'm/j/Y', NULL, $language->language);
+ $tests['[date:since]'] = format_interval((REQUEST_TIME - $date), 2, $language->language);
+ $tests['[date:raw]'] = filter_xss($date);
+
+ // Test to make sure that we generated something for each token.
+ $this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
+
+ 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)));
+ }
+ }
}
class InfoFileParserTestCase extends DrupalUnitTestCase {