StatisticsBlockVisitorsTest.php 2.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php

/**
 * @file
 * Definition of Drupal\statistics\Tests\StatisticsBlockVisitorsTest.
 */

namespace Drupal\statistics\Tests;

/**
 * Tests that the visitor blocking functionality works.
 */
class StatisticsBlockVisitorsTest extends StatisticsTestBase {
  public static function getInfo() {
    return array(
16
17
      'name' => 'Top visitor banning',
      'description' => 'Tests banning of IP addresses via the top visitors report.',
18
19
20
21
22
23
24
25
26
27
28
29
      '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';

    // Verify the IP address from accesslog appears on the top visitors page
30
    // and that a 'ban IP address' link is displayed.
31
32
    $this->drupalLogin($this->blocking_user);
    $this->drupalGet('admin/reports/visitors');
33
34
    $this->assertText($test_ip_address, 'IP address found.');
    $this->assertText(t('ban IP address'), 'Ban IP link displayed');
35
36

    // Block the IP address.
37
38
    $this->clickLink('ban IP address');
    $this->assertText(t('IP address bans'), 'IP banning page displayed.');
39
40
    $edit = array();
    $edit['ip'] = $test_ip_address;
41
42
43
44
    $this->drupalPost('admin/config/people/ban', $edit, t('Add'));
    $ip = db_query("SELECT iid from {ban_ip} WHERE ip = :ip", array(':ip' => $edit['ip']))->fetchField();
    $this->assertNotEqual($ip, FALSE, 'IP address found in database');
    $this->assertRaw(t('The IP address %ip has been banned.', array('%ip' => $edit['ip'])), 'IP address was banned.');
45
46
47
48

    // Verify that the block/unblock link on the top visitors page has been
    // altered.
    $this->drupalGet('admin/reports/visitors');
49
    $this->assertText(t('unban IP address'), 'Unban IP address link displayed');
50
51

    // Unblock the IP address.
52
53
    $this->clickLink('unban IP address');
    $this->assertRaw(t('Are you sure you want to delete %ip?', array('%ip' => $test_ip_address)), 'IP address deletion confirmation found.');
54
    $edit = array();
55
56
    $this->drupalPost('admin/config/people/ban/delete/1', NULL, t('Delete'));
    $this->assertRaw(t('The IP address %ip was deleted.', array('%ip' => $test_ip_address)), 'IP address deleted.');
57
58
  }
}