diff --git a/core/modules/system/lib/Drupal/system/Tests/System/FloodTest.php b/core/modules/system/lib/Drupal/system/Tests/System/FloodTest.php index 550fd89..02bb177 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/FloodTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/FloodTest.php @@ -14,6 +14,14 @@ * Functional tests for the flood control mechanism. */ class FloodTest extends WebTestBase { + + /** + * The Request object that flood classes should use. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $request; + public static function getInfo() { return array( 'name' => 'Flood control mechanism', @@ -22,6 +30,16 @@ public static function getInfo() { ); } + public function setUp() { + parent::setUp(); + + // Flood backends need a request object. Create a dummy one and insert it + // to the container. + $this->request = Request::create('http://example.com/'); + $this->request->server->set('REMOTE_ADDR', '3.3.3.3'); + $this->container->set('request', $this->request); + } + /** * Test flood control mechanism clean-up. */ @@ -56,10 +74,7 @@ function testMemoryBackend() { $window_expired = -1; $name = 'flood_test_cleanup'; - // MemoryBackend needs a request object injected. - $request = Request::create('http://example.com/'); - $request->server->set('REMOTE_ADDR', '3.3.3.3'); - $flood = new \Drupal\Core\Flood\MemoryBackend($request); + $flood = new \Drupal\Core\Flood\MemoryBackend($this->request); // Register expired event. $flood->register($name, $window_expired); // Verify event is not allowed.