NodeTypeTest.php

Same filename in this branch
  1. 10 core/modules/node/tests/src/Kernel/Plugin/migrate/source/d6/NodeTypeTest.php
  2. 10 core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeTypeTest.php
  3. 10 core/modules/node/tests/src/Functional/NodeTypeTest.php
Same filename in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/NodeTypeTest.php
  2. 9 core/modules/node/tests/src/Kernel/Plugin/migrate/source/d6/NodeTypeTest.php
  3. 9 core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeTypeTest.php
  4. 9 core/modules/node/tests/src/Functional/NodeTypeTest.php
  5. 8.9.x core/modules/jsonapi/tests/src/Functional/NodeTypeTest.php
  6. 8.9.x core/modules/node/tests/src/Kernel/Plugin/migrate/source/d6/NodeTypeTest.php
  7. 8.9.x core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeTypeTest.php
  8. 8.9.x core/modules/node/tests/src/Functional/NodeTypeTest.php
  9. 11.x core/modules/jsonapi/tests/src/Functional/NodeTypeTest.php
  10. 11.x core/modules/node/tests/src/Kernel/Plugin/migrate/source/d6/NodeTypeTest.php
  11. 11.x core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeTypeTest.php
  12. 11.x core/modules/node/tests/src/Functional/NodeTypeTest.php

Namespace

Drupal\Tests\jsonapi\Functional

File

core/modules/jsonapi/tests/src/Functional/NodeTypeTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\jsonapi\Functional;

use Drupal\Core\Url;
use Drupal\node\Entity\NodeType;

/**
 * JSON:API integration test for the "NodeType" config entity type.
 *
 * @group jsonapi
 * @group #slow
 */
class NodeTypeTest extends ConfigEntityResourceTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'node',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * {@inheritdoc}
     */
    protected static $entityTypeId = 'node_type';
    
    /**
     * {@inheritdoc}
     */
    protected static $resourceTypeName = 'node_type--node_type';
    
    /**
     * {@inheritdoc}
     *
     * @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 getExpectedDocument() {
        $self_url = Url::fromUri('base:/jsonapi/node_type/node_type/' . $this->entity
            ->uuid())
            ->setAbsolute()
            ->toString(TRUE)
            ->getGeneratedUrl();
        return [
            'jsonapi' => [
                'meta' => [
                    'links' => [
                        'self' => [
                            'href' => 'http://jsonapi.org/format/1.0/',
                        ],
                    ],
                ],
                'version' => '1.0',
            ],
            'links' => [
                'self' => [
                    'href' => $self_url,
                ],
            ],
            'data' => [
                'id' => $this->entity
                    ->uuid(),
                'type' => 'node_type--node_type',
                'links' => [
                    'self' => [
                        'href' => $self_url,
                    ],
                ],
                'attributes' => [
                    '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,
                    'drupal_internal__type' => 'camelids',
                ],
            ],
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getPostDocument() {
        // @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
NodeTypeTest JSON:API integration test for the "NodeType" config entity type.

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