NodeTypeResourceTestBase.php

Same filename in other branches
  1. 8.9.x core/modules/node/tests/src/Functional/Rest/NodeTypeResourceTestBase.php
  2. 8.9.x core/modules/rest/tests/src/Functional/EntityResource/NodeType/NodeTypeResourceTestBase.php
  3. 10 core/modules/node/tests/src/Functional/Rest/NodeTypeResourceTestBase.php
  4. 11.x core/modules/node/tests/src/Functional/Rest/NodeTypeResourceTestBase.php

Namespace

Drupal\Tests\node\Functional\Rest

File

core/modules/node/tests/src/Functional/Rest/NodeTypeResourceTestBase.php

View source
<?php

namespace Drupal\Tests\node\Functional\Rest;

use Drupal\node\Entity\NodeType;
use Drupal\Tests\rest\Functional\EntityResource\ConfigEntityResourceTestBase;

/**
 * ResourceTestBase for NodeType entity.
 */
abstract class NodeTypeResourceTestBase extends ConfigEntityResourceTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'node',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected static $entityTypeId = 'node_type';
    
    /**
     * The NodeType entity.
     *
     * @var \Drupal\node\NodeTypeInterface
     */
    protected $entity;
    
    /**
     * {@inheritdoc}
     */
    protected function setUpAuthorization($method) {
        $this->grantPermissionsToTestedRole([
            'administer content types',
            'access content',
        ]);
    }
    
    /**
     * {@inheritdoc}
     */
    protected function createEntity() {
        // Create a "Camelids" node type.
        $camelids = NodeType::create([
            'name' => 'Camelids',
            'type' => 'camelids',
            'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
        ]);
        $camelids->save();
        return $camelids;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedNormalizedEntity() {
        return [
            'dependencies' => [],
            'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
            'display_submitted' => TRUE,
            'help' => NULL,
            'langcode' => 'en',
            'name' => 'Camelids',
            'new_revision' => TRUE,
            'preview_mode' => 1,
            'status' => TRUE,
            'type' => 'camelids',
            'uuid' => $this->entity
                ->uuid(),
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getNormalizedPostEntity() {
        // @todo Update in https://www.drupal.org/node/2300677.
        return [];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedUnauthorizedAccessMessage($method) {
        return "The 'access content' permission is required.";
    }

}

Classes

Title Deprecated Summary
NodeTypeResourceTestBase ResourceTestBase for NodeType entity.

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