diff options
Diffstat (limited to 'modules/statistics/statistics.test')
-rw-r--r-- | modules/statistics/statistics.test | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/modules/statistics/statistics.test b/modules/statistics/statistics.test index cd312f679..283c2d9da 100644 --- a/modules/statistics/statistics.test +++ b/modules/statistics/statistics.test @@ -312,3 +312,47 @@ class StatisticsAdminTestCase extends DrupalWebTestCase { $this->assertFalse($result, t('Daycounter is zero.')); } } + +/** + * Test statistics token replacement in strings. + */ +class StatisticsTokenReplaceTestCase extends StatisticsTestCase { + public static function getInfo() { + return array( + 'name' => 'Statistics token replacement', + 'description' => 'Generates text using placeholders for dummy content to check statistics token replacement.', + 'group' => 'Statistics', + ); + } + + /** + * Creates a node, then tests the statistics tokens generated from it. + */ + function testStatisticsTokenReplacement() { + global $language; + + // Create user and node. + $user = $this->drupalCreateUser(array('create page content')); + $this->drupalLogin($user); + $node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $user->uid)); + + // Hit the node. + $this->drupalGet('node/' . $node->nid); + $statistics = statistics_get($node->nid); + + // Generate and test tokens. + $tests = array(); + $tests['[node:total-count]'] = 1; + $tests['[node:day-count]'] = 1; + $tests['[node:last-view]'] = format_date($statistics['timestamp']); + $tests['[node:last-view:short]'] = format_date($statistics['timestamp'], 'short'); + + // 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('node' => $node), array('language' => $language)); + $this->assertFalse(strcmp($output, $expected), t('Statistics token %token replaced.', array('%token' => $input))); + } + } +} |