function RequestFormatRouteFilterTest::filterProvider

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php \Drupal\Tests\Core\Routing\RequestFormatRouteFilterTest::filterProvider()
  2. 8.9.x 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 38

Class

RequestFormatRouteFilterTest
@coversDefaultClass \Drupal\Core\Routing\RequestFormatRouteFilter @group Routing

Namespace

Drupal\Tests\Core\Routing

Code

public static 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.