You are here

public function MetatagAsyncWidgetTest::testMetatagAsyncWidget in Metatag Asynchronous Widget 1.0.x

Tests the Metatag Async Widget.

File

tests/src/Functional/MetatagAsyncWidgetTest.php, line 56

Class

MetatagAsyncWidgetTest
Ensures that metatag_async_wdiget works with JavaScript disabled.

Namespace

Drupal\Tests\metatag_async_widget\Functional

Code

public function testMetatagAsyncWidget() {
  $assert = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();

  // Add a Metatag field to the content type.
  $this
    ->drupalGet('admin/structure/types/manage/metatag_node/fields/add-field');
  $assert
    ->fieldExists('new_storage_type')
    ->setValue('metatag');
  $page
    ->pressButton('Save and continue');
  $assert
    ->fieldExists('label')
    ->setValue('Meta tags');
  $assert
    ->fieldExists('field_name')
    ->setValue('meta_tags');
  $page
    ->pressButton('Save and continue');
  $page
    ->pressButton('Save field settings');
  $page
    ->pressButton('Save settings');

  // Set the form display.
  $this
    ->drupalGet('admin/structure/types/manage/metatag_node/form-display');
  $assert
    ->fieldExists('edit-fields-field-meta-tags-type')
    ->setValue('metatag_async_widget_firehose');
  $page
    ->pressButton('Save');
  $assert
    ->pageTextContains('Your settings have been saved.');

  // Create a node.
  $this
    ->drupalGet('node/add/metatag_node');
  $assert
    ->fieldExists('edit-title-0-value')
    ->setValue($this
    ->getRandomGenerator()
    ->sentences('4'));
  $assert
    ->fieldNotExists('edit-field-meta-tags-0-basic-abstract');
  $page
    ->pressButton('Customize meta tags');
  $assert
    ->pageTextContains('Configure the meta tags below.');
  $abstract = $this
    ->getRandomGenerator()
    ->sentences(10);
  $assert
    ->fieldExists('edit-field-meta-tags-0-basic-abstract')
    ->setValue($abstract);
  $page
    ->pressButton('Save');

  // Edit the node and ensure the abstract is saved.
  $page
    ->clickLink('Edit');
  $assert
    ->fieldNotExists('edit-field-meta-tags-0-basic-abstract');
  $page
    ->pressButton('Customize meta tags');
  $assert
    ->fieldValueEquals('edit-field-meta-tags-0-basic-abstract', $abstract);
}