public function LinkCheckerInterfaceTest::testLinkCheckerCreateBlockWithBrokenLinks in Link checker 8
Test block with link.
File
- tests/
src/ Functional/ LinkCheckerInterfaceTest.php, line 169
Class
- LinkCheckerInterfaceTest
- Test case for interface tests.
Namespace
Drupal\Tests\linkchecker\FunctionalCode
public function testLinkCheckerCreateBlockWithBrokenLinks() {
// Confirm that the add block link appears on block overview pages.
$this
->drupalGet(Url::fromRoute('entity.block_content.collection')
->toString());
$url1 = 'http://example.com/block/broken/link';
$body = 'Lorem ipsum dolor sit amet <a href="' . $url1 . '">broken link</a> sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat';
// Add a new custom block by filling out the input form on the
// admin/structure/block/add page.
$random = new Random();
$custom_block = [
'info[0][value]' => $random
->name(8),
'body[0][value]' => $body,
];
$this
->drupalPostForm(Url::fromRoute('block_content.add_page')
->toString(), $custom_block, 'Save');
// Confirm that the custom block has been created, and then query the
// created bid.
$this
->assertText($this
->t('@type @title has been created.', [
'@type' => 'Basic block',
'@title' => $custom_block['info[0][value]'],
]), 'Custom block successfully created.');
// Check that the block exists in the database.
$blocks = \Drupal::entityQuery('block_content')
->condition('info', $custom_block['info[0][value]'])
->execute();
$block = BlockContent::load(reset($blocks));
$this
->assertNotEmpty($block);
// Verify if the content link is extracted properly.
$link = $this
->getLinkCheckerLinkByUrl($url1);
if ($link) {
$this
->assertIdentical($link
->get('url')->value, $url1, new FormattableMarkup('URL %url found.', [
'%url' => $url1,
]));
}
else {
$this
->fail(new FormattableMarkup('URL %url not found.', [
'%url' => $url1,
]));
}
}