You are here

public function ConstraintsTest::testTweetEmbedCodeConstraint in Media entity Twitter 8

Tests TweetEmbedCode constraint.

@covers \Drupal\media_entity_twitter\Plugin\Validation\Constraint\TweetEmbedCodeConstraintValidator @covers \Drupal\media_entity_twitter\Plugin\Validation\Constraint\TweetEmbedCodeConstraint

@dataProvider embedCodeProvider

File

tests/src/Unit/ConstraintsTest.php, line 47

Class

ConstraintsTest
Tests media_entity_twitter constraints.

Namespace

Drupal\Tests\media_entity_twitter\Unit

Code

public function testTweetEmbedCodeConstraint($embed_code, $expected_violation_count) {

  // Check message in constraint.
  $constraint = new TweetEmbedCodeConstraint();
  $this
    ->assertEquals('Not valid Tweet URL/embed code.', $constraint->message, 'Correct constraint message found.');
  $execution_context = $this
    ->getMockBuilder('\\Drupal\\Core\\TypedData\\Validation\\ExecutionContext')
    ->disableOriginalConstructor()
    ->getMock();
  if ($expected_violation_count) {
    $execution_context
      ->expects($this
      ->exactly($expected_violation_count))
      ->method('addViolation')
      ->with($constraint->message);
  }
  else {
    $execution_context
      ->expects($this
      ->exactly($expected_violation_count))
      ->method('addViolation');
  }
  $validator = new TweetEmbedCodeConstraintValidator();
  $validator
    ->initialize($execution_context);
  $validator
    ->validate($this
    ->getMockFieldItem($embed_code), $constraint);
}