function BubbleableMetadataTest::providerTestApplyTo

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

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;
}

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