assertEquals(addslashes('Not valid Instagram URL/Embed code.'), addslashes($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 InstagramEmbedCodeConstraintValidator(); $validator->initialize($execution_context); $definition = $this->getMock(ComplexDataDefinitionInterface::class); $definition->method('getPropertyDefinitions')->willReturn([]); $data = new StringLongItem($definition); $data->set('value', $embed_code); $validator->validate($data, $constraint); } /** * Provided test data for testInstagramEmbedCodeConstraint(). */ public function embedCodeProvider() { return [ 'valid URL' => ['https://instagram.com/p/2hi3DVDgsN/', 0], 'valid embed code' => ['

Once upon a time there were 10 mysterious golden tickets.... #drupalcon

A photo posted by DrupalCon (@drupalcon) on

', 0], 'invalid URL' => ['https://instagram.com/ppp/2hi3DVDgsN/', 1], ]; } }