function BubbleableMetadataTest::providerTestMerge

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

Provides test data for testMerge().

Return value

array

File

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

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 static function providerTestMerge() {
    return [
        // Second operand is a BubbleableMetadata object.
        // All empty.
[
            new BubbleableMetadata(),
            new BubbleableMetadata(),
            new BubbleableMetadata(),
        ],
        // Cache contexts.
[
            (new BubbleableMetadata())->setCacheContexts([
                'foo',
            ]),
            (new BubbleableMetadata())->setCacheContexts([
                'bar',
            ]),
            (new BubbleableMetadata())->setCacheContexts([
                'bar',
                'foo',
            ]),
        ],
        // Cache tags.
[
            (new BubbleableMetadata())->setCacheTags([
                'foo',
            ]),
            (new BubbleableMetadata())->setCacheTags([
                'bar',
            ]),
            (new BubbleableMetadata())->setCacheTags([
                'foo',
                'bar',
            ]),
        ],
        // Cache max-ages.
[
            (new BubbleableMetadata())->setCacheMaxAge(60),
            (new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT),
            (new BubbleableMetadata())->setCacheMaxAge(60),
        ],
        // Assets.
[
            (new BubbleableMetadata())->setAttachments([
                'library' => [
                    'core/foo',
                ],
            ]),
            (new BubbleableMetadata())->setAttachments([
                'library' => [
                    'core/bar',
                ],
            ]),
            (new BubbleableMetadata())->setAttachments([
                'library' => [
                    'core/foo',
                    'core/bar',
                ],
            ]),
        ],
        // Placeholders.
[
            (new BubbleableMetadata())->setAttachments([
                'placeholders' => [
                    '<my-placeholder>' => [
                        'callback',
                        [
                            'A',
                        ],
                    ],
                ],
            ]),
            (new BubbleableMetadata())->setAttachments([
                'placeholders' => [
                    '<my-placeholder>' => [
                        'callback',
                        [
                            'A',
                        ],
                    ],
                ],
            ]),
            (new BubbleableMetadata())->setAttachments([
                'placeholders' => [
                    '<my-placeholder>' => [
                        'callback',
                        [
                            'A',
                        ],
                    ],
                ],
            ]),
        ],
        // Second operand is a CacheableMetadata object.
        // All empty.
[
            new BubbleableMetadata(),
            new CacheableMetadata(),
            new BubbleableMetadata(),
        ],
        // Cache contexts.
[
            (new BubbleableMetadata())->setCacheContexts([
                'foo',
            ]),
            (new CacheableMetadata())->setCacheContexts([
                'bar',
            ]),
            (new BubbleableMetadata())->setCacheContexts([
                'bar',
                'foo',
            ]),
        ],
        // Cache tags.
[
            (new BubbleableMetadata())->setCacheTags([
                'foo',
            ]),
            (new CacheableMetadata())->setCacheTags([
                'bar',
            ]),
            (new BubbleableMetadata())->setCacheTags([
                'foo',
                'bar',
            ]),
        ],
        // Cache max-ages.
[
            (new BubbleableMetadata())->setCacheMaxAge(60),
            (new CacheableMetadata())->setCacheMaxAge(Cache::PERMANENT),
            (new BubbleableMetadata())->setCacheMaxAge(60),
        ],
    ];
}

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