function CacheContextsManagerTest::providerTestOptimizeTokens

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

Provides a list of context token sets.

File

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

Class

CacheContextsManagerTest
Tests Drupal\Core\Cache\Context\CacheContextsManager.

Namespace

Drupal\Tests\Core\Cache\Context

Code

public static function providerTestOptimizeTokens() : array {
  return [
    // No ancestors found, 0 container calls needed.
[
      [
        'a',
        'x',
      ],
      [
        'a',
        'x',
      ],
      0,
    ],
    [
      [
        'a.b',
        'x',
      ],
      [
        'a.b',
        'x',
      ],
      0,
    ],
    // Direct ancestor, single-level hierarchy: 1 call to check max-age.
[
      [
        'a',
        'a.b',
      ],
      [
        'a',
      ],
      1,
    ],
    [
      [
        'a.b',
        'a',
      ],
      [
        'a',
      ],
      1,
    ],
    // Direct ancestor, multi-level hierarchy: 1 call to check max-age.
[
      [
        'a.b',
        'a.b.c',
      ],
      [
        'a.b',
      ],
      1,
    ],
    [
      [
        'a.b.c',
        'a.b',
      ],
      [
        'a.b',
      ],
      1,
    ],
    // Indirect ancestor: 1 call to check max-age.
[
      [
        'a',
        'a.b.c',
      ],
      [
        'a',
      ],
      1,
    ],
    [
      [
        'a.b.c',
        'a',
      ],
      [
        'a',
      ],
      1,
    ],
    // Direct & indirect ancestors: 2 calls (one for each descendant).
[
      [
        'a',
        'a.b',
        'a.b.c',
      ],
      [
        'a',
      ],
      2,
    ],
    [
      [
        'a',
        'a.b.c',
        'a.b',
      ],
      [
        'a',
      ],
      2,
    ],
    [
      [
        'a.b',
        'a',
        'a.b.c',
      ],
      [
        'a',
      ],
      2,
    ],
    [
      [
        'a.b',
        'a.b.c',
        'a',
      ],
      [
        'a',
      ],
      2,
    ],
    [
      [
        'a.b.c',
        'a.b',
        'a',
      ],
      [
        'a',
      ],
      2,
    ],
    [
      [
        'a.b.c',
        'a',
        'a.b',
      ],
      [
        'a',
      ],
      2,
    ],
    // Using parameters: 1 call to check max-age.
[
      [
        'a',
        'a.b.c:foo',
      ],
      [
        'a',
      ],
      1,
    ],
    [
      [
        'a.b.c:foo',
        'a',
      ],
      [
        'a',
      ],
      1,
    ],
    [
      [
        'a.b.c:foo',
        'a.b.c',
      ],
      [
        'a.b.c',
      ],
      1,
    ],
    // max-age 0 is treated as non-optimizable: 2 calls (both have ancestors).
[
      [
        'a.b.no-optimize',
        'a.b',
        'a',
      ],
      [
        'a.b.no-optimize',
        'a',
      ],
      2,
    ],
  ];
}

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