You are here

public function LinkcheckerLinkExtractorServiceTest::testExternalUrls in Link checker 8

Test external URLs.

File

tests/src/Kernel/LinkcheckerLinkExtractorServiceTest.php, line 124

Class

LinkcheckerLinkExtractorServiceTest
Test link extractor service.

Namespace

Drupal\Tests\linkchecker\Kernel

Code

public function testExternalUrls() {

  // Disable blacklist URLs.
  $this->linkcheckerSetting
    ->set('check.disable_link_check_for_urls', '');

  // Enable external URLs only.
  $this->linkcheckerSetting
    ->set('check_links_types', LinkCheckerLinkInterface::TYPE_EXTERNAL);
  $this->linkcheckerSetting
    ->save(TRUE);
  $extracted = $this->extractorService
    ->getLinks($this
    ->getTestUrlList());
  $countExpected = count($this
    ->getExternalUrls()) + count($this
    ->getBlacklistedUrls());
  $countExtracted = count($extracted);
  $this
    ->assertEquals($countExpected, $countExtracted, new FormattableMarkup('Expected to extract @count but get @actual links.', [
    '@count' => $countExpected,
    '@actual' => $countExtracted,
  ]));
  foreach ($this
    ->getExternalUrls() + $this
    ->getBlacklistedUrls() as $url) {
    $this
      ->assertTrue(in_array($url, $extracted), new FormattableMarkup('URL @url was not extracted!', [
      '@url' => $url,
    ]));
  }
}