class MetadataBubblingUrlGeneratorTest

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/MetadataBubblingUrlGeneratorTest.php \Drupal\Tests\Core\Render\MetadataBubblingUrlGeneratorTest
  2. 8.9.x core/tests/Drupal/Tests/Core/Render/MetadataBubblingUrlGeneratorTest.php \Drupal\Tests\Core\Render\MetadataBubblingUrlGeneratorTest
  3. 10 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

Expanded class hierarchy of MetadataBubblingUrlGeneratorTest

File

core/tests/Drupal/Tests/Core/Render/MetadataBubblingUrlGeneratorTest.php, line 18

Namespace

Drupal\Tests\Core\Render
View 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) : void {
        $self = $this;
        $this->renderer
            ->expects($this->exactly($invocations))
            ->method('render')
            ->willReturnCallback(function ($build) {
            $this->assertArrayHasKey('#cache', $build);
        });
        $url = new Url('test_1', [], $options);
        $url->setUrlGenerator($this->generator);
        $url->toString($collect_bubbleable_metadata);
    }
    
    /**
     * Data provider for ::testUrlBubbleableMetadataBubbling().
     */
    public static function providerUrlBubbleableMetadataBubbling() {
        return [
            // No bubbling when bubbleable metadata is collected.
[
                TRUE,
                0,
                [],
            ],
            // Bubbling when bubbleable metadata is not collected.
[
                FALSE,
                1,
                [],
            ],
        ];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ExpectDeprecationTrait::expectDeprecation public function Adds an expected deprecation.
ExpectDeprecationTrait::getCallableName private static function Returns a callable as a string suitable for inclusion in a message.
ExpectDeprecationTrait::setUpErrorHandler public function Sets up the test error handler.
ExpectDeprecationTrait::tearDownErrorHandler public function Tears down the test error handler.
MetadataBubblingUrlGeneratorTest::$renderer protected property The renderer.
MetadataBubblingUrlGeneratorTest::providerUrlBubbleableMetadataBubbling public static function Data provider for ::testUrlBubbleableMetadataBubbling().
MetadataBubblingUrlGeneratorTest::setUp protected function Overrides UrlGeneratorTest::setUp
MetadataBubblingUrlGeneratorTest::testUrlBubbleableMetadataBubbling public function Tests bubbling of cacheable metadata for URLs.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
UnitTestCase::$root protected property The app root.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function
UrlGeneratorTest::$aliasManager protected property The alias manager.
UrlGeneratorTest::$context protected property The request context.
UrlGeneratorTest::$generator protected property The URL generator to test.
UrlGeneratorTest::$processorManager protected property The path processor.
UrlGeneratorTest::$provider protected property The route provider.
UrlGeneratorTest::$requestStack protected property The request stack.
UrlGeneratorTest::$routeProcessorManager protected property The mock route processor manager.
UrlGeneratorTest::aliasManagerCallback public function Return value callback for getAliasByPath() on the mock alias manager.
UrlGeneratorTest::assertGenerateFromRoute protected function Asserts \Drupal\Core\Routing\UrlGenerator::generateFromRoute()'s output.
UrlGeneratorTest::providerTestAliasGenerationWithOptions public static function Provides test data for testAliasGenerationWithOptions.
UrlGeneratorTest::providerTestNoPath public static function Data provider for ::testNoPath().
UrlGeneratorTest::testAbsoluteURLGeneration public function Confirms that absolute URLs work with generated routes.
UrlGeneratorTest::testAbsoluteURLGenerationUsingInterfaceConstants public function Confirms that absolute URLs work with generated routes using interface constants.
UrlGeneratorTest::testAliasGeneration public function Confirms that generated routes will have aliased paths.
UrlGeneratorTest::testAliasGenerationUsingInterfaceConstants public function Confirms that generated routes will have aliased paths using interface constants.
UrlGeneratorTest::testAliasGenerationWithOptions public function Confirms that generated routes will have aliased paths with options.
UrlGeneratorTest::testAliasGenerationWithParameters public function Confirms that generated routes will have aliased paths.
UrlGeneratorTest::testBaseURLGeneration public function Confirms that explicitly setting the base_url works with generated routes.
UrlGeneratorTest::testGenerateWithPathProcessorChangingOptions public function @covers \Drupal\Core\Routing\UrlGenerator::generateFromRoute
UrlGeneratorTest::testGetPathFromRouteTrailing public function Tests URL generation from route with trailing start and end slashes.
UrlGeneratorTest::testGetPathFromRouteWithSubdirectory public function Tests URL generation in a subdirectory.
UrlGeneratorTest::testNoPath public function Tests generating a relative URL with no path.
UrlGeneratorTest::testUrlGenerationWithDisabledPathProcessing public function @covers ::generateFromRoute
UrlGeneratorTest::testUrlGenerationWithDisabledPathProcessingByRoute public function @covers ::generateFromRoute
UrlGeneratorTest::testUrlGenerationWithDisabledPathProcessingByRouteAndOptedInPathProcessing public function @covers ::generateFromRoute
UrlGeneratorTest::testUrlGenerationWithHttpsRequirement public function Tests the 'scheme' route requirement during URL generation.

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