function OptionsRequestSubscriberTest::providerTestOnRequestWithOptionsRequest

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

File

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

Class

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

Namespace

Drupal\Tests\Core\EventSubscriber

Code

public static function providerTestOnRequestWithOptionsRequest() {
    $data = [];
    foreach ([
        'GET',
        'POST',
        'PATCH',
        'PUT',
        'DELETE',
    ] as $method) {
        $collection = new RouteCollection();
        $collection->add('example.1', new Route('/example', [], [], [], '', [], [
            $method,
        ]));
        $data['one_route_' . $method] = [
            $collection,
            $method,
        ];
    }
    foreach ([
        'GET',
        'POST',
        'PATCH',
        'PUT',
        'DELETE',
    ] as $method_a) {
        foreach ([
            'GET',
            'POST',
            'PATCH',
            'PUT',
            'DELETE',
        ] as $method_b) {
            if ($method_a != $method_b) {
                $collection = new RouteCollection();
                $collection->add('example.1', new Route('/example', [], [], [], '', [], [
                    $method_a,
                    $method_b,
                ]));
                $data['one_route_' . $method_a . '_' . $method_b] = [
                    $collection,
                    $method_a . ', ' . $method_b,
                ];
            }
        }
    }
    foreach ([
        'GET',
        'POST',
        'PATCH',
        'PUT',
        'DELETE',
    ] as $method_a) {
        foreach ([
            'GET',
            'POST',
            'PATCH',
            'PUT',
            'DELETE',
        ] as $method_b) {
            foreach ([
                'GET',
                'POST',
                'PATCH',
                'PUT',
                'DELETE',
            ] as $method_c) {
                $collection = new RouteCollection();
                $collection->add('example.1', new Route('/example', [], [], [], '', [], [
                    $method_a,
                ]));
                $collection->add('example.2', new Route('/example', [], [], [], '', [], [
                    $method_a,
                    $method_b,
                ]));
                $collection->add('example.3', new Route('/example', [], [], [], '', [], [
                    $method_b,
                    $method_c,
                ]));
                $methods = array_unique([
                    $method_a,
                    $method_b,
                    $method_c,
                ]);
                $data['multiple_routes_' . $method_a . '_' . $method_b . '_' . $method_c] = [
                    $collection,
                    implode(', ', $methods),
                ];
            }
        }
    }
    return $data;
}

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