getTestLinks example


  protected static $modules = ['link'];

  /** * Tests link validation. */
  public function testExternalLinkValidation() {
    $definition = \Drupal::typedDataManager()
      ->createDataDefinition('field_item:link');
    $link_item = \Drupal::typedDataManager()->create($definition);
    $test_links = $this->getTestLinks();

    foreach ($test_links as $data) {
      [$value$expected_violations] = $data;
      $link_item->setValue($value);
      $violations = $link_item->validate();
      $expected_count = count($expected_violations);
      $this->assertCount($expected_count$violationssprintf('Violation message count error for %s', $value));
      if ($expected_count) {
        $i = 0;
        foreach ($expected_violations as $error_msg) {
          // If the expected message contains a '%' add the current link value.
Home | Imprint | This part of the site doesn't use cookies.