function CacheContextsManagerTest::validateTokensProvider

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

Provides a list of cache context token arrays.

Return value

array

File

core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php, line 204

Class

CacheContextsManagerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Cache%21Context%21CacheContextsManager.php/class/CacheContextsManager/9" title="Converts cache context tokens into cache keys." class="local">\Drupal\Core\Cache\Context\CacheContextsManager</a> @group Cache

Namespace

Drupal\Tests\Core\Cache\Context

Code

public function validateTokensProvider() {
    return [
        [
            [],
            FALSE,
        ],
        [
            [
                'foo',
            ],
            FALSE,
        ],
        [
            [
                'foo',
                'foo.bar',
            ],
            FALSE,
        ],
        [
            [
                'foo',
                'baz:llama',
            ],
            FALSE,
        ],
        // Invalid.
[
            [
                FALSE,
            ],
            'Cache contexts must be strings, boolean given.',
        ],
        [
            [
                TRUE,
            ],
            'Cache contexts must be strings, boolean given.',
        ],
        [
            [
                'foo',
                FALSE,
            ],
            'Cache contexts must be strings, boolean given.',
        ],
        [
            [
                NULL,
            ],
            'Cache contexts must be strings, NULL given.',
        ],
        [
            [
                'foo',
                NULL,
            ],
            'Cache contexts must be strings, NULL given.',
        ],
        [
            [
                1337,
            ],
            'Cache contexts must be strings, integer given.',
        ],
        [
            [
                'foo',
                1337,
            ],
            'Cache contexts must be strings, integer given.',
        ],
        [
            [
                3.14,
            ],
            'Cache contexts must be strings, double given.',
        ],
        [
            [
                'foo',
                3.14,
            ],
            'Cache contexts must be strings, double given.',
        ],
        [
            [
                [],
            ],
            'Cache contexts must be strings, array given.',
        ],
        [
            [
                'foo',
                [],
            ],
            'Cache contexts must be strings, array given.',
        ],
        [
            [
                'foo',
                [
                    'bar',
                ],
            ],
            'Cache contexts must be strings, array given.',
        ],
        [
            [
                new \stdClass(),
            ],
            'Cache contexts must be strings, object given.',
        ],
        [
            [
                'foo',
                new \stdClass(),
            ],
            'Cache contexts must be strings, object given.',
        ],
        // Non-existing.
[
            [
                'foo.bar',
                'qux',
            ],
            '"qux" is not a valid cache context ID.',
        ],
        [
            [
                'qux',
                'baz',
            ],
            '"qux" is not a valid cache context ID.',
        ],
    ];
}

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