LinkCheckerEditFormTest.php in Link checker 8
File
tests/src/Functional/LinkCheckerEditFormTest.php
View source
<?php
namespace Drupal\Tests\linkchecker\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
class LinkCheckerEditFormTest extends BrowserTestBase {
use StringTranslationTrait;
const NODE_TYPE = 'page';
protected $defaultTheme = 'stark';
public static $modules = [
'filter',
'content_translation',
'linkchecker',
'node',
'path',
];
public function setUp() {
parent::setUp();
$node_type = NodeType::create([
'type' => static::NODE_TYPE,
'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();
$this->adminUser = $this
->drupalCreateUser([
'administer linkchecker',
'bypass node access',
'access broken links report',
]);
$this
->drupalLogin($this->adminUser);
}
public function testEditUrlWorks() {
$entity_type_manager = $this->container
->get('entity_type.manager');
$entity = $entity_type_manager
->getStorage('node')
->create([
'type' => self::NODE_TYPE,
'title' => 'test node',
]);
$field_item_list = $entity
->get('body');
$field_item_list
->setValue('<a href="https://example.com">test</a>');
$entity
->save();
$link = $entity_type_manager
->getStorage('linkcheckerlink')
->create([
'entity_id' => [
'target_id' => $entity
->id(),
'target_type' => $entity
->getEntityTypeId(),
],
'entity_field' => $field_item_list
->getFieldDefinition()
->getName(),
'entity_langcode' => $field_item_list
->getLangcode(),
]);
$link
->save();
$this->container
->get('cron')
->run();
$this
->drupalGet($link
->toUrl('edit-form')
->toString());
$this
->assertEqual($this
->getSession()
->getStatusCode(), 200);
}
}