You are here

public function LinkExternalProtocolsConstraintValidatorTest::providerValidate in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/link/tests/src/Unit/Plugin/Validation/Constraint/LinkExternalProtocolsConstraintValidatorTest.php \Drupal\Tests\link\Unit\Plugin\Validation\Constraint\LinkExternalProtocolsConstraintValidatorTest::providerValidate()

Data provider for ::testValidate.

File

core/modules/link/tests/src/Unit/Plugin/Validation/Constraint/LinkExternalProtocolsConstraintValidatorTest.php, line 47

Class

LinkExternalProtocolsConstraintValidatorTest
@coversDefaultClass \Drupal\link\Plugin\Validation\Constraint\LinkExternalProtocolsConstraintValidator @group Link

Namespace

Drupal\Tests\link\Unit\Plugin\Validation\Constraint

Code

public function providerValidate() {
  $data = [];

  // Test allowed protocols.
  $data[] = [
    'http://www.drupal.org',
    TRUE,
  ];
  $data[] = [
    'https://www.drupal.org',
    TRUE,
  ];

  // cSpell:disable-next-line
  $data[] = [
    'magnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C',
    TRUE,
  ];

  // Invalid protocols.
  $data[] = [
    'ftp://ftp.funet.fi/pub/standards/RFC/rfc959.txt',
    FALSE,
  ];
  foreach ($data as &$single_data) {
    $url = Url::fromUri($single_data[0]);
    $link = $this
      ->createMock('Drupal\\link\\LinkItemInterface');
    $link
      ->expects($this
      ->any())
      ->method('getUrl')
      ->willReturn($url);
    $single_data[0] = $link;
  }
  return $data;
}