class MetadataBubblingUrlGeneratorTest in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Render/MetadataBubblingUrlGeneratorTest.php \Drupal\Tests\Core\Render\MetadataBubblingUrlGeneratorTest
Confirm that the MetadataBubblingUrlGenerator is functioning properly.
@coversDefaultClass \Drupal\Core\Render\MetadataBubblingUrlGenerator
@group Render
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\Core\Routing\UrlGeneratorTest
- class \Drupal\Tests\Core\Render\MetadataBubblingUrlGeneratorTest
- class \Drupal\Tests\Core\Routing\UrlGeneratorTest
Expanded class hierarchy of MetadataBubblingUrlGeneratorTest
File
- core/
tests/ Drupal/ Tests/ Core/ Render/ MetadataBubblingUrlGeneratorTest.php, line 16
Namespace
Drupal\Tests\Core\RenderView source
class MetadataBubblingUrlGeneratorTest extends UrlGeneratorTest {
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $renderer;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->renderer = $this
->createMock('\\Drupal\\Core\\Render\\RendererInterface');
$this->renderer
->expects($this
->any())
->method('hasRenderContext')
->willReturn(TRUE);
$this->generator = new MetadataBubblingUrlGenerator($this->generator, $this->renderer);
}
/**
* Tests bubbling of cacheable metadata for URLs.
*
* @param bool $collect_bubbleable_metadata
* Whether bubbleable metadata should be collected.
* @param int $invocations
* The expected amount of invocations for the ::bubble() method.
* @param array $options
* The URL options.
*
* @covers ::bubble
*
* @dataProvider providerUrlBubbleableMetadataBubbling
*/
public function testUrlBubbleableMetadataBubbling($collect_bubbleable_metadata, $invocations, array $options) {
$self = $this;
$this->renderer
->expects($this
->exactly($invocations))
->method('render')
->willReturnCallback(function ($build) use ($self) {
$self
->assertTrue(!empty($build['#cache']));
});
$url = new Url('test_1', [], $options);
$url
->setUrlGenerator($this->generator);
$url
->toString($collect_bubbleable_metadata);
}
/**
* Data provider for ::testUrlBubbleableMetadataBubbling().
*/
public function providerUrlBubbleableMetadataBubbling() {
return [
// No bubbling when bubbleable metadata is collected.
[
TRUE,
0,
[],
],
// Bubbling when bubbleable metadata is not collected.
[
FALSE,
1,
[],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MetadataBubblingUrlGeneratorTest:: |
protected | property | The renderer. | |
MetadataBubblingUrlGeneratorTest:: |
public | function | Data provider for ::testUrlBubbleableMetadataBubbling(). | |
MetadataBubblingUrlGeneratorTest:: |
protected | function |
Overrides UrlGeneratorTest:: |
|
MetadataBubblingUrlGeneratorTest:: |
public | function | Tests bubbling of cacheable metadata for URLs. | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed 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:: |
public static | function | ||
UrlGeneratorTest:: |
protected | property | The alias manager. | |
UrlGeneratorTest:: |
protected | property | The request context. | |
UrlGeneratorTest:: |
protected | property | The url generator to test. | |
UrlGeneratorTest:: |
protected | property | The path processor. | |
UrlGeneratorTest:: |
protected | property | The route provider. | |
UrlGeneratorTest:: |
protected | property | The request stack. | |
UrlGeneratorTest:: |
protected | property | The mock route processor manager. | |
UrlGeneratorTest:: |
public | function | Return value callback for the getAliasByPath() method on the mock alias manager. | |
UrlGeneratorTest:: |
protected | function | Asserts \Drupal\Core\Routing\UrlGenerator::generateFromRoute()'s output. | |
UrlGeneratorTest:: |
public | function | Provides test data for testAliasGenerationWithOptions. | |
UrlGeneratorTest:: |
public | function | Data provider for ::testNoPath(). | |
UrlGeneratorTest:: |
public | function | Confirms that absolute URLs work with generated routes. | |
UrlGeneratorTest:: |
public | function | Confirms that absolute URLs work with generated routes using interface constants. | |
UrlGeneratorTest:: |
public | function | Confirms that generated routes will have aliased paths. | |
UrlGeneratorTest:: |
public | function | Confirms that generated routes will have aliased paths using interface constants. | |
UrlGeneratorTest:: |
public | function | Confirms that generated routes will have aliased paths with options. | |
UrlGeneratorTest:: |
public | function | Confirms that generated routes will have aliased paths. | |
UrlGeneratorTest:: |
public | function | Confirms that explicitly setting the base_url works with generated routes. | |
UrlGeneratorTest:: |
public | function | @covers \Drupal\Core\Routing\UrlGenerator::generateFromRoute | |
UrlGeneratorTest:: |
public | function | Tests URL generation from route with trailing start and end slashes. | |
UrlGeneratorTest:: |
public | function | Tests URL generation in a subdirectory. | |
UrlGeneratorTest:: |
public | function | Tests generating a relative URL with no path. | |
UrlGeneratorTest:: |
public | function | @covers ::generateFromRoute | |
UrlGeneratorTest:: |
public | function | @covers ::generateFromRoute | |
UrlGeneratorTest:: |
public | function | @covers ::generateFromRoute | |
UrlGeneratorTest:: |
public | function | Tests that the 'scheme' route requirement is respected during url generation. |