You are here

class FloodTest in Service Container 7

Same name and namespace in other branches
  1. 7.2 lib/Drupal/service_container/Tests/FloodTest.php \Drupal\service_container\Tests\FloodTest

Hierarchy

Expanded class hierarchy of FloodTest

File

lib/Drupal/service_container/Tests/FloodTest.php, line 10
Contains \Drupal\service_container\Tests\FloodTest.

Namespace

Drupal\service_container\Tests
View source
class FloodTest extends ServiceContainerIntegrationTestBase {

  /**
   * A random name for an event.
   *
   * @var string
   */
  protected $eventName;

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Flood control mechanism',
      'description' => 'Functional tests for the flood control mechanism',
      'group' => 'service_container',
    );
  }

  /**
   * The the flood mechanisms.
   */
  public function testFlood() {
    $threshold = 1;
    $window_expired = -1;
    $name = 'flood_test';

    // Register expired event.
    \Drupal::service('flood')
      ->register($name, $window_expired);
    $this
      ->assertFalse(\Drupal::service('flood')
      ->isAllowed($name, $threshold));
    $this
      ->cronRun();
    $this
      ->assertTrue(\Drupal::service('flood')
      ->isAllowed($name, $threshold));

    // Register unexpired event.
    \Drupal::service('flood')
      ->register($name);
    $this
      ->assertFalse(\Drupal::service('flood')
      ->isAllowed($name, $threshold));
    $this
      ->cronRun();
    $this
      ->assertFalse(\Drupal::service('flood')
      ->isAllowed($name, $threshold));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FloodTest::$eventName protected property A random name for an event.
FloodTest::getInfo public static function
FloodTest::testFlood public function The the flood mechanisms.
ServiceContainerIntegrationTestBase::$container protected property The dependency injection container usable in the test.
ServiceContainerIntegrationTestBase::$profile protected property The profile to install as a basis for testing. 1
ServiceContainerIntegrationTestBase::setUp protected function 5