class UrlGeneratorTraitTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTraitTest.php \Drupal\Tests\Core\Routing\UrlGeneratorTraitTest
@coversDefaultClass \Drupal\Core\Routing\UrlGeneratorTrait @group Routing
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Routing\UrlGeneratorTraitTest
Expanded class hierarchy of UrlGeneratorTraitTest
File
- core/
tests/ Drupal/ Tests/ Core/ Routing/ UrlGeneratorTraitTest.php, line 16 - Contains \Drupal\Tests\Core\Routing\UrlGeneratorTraitTest.
Namespace
Drupal\Tests\Core\RoutingView source
class UrlGeneratorTraitTest extends UnitTestCase {
/**
* @covers ::setUrlGenerator
* @covers ::getUrlGenerator
*/
public function testGetUrlGenerator() {
$url_generator = $this
->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface');
$url_generator_trait_object = $this
->getMockForTrait('Drupal\\Core\\Routing\\UrlGeneratorTrait');
$url_generator_trait_object
->setUrlGenerator($url_generator);
$url_generator_method = new \ReflectionMethod($url_generator_trait_object, 'getUrlGenerator');
$url_generator_method
->setAccessible(TRUE);
$result = $url_generator_method
->invoke($url_generator_trait_object);
$this
->assertEquals($url_generator, $result);
}
/**
* @covers ::redirect
*/
public function testRedirect() {
$route_name = 'some_route_name';
$generated_url = 'some/generated/url';
$url_generator = $this
->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface');
$url_generator
->expects($this
->once())
->method('generateFromRoute')
->with($route_name, [], [
'absolute' => TRUE,
])
->willReturn($generated_url);
$url_generator_trait_object = $this
->getMockForTrait('Drupal\\Core\\Routing\\UrlGeneratorTrait');
$url_generator_trait_object
->setUrlGenerator($url_generator);
$url_generator_method = new \ReflectionMethod($url_generator_trait_object, 'redirect');
$url_generator_method
->setAccessible(TRUE);
$result = $url_generator_method
->invoke($url_generator_trait_object, $route_name);
$this
->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $result);
$this
->assertSame($generated_url, $result
->getTargetUrl());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 | |
UrlGeneratorTraitTest:: |
public | function | @covers ::setUrlGenerator @covers ::getUrlGenerator | |
UrlGeneratorTraitTest:: |
public | function | @covers ::redirect |