You are here

public function MetatagAdminTest::testAvailableConfigEntities in Metatag 8

Confirm the available entity types show on the add-default page.

File

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

Class

MetatagAdminTest
Tests the Metatag administration.

Namespace

Drupal\Tests\metatag\Functional

Code

public function testAvailableConfigEntities() {

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

  // Load the default-add page.
  $this
    ->drupalGet('admin/config/search/metatag/add');
  $session = $this
    ->assertSession();
  $session
    ->statusCodeEquals(200);

  // Confirm the 'type' field exists.
  $session
    ->fieldExists('id');

  // Compile a list of entities from the list.
  $options = $this
    ->cssSelect('select[name="id"] option');
  $types = [];
  foreach ($options as $option) {
    $types[$option
      ->getAttribute('value')] = $option
      ->getAttribute('value');
  }

  // Check through the values that are in the 'select' list, make sure that
  // unwanted items are not present.
  $this
    ->assertArrayNotHasKey('block_content', $types, 'Custom block entities are not supported.');
  $this
    ->assertArrayNotHasKey('comment', $types, 'Comment entities are not supported.');
  $this
    ->assertArrayNotHasKey('menu_link_content', $types, 'Menu link entities are not supported.');
  $this
    ->assertArrayNotHasKey('shortcut', $types, 'Shortcut entities are not supported.');
  $this
    ->assertArrayHasKey('node__page', $types, 'Nodes are supported.');
  $this
    ->assertArrayHasKey('user__user', $types, 'Users are supported.');
  $this
    ->assertArrayHasKey('entity_test', $types, 'Test entities are supported.');
}