grantPermissionsToTestedRole example

protected static $entityTypeId = 'action';

  /** * @var \Drupal\system\ActionConfigEntityInterface */
  protected $entity;

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    $this->grantPermissionsToTestedRole(['administer actions']);
  }

  /** * {@inheritdoc} */
  protected function createEntity() {
    $action = Action::create([
      'id' => 'user_add_role_action.' . RoleInterface::ANONYMOUS_ID,
      'type' => 'user',
      'label' => t('Add the anonymous role to the selected users'),
      'configuration' => [
        
/** * {@inheritdoc} * * @var \Drupal\shortcut\ShortcutSetInterface */
  protected $entity;

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    $this->grantPermissionsToTestedRole(['administer workflows']);
  }

  /** * {@inheritdoc} */
  protected function createEntity() {
    $workflow = Workflow::create([
      'id' => 'rest_workflow',
      'label' => 'REST Workflow',
      'type' => 'workflow_type_complex_test',
    ]);
    
/** * @var \Drupal\taxonomy\TermInterface */
  protected $entity;

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    switch ($method) {
      case 'GET':
        $this->grantPermissionsToTestedRole(['access content']);
        break;

      case 'POST':
        $this->grantPermissionsToTestedRole(['create terms in camelids']);
        break;

      case 'PATCH':
        // Grant the 'create url aliases' permission to test the case when         // the path field is accessible, see         // \Drupal\Tests\rest\Functional\EntityResource\Node\NodeResourceTestBase         // for a negative test.
/** * {@inheritdoc} * * @var \Drupal\media\MediaTypeInterface */
  protected $entity;

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    $this->grantPermissionsToTestedRole(['administer media types']);
  }

  /** * {@inheritdoc} */
  protected function createEntity() {
    // Create a "Camelids" media type.     $camelids = MediaType::create([
      'name' => 'Camelids',
      'id' => 'camelids',
      'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
      
protected $entity;

  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    $this->grantPermissionsToTestedRole(['administer display modes']);
  }

  /** * {@inheritdoc} */
  protected function createEntity() {
    $entity_form_mode = EntityFormMode::create([
      'id' => 'user.test',
      'label' => 'Test',
      'targetEntityType' => 'user',
    ]);
    
/** * {@inheritdoc} */
  protected static $resourceConfigId = 'entity.node';

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    switch ($method) {
      case 'GET':
        $this->grantPermissionsToTestedRole(['access content']);
        break;

      default:
        throw new \UnexpectedValueException();
    }
  }

  /** * {@inheritdoc} */
  protected function setUp(): void {
    
'sticky' => "The 'administer nodes' permission is required.",
    'path' => "The following permissions are required: 'create url aliases' OR 'administer url aliases'.",
    'revision_uid' => NULL,
  ];

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    switch ($method) {
      case 'GET':
        $this->grantPermissionsToTestedRole(['access content']);
        break;

      case 'POST':
        $this->grantPermissionsToTestedRole(['access content', 'create camelids content']);
        break;

      case 'PATCH':
        // Do not grant the 'create url aliases' permission to test the case         // when the path field is protected/not accessible, see         // \Drupal\Tests\rest\Functional\EntityResource\Term\TermResourceTestBase         // for a positive test.
/** * {@inheritdoc} * * @var \Drupal\tour\TourInterface */
  protected $entity;

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    $this->grantPermissionsToTestedRole(['access tour']);
  }

  /** * {@inheritdoc} */
  protected function createEntity() {
    $tour = Tour::create([
      'id' => 'tour-llama',
      'label' => 'Llama tour',
      'langcode' => 'en',
      'module' => 'tour',
      
/** * @var \Drupal\node\NodeInterface */
  protected $entity;

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    switch ($method) {
      case 'GET':
        $this->grantPermissionsToTestedRole(['access content']);
        break;

      case 'POST':
        $this->grantPermissionsToTestedRole(['access content', 'create camelids content']);
        break;

      case 'PATCH':
        // Do not grant the 'create url aliases' permission to test the case         // when the path field is protected/not accessible, see         // \Drupal\Tests\rest\Functional\EntityResource\Term\TermResourceTestBase         // for a positive test.
/** * {@inheritdoc} * * @var \Drupal\user\RoleInterface */
  protected $entity;

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    $this->grantPermissionsToTestedRole(['administer url aliases']);
  }

  /** * {@inheritdoc} */
  protected function createEntity() {
    $path_alias = PathAlias::create([
      'alias' => '/frontpage1',
      'path' => '/<front>',
      'langcode' => 'en',
    ]);
    
/** * {@inheritdoc} * * @var \Drupal\system\MenuInterface */
  protected $entity;

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    $this->grantPermissionsToTestedRole(['administer menu']);
  }

  /** * {@inheritdoc} */
  protected function createEntity() {
    $menu = Menu::create([
      'id' => 'menu',
      'label' => 'Menu',
      'description' => 'Menu',
    ]);
    
/** * {@inheritdoc} */
  protected static $secondCreatedEntityId = 5;

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    switch ($method) {
      case 'GET':
        $this->grantPermissionsToTestedRole(['access user profiles']);
        break;

      case 'POST':
      case 'PATCH':
      case 'DELETE':
        $this->grantPermissionsToTestedRole(['administer users']);
        break;
    }
  }

  /** * {@inheritdoc} */
protected $entity;

  /** * {@inheritdoc} */
  protected static $labelFieldName = 'subject';

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    $this->grantPermissionsToTestedRole(['access site-wide contact form']);
  }

  /** * {@inheritdoc} */
  protected function createEntity() {
    if (!ContactForm::load('camelids')) {
      // Create a "Camelids" contact form.       ContactForm::create([
        'id' => 'camelids',
        'label' => 'Llama',
        
protected $entity;

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    switch ($method) {
      case 'GET':
      case 'POST':
      case 'PATCH':
      case 'DELETE':
        $this->grantPermissionsToTestedRole(['access shortcuts', 'customize shortcut links']);
        break;
    }
  }

  /** * {@inheritdoc} */
  protected function createEntity() {
    // Create shortcut.     $shortcut = Shortcut::create([
      'shortcut_set' => 'default',
      
protected $entity;

  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUpAuthorization($method) {
    $this->grantPermissionsToTestedRole(['administer languages']);
  }

  /** * {@inheritdoc} */
  protected function createEntity() {
    // Create a "Camelids" node type.     $camelids = NodeType::create([
      'name' => 'Camelids',
      'type' => 'camelids',
    ]);
    
Home | Imprint | This part of the site doesn't use cookies.