You are here

public function MetatagAdminTest::testDefaultProtected in Metatag 8

Test that protected Metatag defaults cannot be deleted.

File

tests/src/Functional/MetatagAdminTest.php, line 424

Class

MetatagAdminTest
Tests the Metatag administration.

Namespace

Drupal\Tests\metatag\Functional

Code

public function testDefaultProtected() {

  // Initiate session with a user who can manage metatags.
  $permissions = [
    'administer site configuration',
    'administer meta tags',
  ];
  $account = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($account);
  $session = $this
    ->assertSession();

  // Add default metatag for Articles.
  $edit = [
    'id' => 'node__article',
  ];
  $this
    ->drupalPostForm('/admin/config/search/metatag/add', $edit, 'Save');

  // Check that protected defaults contains "Revert" link instead of "Delete".
  foreach (MetatagManager::protectedDefaults() as $protected) {
    $session
      ->linkByHrefExists('/admin/config/search/metatag/' . $protected);
    $session
      ->linkByHrefExists('/admin/config/search/metatag/' . $protected . '/revert');
    $session
      ->linkByHrefNotExists('/admin/config/search/metatag/' . $protected . '/delete');
  }

  // Confirm that non protected defaults can be deleted.
  $session
    ->linkByHrefExists('/admin/config/search/metatag/node__article');
  $session
    ->linkByHrefNotExists('/admin/config/search/metatag/node__article/revert');
  $session
    ->linkByHrefExists('/admin/config/search/metatag/node__article/delete');

  // Visit each protected default page to confirm "Delete" button is hidden.
  foreach (MetatagManager::protectedDefaults() as $protected) {
    $this
      ->drupalGet('/admin/config/search/metatag/' . $protected);
    $session
      ->linkNotExists('Delete');
  }

  // Confirm that non protected defaults can be deleted.
  $this
    ->drupalGet('/admin/config/search/metatag/node__article');
  $session
    ->linkExists('Delete');
}