class MetadataBubblingUrlGeneratorTest

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

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() {
        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

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
MetadataBubblingUrlGeneratorTest::$renderer protected property The renderer.
MetadataBubblingUrlGeneratorTest::providerUrlBubbleableMetadataBubbling public function Data provider for ::testUrlBubbleableMetadataBubbling().
MetadataBubblingUrlGeneratorTest::setUp protected function Overrides UrlGeneratorTest::setUp
MetadataBubblingUrlGeneratorTest::testUrlBubbleableMetadataBubbling public function Tests bubbling of cacheable metadata for URLs.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
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::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
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 the getAliasByPath() method on the mock alias
manager.
UrlGeneratorTest::assertGenerateFromRoute protected function Asserts \Drupal\Core\Routing\UrlGenerator::generateFromRoute()'s output.
UrlGeneratorTest::providerTestAliasGenerationWithOptions public function Provides test data for testAliasGenerationWithOptions.
UrlGeneratorTest::providerTestNoPath public 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::testGenerateWithPathProcessorChangingQueryParameter 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 Test that the 'scheme' route requirement is respected during url generation.

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