function OEmbedResourceConstraintValidatorTest::testValidateEmptySource

Same name in other branches
  1. 9 core/modules/media/tests/src/Kernel/OEmbedResourceConstraintValidatorTest.php \Drupal\Tests\media\Kernel\OEmbedResourceConstraintValidatorTest::testValidateEmptySource()
  2. 8.9.x core/modules/media/tests/src/Kernel/OEmbedResourceConstraintValidatorTest.php \Drupal\Tests\media\Kernel\OEmbedResourceConstraintValidatorTest::testValidateEmptySource()
  3. 11.x core/modules/media/tests/src/Kernel/OEmbedResourceConstraintValidatorTest.php \Drupal\Tests\media\Kernel\OEmbedResourceConstraintValidatorTest::testValidateEmptySource()

@covers ::validate

File

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

Class

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

Namespace

Drupal\Tests\media\Kernel

Code

public function testValidateEmptySource() : void {
    $media = Media::create([
        'bundle' => $this->createMediaType('oembed:video')
            ->id(),
    ]);
    $constraint = new OEmbedResourceConstraint();
    // The media item has an empty source value, so the constraint validator
    // should add a violation and return early before invoking the URL resolver.
    $context = $this->prophesize(ExecutionContextInterface::class);
    $context->addViolation($constraint->invalidResourceMessage)
        ->shouldBeCalled();
    $url_resolver = $this->prophesize(UrlResolverInterface::class);
    $url_resolver->getProviderByUrl(Argument::any())
        ->shouldNotBeCalled();
    $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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.