function AccessResultTest::andOrCacheabilityPropagationProvider
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::andOrCacheabilityPropagationProvider()
- 8.9.x core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::andOrCacheabilityPropagationProvider()
- 10 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::andOrCacheabilityPropagationProvider()
Provides a list of access result pairs and operations to test.
This tests the propagation of cacheability metadata. Rather than testing every single bit of cacheability metadata, which would lead to a mind- boggling number of permutations, in this test, we only consider the permutations of all pairs of the following set:
- Allowed, implements CDI and is cacheable.
- Allowed, implements CDI and is not cacheable.
- Allowed, does not implement CDI (hence not cacheable).
- Forbidden, implements CDI and is cacheable.
- Forbidden, implements CDI and is not cacheable.
- Forbidden, does not implement CDI (hence not cacheable).
- Neutral, implements CDI and is cacheable.
- Neutral, implements CDI and is not cacheable.
- Neutral, does not implement CDI (hence not cacheable).
(Where "CDI" is CacheableDependencyInterface.)
This leads to 72 permutations (9!/(9-2)! = 9*8 = 72) per operation. There are two operations to test (AND and OR), so that leads to a grand total of 144 permutations, all of which are tested.
There are two "contagious" patterns:
- Any operation with a forbidden access result yields a forbidden result. This therefore also applies to the cacheability metadata associated with a forbidden result. This is the case for bullets 4, 5 and 6 in the set above.
- Any operation yields an access result object that is of the same class (implementation) as the first operand. This is because operations are invoked on the first operand. Therefore, if the first implementation does not implement CacheableDependencyInterface, then the result won't either. This is the case for bullets 3, 6 and 9 in the set above.
File
-
core/
tests/ Drupal/ Tests/ Core/ Access/ AccessResultTest.php, line 587
Class
- AccessResultTest
- @coversDefaultClass \Drupal\Core\Access\AccessResult @group Access
Namespace
Drupal\Tests\Core\AccessCode
public static function andOrCacheabilityPropagationProvider() {
// ct: cacheable=true, cf: cacheable=false, un: uncacheable.
// Note: the test cases that have a "un" access result as the first operand
// test UncacheableTestAccessResult, not AccessResult. However, we
// definitely want to verify that AccessResult's orIf() and andIf() methods
// work correctly when given an AccessResultInterface implementation that
// does not implement CacheableDependencyInterface, and we want to test the
// full gamut of permutations, so that's not a problem.
$allowed_ct = AccessResult::allowed();
$allowed_cf = AccessResult::allowed()->setCacheMaxAge(0);
$allowed_un = new UncacheableTestAccessResult('ALLOWED');
$forbidden_ct = AccessResult::forbidden();
$forbidden_cf = AccessResult::forbidden()->setCacheMaxAge(0);
$forbidden_un = new UncacheableTestAccessResult('FORBIDDEN');
$neutral_ct = AccessResult::neutral();
$neutral_cf = AccessResult::neutral()->setCacheMaxAge(0);
$neutral_un = new UncacheableTestAccessResult('NEUTRAL');
// Structure:
// - First column: first access result.
// - Second column: operator ('OR' or 'AND').
// - Third column: second access result.
// - Fourth column: whether result implements CacheableDependencyInterface
// - Fifth column: whether the result is cacheable (if column 4 is TRUE)
return [
// Allowed (ct) OR allowed (ct,cf,un).
[
$allowed_ct,
'OR',
$allowed_ct,
TRUE,
TRUE,
],
[
$allowed_ct,
'OR',
$allowed_cf,
TRUE,
TRUE,
],
[
$allowed_ct,
'OR',
$allowed_un,
TRUE,
TRUE,
],
// Allowed (cf) OR allowed (ct,cf,un).
[
$allowed_cf,
'OR',
$allowed_ct,
TRUE,
TRUE,
],
[
$allowed_cf,
'OR',
$allowed_cf,
TRUE,
FALSE,
],
[
$allowed_cf,
'OR',
$allowed_un,
TRUE,
FALSE,
],
// Allowed (un) OR allowed (ct,cf,un).
[
$allowed_un,
'OR',
$allowed_ct,
FALSE,
NULL,
],
[
$allowed_un,
'OR',
$allowed_cf,
FALSE,
NULL,
],
[
$allowed_un,
'OR',
$allowed_un,
FALSE,
NULL,
],
// Allowed (ct) OR forbidden (ct,cf,un).
[
$allowed_ct,
'OR',
$forbidden_ct,
TRUE,
TRUE,
],
[
$allowed_ct,
'OR',
$forbidden_cf,
TRUE,
FALSE,
],
[
$allowed_ct,
'OR',
$forbidden_un,
TRUE,
FALSE,
],
// Allowed (cf) OR forbidden (ct,cf,un).
[
$allowed_cf,
'OR',
$forbidden_ct,
TRUE,
TRUE,
],
[
$allowed_cf,
'OR',
$forbidden_cf,
TRUE,
FALSE,
],
[
$allowed_cf,
'OR',
$forbidden_un,
TRUE,
FALSE,
],
// Allowed (un) OR forbidden (ct,cf,un).
[
$allowed_un,
'OR',
$forbidden_ct,
FALSE,
NULL,
],
[
$allowed_un,
'OR',
$forbidden_cf,
FALSE,
NULL,
],
[
$allowed_un,
'OR',
$forbidden_un,
FALSE,
NULL,
],
// Allowed (ct) OR neutral (ct,cf,un).
[
$allowed_ct,
'OR',
$neutral_ct,
TRUE,
TRUE,
],
[
$allowed_ct,
'OR',
$neutral_cf,
TRUE,
TRUE,
],
[
$allowed_ct,
'OR',
$neutral_un,
TRUE,
TRUE,
],
// Allowed (cf) OR neutral (ct,cf,un).
[
$allowed_cf,
'OR',
$neutral_ct,
TRUE,
FALSE,
],
[
$allowed_cf,
'OR',
$neutral_cf,
TRUE,
FALSE,
],
[
$allowed_cf,
'OR',
$neutral_un,
TRUE,
FALSE,
],
// Allowed (un) OR neutral (ct,cf,un).
[
$allowed_un,
'OR',
$neutral_ct,
FALSE,
NULL,
],
[
$allowed_un,
'OR',
$neutral_cf,
FALSE,
NULL,
],
[
$allowed_un,
'OR',
$neutral_un,
FALSE,
NULL,
],
// Forbidden (ct) OR allowed (ct,cf,un).
[
$forbidden_ct,
'OR',
$allowed_ct,
TRUE,
TRUE,
],
[
$forbidden_ct,
'OR',
$allowed_cf,
TRUE,
TRUE,
],
[
$forbidden_ct,
'OR',
$allowed_un,
TRUE,
TRUE,
],
// Forbidden (cf) OR allowed (ct,cf,un).
[
$forbidden_cf,
'OR',
$allowed_ct,
TRUE,
FALSE,
],
[
$forbidden_cf,
'OR',
$allowed_cf,
TRUE,
FALSE,
],
[
$forbidden_cf,
'OR',
$allowed_un,
TRUE,
FALSE,
],
// Forbidden (un) OR allowed (ct,cf,un).
[
$forbidden_un,
'OR',
$allowed_ct,
FALSE,
NULL,
],
[
$forbidden_un,
'OR',
$allowed_cf,
FALSE,
NULL,
],
[
$forbidden_un,
'OR',
$allowed_un,
FALSE,
NULL,
],
// Forbidden (ct) OR neutral (ct,cf,un).
[
$forbidden_ct,
'OR',
$neutral_ct,
TRUE,
TRUE,
],
[
$forbidden_ct,
'OR',
$neutral_cf,
TRUE,
TRUE,
],
[
$forbidden_ct,
'OR',
$neutral_un,
TRUE,
TRUE,
],
// Forbidden (cf) OR neutral (ct,cf,un).
[
$forbidden_cf,
'OR',
$neutral_ct,
TRUE,
FALSE,
],
[
$forbidden_cf,
'OR',
$neutral_cf,
TRUE,
FALSE,
],
[
$forbidden_cf,
'OR',
$neutral_un,
TRUE,
FALSE,
],
// Forbidden (un) OR neutral (ct,cf,un).
[
$forbidden_un,
'OR',
$neutral_ct,
FALSE,
NULL,
],
[
$forbidden_un,
'OR',
$neutral_cf,
FALSE,
NULL,
],
[
$forbidden_un,
'OR',
$neutral_un,
FALSE,
NULL,
],
// Forbidden (ct) OR forbidden (ct,cf,un).
[
$forbidden_ct,
'OR',
$forbidden_ct,
TRUE,
TRUE,
],
[
$forbidden_ct,
'OR',
$forbidden_cf,
TRUE,
TRUE,
],
[
$forbidden_ct,
'OR',
$forbidden_un,
TRUE,
TRUE,
],
// Forbidden (cf) OR forbidden (ct,cf,un).
[
$forbidden_cf,
'OR',
$forbidden_ct,
TRUE,
TRUE,
],
[
$forbidden_cf,
'OR',
$forbidden_cf,
TRUE,
FALSE,
],
[
$forbidden_cf,
'OR',
$forbidden_un,
TRUE,
FALSE,
],
// Forbidden (un) OR forbidden (ct,cf,un).
[
$forbidden_un,
'OR',
$forbidden_ct,
FALSE,
NULL,
],
[
$forbidden_un,
'OR',
$forbidden_cf,
FALSE,
NULL,
],
[
$forbidden_un,
'OR',
$forbidden_un,
FALSE,
NULL,
],
// Neutral (ct) OR allowed (ct,cf,un).
[
$neutral_ct,
'OR',
$allowed_ct,
TRUE,
TRUE,
],
[
$neutral_ct,
'OR',
$allowed_cf,
TRUE,
FALSE,
],
[
$neutral_ct,
'OR',
$allowed_un,
TRUE,
FALSE,
],
// Neutral (cf) OR allowed (ct,cf,un).
[
$neutral_cf,
'OR',
$allowed_ct,
TRUE,
TRUE,
],
[
$neutral_cf,
'OR',
$allowed_cf,
TRUE,
FALSE,
],
[
$neutral_cf,
'OR',
$allowed_un,
TRUE,
FALSE,
],
// Neutral (un) OR allowed (ct,cf,un).
[
$neutral_un,
'OR',
$allowed_ct,
FALSE,
NULL,
],
[
$neutral_un,
'OR',
$allowed_cf,
FALSE,
NULL,
],
[
$neutral_un,
'OR',
$allowed_un,
FALSE,
NULL,
],
// Neutral (ct) OR neutral (ct,cf,un).
[
$neutral_ct,
'OR',
$neutral_ct,
TRUE,
TRUE,
],
[
$neutral_ct,
'OR',
$neutral_cf,
TRUE,
TRUE,
],
[
$neutral_ct,
'OR',
$neutral_un,
TRUE,
TRUE,
],
// Neutral (cf) OR neutral (ct,cf,un).
[
$neutral_cf,
'OR',
$neutral_ct,
TRUE,
TRUE,
],
[
$neutral_cf,
'OR',
$neutral_cf,
TRUE,
FALSE,
],
[
$neutral_cf,
'OR',
$neutral_un,
TRUE,
FALSE,
],
// Neutral (un) OR neutral (ct,cf,un).
[
$neutral_un,
'OR',
$neutral_ct,
FALSE,
NULL,
],
[
$neutral_un,
'OR',
$neutral_cf,
FALSE,
NULL,
],
[
$neutral_un,
'OR',
$neutral_un,
FALSE,
NULL,
],
// Neutral (ct) OR forbidden (ct,cf,un).
[
$neutral_ct,
'OR',
$forbidden_ct,
TRUE,
TRUE,
],
[
$neutral_ct,
'OR',
$forbidden_cf,
TRUE,
FALSE,
],
[
$neutral_ct,
'OR',
$forbidden_un,
TRUE,
FALSE,
],
// Neutral (cf) OR forbidden (ct,cf,un).
[
$neutral_cf,
'OR',
$forbidden_ct,
TRUE,
TRUE,
],
[
$neutral_cf,
'OR',
$forbidden_cf,
TRUE,
FALSE,
],
[
$neutral_cf,
'OR',
$forbidden_un,
TRUE,
FALSE,
],
// Neutral (un) OR forbidden (ct,cf,un).
[
$neutral_un,
'OR',
$forbidden_ct,
FALSE,
NULL,
],
[
$neutral_un,
'OR',
$forbidden_cf,
FALSE,
NULL,
],
[
$neutral_un,
'OR',
$forbidden_un,
FALSE,
NULL,
],
// Allowed (ct) AND allowed (ct,cf,un).
[
$allowed_ct,
'AND',
$allowed_ct,
TRUE,
TRUE,
],
[
$allowed_ct,
'AND',
$allowed_cf,
TRUE,
FALSE,
],
[
$allowed_ct,
'AND',
$allowed_un,
TRUE,
FALSE,
],
// Allowed (cf) AND allowed (ct,cf,un).
[
$allowed_cf,
'AND',
$allowed_ct,
TRUE,
FALSE,
],
[
$allowed_cf,
'AND',
$allowed_cf,
TRUE,
FALSE,
],
[
$allowed_cf,
'AND',
$allowed_un,
TRUE,
FALSE,
],
// Allowed (un) AND allowed (ct,cf,un).
[
$allowed_un,
'AND',
$allowed_ct,
FALSE,
NULL,
],
[
$allowed_un,
'AND',
$allowed_cf,
FALSE,
NULL,
],
[
$allowed_un,
'AND',
$allowed_un,
FALSE,
NULL,
],
// Allowed (ct) AND forbidden (ct,cf,un).
[
$allowed_ct,
'AND',
$forbidden_ct,
TRUE,
TRUE,
],
[
$allowed_ct,
'AND',
$forbidden_cf,
TRUE,
FALSE,
],
[
$allowed_ct,
'AND',
$forbidden_un,
TRUE,
FALSE,
],
// Allowed (cf) AND forbidden (ct,cf,un).
[
$allowed_cf,
'AND',
$forbidden_ct,
TRUE,
TRUE,
],
[
$allowed_cf,
'AND',
$forbidden_cf,
TRUE,
FALSE,
],
[
$allowed_cf,
'AND',
$forbidden_un,
TRUE,
FALSE,
],
// Allowed (un) AND forbidden (ct,cf,un).
[
$allowed_un,
'AND',
$forbidden_ct,
FALSE,
NULL,
],
[
$allowed_un,
'AND',
$forbidden_cf,
FALSE,
NULL,
],
[
$allowed_un,
'AND',
$forbidden_un,
FALSE,
NULL,
],
// Allowed (ct) AND neutral (ct,cf,un).
[
$allowed_ct,
'AND',
$neutral_ct,
TRUE,
TRUE,
],
[
$allowed_ct,
'AND',
$neutral_cf,
TRUE,
FALSE,
],
[
$allowed_ct,
'AND',
$neutral_un,
TRUE,
FALSE,
],
// Allowed (cf) AND neutral (ct,cf,un).
[
$allowed_cf,
'AND',
$neutral_ct,
TRUE,
FALSE,
],
[
$allowed_cf,
'AND',
$neutral_cf,
TRUE,
FALSE,
],
[
$allowed_cf,
'AND',
$neutral_un,
TRUE,
FALSE,
],
// Allowed (un) AND neutral (ct,cf,un).
[
$allowed_un,
'AND',
$neutral_ct,
FALSE,
NULL,
],
[
$allowed_un,
'AND',
$neutral_cf,
FALSE,
NULL,
],
[
$allowed_un,
'AND',
$neutral_un,
FALSE,
NULL,
],
// Forbidden (ct) AND allowed (ct,cf,un).
[
$forbidden_ct,
'AND',
$allowed_ct,
TRUE,
TRUE,
],
[
$forbidden_ct,
'AND',
$allowed_cf,
TRUE,
TRUE,
],
[
$forbidden_ct,
'AND',
$allowed_un,
TRUE,
TRUE,
],
// Forbidden (cf) AND allowed (ct,cf,un).
[
$forbidden_cf,
'AND',
$allowed_ct,
TRUE,
FALSE,
],
[
$forbidden_cf,
'AND',
$allowed_cf,
TRUE,
FALSE,
],
[
$forbidden_cf,
'AND',
$allowed_un,
TRUE,
FALSE,
],
// Forbidden (un) AND allowed (ct,cf,un).
[
$forbidden_un,
'AND',
$allowed_ct,
FALSE,
NULL,
],
[
$forbidden_un,
'AND',
$allowed_cf,
FALSE,
NULL,
],
[
$forbidden_un,
'AND',
$allowed_un,
FALSE,
NULL,
],
// Forbidden (ct) AND neutral (ct,cf,un).
[
$forbidden_ct,
'AND',
$neutral_ct,
TRUE,
TRUE,
],
[
$forbidden_ct,
'AND',
$neutral_cf,
TRUE,
TRUE,
],
[
$forbidden_ct,
'AND',
$neutral_un,
TRUE,
TRUE,
],
// Forbidden (cf) AND neutral (ct,cf,un).
[
$forbidden_cf,
'AND',
$neutral_ct,
TRUE,
FALSE,
],
[
$forbidden_cf,
'AND',
$neutral_cf,
TRUE,
FALSE,
],
[
$forbidden_cf,
'AND',
$neutral_un,
TRUE,
FALSE,
],
// Forbidden (un) AND neutral (ct,cf,un).
[
$forbidden_un,
'AND',
$neutral_ct,
FALSE,
NULL,
],
[
$forbidden_un,
'AND',
$neutral_cf,
FALSE,
NULL,
],
[
$forbidden_un,
'AND',
$neutral_un,
FALSE,
NULL,
],
// Forbidden (ct) AND forbidden (ct,cf,un).
[
$forbidden_ct,
'AND',
$forbidden_ct,
TRUE,
TRUE,
],
[
$forbidden_ct,
'AND',
$forbidden_cf,
TRUE,
TRUE,
],
[
$forbidden_ct,
'AND',
$forbidden_un,
TRUE,
TRUE,
],
// Forbidden (cf) AND forbidden (ct,cf,un).
[
$forbidden_cf,
'AND',
$forbidden_ct,
TRUE,
FALSE,
],
[
$forbidden_cf,
'AND',
$forbidden_cf,
TRUE,
FALSE,
],
[
$forbidden_cf,
'AND',
$forbidden_un,
TRUE,
FALSE,
],
// Forbidden (un) AND forbidden (ct,cf,un).
[
$forbidden_un,
'AND',
$forbidden_ct,
FALSE,
NULL,
],
[
$forbidden_un,
'AND',
$forbidden_cf,
FALSE,
NULL,
],
[
$forbidden_un,
'AND',
$forbidden_un,
FALSE,
NULL,
],
// Neutral (ct) AND allowed (ct,cf,un).
[
$neutral_ct,
'AND',
$allowed_ct,
TRUE,
TRUE,
],
[
$neutral_ct,
'AND',
$allowed_cf,
TRUE,
TRUE,
],
[
$neutral_ct,
'AND',
$allowed_un,
TRUE,
TRUE,
],
// Neutral (cf) AND allowed (ct,cf,un).
[
$neutral_cf,
'AND',
$allowed_ct,
TRUE,
FALSE,
],
[
$neutral_cf,
'AND',
$allowed_cf,
TRUE,
FALSE,
],
[
$neutral_cf,
'AND',
$allowed_un,
TRUE,
FALSE,
],
// Neutral (un) AND allowed (ct,cf,un).
[
$neutral_un,
'AND',
$allowed_ct,
FALSE,
NULL,
],
[
$neutral_un,
'AND',
$allowed_cf,
FALSE,
NULL,
],
[
$neutral_un,
'AND',
$allowed_un,
FALSE,
NULL,
],
// Neutral (ct) AND neutral (ct,cf,un).
[
$neutral_ct,
'AND',
$neutral_ct,
TRUE,
TRUE,
],
[
$neutral_ct,
'AND',
$neutral_cf,
TRUE,
TRUE,
],
[
$neutral_ct,
'AND',
$neutral_un,
TRUE,
TRUE,
],
// Neutral (cf) AND neutral (ct,cf,un).
[
$neutral_cf,
'AND',
$neutral_ct,
TRUE,
FALSE,
],
[
$neutral_cf,
'AND',
$neutral_cf,
TRUE,
FALSE,
],
[
$neutral_cf,
'AND',
$neutral_un,
TRUE,
FALSE,
],
// Neutral (un) AND neutral (ct,cf,un).
[
$neutral_un,
'AND',
$neutral_ct,
FALSE,
NULL,
],
[
$neutral_un,
'AND',
$neutral_cf,
FALSE,
NULL,
],
[
$neutral_un,
'AND',
$neutral_un,
FALSE,
NULL,
],
// Neutral (ct) AND forbidden (ct,cf,un).
[
$neutral_ct,
'AND',
$forbidden_ct,
TRUE,
TRUE,
],
[
$neutral_ct,
'AND',
$forbidden_cf,
TRUE,
FALSE,
],
[
$neutral_ct,
'AND',
$forbidden_un,
TRUE,
FALSE,
],
// Neutral (cf) AND forbidden (ct,cf,un).
[
$neutral_cf,
'AND',
$forbidden_ct,
TRUE,
TRUE,
],
[
$neutral_cf,
'AND',
$forbidden_cf,
TRUE,
FALSE,
],
[
$neutral_cf,
'AND',
$forbidden_un,
TRUE,
FALSE,
],
// Neutral (un) AND forbidden (ct,cf,un).
[
$neutral_un,
'AND',
$forbidden_ct,
FALSE,
NULL,
],
[
$neutral_un,
'AND',
$forbidden_cf,
FALSE,
NULL,
],
[
$neutral_un,
'AND',
$forbidden_un,
FALSE,
NULL,
],
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.