class RequestFormatRouteFilterTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php \Drupal\Tests\Core\Routing\RequestFormatRouteFilterTest
@coversDefaultClass \Drupal\Core\Routing\RequestFormatRouteFilter @group Routing
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Routing\RequestFormatRouteFilterTest
Expanded class hierarchy of RequestFormatRouteFilterTest
File
- core/
tests/ Drupal/ Tests/ Core/ Routing/ RequestFormatRouteFilterTest.php, line 20 - Contains \Drupal\Tests\Core\Routing\RequestFormatRouteFilterTest.
Namespace
Drupal\Tests\Core\RoutingView source
class RequestFormatRouteFilterTest extends UnitTestCase {
/**
* @covers ::applies
*/
public function testAppliesWithoutFormat() {
$route_filter = new RequestFormatRouteFilter();
$route = new Route('/test');
$this
->assertFalse($route_filter
->applies($route));
}
/**
* @covers ::applies
*/
public function testAppliesWithFormat() {
$route_filter = new RequestFormatRouteFilter();
$route = new Route('/test');
$route
->setRequirement('_format', 'json');
$this
->assertTrue($route_filter
->applies($route));
}
/**
* @covers ::filter
*/
public function testFilter() {
$route_filter = new RequestFormatRouteFilter();
$route_without_format = new Route('/test');
$route_with_format = $route = new Route('/test');
$route_with_format
->setRequirement('_format', 'json');
$route_with_multiple_formats = $route = 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);
$request = new Request();
$request
->setRequestFormat('xml');
$collection = $route_filter
->filter($collection, $request);
$this
->assertCount(2, $collection);
$this
->assertEquals(array_keys($collection
->all())[0], 'test_2');
$this
->assertEquals(array_keys($collection
->all())[1], 'test_0');
}
/**
* @covers ::filter
* @expectedException \Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException
* @expectedExceptionMessage No route found for the specified format xml.
*/
public function testNoRouteFound() {
$collection = new RouteCollection();
$route_with_format = $route = new Route('/test');
$route_with_format
->setRequirement('_format', 'json');
$collection
->add('test_0', $route_with_format);
$collection
->add('test_1', clone $route_with_format);
$request = Request::create('test?_format=xml', 'GET');
$request
->setRequestFormat('xml');
$route_filter = new RequestFormatRouteFilter();
$route_filter
->filter($collection, $request);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RequestFormatRouteFilterTest:: |
public | function | @covers ::applies | |
RequestFormatRouteFilterTest:: |
public | function | @covers ::applies | |
RequestFormatRouteFilterTest:: |
public | function | @covers ::filter | |
RequestFormatRouteFilterTest:: |
public | function | @covers ::filter @expectedException \Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException @expectedExceptionMessage No route found for the specified format xml. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 259 |