summaryrefslogtreecommitdiff
path: root/modules/statistics
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-12-20 19:41:57 +0000
committerDries Buytaert <dries@buytaert.net>2009-12-20 19:41:57 +0000
commit711020074f364c00ddf3370be54a53397dadb9a5 (patch)
tree153ceb4d26356260f22b67b6fae52d820e06380e /modules/statistics
parent8bac5dc63f56ab510f2c9832abbb180208233cb8 (diff)
downloadbrdo-711020074f364c00ddf3370be54a53397dadb9a5.tar.gz
brdo-711020074f364c00ddf3370be54a53397dadb9a5.tar.bz2
- Patch #659578 by mcarbone, jhodgdon: fixed statistics pages and added some extra tests. One critical bug less.
Diffstat (limited to 'modules/statistics')
-rw-r--r--modules/statistics/statistics.admin.inc8
-rw-r--r--modules/statistics/statistics.test101
2 files changed, 92 insertions, 17 deletions
diff --git a/modules/statistics/statistics.admin.inc b/modules/statistics/statistics.admin.inc
index 845918883..72485ab88 100644
--- a/modules/statistics/statistics.admin.inc
+++ b/modules/statistics/statistics.admin.inc
@@ -56,7 +56,7 @@ function statistics_top_pages() {
array('data' => t('Total page generation time'), 'field' => 'total_time')
);
- $query = db_select('accesslog', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort');
+ $query = db_select('accesslog', 'a', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort');
$query->addExpression('COUNT(path)', 'hits');
// MAX(title) avoids having empty node titles which otherwise causes duplicates in the top pages list
$query->addExpression('MAX(title)', 'title');
@@ -64,12 +64,12 @@ function statistics_top_pages() {
$query->addExpression('SUM(timer)', 'total_time');
$query
- ->fields('accesslog', array('path'))
+ ->fields('a', array('path'))
->groupBy('path')
->limit(30)
->orderByHeader($header);
- $count_query = db_select('accesslog', array('target' => 'slave'));
+ $count_query = db_select('accesslog', 'a', array('target' => 'slave'));
$count_query->addExpression('COUNT(DISTINCT path)');
$query->setCountQuery($count_query);
@@ -164,7 +164,7 @@ function statistics_top_referrers() {
->limit(30)
->orderByHeader($header);
- $count_query = db_select('accesslog', array('target' => 'slave'));
+ $count_query = db_select('accesslog', 'a', array('target' => 'slave'));
$count_query->addExpression('COUNT(DISTINCT url)');
$count_query
->where('LOWER(url) NOT LIKE :host', array(':host' => '%' . $_SERVER['HTTP_HOST'] . '%'))
diff --git a/modules/statistics/statistics.test b/modules/statistics/statistics.test
index 43a5ccbc5..67c92a5eb 100644
--- a/modules/statistics/statistics.test
+++ b/modules/statistics/statistics.test
@@ -1,14 +1,10 @@
<?php
// $Id$
-class StatisticsBlockVisitorsTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Top visitor blocking',
- 'description' => 'Tests blocking of IP addresses via the top visitors report.',
- 'group' => 'Statistics'
- );
- }
+/**
+ * Sets up a base class for the Statistics module.
+ */
+class StatisticsTestCase extends DrupalWebTestCase {
function setUp() {
parent::setUp('statistics');
@@ -16,6 +12,9 @@ class StatisticsBlockVisitorsTestCase extends DrupalWebTestCase {
// Create user.
$this->blocking_user = $this->drupalCreateUser(array('block IP addresses', 'access statistics'));
+ // Enable access logging.
+ variable_set('statistics_enable_access_log', 1);
+
// Insert dummy access by anonymous user into access log.
db_insert('accesslog')
->fields(array(
@@ -30,17 +29,92 @@ class StatisticsBlockVisitorsTestCase extends DrupalWebTestCase {
))
->execute();
}
+}
+
+/**
+ * Tests that report pages render properly, and that access logging works.
+ */
+class StatisticsReportsTestCase extends StatisticsTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Statistics reports tests',
+ 'description' => 'Tests display of statistics report pages and access logging.',
+ 'group' => 'Statistics'
+ );
+ }
+
+ /**
+ * Verifies that 'Recent hits' renders properly and displays the added hit.
+ */
+ function testRecentHits() {
+ $this->drupalLogin($this->blocking_user);
+ $this->drupalGet('admin/reports/hits');
+ $this->assertText('test', t('Hit title found.'));
+ $this->assertText('node/1', t('Hit URL found.'));
+ $this->assertText('Anonymous', t('Hit user found.'));
+ }
/**
- * Blocks an IP address via the top visitors report then uses the same page to unblock it.
+ * Verifies that 'Top pages' renders properly and displays the added hit.
+ */
+ function testTopPages() {
+ $this->drupalLogin($this->blocking_user);
+ $this->drupalGet('admin/reports/pages');
+ $this->assertText('test', t('Hit title found.'));
+ $this->assertText('node/1', t('Hit URL found.'));
+ }
+
+ /**
+ * Verifies that 'Top referrers' renders properly and displays the added hit.
+ */
+ function testTopReferrers() {
+ $this->drupalLogin($this->blocking_user);
+ $this->drupalGet('admin/reports/referrers');
+ $this->assertText('http://example.com', t('Hit referrer found.'));
+ }
+
+ /**
+ * Verifies that 'Details' page renders properly and displays the added hit.
+ */
+ function testDetails() {
+ $this->drupalLogin($this->blocking_user);
+ $this->drupalGet('admin/reports/access/1');
+ $this->assertText('test', t('Hit title found.'));
+ $this->assertText('node/1', t('Hit URL found.'));
+ $this->assertText('Anonymous', t('Hit user found.'));
+ }
+
+ /**
+ * Verifies that access logging is working and is reported correctly.
+ */
+ function testAccessLogging() {
+ $this->drupalLogin($this->blocking_user);
+ $this->drupalGet('admin/reports/referrers');
+ $this->drupalGet('admin/reports/hits');
+ $this->assertText('Top referrers in the past 3 days', t('Hit title found.'));
+ $this->assertText('admin/reports/referrers', t('Hit URL found.'));
+ }
+}
+
+/**
+ * Tests that the visitor blocking functionality works.
+ */
+class StatisticsBlockVisitorsTestCase extends StatisticsTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Top visitor blocking',
+ 'description' => 'Tests blocking of IP addresses via the top visitors report.',
+ 'group' => 'Statistics'
+ );
+ }
+
+ /**
+ * Blocks an IP address via the top visitors report and then unblocks it.
*/
function testIPAddressBlocking() {
// IP address for testing.
$test_ip_address = '192.168.1.1';
- // Enable access logging (redundant since we insert the data manually).
- variable_set('statistics_enable_access_log', 1);
-
// Verify the IP address from accesslog appears on the top visitors page
// and that a 'block IP address' link is displayed.
$this->drupalLogin($this->blocking_user);
@@ -58,7 +132,8 @@ class StatisticsBlockVisitorsTestCase extends DrupalWebTestCase {
$this->assertNotEqual($ip, FALSE, t('IP address found in database'));
$this->assertRaw(t('The IP address %ip has been blocked.', array('%ip' => $edit['ip'])), t('IP address was blocked.'));
- // Verify that the block/unblock link on the top visitors page has been altered.
+ // Verify that the block/unblock link on the top visitors page has been
+ // altered.
$this->drupalGet('admin/reports/visitors');
$this->assertText(t('unblock IP address'), t('Unblock IP address link displayed'));