function BubbleableMetadataTest::providerTestMerge

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php \Drupal\Tests\Core\Render\BubbleableMetadataTest::providerTestMerge()
  2. 10 core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php \Drupal\Tests\Core\Render\BubbleableMetadataTest::providerTestMerge()
  3. 11.x 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 68

Class

BubbleableMetadataTest
@coversDefaultClass \Drupal\Core\Render\BubbleableMetadata @group Render

Namespace

Drupal\Tests\Core\Render

Code

public 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.