You are here

public function LinkcheckerLinkExtractorServiceTest::testBlacklistedUrls in Link checker 8

Test blacklisted URLs.

File

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

Class

LinkcheckerLinkExtractorServiceTest
Test link extractor service.

Namespace

Drupal\Tests\linkchecker\Kernel

Code

public function testBlacklistedUrls() {

  // Enable blacklist URLs.
  $this->linkcheckerSetting
    ->set('check.disable_link_check_for_urls', "example.com\nexample.net\nexample.org");

  // Enable internal links URLs only.
  $this->linkcheckerSetting
    ->set('check_links_types', LinkCheckerLinkInterface::TYPE_ALL);
  $this->linkcheckerSetting
    ->save(TRUE);
  $extracted = $this->extractorService
    ->getLinks($this
    ->getTestUrlList(), $this->baseUrl . '/' . $this->folder1 . '/' . $this->folder2);
  $countExpected = count($this
    ->getTestUrlList()) - count($this
    ->getBlacklistedUrls()) - count($this
    ->getUnsupportedUrls());
  $countExtracted = count($extracted);
  $this
    ->assertEquals($countExpected, $countExtracted, new FormattableMarkup('Expected to extract @count but get @actual links.', [
    '@count' => $countExpected,
    '@actual' => $countExtracted,
  ]));
  foreach ($this
    ->getBlacklistedUrls() as $url) {
    $this
      ->assertNotTrue(in_array($url, $extracted), new FormattableMarkup('Blacklisted URL @url was extracted!', [
      '@url' => $url,
    ]));
  }
}