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


PHP Role::label方法代码示例

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


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

示例1: testConditions

 /**
  * Test the user_role condition.
  */
 public function testConditions()
 {
     // Grab the user role condition and configure it to check against
     // authenticated user roles.
     /** @var $condition \Drupal\Core\Condition\ConditionInterface */
     $condition = $this->manager->createInstance('user_role')->setConfig('roles', array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID))->setContextValue('user', $this->anonymous);
     $this->assertFalse($condition->execute(), 'Anonymous users fail role checks for authenticated.');
     // Check for the proper summary.
     // Summaries require an extra space due to negate handling in summary().
     $this->assertEqual($condition->summary(), 'The user is a member of Authenticated user');
     // Set the user role to anonymous.
     $condition->setConfig('roles', array(DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID));
     $this->assertTrue($condition->execute(), 'Anonymous users pass role checks for anonymous.');
     // Check for the proper summary.
     $this->assertEqual($condition->summary(), 'The user is a member of Anonymous user');
     // Set the user role to check anonymous or authenticated.
     $condition->setConfig('roles', array(DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID));
     $this->assertTrue($condition->execute(), 'Anonymous users pass role checks for anonymous or authenticated.');
     // Check for the proper summary.
     $this->assertEqual($condition->summary(), 'The user is a member of Anonymous user, Authenticated user');
     // Set the context to the authenticated user and check that they also pass
     // against anonymous or authenticated roles.
     $condition->setContextValue('user', $this->authenticated);
     $this->assertTrue($condition->execute(), 'Authenticated users pass role checks for anonymous or authenticated.');
     // Set the role to just authenticated and recheck.
     $condition->setConfig('roles', array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID));
     $this->assertTrue($condition->execute(), 'Authenticated users pass role checks for authenticated.');
     // Test Constructor injection.
     $condition = $this->manager->createInstance('user_role', array('roles' => array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID), 'context' => array('user' => $this->authenticated)));
     $this->assertTrue($condition->execute(), 'Constructor injection of context and configuration working as anticipated.');
     // Check the negated summary.
     $condition->setConfig('negate', TRUE);
     $this->assertEqual($condition->summary(), 'The user is not a member of Authenticated user');
     // Check the complex negated summary.
     $condition->setConfig('roles', array(DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID));
     $this->assertEqual($condition->summary(), 'The user is not a member of Anonymous user, Authenticated user');
     // Check a custom role.
     $condition->setConfig('roles', array($this->role->id() => $this->role->id()));
     $condition->setConfig('negate', FALSE);
     $this->assertTrue($condition->execute(), 'Authenticated user is a member of the custom role.');
     $this->assertEqual($condition->summary(), String::format('The user is a member of @roles', array('@roles' => $this->role->label())));
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:45,代码来源:UserRoleConditionTest.php


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