summaryrefslogtreecommitdiff
path: root/modules/statistics
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/statistics
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/statistics')
-rw-r--r--modules/statistics/statistics.test44
-rw-r--r--modules/statistics/statistics.tokens.inc12
2 files changed, 50 insertions, 6 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)));
+ }
+ }
+}
diff --git a/modules/statistics/statistics.tokens.inc b/modules/statistics/statistics.tokens.inc
index 5261c4b16..1eb5b5d32 100644
--- a/modules/statistics/statistics.tokens.inc
+++ b/modules/statistics/statistics.tokens.inc
@@ -10,11 +10,11 @@
* Implements hook_token_info().
*/
function statistics_token_info() {
- $node['views'] = array(
+ $node['total-count'] = array(
'name' => t("Number of views"),
'description' => t("The number of visitors who have read the node."),
);
- $node['day-views'] = array(
+ $node['day-count'] = array(
'name' => t("Views today"),
'description' => t("The number of visitors who have read the node today."),
);
@@ -40,13 +40,13 @@ function statistics_tokens($type, $tokens, array $data = array(), array $options
$node = $data['node'];
foreach ($tokens as $name => $original) {
- if ($name == 'views') {
+ if ($name == 'total-count') {
$statistics = statistics_get($node->nid);
- $replacements[$original] = $statistics['totalviews'];
+ $replacements[$original] = $statistics['totalcount'];
}
- elseif ($name == 'views-today') {
+ elseif ($name == 'day-count') {
$statistics = statistics_get($node->nid);
- $replacements[$original] = $statistics['dayviews'];
+ $replacements[$original] = $statistics['daycount'];
}
elseif ($name == 'last-view') {
$statistics = statistics_get($node->nid);