resolveConditions example

class ConditionAccessResolverTraitTest extends UnitTestCase {

  /** * Tests the resolveConditions() method. * * @covers ::resolveConditions * * @dataProvider providerTestResolveConditions */
  public function testResolveConditions($conditions$logic$expected) {
    $trait_object = new TestConditionAccessResolverTrait();
    $this->assertEquals($expected$trait_object->resolveConditions($conditions$logic));
  }

  public function providerTestResolveConditions() {
    $data = [];

    $condition_true = $this->createMock('Drupal\Core\Condition\ConditionInterface');
    $condition_true->expects($this->any())
      ->method('execute')
      ->willReturn(TRUE);
    $condition_false = $this->createMock('Drupal\Core\Condition\ConditionInterface');
    $condition_false->expects($this->any())
      
// If any context is missing then we might be missing cacheable         // metadata, and don't know based on what conditions the block is         // accessible or not. Make sure the result cannot be cached.         $access = AccessResult::forbidden()->setCacheMaxAge(0);
      }
      elseif ($missing_value) {
        // The contexts exist but have no value. Deny access without         // disabling caching. For example the node type condition will have a         // missing context on any non-node route like the frontpage.         $access = AccessResult::forbidden();
      }
      elseif ($this->resolveConditions($conditions, 'and') !== FALSE) {
        // Delegate to the plugin.         $block_plugin = $entity->getPlugin();
        try {
          if ($block_plugin instanceof ContextAwarePluginInterface) {
            $contexts = $this->contextRepository->getRuntimeContexts(array_values($block_plugin->getContextMapping()));
            $this->contextHandler->applyContextMapping($block_plugin$contexts);
          }
          $access = $block_plugin->access($account, TRUE);
        }
        catch (MissingValueContextException $e) {
          // The contexts exist but have no value. Deny access without
Home | Imprint | This part of the site doesn't use cookies.