EntityViewDisplayResourceTestBase.php

Same filename in other branches
  1. 9 core/tests/Drupal/FunctionalTests/Rest/EntityViewDisplayResourceTestBase.php
  2. 8.9.x core/modules/rest/tests/src/Functional/EntityResource/EntityViewDisplay/EntityViewDisplayResourceTestBase.php
  3. 8.9.x core/tests/Drupal/FunctionalTests/Rest/EntityViewDisplayResourceTestBase.php
  4. 11.x core/tests/Drupal/FunctionalTests/Rest/EntityViewDisplayResourceTestBase.php

Namespace

Drupal\FunctionalTests\Rest

File

core/tests/Drupal/FunctionalTests/Rest/EntityViewDisplayResourceTestBase.php

View source
<?php

declare (strict_types=1);
namespace Drupal\FunctionalTests\Rest;

use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\rest\Functional\EntityResource\ConfigEntityResourceTestBase;
abstract class EntityViewDisplayResourceTestBase extends ConfigEntityResourceTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'node',
        'field_ui',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected static $entityTypeId = 'entity_view_display';
    
    /**
     * {@inheritdoc}
     */
    protected static $patchProtectedFieldNames = [];
    
    /**
     * @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface
     */
    protected $entity;
    
    /**
     * {@inheritdoc}
     */
    protected function setUpAuthorization($method) {
        $this->grantPermissionsToTestedRole([
            'administer node display',
        ]);
    }
    
    /**
     * {@inheritdoc}
     */
    protected function createEntity() {
        // Create a "Camelids" node type.
        $camelids = NodeType::create([
            'name' => 'Camelids',
            'type' => 'camelids',
        ]);
        $camelids->save();
        // Create a view display.
        $view_display = EntityViewDisplay::create([
            'targetEntityType' => 'node',
            'bundle' => 'camelids',
            'mode' => 'default',
            'status' => TRUE,
        ]);
        $view_display->save();
        return $view_display;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedNormalizedEntity() {
        return [
            'bundle' => 'camelids',
            'content' => [
                'links' => [
                    'region' => 'content',
                    'weight' => 100,
                    'settings' => [],
                    'third_party_settings' => [],
                ],
            ],
            'dependencies' => [
                'config' => [
                    'node.type.camelids',
                ],
                'module' => [
                    'user',
                ],
            ],
            'hidden' => [],
            'id' => 'node.camelids.default',
            'langcode' => 'en',
            'mode' => 'default',
            'status' => TRUE,
            'targetEntityType' => 'node',
            'uuid' => $this->entity
                ->uuid(),
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getNormalizedPostEntity() {
        // @todo Update in https://www.drupal.org/node/2300677.
        return [];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedCacheContexts() {
        return [
            'user.permissions',
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedUnauthorizedAccessMessage($method) {
        return "The 'administer node display' permission is required.";
    }

}

Classes

Title Deprecated Summary
EntityViewDisplayResourceTestBase

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