VocabularyTest.php

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

Namespace

Drupal\Tests\jsonapi\Functional

File

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

View source
<?php

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

use Drupal\Core\Url;
use Drupal\taxonomy\Entity\Vocabulary;

/**
 * JSON:API integration test for the "vocabulary" config entity type.
 *
 * @group jsonapi
 * @group #slow
 */
class VocabularyTest extends ConfigEntityResourceTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'taxonomy',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * {@inheritdoc}
     */
    protected static $entityTypeId = 'taxonomy_vocabulary';
    
    /**
     * {@inheritdoc}
     */
    protected static $resourceTypeName = 'taxonomy_vocabulary--taxonomy_vocabulary';
    
    /**
     * {@inheritdoc}
     *
     * @var \Drupal\taxonomy\VocabularyInterface
     */
    protected $entity;
    
    /**
     * {@inheritdoc}
     */
    protected function setUpAuthorization($method) {
        $this->grantPermissionsToTestedRole([
            'administer taxonomy',
        ]);
    }
    
    /**
     * {@inheritdoc}
     */
    protected function createEntity() {
        $vocabulary = Vocabulary::create([
            'name' => 'Llama',
            'vid' => 'llama',
        ]);
        $vocabulary->save();
        return $vocabulary;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedDocument() {
        $self_url = Url::fromUri('base:/jsonapi/taxonomy_vocabulary/taxonomy_vocabulary/' . $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' => 'taxonomy_vocabulary--taxonomy_vocabulary',
                'links' => [
                    'self' => [
                        'href' => $self_url,
                    ],
                ],
                'attributes' => [
                    'langcode' => 'en',
                    'status' => TRUE,
                    'dependencies' => [],
                    'name' => 'Llama',
                    'new_revision' => FALSE,
                    'description' => NULL,
                    'weight' => 0,
                    'drupal_internal__vid' => 'llama',
                ],
            ],
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getPostDocument() {
        // @todo Update in https://www.drupal.org/node/2300677.
        return [];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedUnauthorizedAccessMessage($method) {
        if ($method === 'GET') {
            return "The following permissions are required: 'access taxonomy overview' OR 'administer taxonomy'.";
        }
        return parent::getExpectedUnauthorizedAccessMessage($method);
    }

}

Classes

Title Deprecated Summary
VocabularyTest JSON:API integration test for the "vocabulary" config entity type.

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