You are here

public function OEmbedResourceConstraintValidatorTest::testValidateUrlResolverInvoked in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media/tests/src/Kernel/OEmbedResourceConstraintValidatorTest.php \Drupal\Tests\media\Kernel\OEmbedResourceConstraintValidatorTest::testValidateUrlResolverInvoked()
  2. 10 core/modules/media/tests/src/Kernel/OEmbedResourceConstraintValidatorTest.php \Drupal\Tests\media\Kernel\OEmbedResourceConstraintValidatorTest::testValidateUrlResolverInvoked()

@covers ::validate

File

core/modules/media/tests/src/Kernel/OEmbedResourceConstraintValidatorTest.php, line 69

Class

OEmbedResourceConstraintValidatorTest
@coversDefaultClass \Drupal\media\Plugin\Validation\Constraint\OEmbedResourceConstraintValidator

Namespace

Drupal\Tests\media\Kernel

Code

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);
}