function BubbleableMetadataTest::providerTestAddCacheableDependency

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php \Drupal\Tests\Core\Render\BubbleableMetadataTest::providerTestAddCacheableDependency()
  2. 8.9.x core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php \Drupal\Tests\Core\Render\BubbleableMetadataTest::providerTestAddCacheableDependency()
  3. 10 core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php \Drupal\Tests\Core\Render\BubbleableMetadataTest::providerTestAddCacheableDependency()

Provides test data for testMerge().

Return value

array

File

core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php, line 618

Class

BubbleableMetadataTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21BubbleableMetadata.php/class/BubbleableMetadata/11.x" title="Value object used for bubbleable rendering metadata." class="local">\Drupal\Core\Render\BubbleableMetadata</a> @group Render

Namespace

Drupal\Tests\Core\Render

Code

public function providerTestAddCacheableDependency() {
    return [
        // Merge in a cacheable metadata.
'merge-cacheable-metadata' => [
            (new BubbleableMetadata())->setCacheContexts([
                'foo',
            ])
                ->setCacheTags([
                'foo',
            ])
                ->setCacheMaxAge(20),
            (new CacheableMetadata())->setCacheContexts([
                'bar',
            ])
                ->setCacheTags([
                'bar',
            ])
                ->setCacheMaxAge(60),
            (new BubbleableMetadata())->setCacheContexts([
                'foo',
                'bar',
            ])
                ->setCacheTags([
                'foo',
                'bar',
            ])
                ->setCacheMaxAge(20),
        ],
        'merge-bubbleable-metadata' => [
            (new BubbleableMetadata())->setCacheContexts([
                'foo',
            ])
                ->setCacheTags([
                'foo',
            ])
                ->setCacheMaxAge(20)
                ->setAttachments([
                'foo' => [],
            ]),
            (new BubbleableMetadata())->setCacheContexts([
                'bar',
            ])
                ->setCacheTags([
                'bar',
            ])
                ->setCacheMaxAge(60)
                ->setAttachments([
                'bar' => [],
            ]),
            (new BubbleableMetadata())->setCacheContexts([
                'foo',
                'bar',
            ])
                ->setCacheTags([
                'foo',
                'bar',
            ])
                ->setCacheMaxAge(20)
                ->setAttachments([
                'foo' => [],
                'bar' => [],
            ]),
        ],
        'merge-attachments-metadata' => [
            (new BubbleableMetadata())->setAttachments([
                'foo' => [],
            ]),
            (new BubbleableMetadata())->setAttachments([
                'bar' => [],
            ]),
            (new BubbleableMetadata())->setAttachments([
                'foo' => [],
                'bar' => [],
            ]),
        ],
    ];
}

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