function OptionsRequestSubscriberTest::testWithOptionsRequest

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/EventSubscriber/OptionsRequestSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\OptionsRequestSubscriberTest::testWithOptionsRequest()
  2. 10 core/tests/Drupal/Tests/Core/EventSubscriber/OptionsRequestSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\OptionsRequestSubscriberTest::testWithOptionsRequest()
  3. 11.x core/tests/Drupal/Tests/Core/EventSubscriber/OptionsRequestSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\OptionsRequestSubscriberTest::testWithOptionsRequest()

@covers ::onRequest @dataProvider providerTestOnRequestWithOptionsRequest

File

core/tests/Drupal/Tests/Core/EventSubscriber/OptionsRequestSubscriberTest.php, line 58

Class

OptionsRequestSubscriberTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21EventSubscriber%21OptionsRequestSubscriber.php/class/OptionsRequestSubscriber/9" title="Handles options requests." class="local">\Drupal\Core\EventSubscriber\OptionsRequestSubscriber</a> @group EventSubscriber

Namespace

Drupal\Tests\Core\EventSubscriber

Code

public function testWithOptionsRequest(RouteCollection $collection, $expected_header) {
    $kernel = $this->prophesize(HttpKernelInterface::class);
    $request = Request::create('/example', 'OPTIONS');
    $route_provider = $this->prophesize(RouteProviderInterface::class);
    $route_provider->getRouteCollectionForRequest($request)
        ->willReturn($collection)
        ->shouldBeCalled();
    $subscriber = new OptionsRequestSubscriber($route_provider->reveal());
    $event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
    $subscriber->onRequest($event);
    $this->assertTrue($event->hasResponse());
    $response = $event->getResponse();
    $this->assertEquals(200, $response->getStatusCode());
    $this->assertEquals($expected_header, $response->headers
        ->get('Allow'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.