You are here

IpAnonymizeTestCase.php in IP Anonymize 8

File

tests/src/Functional/IpAnonymizeTestCase.php
View source
<?php

namespace Drupal\Tests\ip_anon\Functional;

use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\Traits\Core\CronRunTrait;

/**
 * Tests basic IP Anonymize functionality.
 *
 * @group IP Anonymize
 */
class IpAnonymizeTestCase extends BrowserTestBase {
  use CronRunTrait;
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = [
    'ip_anon',
    'dblog',
  ];

  /**
   * Basic tests for IP Anonymize module.
   */
  public function testIpAnonymize() {
    $admin_user = $this
      ->drupalCreateUser([
      'administer site configuration',
    ]);
    $this
      ->drupalLogin($admin_user);
    $this
      ->assertNotEmpty($this
      ->getIp());
    $this
      ->drupalGet('admin/config/people/ip_anon');
    $config['policy'] = 1;
    $config['period_watchdog'] = 0;
    $this
      ->submitForm($config, $this
      ->t('Save configuration'));
    $this
      ->cronRun();
    $this
      ->assertEmpty($this
      ->getIp());
  }

  /**
   * Get IP address from watchdog table.
   */
  protected function getIp() {
    return $this->container
      ->get('database')
      ->select('watchdog', 'w')
      ->fields('w', [
      'hostname',
    ])
      ->orderBy('wid')
      ->range(0, 1)
      ->execute()
      ->fetchField();
  }

}

Classes

Namesort descending Description
IpAnonymizeTestCase Tests basic IP Anonymize functionality.