summaryrefslogtreecommitdiffstats
path: root/core/modules/media/tests/modules
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/media/tests/modules')
-rw-r--r--core/modules/media/tests/modules/media_test_source/config/schema/media_test_source.schema.yml15
-rw-r--r--core/modules/media/tests/modules/media_test_source/media_test_source.info.yml6
-rw-r--r--core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraint.php25
-rw-r--r--core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraintValidator.php34
-rw-r--r--core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/Test.php88
-rw-r--r--core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestTranslation.php36
-rw-r--r--core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestWithConstraints.php34
-rw-r--r--core/modules/media/tests/modules/media_test_type/config/install/media.type.test.yml11
-rw-r--r--core/modules/media/tests/modules/media_test_type/media_test_type.info.yml8
-rw-r--r--core/modules/media/tests/modules/media_test_views/config/install/views.view.test_media_bulk_form.yml154
-rw-r--r--core/modules/media/tests/modules/media_test_views/media_test_views.info.yml9
11 files changed, 420 insertions, 0 deletions
diff --git a/core/modules/media/tests/modules/media_test_source/config/schema/media_test_source.schema.yml b/core/modules/media/tests/modules/media_test_source/config/schema/media_test_source.schema.yml
new file mode 100644
index 0000000..089aeac
--- /dev/null
+++ b/core/modules/media/tests/modules/media_test_source/config/schema/media_test_source.schema.yml
@@ -0,0 +1,15 @@
+media.source.test:
+ type: media.source.field_aware
+ label: 'Test media source configuration'
+ mapping:
+ test_config_value:
+ type: string
+ label: 'Test config value'
+
+media.source.test_translation:
+ type: media.source.test
+ label: 'Test media source with translations'
+
+media.source.test_constraints:
+ type: media.source.test
+ label: 'Test media source with constraints configuration'
diff --git a/core/modules/media/tests/modules/media_test_source/media_test_source.info.yml b/core/modules/media/tests/modules/media_test_source/media_test_source.info.yml
new file mode 100644
index 0000000..c0a8736
--- /dev/null
+++ b/core/modules/media/tests/modules/media_test_source/media_test_source.info.yml
@@ -0,0 +1,6 @@
+name: 'Test media source'
+type: module
+description: 'Provides test media source to test configuration forms.'
+core: 8.x
+package: Testing
+version: VERSION
diff --git a/core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraint.php b/core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraint.php
new file mode 100644
index 0000000..3d466b3
--- /dev/null
+++ b/core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraint.php
@@ -0,0 +1,25 @@
+<?php
+
+namespace Drupal\media_test_source\Plugin\Validation\Constraint;
+
+use Symfony\Component\Validator\Constraint;
+
+/**
+ * A media test constraint.
+ *
+ * @Constraint(
+ * id = "MediaTestConstraint",
+ * label = @Translation("Media constraint for test purposes.", context = "Validation"),
+ * type = { "entity", "string" }
+ * )
+ */
+class MediaTestConstraint extends Constraint {
+
+ /**
+ * The default violation message.
+ *
+ * @var string
+ */
+ public $message = 'Inappropriate text.';
+
+}
diff --git a/core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraintValidator.php b/core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraintValidator.php
new file mode 100644
index 0000000..1c74443
--- /dev/null
+++ b/core/modules/media/tests/modules/media_test_source/src/Plugin/Validation/Constraint/MediaTestConstraintValidator.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Drupal\media_test_source\Plugin\Validation\Constraint;
+
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Field\FieldItemListInterface;
+use Symfony\Component\Validator\Constraint;
+use Symfony\Component\Validator\ConstraintValidator;
+
+/**
+ * Validates the MediaTestConstraint.
+ */
+class MediaTestConstraintValidator extends ConstraintValidator {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function validate($value, Constraint $constraint) {
+ if ($value instanceof EntityInterface) {
+ $string_to_test = $value->label();
+ }
+ elseif ($value instanceof FieldItemListInterface) {
+ $string_to_test = $value->value;
+ }
+ else {
+ return;
+ }
+
+ if (strpos($string_to_test, 'love Drupal') === FALSE) {
+ $this->context->addViolation($constraint->message);
+ }
+ }
+
+}
diff --git a/core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/Test.php b/core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/Test.php
new file mode 100644
index 0000000..b7baaa5
--- /dev/null
+++ b/core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/Test.php
@@ -0,0 +1,88 @@
+<?php
+
+namespace Drupal\media_test_source\Plugin\media\Source;
+
+use Drupal\Component\Utility\NestedArray;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\media\MediaInterface;
+use Drupal\media\MediaSourceBase;
+
+/**
+ * Provides test media source.
+ *
+ * @MediaSource(
+ * id = "test",
+ * label = @Translation("Test source"),
+ * description = @Translation("Test media source."),
+ * allowed_field_types = {"string"},
+ * )
+ */
+class Test extends MediaSourceBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getMetadataAttributes() {
+ // The metadata attributes are kept in state storage. This allows tests to
+ // change the metadata attributes and makes it easier to test different
+ // variations.
+ $attributes = \Drupal::state()->get('media_source_test_attributes', [
+ 'attribute_1' => ['label' => $this->t('Attribute 1'), 'value' => 'Value 1'],
+ 'attribute_2' => ['label' => $this->t('Attribute 2'), 'value' => 'Value 1'],
+ ]);
+ return array_map(function ($item) {
+ return $item['label'];
+ }, $attributes);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getMetadata(MediaInterface $media, $attribute_name) {
+ $attributes = \Drupal::state()->get('media_source_test_attributes', [
+ 'attribute_1' => ['label' => $this->t('Attribute 1'), 'value' => 'Value 1'],
+ 'attribute_2' => ['label' => $this->t('Attribute 2'), 'value' => 'Value 1'],
+ ]);
+
+ if (in_array($attribute_name, array_keys($attributes))) {
+ return $attributes[$attribute_name]['value'];
+ }
+
+ return parent::getMetadata($media, $attribute_name);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getPluginDefinition() {
+ return NestedArray::mergeDeep(
+ parent::getPluginDefinition(),
+ \Drupal::state()->get('media_source_test_definition', [])
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function defaultConfiguration() {
+ return parent::defaultConfiguration() + [
+ 'test_config_value' => 'This is default value.',
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
+ $form = parent::buildConfigurationForm($form, $form_state);
+
+ $form['test_config_value'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Test config value'),
+ '#default_value' => $this->configuration['test_config_value'],
+ ];
+
+ return $form;
+ }
+
+}
diff --git a/core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestTranslation.php b/core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestTranslation.php
new file mode 100644
index 0000000..947f067
--- /dev/null
+++ b/core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestTranslation.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Drupal\media_test_source\Plugin\media\Source;
+
+use Drupal\media\MediaInterface;
+
+/**
+ * Provides test media source.
+ *
+ * @MediaSource(
+ * id = "test_translation",
+ * label = @Translation("Test source with translations"),
+ * description = @Translation("Test media source with translations."),
+ * allowed_field_types = {"string"},
+ * thumbnail_alt_metadata_attribute = "test_thumbnail_alt",
+ * )
+ */
+class TestTranslation extends Test {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getMetadata(MediaInterface $media, $attribute_name) {
+ if ($attribute_name == 'thumbnail_uri') {
+ return 'public://' . $media->language()->getId() . '.png';
+ }
+
+ if ($attribute_name == 'test_thumbnail_alt') {
+ $langcode = $media->language()->getId();
+ return $this->t('Test Thumbnail @language', ['@language' => $langcode], ['langcode' => $langcode]);
+ }
+
+ return parent::getMetadata($media, $attribute_name);
+ }
+
+}
diff --git a/core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestWithConstraints.php b/core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestWithConstraints.php
new file mode 100644
index 0000000..98039ca
--- /dev/null
+++ b/core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestWithConstraints.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Drupal\media_test_source\Plugin\media\Source;
+
+use Drupal\media\MediaSourceEntityConstraintsInterface;
+use Drupal\media\MediaSourceFieldConstraintsInterface;
+
+/**
+ * Provides generic media type.
+ *
+ * @MediaSource(
+ * id = "test_constraints",
+ * label = @Translation("Test source with constraints"),
+ * description = @Translation("Test media source that provides constraints."),
+ * allowed_field_types = {"string_long"},
+ * )
+ */
+class TestWithConstraints extends Test implements MediaSourceEntityConstraintsInterface, MediaSourceFieldConstraintsInterface {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getEntityConstraints() {
+ return \Drupal::state()->get('media_source_test_entity_constraints', []);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getSourceFieldConstraints() {
+ return \Drupal::state()->get('media_source_test_field_constraints', []);
+ }
+
+}
diff --git a/core/modules/media/tests/modules/media_test_type/config/install/media.type.test.yml b/core/modules/media/tests/modules/media_test_type/config/install/media.type.test.yml
new file mode 100644
index 0000000..96beb46
--- /dev/null
+++ b/core/modules/media/tests/modules/media_test_type/config/install/media.type.test.yml
@@ -0,0 +1,11 @@
+id: test
+label: 'Test type'
+description: 'Test type.'
+source: test
+source_configuration:
+ test_config_value: 'Kakec'
+status: true
+langcode: en
+dependencies: { }
+field_map:
+ metadata_attribute: 'field_attribute_config_test'
diff --git a/core/modules/media/tests/modules/media_test_type/media_test_type.info.yml b/core/modules/media/tests/modules/media_test_type/media_test_type.info.yml
new file mode 100644
index 0000000..7eec4e3
--- /dev/null
+++ b/core/modules/media/tests/modules/media_test_type/media_test_type.info.yml
@@ -0,0 +1,8 @@
+name: 'Media test type'
+type: module
+description: 'Provides test type for a media item.'
+core: 8.x
+package: Testing
+version: VERSION
+dependencies:
+ - media_test_source
diff --git a/core/modules/media/tests/modules/media_test_views/config/install/views.view.test_media_bulk_form.yml b/core/modules/media/tests/modules/media_test_views/config/install/views.view.test_media_bulk_form.yml
new file mode 100644
index 0000000..dd432bb
--- /dev/null
+++ b/core/modules/media/tests/modules/media_test_views/config/install/views.view.test_media_bulk_form.yml
@@ -0,0 +1,154 @@
+langcode: en
+status: true
+dependencies:
+ module:
+ - media
+ - user
+id: test_media_bulk_form
+label: ''
+module: views
+description: ''
+tag: ''
+base_table: media_field_data
+base_field: mid
+core: 8.x
+display:
+ default:
+ display_plugin: default
+ id: default
+ display_title: Master
+ position: 0
+ display_options:
+ style:
+ type: table
+ row:
+ type: fields
+ fields:
+ media_bulk_form:
+ id: media_bulk_form
+ table: media
+ field: media_bulk_form
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: false
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ action_title: 'With selection'
+ include_exclude: exclude
+ selected_actions: { }
+ entity_type: media
+ plugin_id: media_bulk_form
+ name:
+ id: name
+ table: media_field_data
+ field: name
+ entity_type: media
+ entity_field: media
+ hide_empty: false
+ empty_zero: false
+ settings:
+ link_to_entity: false
+ plugin_id: field
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: 'Media name'
+ exclude: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_alter_empty: true
+ click_sort_column: value
+ type: string
+ group_column: value
+ group_columns: { }
+ group_rows: true
+ delta_limit: 0
+ delta_offset: 0
+ delta_reversed: false
+ delta_first_last: false
+ multi_type: separator
+ separator: ', '
+ field_api_classes: false
+ status:
+ id: status
+ table: media_field_data
+ field: status
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: Status
+ exclude: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ click_sort_column: value
+ type: boolean
+ settings:
+ format: custom
+ format_custom_true: Published
+ format_custom_false: Unpublished
+ group_column: value
+ group_columns: { }
+ group_rows: true
+ delta_limit: 0
+ delta_offset: 0
+ delta_reversed: false
+ delta_first_last: false
+ multi_type: separator
+ separator: ', '
+ field_api_classes: false
+ entity_type: media
+ entity_field: status
+ plugin_id: field
+ sorts:
+ mid:
+ id: mid
+ table: media_field_data
+ field: mid
+ relationship: none
+ group_type: group
+ admin_label: ''
+ order: ASC
+ exposed: false
+ expose:
+ label: ''
+ entity_type: media
+ entity_field: mid
+ plugin_id: standard
+ title: 'Entity bulk form test view'
+ header: { }
+ footer: { }
+ empty: { }
+ relationships: { }
+ arguments: { }
+ display_extenders: { }
+ page_1:
+ display_plugin: page
+ id: page_1
+ display_title: Page
+ position: 1
+ display_options:
+ path: test-media-bulk-form
diff --git a/core/modules/media/tests/modules/media_test_views/media_test_views.info.yml b/core/modules/media/tests/modules/media_test_views/media_test_views.info.yml
new file mode 100644
index 0000000..4962319
--- /dev/null
+++ b/core/modules/media/tests/modules/media_test_views/media_test_views.info.yml
@@ -0,0 +1,9 @@
+name: 'Media test views'
+type: module
+description: 'Provides default views for views media tests.'
+package: Testing
+version: VERSION
+core: 8.x
+dependencies:
+ - media
+ - views