update drupal

This commit is contained in:
Tessier
2020-10-15 11:59:37 +02:00
parent ebb5db14b5
commit d8b9162932
558 changed files with 5954 additions and 4475 deletions
@@ -84,9 +84,9 @@ class EditorMediaDialogTest extends KernelTestBase {
]);
$form_state->setRequestMethod('POST');
EditorMediaDialog::create($this->container)
$form = EditorMediaDialog::create($this->container)
->buildForm([], $form_state, $editor->reveal());
$this->pass('Form was built without errors.');
$this->assertNotNull($form, 'Form should have been built without errors.');
}
}
@@ -4,6 +4,8 @@ namespace Drupal\Tests\media\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\media\Entity\Media;
use Drupal\media\OEmbed\Provider;
use Drupal\media\OEmbed\ResourceFetcher;
use Drupal\media\OEmbed\UrlResolverInterface;
use Drupal\media\Plugin\Validation\Constraint\OEmbedResourceConstraint;
use Drupal\media\Plugin\Validation\Constraint\OEmbedResourceConstraintValidator;
@@ -37,7 +39,7 @@ class OEmbedResourceConstraintValidatorTest extends KernelTestBase {
/**
* @covers ::validate
*/
public function testValidate() {
public function testValidateEmptySource() {
$media = Media::create([
'bundle' => $this->createMediaType('oembed:video')->id(),
]);
@@ -52,7 +54,55 @@ class OEmbedResourceConstraintValidatorTest extends KernelTestBase {
$url_resolver = $this->prophesize(UrlResolverInterface::class);
$url_resolver->getProviderByUrl(Argument::any())->shouldNotBeCalled();
$value = new class ($media) {
$validator = new OEmbedResourceConstraintValidator(
$url_resolver->reveal(),
$this->container->get('media.oembed.resource_fetcher'),
$this->container->get('logger.factory')
);
$validator->initialize($context->reveal());
$validator->validate($this->getValue($media), $constraint);
}
/**
* @covers ::validate
*/
public function testValidateUrlResolverInvoked() {
$media = Media::create([
'bundle' => $this->createMediaType('oembed:video')->id(),
'field_media_oembed_video' => 'source value',
]);
$constraint = new OEmbedResourceConstraint();
$context = $this->prophesize(ExecutionContextInterface::class);
$provider = $this->prophesize(Provider::class);
$provider->getName()->willReturn('YouTube');
$url_resolver = $this->prophesize(UrlResolverInterface::class);
$url_resolver->getProviderByUrl(Argument::any())->willReturn($provider->reveal());
$url_resolver->getResourceUrl(Argument::any())->shouldBeCalledOnce();
$validator = new OEmbedResourceConstraintValidator(
$url_resolver->reveal(),
$this->prophesize(ResourceFetcher::class)->reveal(),
$this->container->get('logger.factory')
);
$validator->initialize($context->reveal());
$validator->validate($this->getValue($media), $constraint);
}
/**
* Wraps a media entity in an anonymous class to mock a field value.
*
* @param \Drupal\media\Entity\Media $media
* The media object.
*
* @return object
* The mock field value to validate.
*/
protected function getValue(Media $media) {
return new class ($media) {
public function __construct($entity) {
$this->entity = $entity;
@@ -63,14 +113,6 @@ class OEmbedResourceConstraintValidatorTest extends KernelTestBase {
}
};
$validator = new OEmbedResourceConstraintValidator(
$url_resolver->reveal(),
$this->container->get('media.oembed.resource_fetcher'),
$this->container->get('logger.factory')
);
$validator->initialize($context->reveal());
$validator->validate($value, $constraint);
}
}
@@ -2,20 +2,23 @@
namespace Drupal\Tests\media\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Url;
use Drupal\media\Entity\Media;
use Drupal\media\OEmbed\Resource;
use Drupal\media\OEmbed\ResourceFetcherInterface;
use Drupal\media\OEmbed\UrlResolverInterface;
use Drupal\media\Plugin\media\Source\OEmbed;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\media\Plugin\media\Source\OEmbed
*
* @group media
*/
class OEmbedSourceTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['media'];
class OEmbedSourceTest extends MediaKernelTestBase {
/**
* @covers ::getMetadata
@@ -34,4 +37,49 @@ class OEmbedSourceTest extends KernelTestBase {
$this->assertNull($plugin->getMetadata($media->reveal(), 'type'));
}
/**
* @covers ::getLocalThumbnailUri
*/
public function testLocalThumbnailUriQueryStringIsIgnored() {
// There's no need to resolve the resource URL in this test; we just need
// to fetch the resource.
$this->container->set(
'media.oembed.url_resolver',
$this->prophesize(UrlResolverInterface::class)->reveal()
);
$thumbnail_url = Url::fromUri('internal:/core/misc/druplicon.png?foo=bar');
// Create a mocked resource whose thumbnail URL contains a query string.
$resource = $this->prophesize(Resource::class);
$resource->getTitle()->willReturn('Test resource');
$resource->getThumbnailUrl()->willReturn($thumbnail_url);
// The source plugin will try to fetch the remote thumbnail, so mock the
// HTTP client to ensure that request returns an empty "OK" response.
$http_client = $this->prophesize(Client::class);
$http_client->get(Argument::type('string'))->willReturn(new Response());
$this->container->set('http_client', $http_client->reveal());
// Mock the resource fetcher so that it will return our mocked resource.
$resource_fetcher = $this->prophesize(ResourceFetcherInterface::class);
$resource_fetcher->fetchResource(NULL)->willReturn($resource->reveal());
$this->container->set('media.oembed.resource_fetcher', $resource_fetcher->reveal());
$media_type = $this->createMediaType('oembed:video');
$source = $media_type->getSource();
$media = Media::create([
'bundle' => $media_type->id(),
$source->getSourceFieldDefinition($media_type)->getName() => $this->randomString(),
]);
$media->save();
// Get the local thumbnail URI and ensure that it does not contain any
// query string.
$local_thumbnail_uri = $media_type->getSource()->getMetadata($media, 'thumbnail_uri');
$expected_uri = 'public://oembed_thumbnails/' . Crypt::hashBase64('/core/misc/druplicon.png') . '.png';
$this->assertSame($expected_uri, $local_thumbnail_uri);
}
}