VocabularyResourceTestBase.php

Same filename in this branch
  1. 8.9.x core/modules/rest/tests/src/Functional/EntityResource/Vocabulary/VocabularyResourceTestBase.php
Same filename in other branches
  1. 9 core/modules/taxonomy/tests/src/Functional/Rest/VocabularyResourceTestBase.php
  2. 10 core/modules/taxonomy/tests/src/Functional/Rest/VocabularyResourceTestBase.php
  3. 11.x core/modules/taxonomy/tests/src/Functional/Rest/VocabularyResourceTestBase.php

Namespace

Drupal\Tests\taxonomy\Functional\Rest

File

core/modules/taxonomy/tests/src/Functional/Rest/VocabularyResourceTestBase.php

View source
<?php

namespace Drupal\Tests\taxonomy\Functional\Rest;

use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
abstract class VocabularyResourceTestBase extends EntityResourceTestBase {
    
    /**
     * {@inheritdoc}
     */
    public static $modules = [
        'taxonomy',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected static $entityTypeId = 'taxonomy_vocabulary';
    
    /**
     * @var \Drupal\taxonomy\VocabularyInterface
     */
    protected $entity;
    
    /**
     * {@inheritdoc}
     */
    protected function setUpAuthorization($method) {
        $this->grantPermissionsToTestedRole([
            'administer taxonomy',
        ]);
    }
    
    /**
     * {@inheritdoc}
     */
    protected function createEntity() {
        $vocabulary = Vocabulary::create([
            'name' => 'Llama',
            'vid' => 'llama',
        ]);
        $vocabulary->save();
        return $vocabulary;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedNormalizedEntity() {
        return [
            'uuid' => $this->entity
                ->uuid(),
            'vid' => 'llama',
            'langcode' => 'en',
            'status' => TRUE,
            'dependencies' => [],
            'name' => 'Llama',
            'description' => NULL,
            'weight' => 0,
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getNormalizedPostEntity() {
        // @todo Update in https://www.drupal.org/node/2300677.
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedUnauthorizedAccessMessage($method) {
        if ($this->config('rest.settings')
            ->get('bc_entity_resource_permissions')) {
            return parent::getExpectedUnauthorizedAccessMessage($method);
        }
        if ($method === 'GET') {
            return "The following permissions are required: 'access taxonomy overview' OR 'administer taxonomy'.";
        }
        return parent::getExpectedUnauthorizedAccessMessage($method);
    }

}

Classes

Title Deprecated Summary
VocabularyResourceTestBase

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