Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Sep 8, 2023
1 parent 05cbbb8 commit 587d16a
Show file tree
Hide file tree
Showing 42 changed files with 63 additions and 74 deletions.
8 changes: 8 additions & 0 deletions config/schema/stanford_media.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,18 @@ field.formatter.settings.embeddable_formatter:
max_height:
type: integer
label: 'Maximum height'
loading:
type: mapping
label: 'oEmbed loading settings'
mapping:
attribute:
type: string
label: 'Loading attribute'
allowed_tags:
type: string
label: 'Allowed HTML tags'


media.source.google_form:
type: media.source.field_aware
label: '"Google Form" media source configuration'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: 'Media Duplicate Validation'
type: module
description: 'Media Validation plugins to help prevent duplication of media items'
core_version_requirement: ^9.4 || ^10
version: 9.0.1
core_version_requirement: ^10
version: 10.0.0
package: media
dependencies:
- drupal:media
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ColorMeanTest extends MediaDuplicateValidationTestBase {
/**
* {@inheritdoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$this->plugin = $this->duplicationManager->createInstance('color_mean');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Md5Test extends MediaDuplicateValidationTestBase {
/**
* {@inheritdoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$this->plugin = $this->duplicationManager->createInstance('md5');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract class MediaDuplicateValidationTestBase extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$this->installEntitySchema('media');
$this->installEntitySchema('file');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* @FieldFormatter (
* id = "media_responsive_image_formatter",
* label = @Translation("Media Responsive Image Style"),
* description = @Translation("Apply a responsive image style to image media
* items."), field_types = {
* description = @Translation("Apply a responsive image style to image media items."),
* field_types = {
* "entity_reference"
* }
* )
Expand Down
4 changes: 2 additions & 2 deletions stanford_media.info.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Stanford Media
description: Provides media module configuration and plugins.
core_version_requirement: ^9.4 || ^10
core_version_requirement: ^10
package: media
type: module
version: 9.1.0
version: 10.0.0
dependencies:
- dropzonejs:dropzonejs
- drupal:breakpoint
Expand Down
11 changes: 0 additions & 11 deletions stanford_media.module
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ function stanford_media_field_widget_text_textarea_form_alter(&$element, FormSta
$element['#attached']['library'][] = 'stanford_media/admin';
}

/**
* Implements hook_ckeditor_css_alter().
*/
function stanford_media_ckeditor_css_alter(array &$css, Editor $editor) {
/** @var \Drupal\Core\Extension\ModuleExtensionList $extensions */
$extensions = \Drupal::service('extension.list.module');
// Add styles inside the ckeditor iframe.
$css[] = $extensions->getPath('stanford_media') . '/dist/css/stanford_media.admin.css';
$css[] = $extensions->getPath('stanford_media') . '/dist/css/stanford_media.css';
}

/**
* Implements hook_theme_registry_alter().
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/Form/MediaLibraryEmbeddableFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MediaLibraryEmbeddableFormTest extends StanfordMediaTestBase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$this->installConfig('media_library');

Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/Form/MediaLibraryGoogleFormFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MediaLibraryGoogleFormFormTest extends StanfordMediaTestBase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$this->installConfig('media_library');

Expand Down
4 changes: 2 additions & 2 deletions tests/src/Kernel/Form/StanfordMediaDialogFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class StanfordMediaDialogFormTest extends StanfordMediaTestBase {
'media_library',
'views',
'editor',
'ckeditor',
'ckeditor5',
'filter',
];

Expand All @@ -49,7 +49,7 @@ public function testFormStructure() {
FilterFormat::create(['format' => 'html', 'name' => 'test format'])->save();
$editor = Editor::create([
'format' => 'html',
'editor' => 'ckeditor',
'editor' => 'ckeditor5',
]);
$editor->save();
$media = Media::create(['bundle' => 'file']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class EmbeddableFormatterTest extends KernelTestBase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$this->installEntitySchema('user');
$this->installEntitySchema('media');
Expand Down Expand Up @@ -106,14 +106,12 @@ protected function setUp(): void {
]);
$this->mediaType->save();

$this->mediaType
->set('source_configuration', [
'oembed_field_name' => 'field_media_embeddable_oembed',
'unstructured_field_name' => 'field_media_embeddable_code',
'thumbnails_directory' => 'public://oembed_thumbnails',
'source_field' => 'field_media_embeddable_oembed',
])
->save();
$this->mediaType->set('source_configuration', [
'oembed_field_name' => 'field_media_embeddable_oembed',
'unstructured_field_name' => 'field_media_embeddable_code',
'thumbnails_directory' => 'public://oembed_thumbnails',
'source_field' => 'field_media_embeddable_oembed',
])->save();

// Create the fields we need.
$field_storage = FieldStorageConfig::create([
Expand Down Expand Up @@ -162,15 +160,13 @@ protected function setUp(): void {
];

/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */

$display = EntityViewDisplay::create([
'targetEntityType' => 'media',
'bundle' => 'embeddable',
'mode' => 'default',
'status' => TRUE,
]);
$display
->setComponent('field_media_embeddable_code', $display_options)
$display->setComponent('field_media_embeddable_code', $display_options)
->setComponent('field_media_embeddable_oembed', $display_options)
->removeComponent('thumbnail')
->save();
Expand Down Expand Up @@ -237,7 +233,6 @@ public function getMagicMethodCallback($method, $args) {
* Formatter should not apply to things that aren't media.
*/
public function testNonMediaField() {

EntityTestBundle::create(['id' => 'test'])->save();

$field_storage = FieldStorageConfig::create([
Expand All @@ -257,14 +252,12 @@ public function testNonMediaField() {
$field_config->save();

$this->assertFalse(EmbeddableFormatter::isApplicable($field_config));

}

/**
* Formatter should not apply to things that aren't embeddable.
*/
public function testOtherMediaTypeField() {

$mediaType = MediaType::create([
'id' => 'video',
'label' => 'video',
Expand All @@ -274,7 +267,6 @@ public function testOtherMediaTypeField() {
$source_field = $mediaType->getSource()->createSourceField($mediaType);

$this->assertFalse(EmbeddableFormatter::isApplicable($source_field));

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class GoogleFormFormatterTest extends KernelTestBase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$this->installEntitySchema('user');
$this->installEntitySchema('media');
Expand Down Expand Up @@ -160,7 +160,7 @@ public function testGoogleFormatter() {
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('media');
$display = $view_builder->view($this->media, 'default');
$display = \Drupal::service('renderer')->renderPlain($display);

preg_match('/<iframe.*src="http:\/\/google.com\/forms\/a\/b\/formid\/viewform"/', $display, $matches);
$this->assertCount(1, $matches);
preg_match('/<iframe.*height="750".*/', $display, $matches);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class MediaImageFormatterTest extends KernelTestBase {
'field',
'file',
'media',
'entity_reference',
];

/**
Expand All @@ -48,7 +47,7 @@ class MediaImageFormatterTest extends KernelTestBase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$this->installEntitySchema('user');
$this->installEntitySchema('node');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class MultiMediaFormatterTest extends KernelTestBase {
'field',
'file',
'media',
'entity_reference',
'breakpoint',
'responsive_image',
];
Expand Down Expand Up @@ -79,7 +78,7 @@ class MultiMediaFormatterTest extends KernelTestBase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$this->installEntitySchema('user');
$this->installEntitySchema('node');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class MediaEmbedMarkupFilterTest extends MediaEmbedFilterTestBase {
'system',
'text',
'user',
'entity_reference',
'breakpoint',
'responsive_image',
'responsive_image_test_module',
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/Plugin/media/Source/EmbeddableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class EmbeddableTest extends KernelTestBase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {

parent::setUp();
$this->installEntitySchema('user');
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/Plugin/media/Source/GoogleFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GoogleFormTest extends KernelTestBase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$this->installEntitySchema('user');
$this->installEntitySchema('media');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class EntityUsageLinkTest extends KernelTestBase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('user');
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/StanfordMediaTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class StanfordMediaTestBase extends KernelTestBase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$this->installEntitySchema('file');
$this->installEntitySchema('user');
Expand Down
7 changes: 5 additions & 2 deletions tests/src/Unit/Controller/MediaAddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Routing\CurrentRouteMatch;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Utility\LinkGeneratorInterface;
use Drupal\media\MediaTypeInterface;
Expand Down Expand Up @@ -40,7 +41,7 @@ class MediaAddTest extends UnitTestCase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();

$media_definition = $this->createMock(EntityTypeInterface::class);
Expand Down Expand Up @@ -75,6 +76,8 @@ protected function setUp(): void {

$link_generator = $this->createMock(LinkGeneratorInterface::class);

$current_route_match = $this->createMock(CurrentRouteMatch::class);

$this->container = new ContainerBuilder();
$this->container->set('entity_type.manager', $entity_type_manager);
$this->container->set('entity_type.bundle.info', $bundle_info);
Expand All @@ -84,7 +87,7 @@ protected function setUp(): void {
$this->container->set('url_generator', $url_generator);
$this->container->set('plugin.manager.bundle_suggestion_manager', $bundle_suggestion);
$this->container->set('link_generator', $link_generator);

$this->container->set('current_route_match', $current_route_match);
\Drupal::setContainer($this->container);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/Unit/Form/MediaLibraryEmbeddableFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MediaLibraryEmbeddableFormTest extends UnitTestCase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$container = new ContainerBuilder();
$container->set('string_translation', $this->getStringTranslationStub());
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Unit/Form/MediaLibraryGoogleFormFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MediaLibraryGoogleFormFormTest extends UnitTestCase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$container = new ContainerBuilder();
$container->set('string_translation', $this->getStringTranslationStub());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class BundleSuggestionTestBase extends UnitTestCase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();

$media_source = $this->createMock(MediaSourceInterface::class);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Unit/Plugin/BundleSuggestionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BundleSuggestionManagerTest extends UnitTestCase {
/**
* {@inheritDoc}
*/
protected function setUp(): void {
public function setup(): void {
parent::setUp();
$namespaces = $this->createMock(\Traversable::class);
$cache = $this->getCacheStub();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AirtableValidatorTest extends UnitTestCase {
/**
* {@inheritDoc}
*/
protected function setup(): void {
public function setup(): void {
parent::setUp();
$this->plugin = new AirtableValidator([], '', []);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GoogleIframeValidatorTest extends UnitTestCase {
/**
* {@inheritDoc}
*/
protected function setup(): void {
public function setup(): void {
parent::setUp();
$this->plugin = new GoogleIframeValidator([], '', []);
}
Expand Down
Loading

0 comments on commit 587d16a

Please sign in to comment.