Commit 71102007 authored by Dries's avatar Dries
Browse files

- Patch #659578 by mcarbone, jhodgdon: fixed statistics pages and added some...

- Patch #659578 by mcarbone, jhodgdon: fixed statistics pages and added some extra tests. One critical bug less.
parent 8bac5dc6
......@@ -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'] . '%'))
......
<?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'));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment