function BubbleableMetadataTest::providerTestMerge
Provides test data for testMerge().
Return value
array An array of test data for testMerge().
File
- 
              core/tests/ Drupal/ Tests/ Core/ Render/ BubbleableMetadataTest.php, line 77 
Class
Namespace
Drupal\Tests\Core\RenderCode
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.
