Commit f135eb20 authored by alexpott's avatar alexpott

Issue #2843771 by arshadcn, Wim Leers: EntityResource: Add an admin permission...

Issue #2843771 by arshadcn, Wim Leers: EntityResource: Add an admin permission to RdfMapping entity and provide comprehensive test coverage
parent d75c6196
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\RdfMapping;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\RdfMapping\RdfMappingResourceTestBase;
/**
* @group hal
*/
class RdfMappingHalJsonAnonTest extends RdfMappingResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
}
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\RdfMapping;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\RdfMapping\RdfMappingResourceTestBase;
/**
* @group hal
*/
class RdfMappingHalJsonBasicAuthTest extends RdfMappingResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal', 'basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\RdfMapping;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\RdfMapping\RdfMappingResourceTestBase;
/**
* @group hal
*/
class RdfMappingHalJsonCookieTest extends RdfMappingResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
......@@ -22,6 +22,7 @@
* entity_keys = {
* "id" = "id"
* },
* admin_permission = "administer site configuration",
* config_export = {
* "id",
* "targetEntityType",
......
<?php
namespace Drupal\Tests\rest\Functional\EntityResource\RdfMapping;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group rest
*/
class RdfMappingJsonAnonTest extends RdfMappingResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}
<?php
namespace Drupal\Tests\rest\Functional\EntityResource\RdfMapping;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group rest
*/
class RdfMappingJsonBasicAuthTest extends RdfMappingResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
<?php
namespace Drupal\Tests\rest\Functional\EntityResource\RdfMapping;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group rest
*/
class RdfMappingJsonCookieTest extends RdfMappingResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
<?php
namespace Drupal\Tests\rest\Functional\EntityResource\RdfMapping;
use Drupal\node\Entity\NodeType;
use Drupal\rdf\Entity\RdfMapping;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
abstract class RdfMappingResourceTestBase extends EntityResourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'rdf'];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'rdf_mapping';
/**
* @var \Drupal\rdf\RdfMappingInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
$this->grantPermissionsToTestedRole(['administer site configuration']);
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
// Create a "Camelids" node type.
$camelids = NodeType::create([
'name' => 'Camelids',
'type' => 'camelids',
]);
$camelids->save();
// Create the RDF mapping.
$llama = RdfMapping::create([
'targetEntityType' => 'node',
'bundle' => 'camelids',
]);
$llama->setBundleMapping([
'types' => ['sioc:Item', 'foaf:Document'],
])
->setFieldMapping('title', [
'properties' => ['dc:title'],
])
->setFieldMapping('created', [
'properties' => ['dc:date', 'dc:created'],
'datatype' => 'xsd:dateTime',
'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'],
])
->save();
return $llama;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
return [
'bundle' => 'camelids',
'dependencies' => [
'config' => [
'node.type.camelids',
],
'module' => [
'node',
],
],
'fieldMappings' => [
'title' => [
'properties' => [
'dc:title',
],
],
'created' => [
'properties' => [
'dc:date',
'dc:created',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value',
],
],
],
'id' => 'node.camelids',
'langcode' => 'en',
'status' => TRUE,
'targetEntityType' => 'node',
'types' => [
'sioc:Item',
'foaf:Document',
],
'uuid' => $this->entity->uuid(),
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
// @todo Update in https://www.drupal.org/node/2300677.
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return [
'user.permissions',
];
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment