function CacheableMetadataTest::providerTestCreateFromRenderArray

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php \Drupal\Tests\Core\Cache\CacheableMetadataTest::providerTestCreateFromRenderArray()
  2. 10 core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php \Drupal\Tests\Core\Cache\CacheableMetadataTest::providerTestCreateFromRenderArray()
  3. 11.x core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php \Drupal\Tests\Core\Cache\CacheableMetadataTest::providerTestCreateFromRenderArray()

Provides test data for createFromRenderArray().

Return value

array

File

core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php, line 148

Class

CacheableMetadataTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Cache%21CacheableMetadata.php/class/CacheableMetadata/9" title="Defines a generic class for passing cacheability metadata." class="local">\Drupal\Core\Cache\CacheableMetadata</a> @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function providerTestCreateFromRenderArray() {
    $data = [];
    $empty_metadata = new CacheableMetadata();
    $nonempty_metadata = new CacheableMetadata();
    $nonempty_metadata->setCacheContexts([
        'qux',
    ])
        ->setCacheTags([
        'foo:bar',
    ]);
    $empty_render_array = [];
    $nonempty_render_array = [
        '#cache' => [
            'contexts' => [
                'qux',
            ],
            'tags' => [
                'foo:bar',
            ],
            'max-age' => Cache::PERMANENT,
        ],
    ];
    $data[] = [
        $empty_render_array,
        $empty_metadata,
    ];
    $data[] = [
        $nonempty_render_array,
        $nonempty_metadata,
    ];
    return $data;
}

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