View source
<?php
namespace Drupal\Tests\jsonapi_extras\Functional;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\jsonapi\Functional\JsonApiFunctionalTestBase;
use Drupal\user\Entity\Role;
abstract class JsonApiExtrasFunctionalTestBase extends JsonApiFunctionalTestBase {
protected function setUp() {
parent::setUp();
$this
->createEntityReferenceField('taxonomy_term', 'tags', 'vocabs', 'Vocabularies', 'taxonomy_vocabulary', 'default', [
'target_bundles' => [
'tags' => 'taxonomy_vocabulary',
],
'auto_create' => TRUE,
], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
FieldStorageConfig::create([
'field_name' => 'field_timestamp',
'entity_type' => 'node',
'type' => 'timestamp',
'settings' => [],
'cardinality' => 1,
])
->save();
$field_config = FieldConfig::create([
'field_name' => 'field_timestamp',
'label' => 'Timestamp',
'entity_type' => 'node',
'bundle' => 'article',
'required' => FALSE,
'settings' => [],
'description' => '',
]);
$field_config
->save();
$config = \Drupal::configFactory()
->getEditable('jsonapi_extras.settings');
$config
->set('path_prefix', 'api');
$config
->set('include_count', TRUE);
$config
->save(TRUE);
$this
->grantPermissions(Role::load(Role::ANONYMOUS_ID), [
'access jsonapi resource list',
]);
static::overrideResources();
$this
->resetAll();
$role = $this->user
->get('roles')[0]->entity;
$this
->grantPermissions($role, [
'administer nodes',
'administer site configuration',
]);
}
protected function drupalGet($path, array $options = [], array $headers = []) {
if (empty($headers['Accept']) && empty($headers['accept'])) {
$headers['Accept'] = 'application/vnd.api+json';
}
return parent::drupalGet($path, $options, $headers);
}
protected static function overrideResources() {
}
}