Drupal 8  8.0.2
AccessResultTest Class Reference
Inheritance diagram for AccessResultTest:

Public Member Functions

 testConstruction ()
 
 testAccessAllowed ()
 
 testAccessForbidden ()
 
 testAccessConditionallyAllowed ()
 
 testAccessConditionallyForbidden ()
 
 testAndIf ()
 
 testOrIf ()
 
 testCacheMaxAge ()
 
 testCacheContexts ()
 
 testCacheTags ()
 
 testInheritCacheability ()
 
 andOrCacheabilityPropagationProvider ()
 
 testAndOrCacheabilityPropagation (AccessResultInterface $first, $op, AccessResultInterface $second, $implements_cacheable_dependency_interface, $is_cacheable)
 
 testOrIfCacheabilityMerging ()
 
 testAllowedIfHasPermissions ($permissions, $conjunction, AccessResult $expected_access)
 
 providerTestAllowedIfHasPermissions ()
 
- Public Member Functions inherited from UnitTestCase
 randomMachineName ($length=8)
 
 getConfigFactoryStub (array $configs=array())
 
 getConfigStorageStub (array $configs)
 
 getStringTranslationStub ()
 

Protected Member Functions

 setUp ()
 
 assertDefaultCacheability (AccessResult $access)
 
- Protected Member Functions inherited from UnitTestCase
 setUp ()
 
 getRandomGenerator ()
 
 assertArrayEquals (array $expected, array $actual, $message=NULL)
 
 getBlockMockWithMachineName ($machine_name)
 
 getContainerWithCacheTagsInvalidator (CacheTagsInvalidatorInterface $cache_tags_validator)
 
 getClassResolverStub ()
 

Protected Attributes

 $cacheContextsManager
 
- Protected Attributes inherited from UnitTestCase
 $randomGenerator
 
 $root
 

Detailed Description

Access

Member Function Documentation

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.

References AccessResult\allowed(), AccessResult\forbidden(), and AccessResult\neutral().

Here is the call graph for this function:

providerTestAllowedIfHasPermissions ( )

Provides data for the testAllowedIfHasPermissions() method.

Returns
array

References AccessResult\allowedIf().

Here is the call graph for this function:

setUp ( )
protected

{}

References Drupal\setContainer().

Here is the call graph for this function:

testAccessAllowed ( )

::allowed ::isAllowed ::isForbidden ::isNeutral

References AccessResult\allowed(), AccessResult\isAllowed(), AccessResult\isForbidden(), and AccessResult\isNeutral().

Here is the call graph for this function:

testAccessConditionallyAllowed ( )

::allowedIf ::isAllowed ::isForbidden ::isNeutral

References AccessResult\allowedIf(), AccessResult\isAllowed(), AccessResult\isForbidden(), and AccessResult\isNeutral().

Here is the call graph for this function:

testAccessConditionallyForbidden ( )

::forbiddenIf ::isAllowed ::isForbidden ::isNeutral

References AccessResult\forbiddenIf(), AccessResult\isAllowed(), AccessResult\isForbidden(), and AccessResult\isNeutral().

Here is the call graph for this function:

testAccessForbidden ( )

::forbidden ::isAllowed ::isForbidden ::isNeutral

References AccessResult\forbidden(), AccessResult\isAllowed(), AccessResult\isForbidden(), and AccessResult\isNeutral().

Here is the call graph for this function:

testAllowedIfHasPermissions (   $permissions,
  $conjunction,
AccessResult  $expected_access 
)

Tests allowedIfHasPermissions().

::allowedIfHasPermissions

providerTestAllowedIfHasPermissions

Parameters
string[]$permissions The permissions to check for.
string$conjunctionThe conjunction to use when checking for permission. 'AND' or 'OR'.
\Drupal\Core\Access\AccessResult$expected_accessThe expected access check result.

References AccessResult\allowedIfHasPermissions(), and AccessResult\cachePerPermissions().

Here is the call graph for this function:

testAndIf ( )

::andIf

References AccessResult\allowed(), AccessResult\andIf(), AccessResult\forbidden(), AccessResult\isAllowed(), AccessResult\isForbidden(), AccessResult\isNeutral(), and AccessResult\neutral().

Here is the call graph for this function:

testAndOrCacheabilityPropagation ( AccessResultInterface  $first,
  $op,
AccessResultInterface  $second,
  $implements_cacheable_dependency_interface,
  $is_cacheable 
)

::andIf ::orIf ::inheritCacheability

andOrCacheabilityPropagationProvider

References AccessResultInterface\andIf(), and AccessResultInterface\orIf().

Here is the call graph for this function:

testCacheContexts ( )

::addCacheContexts ::resetCacheContexts ::getCacheContexts ::cachePerPermissions ::cachePerUser ::allowedIfHasPermission

References RefinableCacheableDependencyInterface\addCacheContexts(), AccessResult\allowedIfHasPermission(), AccessResult\getCacheContexts(), AccessResult\getCacheMaxAge(), AccessResult\getCacheTags(), AccessResult\isAllowed(), AccessResult\isForbidden(), AccessResult\isNeutral(), AccessResult\neutral(), Cache\PERMANENT, and AccessResult\resetCacheContexts().

Here is the call graph for this function:

testCacheMaxAge ( )

::setCacheMaxAge ::getCacheMaxAge

References AccessResult\neutral(), and Cache\PERMANENT.

Here is the call graph for this function:

testCacheTags ( )

::addCacheTags ::addCacheableDependency ::getCacheTags ::resetCacheTags

References RefinableCacheableDependencyInterface\addCacheTags(), AccessResult\getCacheContexts(), AccessResult\getCacheMaxAge(), AccessResult\getCacheTags(), AccessResult\isAllowed(), AccessResult\isForbidden(), AccessResult\isNeutral(), AccessResult\neutral(), Cache\PERMANENT, and AccessResult\resetCacheTags().

Here is the call graph for this function:

testConstruction ( )

Tests the construction of an AccessResult object.

::neutral

References AccessResult\isAllowed(), AccessResult\isForbidden(), AccessResult\isNeutral(), and AccessResult\neutral().

Here is the call graph for this function:

testInheritCacheability ( )

::inheritCacheability

References AccessResult\allowed(), AccessResult\forbidden(), AccessResult\getCacheContexts(), AccessResult\getCacheMaxAge(), AccessResult\getCacheTags(), and AccessResult\inheritCacheability().

Here is the call graph for this function:

testOrIf ( )

::orIf

References AccessResult\allowed(), AccessResult\forbidden(), AccessResult\isAllowed(), AccessResult\isForbidden(), AccessResult\isNeutral(), AccessResult\neutral(), and AccessResult\orIf().

Here is the call graph for this function:

testOrIfCacheabilityMerging ( )

::orIf

Tests the special case of ORing non-forbidden access results that are both cacheable but have different cacheability metadata. This is only the case for non-forbidden access results; we still abort the ORing process as soon as a forbidden access result is encountered. This is tested in ::testOrIf().

References AccessResult\allowed(), AccessResult\neutral(), AccessResult\orIf(), and AccessResult\setCacheMaxAge().

Here is the call graph for this function:


The documentation for this class was generated from the following file: