Mercurial > hg > isophonics-drupal-site
diff core/modules/jsonapi/tests/src/Functional/VocabularyTest.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/jsonapi/tests/src/Functional/VocabularyTest.php Thu May 09 15:33:08 2019 +0100 @@ -0,0 +1,110 @@ +<?php + +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 + */ +class VocabularyTest extends ResourceTestBase { + + /** + * {@inheritdoc} + */ + public static $modules = ['taxonomy']; + + /** + * {@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', + 'description' => NULL, + 'weight' => 0, + 'drupal_internal__vid' => 'llama', + ], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getPostDocument() { + // @todo Update in https://www.drupal.org/node/2300677. + } + + /** + * {@inheritdoc} + */ + protected function getExpectedUnauthorizedAccessMessage($method) { + if ($method === 'GET') { + return "The following permissions are required: 'access taxonomy overview' OR 'administer taxonomy'."; + } + return parent::getExpectedUnauthorizedAccessMessage($method); + } + +}