You are here

public function LinkcheckerLinkExtractorServiceTest::testRelativeUrls in Link checker 8

Test relative URLs.

File

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

Class

LinkcheckerLinkExtractorServiceTest
Test link extractor service.

Namespace

Drupal\Tests\linkchecker\Kernel

Code

public function testRelativeUrls() {

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

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