ShortcutSetTest.php

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

Namespace

Drupal\Tests\jsonapi\Functional

File

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

View source
<?php

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

use Drupal\Core\Url;
use Drupal\shortcut\Entity\ShortcutSet;

/**
 * JSON:API integration test for the "ShortcutSet" config entity type.
 *
 * @group jsonapi
 */
class ShortcutSetTest extends ConfigEntityResourceTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'shortcut',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * {@inheritdoc}
     */
    protected static $entityTypeId = 'shortcut_set';
    
    /**
     * {@inheritdoc}
     */
    protected static $resourceTypeName = 'shortcut_set--shortcut_set';
    
    /**
     * {@inheritdoc}
     *
     * @var \Drupal\shortcut\ShortcutSetInterface
     */
    protected $entity;
    
    /**
     * {@inheritdoc}
     */
    protected function setUpAuthorization($method) : void {
        switch ($method) {
            case 'GET':
                $this->grantPermissionsToTestedRole([
                    'access shortcuts',
                ]);
                break;
            case 'POST':
            case 'PATCH':
                $this->grantPermissionsToTestedRole([
                    'access shortcuts',
                    'customize shortcut links',
                ]);
                break;
            case 'DELETE':
                $this->grantPermissionsToTestedRole([
                    'administer shortcuts',
                ]);
                break;
        }
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedUnauthorizedAccessMessage($method) {
        switch ($method) {
            case 'GET':
                return "The 'access shortcuts' permission is required.";
            default:
                return parent::getExpectedUnauthorizedAccessMessage($method);
        }
    }
    
    /**
     * {@inheritdoc}
     */
    protected function createEntity() {
        $set = ShortcutSet::create([
            'id' => 'llama-set',
            'label' => 'Llama Set',
        ]);
        $set->save();
        return $set;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedDocument() : array {
        $self_url = Url::fromUri('base:/jsonapi/shortcut_set/shortcut_set/' . $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' => 'shortcut_set--shortcut_set',
                'links' => [
                    'self' => [
                        'href' => $self_url,
                    ],
                ],
                'attributes' => [
                    'label' => 'Llama Set',
                    'status' => TRUE,
                    'langcode' => 'en',
                    'dependencies' => [],
                    'drupal_internal__id' => 'llama-set',
                ],
            ],
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getPostDocument() : array {
        // @todo Update in https://www.drupal.org/node/2300677.
        return [];
    }

}

Classes

Title Deprecated Summary
ShortcutSetTest JSON:API integration test for the "ShortcutSet" config entity type.

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