function AccessResultTest::testAndOrCacheabilityPropagation

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testAndOrCacheabilityPropagation()
  2. 10 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testAndOrCacheabilityPropagation()
  3. 11.x core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testAndOrCacheabilityPropagation()

@covers ::andIf @covers ::orIf @covers ::inheritCacheability

@dataProvider andOrCacheabilityPropagationProvider

File

core/tests/Drupal/Tests/Core/Access/AccessResultTest.php, line 857

Class

AccessResultTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Access%21AccessResult.php/class/AccessResult/8.9.x" title="Value object for passing an access result with cacheability metadata." class="local">\Drupal\Core\Access\AccessResult</a> @group Access

Namespace

Drupal\Tests\Core\Access

Code

public function testAndOrCacheabilityPropagation(AccessResultInterface $first, $op, AccessResultInterface $second, $implements_cacheable_dependency_interface, $is_cacheable) {
    if ($op === 'OR') {
        $result = $first->orIf($second);
    }
    elseif ($op === 'AND') {
        $result = $first->andIf($second);
    }
    else {
        throw new \LogicException('Invalid operator specified');
    }
    if ($implements_cacheable_dependency_interface) {
        $this->assertInstanceOf(CacheableDependencyInterface::class, $result);
        if ($result instanceof CacheableDependencyInterface) {
            $this->assertSame($is_cacheable, $result->getCacheMaxAge() !== 0, 'getCacheMaxAge() matches expectations.');
        }
    }
    else {
        $this->assertNotInstanceOf(CacheableDependencyInterface::class, $result);
    }
}

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