class MetadataBubblingUrlGeneratorTest

Same name in other branches
  1. 8.9.x 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() : 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) {
            $this->assertArrayHasKey('#cache', $build);
        });
        $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.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
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.
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 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::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.