View source
<?php
namespace Drupal\Tests\feeds\Kernel;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\Tests\feeds\Traits\FeedCreationTrait;
use Drupal\Tests\feeds\Traits\FeedsCommonTrait;
use Drupal\Tests\feeds\Traits\FeedsReflectionTrait;
abstract class FeedsKernelTestBase extends EntityKernelTestBase {
use FeedCreationTrait;
use FeedsCommonTrait;
use FeedsReflectionTrait;
public static $modules = [
'field',
'node',
'feeds',
'text',
'filter',
'options',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('feeds_feed');
$this
->installEntitySchema('feeds_subscription');
$this
->installSchema('feeds', 'feeds_clean_list');
$this
->installSchema('node', 'node_access');
$this
->setUpNodeType();
}
protected function installTaxonomyModuleWithVocabulary() {
$this
->installModule('taxonomy');
$this
->installConfig([
'filter',
'taxonomy',
]);
$this
->installEntitySchema('taxonomy_term');
$vocabulary = $this->entityTypeManager
->getStorage('taxonomy_vocabulary')
->create([
'vid' => 'tags',
'name' => 'Tags',
]);
$vocabulary
->save();
return $vocabulary;
}
protected function setUpBodyField() {
$this
->installConfig([
'field',
'filter',
'node',
]);
node_add_body_field($this->nodeType);
}
protected function setUpTermReferenceField() {
$vocabulary = $this
->installTaxonomyModuleWithVocabulary();
$this
->createFieldWithStorage('field_tags', [
'type' => 'entity_reference',
'storage' => [
'settings' => [
'target_type' => 'taxonomy_term',
],
],
'field' => [
'settings' => [
'handler' => 'default',
'handler_settings' => [
'target_bundles' => [
$vocabulary
->id() => $vocabulary
->id(),
],
],
],
],
]);
return $vocabulary;
}
protected function setUpFileFields() {
$this
->installModule('file');
$this
->installConfig([
'field',
'node',
'file',
]);
$this
->installEntitySchema('file');
$this
->installSchema('file', [
'file_usage',
]);
$this
->createFieldWithStorage('field_file', [
'type' => 'file',
'bundle' => 'article',
'field' => [
'settings' => [
'file_extensions' => 'txt',
],
],
]);
$this
->installModule('image');
$this
->installConfig([
'image',
]);
$this
->createFieldWithStorage('field_image', [
'type' => 'image',
'bundle' => 'article',
'field' => [
'settings' => [
'file_extensions' => 'svg',
],
],
]);
}
}