2008-05-07 19:17:50 +00:00
|
|
|
<?php
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
class StatisticsBlockVisitorsTestCase extends DrupalWebTestCase {
|
2009-03-31 01:49:55 +00:00
|
|
|
public static function getInfo() {
|
2008-05-07 19:17:50 +00:00
|
|
|
return array(
|
|
|
|
'name' => t('Top visitor blocking'),
|
|
|
|
'description' => t('Tests blocking of IP addresses via the top visitors report.'),
|
|
|
|
'group' => t('Statistics')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setUp() {
|
|
|
|
parent::setUp('statistics');
|
|
|
|
|
|
|
|
// Create user.
|
|
|
|
$this->blocking_user = $this->drupalCreateUser(array('block IP addresses', 'access statistics'));
|
|
|
|
|
2008-05-10 07:32:02 +00:00
|
|
|
// Insert dummy access by anonymous user into access log.
|
2009-04-13 10:40:13 +00:00
|
|
|
db_insert('accesslog')
|
|
|
|
->fields(array(
|
|
|
|
'title' => 'test',
|
|
|
|
'path' => 'node/1',
|
|
|
|
'url' => 'http://example.com',
|
|
|
|
'hostname' => '192.168.1.1',
|
|
|
|
'uid' => 0,
|
|
|
|
'sid' => 10,
|
|
|
|
'timer' => 10,
|
|
|
|
'timestamp' => REQUEST_TIME,
|
|
|
|
))
|
|
|
|
->execute();
|
2008-05-07 19:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blocks an IP address via the top visitors report then uses the same page to unblock 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
|
2008-12-30 16:43:20 +00:00
|
|
|
// and that a 'block IP address' link is displayed.
|
2008-05-07 19:17:50 +00:00
|
|
|
$this->drupalLogin($this->blocking_user);
|
|
|
|
$this->drupalGet('admin/reports/visitors');
|
|
|
|
$this->assertText($test_ip_address, t('IP address found.'));
|
|
|
|
$this->assertText(t('block IP address'), t('Block IP link displayed'));
|
|
|
|
|
|
|
|
// Block the IP address.
|
|
|
|
$this->clickLink('block IP address');
|
|
|
|
$this->assertText(t('IP address blocking'), t('IP blocking page displayed.'));
|
|
|
|
$edit = array();
|
|
|
|
$edit['ip'] = $test_ip_address;
|
|
|
|
$this->drupalPost('admin/settings/ip-blocking', $edit, t('Save'));
|
2009-04-13 10:40:13 +00:00
|
|
|
$ip = db_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $edit['ip']))->fetchField();
|
|
|
|
$this->assertNotEqual($ip, FALSE, t('IP address found in database'));
|
2008-05-07 19:17:50 +00:00
|
|
|
$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.
|
|
|
|
$this->drupalGet('admin/reports/visitors');
|
|
|
|
$this->assertText(t('unblock IP address'), t('Unblock IP address link displayed'));
|
|
|
|
|
|
|
|
// Unblock the IP address.
|
|
|
|
$this->clickLink('unblock IP address');
|
|
|
|
$this->assertRaw(t('Are you sure you want to delete %ip?', array('%ip' => $test_ip_address)), t('IP address deletion confirmation found.'));
|
|
|
|
$edit = array();
|
|
|
|
$this->drupalPost('admin/settings/ip-blocking/delete/1', NULL, t('Delete'));
|
|
|
|
$this->assertRaw(t('The IP address %ip was deleted.', array('%ip' => $test_ip_address)), t('IP address deleted.'));
|
|
|
|
}
|
|
|
|
}
|