You are here

public function BubbleableMetadataTest::providerTestMerge in Drupal 9

Same name and namespace in other branches
  1. 8 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 71

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),
    ],
  ];
}