You are here

class IPBanTestBase in IP Ban 8

Same name in this branch
  1. 8 ip_ban.test \IPBanTestBase
  2. 8 src/Tests/IPBanTestBase.php \Drupal\ip_ban\Tests\IPBanTestBase
Same name and namespace in other branches
  1. 7 ip_ban.test \IPBanTestBase

Base class for common test configuration.

Hierarchy

Expanded class hierarchy of IPBanTestBase

File

./ip_ban.test, line 14
Tests for ip_ban.module.

View source
class IPBanTestBase extends DrupalWebTestCase {
  protected $adminSitesUser;
  protected $ipBanType;

  /**
   * Implement setUp().
   */
  public function setUp() {

    // ip2country is required by ip_ban, and therefore needed for some of the
    // unit and functional testing.
    parent::setUp(array(
      'ip_ban',
      'ip2country',
    ));

    // Add a content type to create dummy page for testing valid paths and
    // proper redirects.
    $this->ipBanType = $this
      ->drupalCreateContentType(array(
      'name' => 'IP Ban Node',
      'type' => 'ipban_node',
    ));

    // Create and log in our privileged user.
    $this->adminSitesUser = $this
      ->drupalCreateUser(array(
      'administer site configuration',
      'create ipban_node content',
      'edit any ipban_node content',
      'access content',
      'bypass node access',
      'administer blocks',
      // The admin must have this permission to avoid immediately losing access
      // when using a spoofed IP address.
      'ignore ip_ban',
    ));
  }

  /**
   * Add a node of type ipban-node for path and other testing.
   */
  public function addBanNode($title = '') {
    if (empty($title)) {
      $title = $this
        ->randomName();
    }
    $edit = array(
      'title' => $title,
    );
    $this
      ->drupalPost('node/add/ipban-node', $edit, t('Save'));
    $this
      ->assertText('IP Ban Node ' . $edit['title'] . ' has been created', 'Found node creation message');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
IPBanTestBase::$adminSitesUser protected property
IPBanTestBase::$ipBanType protected property
IPBanTestBase::addBanNode public function Add a node of type ipban-node for path and other testing.
IPBanTestBase::setUp public function Implement setUp(). 4