You are here

public function RelToAbsTest::testRelToAbsFilterUnitTestCase in Relative Path to Absolute URLs 8

Unit test to check relative to absolute url conversion.

File

src/Tests/RelToAbsTest.php, line 31

Class

RelToAbsTest
Ensure that the rel_to_abs filter provided functions properly.

Namespace

Drupal\rel_to_abs\Tests

Code

public function testRelToAbsFilterUnitTestCase() {
  $language = \Drupal::getContainer()
    ->get('language_manager')
    ->getLanguage(LanguageInterface::LANGCODE_NOT_SPECIFIED);
  $front = \Drupal::url('<front>', array(), array(
    'absolute' => TRUE,
    'language' => $language,
  ));
  $filter = new RelToAbs(array(), 'rel_to_abs', array(
    'provider' => 'rel_to_abs',
  ));
  $markup = '<div><a href="/node/1">link</a><img src="/files/test.jpg"/><span background="/files/test.jpg">test</span><a href="mailto:test@test.test"></a><a href="#anchor"></a></div>';
  $check = '<div><a href="' . $front . '/node/1">link</a><img src="' . $front . '/files/test.jpg"/><span background="' . $front . '/files/test.jpg">test</span><a href="mailto:test@test.test"></a><a href="#anchor"></a></div>';
  $result = $filter
    ->process($markup, NULL);
  $this
    ->assertEqual($check, $result);
}