You are here

public function LinkCheckerEditFormTest::testEditUrlWorks in Link checker 8

Test that we can go to individual edit URls of entities.

See also

https://www.drupal.org/project/linkchecker/issues/3118940

File

tests/src/Functional/LinkCheckerEditFormTest.php, line 67

Class

LinkCheckerEditFormTest
Test Link checker module edit form.

Namespace

Drupal\Tests\linkchecker\Functional

Code

public function testEditUrlWorks() {

  /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
  $entity_type_manager = $this->container
    ->get('entity_type.manager');

  /** @var \Drupal\node\NodeInterface $entity */
  $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();

  /** @var \Drupal\linkchecker\Entity\LinkCheckerLink $link */
  $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();

  // Run cron.
  $this->container
    ->get('cron')
    ->run();

  // Now visit edit form for the linkchecker entity.
  $this
    ->drupalGet($link
    ->toUrl('edit-form')
    ->toString());
  $this
    ->assertEqual($this
    ->getSession()
    ->getStatusCode(), 200);
}