function RequestFormatRouteFilterTest::filterProvider

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

File

core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php, line 36

Class

RequestFormatRouteFilterTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Routing%21RequestFormatRouteFilter.php/class/RequestFormatRouteFilter/9" title="Provides a route filter, which filters by the request format." class="local">\Drupal\Core\Routing\RequestFormatRouteFilter</a> @group Routing

Namespace

Drupal\Tests\Core\Routing

Code

public function filterProvider() {
    $route_without_format = new Route('/test');
    $route_with_format = new Route('/test');
    $route_with_format->setRequirement('_format', 'json');
    $route_with_multiple_formats = new Route('/test');
    $route_with_multiple_formats->setRequirement('_format', 'json|xml');
    $collection = new RouteCollection();
    $collection->add('test_0', $route_without_format);
    $collection->add('test_1', $route_with_format);
    $collection->add('test_2', $route_with_multiple_formats);
    $sole_route_match_single_format = new RouteCollection();
    $sole_route_match_single_format->add('sole_route_single_format', $route_with_format);
    return [
        'nothing requested' => [
            clone $collection,
            '',
            [
                'test_0',
            ],
        ],
        'xml requested' => [
            clone $collection,
            'xml',
            [
                'test_2',
                'test_0',
            ],
        ],
        'json requested' => [
            clone $collection,
            'json',
            [
                'test_1',
                'test_2',
                'test_0',
            ],
        ],
        'html format requested' => [
            clone $collection,
            'html',
            [
                'test_0',
            ],
        ],
        'no format requested, defaults to html' => [
            clone $collection,
            NULL,
            [
                'test_0',
            ],
        ],
        'no format requested, single route match with single format, defaults to that format' => [
            clone $sole_route_match_single_format,
            NULL,
            [
                'sole_route_single_format',
            ],
        ],
    ];
}

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