当前位置: 首页>>代码示例>>PHP>>正文


PHP AccessResult::cachePerPermissions方法代码示例

本文整理汇总了PHP中Drupal\Core\Access\AccessResult::cachePerPermissions方法的典型用法代码示例。如果您正苦于以下问题:PHP AccessResult::cachePerPermissions方法的具体用法?PHP AccessResult::cachePerPermissions怎么用?PHP AccessResult::cachePerPermissions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Access\AccessResult的用法示例。


在下文中一共展示了AccessResult::cachePerPermissions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAccess

 /**
  * Tests the method for checking access to routes.
  *
  * @param bool $entity_is_editable
  *   Whether the subject entity is editable.
  * @param bool $field_storage_is_accessible
  *   Whether the user has access to the field storage entity.
  * @param \Drupal\Core\Access\AccessResult $expected_result
  *   The expected result of the access call.
  *
  * @dataProvider providerTestAccess
  */
 public function testAccess($entity_is_editable, $field_storage_is_accessible, AccessResult $expected_result)
 {
     $entity = $this->createMockEntity();
     $entity->expects($this->any())->method('access')->willReturn(AccessResult::allowedIf($entity_is_editable)->cachePerPermissions());
     $field_storage = $this->getMock('Drupal\\field\\FieldStorageConfigInterface');
     $field_storage->expects($this->any())->method('access')->willReturn(AccessResult::allowedIf($field_storage_is_accessible));
     $expected_result->cachePerPermissions();
     $field_name = 'valid';
     $entity_with_field = clone $entity;
     $entity_with_field->expects($this->any())->method('get')->with($field_name)->will($this->returnValue($field_storage));
     $entity_with_field->expects($this->once())->method('hasTranslation')->with(LanguageInterface::LANGCODE_NOT_SPECIFIED)->will($this->returnValue(TRUE));
     $account = $this->getMock('Drupal\\Core\\Session\\AccountInterface');
     $access = $this->editAccessCheck->access($entity_with_field, $field_name, LanguageInterface::LANGCODE_NOT_SPECIFIED, $account);
     $this->assertEquals($expected_result, $access);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:27,代码来源:EditEntityFieldAccessCheckTest.php

示例2: testAllowedIfHasPermissions

 /**
  * Tests allowedIfHasPermissions().
  *
  * @covers ::allowedIfHasPermissions
  *
  * @dataProvider providerTestAllowedIfHasPermissions
  *
  * @param string[] $permissions
  *   The permissions to check for.
  * @param string $conjunction
  *   The conjunction to use when checking for permission. 'AND' or 'OR'.
  * @param \Drupal\Core\Access\AccessResult $expected_access
  *   The expected access check result.
  */
 public function testAllowedIfHasPermissions($permissions, $conjunction, AccessResult $expected_access)
 {
     $account = $this->getMock('\\Drupal\\Core\\Session\\AccountInterface');
     $account->expects($this->any())->method('hasPermission')->willReturnMap([['allowed', TRUE], ['denied', FALSE]]);
     if ($permissions) {
         $expected_access->cachePerPermissions();
     }
     $access_result = AccessResult::allowedIfHasPermissions($account, $permissions, $conjunction);
     $this->assertEquals($expected_access, $access_result);
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:24,代码来源:AccessResultTest.php


注:本文中的Drupal\Core\Access\AccessResult::cachePerPermissions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。