You are here

public function BubbleableMetadataTest::providerTestApplyTo 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::providerTestApplyTo()

Provides test data for testApplyTo().

Return value

array

File

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

Class

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

Namespace

Drupal\Tests\Core\Render

Code

public function providerTestApplyTo() {
  $data = [];
  $empty_metadata = new BubbleableMetadata();
  $nonempty_metadata = new BubbleableMetadata();
  $nonempty_metadata
    ->setCacheContexts([
    'qux',
  ])
    ->setCacheTags([
    'foo:bar',
  ])
    ->setAttachments([
    'settings' => [
      'foo' => 'bar',
    ],
  ]);
  $empty_render_array = [];
  $nonempty_render_array = [
    '#cache' => [
      'contexts' => [
        'qux',
      ],
      'tags' => [
        'llamas:are:awesome:but:kittens:too',
      ],
      'max-age' => Cache::PERMANENT,
    ],
    '#attached' => [
      'library' => [
        'core/jquery',
      ],
    ],
  ];
  $expected_when_empty_metadata = [
    '#cache' => [
      'contexts' => [],
      'tags' => [],
      'max-age' => Cache::PERMANENT,
    ],
    '#attached' => [],
  ];
  $data[] = [
    $empty_metadata,
    $empty_render_array,
    $expected_when_empty_metadata,
  ];
  $data[] = [
    $empty_metadata,
    $nonempty_render_array,
    $expected_when_empty_metadata,
  ];
  $expected_when_nonempty_metadata = [
    '#cache' => [
      'contexts' => [
        'qux',
      ],
      'tags' => [
        'foo:bar',
      ],
      'max-age' => Cache::PERMANENT,
    ],
    '#attached' => [
      'settings' => [
        'foo' => 'bar',
      ],
    ],
  ];
  $data[] = [
    $nonempty_metadata,
    $empty_render_array,
    $expected_when_nonempty_metadata,
  ];
  $data[] = [
    $nonempty_metadata,
    $nonempty_render_array,
    $expected_when_nonempty_metadata,
  ];
  return $data;
}