You are here

protected function LinkCheckerInterfaceTest::setUp in Link checker 8

Overrides BrowserTestBase::setUp

File

tests/src/Functional/LinkCheckerInterfaceTest.php, line 46

Class

LinkCheckerInterfaceTest
Test case for interface tests.

Namespace

Drupal\Tests\linkchecker\Functional

Code

protected function setUp() {
  parent::setUp();
  $full_html_format = FilterFormat::create([
    'format' => 'full_html',
    'name' => 'Full HTML',
  ]);
  $full_html_format
    ->save();

  // Create Basic page and Article node types.
  $node_type = NodeType::create([
    'type' => 'page',
    'name' => 'Basic page',
    'format' => 'full_html',
  ]);
  $node_type
    ->save();
  $node_body_field = node_add_body_field($node_type);
  $node_body_field
    ->setThirdPartySetting('linkchecker', 'scan', TRUE);
  $node_body_field
    ->setThirdPartySetting('linkchecker', 'extractor', 'html_link_extractor');
  $node_body_field
    ->save();
  $block_type = BlockContentType::create([
    'id' => 'block',
    'label' => 'Basic block',
  ]);
  $block_type
    ->save();
  $block_body_field = block_content_add_body_field($block_type
    ->id());
  $block_body_field
    ->setThirdPartySetting('linkchecker', 'scan', TRUE);
  $block_body_field
    ->setThirdPartySetting('linkchecker', 'extractor', 'html_link_extractor');
  $block_body_field
    ->save();

  // Configure basic settings.
  $this
    ->config('linkchecker.settings')
    ->set('default_url_scheme', 'http://')
    ->save();
  $this
    ->config('linkchecker.settings')
    ->set('base_path', 'example.org/')
    ->save();
  $this
    ->config('linkchecker.settings')
    ->set('check.disable_link_check_for_urls', '')
    ->save();
  $this
    ->config('linkchecker.settings')
    ->set('check_links_types', LinkCheckerLinkInterface::TYPE_ALL)
    ->save();

  // Core enables the URL filter for "Full HTML" by default.
  // -> Blacklist / Disable URL filter for testing.
  $this
    ->config('linkchecker.settings')
    ->set('extract.filter_blacklist', [
    'filter_url' => 'filter_url',
  ])
    ->save();

  // Extract from all link checker supported HTML tags.
  $this
    ->config('linkchecker.settings')
    ->set('extract.from_a', 1)
    ->save();
  $this
    ->config('linkchecker.settings')
    ->set('extract.from_audio', 1)
    ->save();
  $this
    ->config('linkchecker.settings')
    ->set('extract.from_embed', 1)
    ->save();
  $this
    ->config('linkchecker.settings')
    ->set('extract.from_iframe', 1)
    ->save();
  $this
    ->config('linkchecker.settings')
    ->set('extract.from_img', 1)
    ->save();
  $this
    ->config('linkchecker.settings')
    ->set('extract.from_object', 1)
    ->save();
  $this
    ->config('linkchecker.settings')
    ->set('extract.from_video', 1)
    ->save();
  $permissions = [
    // Block permissions.
    'administer blocks',
    // Comment permissions.
    'administer comments',
    'access comments',
    'post comments',
    'skip comment approval',
    'edit own comments',
    // Node permissions.
    'create page content',
    'edit own page content',
    // Path aliase permissions.
    'administer url aliases',
    'create url aliases',
    // Content filter permissions.
    $full_html_format
      ->getPermissionName(),
  ];

  // User to set up linkchecker.
  $this->admin_user = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($this->admin_user);
}