View source
<?php
namespace Drupal\Tests\jsonapi\Kernel\ResourceType;
use Drupal\jsonapi\ResourceType\ResourceType;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\NodeType;
class ResourceTypeRepositoryTest extends KernelTestBase {
public static $modules = [
'node',
'jsonapi',
'serialization',
'system',
'user',
];
protected $resourceTypeRepository;
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('node');
$this
->installEntitySchema('user');
$this
->installSchema('system', [
'sequences',
]);
$this
->installSchema('node', [
'node_access',
]);
$this
->installSchema('user', [
'users_data',
]);
NodeType::create([
'type' => 'article',
])
->save();
NodeType::create([
'type' => 'page',
])
->save();
$this->resourceTypeRepository = $this->container
->get('jsonapi.resource_type.repository');
}
public function testAll() {
$all = $this->resourceTypeRepository
->all();
$this
->assertNotEmpty($all);
array_walk($all, function (ResourceType $resource_type) {
$this
->assertNotEmpty($resource_type
->getDeserializationTargetClass());
$this
->assertNotEmpty($resource_type
->getEntityTypeId());
$this
->assertNotEmpty($resource_type
->getTypeName());
});
}
public function testGet($entity_type_id, $bundle, $entity_class) {
$resource_type = $this->resourceTypeRepository
->get($entity_type_id, $bundle);
$this
->assertInstanceOf(ResourceType::class, $resource_type);
$this
->assertSame($entity_class, $resource_type
->getDeserializationTargetClass());
$this
->assertSame($entity_type_id, $resource_type
->getEntityTypeId());
$this
->assertSame($bundle, $resource_type
->getBundle());
$this
->assertSame($entity_type_id . '--' . $bundle, $resource_type
->getTypeName());
}
public function getProvider() {
return [
[
'node',
'article',
'Drupal\\node\\Entity\\Node',
],
[
'node_type',
'node_type',
'Drupal\\node\\Entity\\NodeType',
],
[
'menu',
'menu',
'Drupal\\system\\Entity\\Menu',
],
];
}
}