ConfigTestResourceTestBase.php

Same filename in this branch
  1. 8.9.x core/modules/rest/tests/src/Functional/EntityResource/ConfigTest/ConfigTestResourceTestBase.php
Same filename in other branches
  1. 9 core/modules/config/tests/config_test/tests/src/Functional/Rest/ConfigTestResourceTestBase.php
  2. 10 core/modules/config/tests/config_test/tests/src/Functional/Rest/ConfigTestResourceTestBase.php
  3. 11.x core/modules/config/tests/config_test/tests/src/Functional/Rest/ConfigTestResourceTestBase.php

Namespace

Drupal\Tests\config_test\Functional\Rest

File

core/modules/config/tests/config_test/tests/src/Functional/Rest/ConfigTestResourceTestBase.php

View source
<?php

namespace Drupal\Tests\config_test\Functional\Rest;

use Drupal\config_test\Entity\ConfigTest;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
abstract class ConfigTestResourceTestBase extends EntityResourceTestBase {
    
    /**
     * {@inheritdoc}
     */
    public static $modules = [
        'config_test',
        'config_test_rest',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected static $entityTypeId = 'config_test';
    
    /**
     * @var \Drupal\config_test\ConfigTestInterface
     */
    protected $entity;
    
    /**
     * {@inheritdoc}
     */
    protected function setUpAuthorization($method) {
        $this->grantPermissionsToTestedRole([
            'view config_test',
        ]);
    }
    
    /**
     * {@inheritdoc}
     */
    protected function createEntity() {
        $config_test = ConfigTest::create([
            'id' => 'llama',
            'label' => 'Llama',
        ]);
        $config_test->save();
        return $config_test;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedNormalizedEntity() {
        $normalization = [
            'uuid' => $this->entity
                ->uuid(),
            'id' => 'llama',
            'weight' => 0,
            'langcode' => 'en',
            'status' => TRUE,
            'dependencies' => [],
            'label' => 'Llama',
            'style' => NULL,
            'size' => NULL,
            'size_value' => NULL,
            'protected_property' => NULL,
        ];
        return $normalization;
    }
    
    /**
     * {@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);
        }
        switch ($method) {
            case 'GET':
                return "The 'view config_test' permission is required.";
            default:
                return parent::getExpectedUnauthorizedAccessMessage($method);
        }
    }

}

Classes

Title Deprecated Summary
ConfigTestResourceTestBase

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