summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/linkit_media_test/config/schema/linkit_media_test.schema.yml7
-rw-r--r--tests/linkit_media_test/config/schema/linkit_test.schema.yml8
-rw-r--r--tests/linkit_media_test/linkit_media_test.info.yml10
-rw-r--r--tests/linkit_media_test/src/Plugin/MediaEntity/Type/TestType.php27
-rw-r--r--tests/src/Kernel/Matchers/FileMatcherTest.php1
-rw-r--r--tests/src/Kernel/SubstitutionPluginTest.php80
6 files changed, 51 insertions, 82 deletions
diff --git a/tests/linkit_media_test/config/schema/linkit_media_test.schema.yml b/tests/linkit_media_test/config/schema/linkit_media_test.schema.yml
deleted file mode 100644
index 2e13885..0000000
--- a/tests/linkit_media_test/config/schema/linkit_media_test.schema.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-media_entity.bundle.type.test_type:
- type: mapping
- label: 'Test type configuration'
- mapping:
- source_field:
- type: string
- label: 'Field with source information'
diff --git a/tests/linkit_media_test/config/schema/linkit_test.schema.yml b/tests/linkit_media_test/config/schema/linkit_test.schema.yml
deleted file mode 100644
index ce29e8f..0000000
--- a/tests/linkit_media_test/config/schema/linkit_test.schema.yml
+++ /dev/null
@@ -1,8 +0,0 @@
-# Schema for the configuration files of the Linkit test module.
-
-# Plugin \Drupal\linkit_test\Plugin\Linkit\Matcher\ConfigurableDummyMatcher
-linkit.matcher.configurable_dummy_matcher:
- type: linkit.matcher
- mapping:
- dummy_setting:
- type: boolean
diff --git a/tests/linkit_media_test/linkit_media_test.info.yml b/tests/linkit_media_test/linkit_media_test.info.yml
deleted file mode 100644
index 5a4b0ca..0000000
--- a/tests/linkit_media_test/linkit_media_test.info.yml
+++ /dev/null
@@ -1,10 +0,0 @@
-name: 'Linkit media test module'
-description: 'Support module for Linkit media testing.'
-package: Testing
-type: module
-core: 8.x
-dependencies:
- - linkit:linkit
- - drupal:field
- - drupal:text
- - media_entity:media_entity
diff --git a/tests/linkit_media_test/src/Plugin/MediaEntity/Type/TestType.php b/tests/linkit_media_test/src/Plugin/MediaEntity/Type/TestType.php
deleted file mode 100644
index a14b5cb..0000000
--- a/tests/linkit_media_test/src/Plugin/MediaEntity/Type/TestType.php
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-
-namespace Drupal\linkit_media_test\Plugin\MediaEntity\Type;
-
-use Drupal\media_entity\Plugin\MediaEntity\Type\Generic;
-
-/**
- * Provides generic media type.
- *
- * @MediaType(
- * id = "test_type",
- * label = @Translation("Test type"),
- * description = @Translation("Test media type.")
- * )
- */
-class TestType extends Generic {
-
- /**
- * {@inheritdoc}
- */
- public function defaultConfiguration() {
- return [
- 'source_field' => 'field_media_file',
- ];
- }
-
-}
diff --git a/tests/src/Kernel/Matchers/FileMatcherTest.php b/tests/src/Kernel/Matchers/FileMatcherTest.php
index 84f1c85..4999aae 100644
--- a/tests/src/Kernel/Matchers/FileMatcherTest.php
+++ b/tests/src/Kernel/Matchers/FileMatcherTest.php
@@ -4,7 +4,6 @@ namespace Drupal\Tests\linkit\Kernel\Matchers;
use Drupal\file\Entity\File;
use Drupal\Tests\linkit\Kernel\LinkitKernelTestBase;
-use Drupal\user\Entity\User;
/**
* Tests file matcher.
diff --git a/tests/src/Kernel/SubstitutionPluginTest.php b/tests/src/Kernel/SubstitutionPluginTest.php
index 50da921..18f7894 100644
--- a/tests/src/Kernel/SubstitutionPluginTest.php
+++ b/tests/src/Kernel/SubstitutionPluginTest.php
@@ -3,14 +3,13 @@
namespace Drupal\Tests\linkit\Kernel;
use Drupal\entity_test\Entity\EntityTest;
-use Drupal\field\Entity\FieldConfig;
-use Drupal\field\Entity\FieldStorageConfig;
use Drupal\file\Entity\File;
use Drupal\linkit\Plugin\Linkit\Substitution\Canonical as CanonicalSubstitutionPlugin;
use Drupal\linkit\Plugin\Linkit\Substitution\File as FileSubstitutionPlugin;
use Drupal\linkit\Plugin\Linkit\Substitution\Media as MediaSubstitutionPlugin;
-// use Drupal\media_entity\Entity\Media;
-// use Drupal\media_entity\Entity\MediaBundle;
+use Drupal\media\Entity\Media;
+use Drupal\media\Entity\MediaType;
+use Drupal\Core\DependencyInjection\ContainerBuilder;
/**
* Tests the substitution plugins.
@@ -43,10 +42,9 @@ class SubstitutionPluginTest extends LinkitKernelTestBase {
public static $modules = [
'file',
'entity_test',
- // 'media_entity',
+ 'media',
'image',
'field',
- // 'linkit_media_test',
];
/**
@@ -59,11 +57,43 @@ class SubstitutionPluginTest extends LinkitKernelTestBase {
$this->installEntitySchema('file');
$this->installEntitySchema('entity_test');
- // $this->installEntitySchema('media');
- // $this->installEntitySchema('media_bundle');
+ $this->installEntitySchema('media');
+ $this->installEntitySchema('media_type');
$this->installEntitySchema('field_storage_config');
$this->installEntitySchema('field_config');
$this->installSchema('file', ['file_usage']);
+
+ unset($GLOBALS['config']['system.file']);
+ \Drupal::configFactory()->getEditable('system.file')->set('default_scheme', 'public')->save();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function register(ContainerBuilder $container) {
+ parent::register($container);
+
+ $container->register('stream_wrapper.public', 'Drupal\Core\StreamWrapper\PublicStream')
+ ->addTag('stream_wrapper', ['scheme' => 'public']);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUpFilesystem() {
+ $public_file_directory = $this->siteDirectory . '/files';
+
+ require_once 'core/includes/file.inc';
+
+ mkdir($this->siteDirectory, 0775);
+ mkdir($this->siteDirectory . '/files', 0775);
+ mkdir($this->siteDirectory . '/files/config/' . CONFIG_SYNC_DIRECTORY, 0775, TRUE);
+
+ $this->setSetting('file_public_path', $public_file_directory);
+
+ $GLOBALS['config_directories'] = [
+ CONFIG_SYNC_DIRECTORY => $this->siteDirectory . '/files/config/sync',
+ ];
}
/**
@@ -107,30 +137,22 @@ class SubstitutionPluginTest extends LinkitKernelTestBase {
/**
* Test the media substitution.
*/
- /*
public function testMediaSubstitution() {
// Set up media bundle and fields.
- MediaBundle::create([
+ $media_type = MediaType::create([
'label' => 'test',
'id' => 'test',
- 'description' => 'test bundle.',
- 'type' => 'test_type',
- ])->save();
- FieldStorageConfig::create([
- 'field_name' => 'field_media_file',
- 'entity_type' => 'media',
- 'type' => 'file',
- 'settings' => [],
- ])->save();
- FieldConfig::create([
- 'entity_type' => 'media',
- 'bundle' => 'test',
- 'field_name' => 'field_media_file',
- 'label' => 'Media field',
- 'settings' => [
- 'file_extensions' => 'txt',
- ],
+ 'description' => 'Test type.',
+ 'source' => 'file',
+ ]);
+ $media_type->save();
+ $source_field = $media_type->getSource()->createSourceField($media_type);
+ $source_field->getFieldStorageDefinition()->save();
+ $source_field->save();
+ $media_type->set('source_configuration', [
+ 'source_field' => $source_field->getName(),
])->save();
+
$file = File::create([
'uid' => 1,
'filename' => 'druplicon.txt',
@@ -139,9 +161,10 @@ class SubstitutionPluginTest extends LinkitKernelTestBase {
'status' => FILE_STATUS_PERMANENT,
]);
$file->save();
+
$media = Media::create([
'bundle' => 'test',
- 'field_media_file' => ['target_id' => $file->id()],
+ $source_field->getName() => ['target_id' => $file->id()],
]);
$media->save();
@@ -154,6 +177,5 @@ class SubstitutionPluginTest extends LinkitKernelTestBase {
$entity_type = $this->entityTypeManager->getDefinition('file');
$this->assertFalse(MediaSubstitutionPlugin::isApplicable($entity_type), 'The entity type File is not applicable the media substitution.');
}
- */
}