You are here

public function ModalFormTest::testModalOption in Flag 8.4

Tests the modal form option for confirm and field entry link types.

File

tests/src/FunctionalJavascript/ModalFormTest.php, line 88

Class

ModalFormTest
Tests modal form options for action link plugins.

Namespace

Drupal\Tests\flag\FunctionalJavascript

Code

public function testModalOption() {

  // Verify default, non-modal behavior.
  $this
    ->drupalGet($this->node
    ->toUrl());
  $this
    ->clickLink($this->flag
    ->getShortText('flag'));

  // Should be on the confirm form page, since this isn't using a modal.
  $expected = Url::fromRoute('flag.confirm_flag', [
    'flag' => $this->flag
      ->id(),
    'entity_id' => $this->node
      ->id(),
  ]);
  $this
    ->assertSession()
    ->addressEquals($expected
    ->getInternalPath());
  $this
    ->assertSession()
    ->buttonExists(t('Create flagging'))
    ->press();
  $this
    ->assertSession()
    ->addressEquals($this->node
    ->toUrl());

  // Unflag.
  $this
    ->clickLink($this->flag
    ->getShortText('unflag'));
  $expected = Url::fromRoute('flag.confirm_unflag', [
    'flag' => $this->flag
      ->id(),
    'entity_id' => $this->node
      ->id(),
  ]);
  $this
    ->assertSession()
    ->addressEquals($expected
    ->getInternalPath());
  $this
    ->assertSession()
    ->buttonExists(t('Delete flagging'))
    ->press();
  $this
    ->assertSession()
    ->addressEquals($this->node
    ->toUrl());

  // Set the modal option for the 'confirm' link.
  $configuration = $this->flag
    ->getLinkTypePlugin()
    ->getConfiguration();
  $configuration['form_behavior'] = 'modal';
  $this->flag
    ->getLinkTypePlugin()
    ->setConfiguration($configuration);
  $this->flag
    ->save();
  $this
    ->drupalGet($this->node
    ->toUrl());
  $this
    ->clickLink($this->flag
    ->getShortText('flag'));
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Should still be on the node url, as this is using a modal.
  $this
    ->assertSession()
    ->addressEquals($this->node
    ->toUrl()
    ->getInternalPath());

  // Note, there is some odd behavior calling the `press()` method on the
  // button, so after asserting it exists, click via this method.
  $this
    ->assertSession()
    ->buttonExists(t('Create flagging'));
  $this
    ->click('button:contains("Create flagging")');
  $this
    ->assertSession()
    ->addressEquals($this->node
    ->toUrl()
    ->getInternalPath());

  // Unflag.
  $this
    ->clickLink($this->flag
    ->getShortText('unflag'));
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->addressEquals($this->node
    ->toUrl()
    ->getInternalPath());
  $this
    ->assertSession()
    ->buttonExists(t('Delete flagging'));
  $this
    ->click('button:contains("Delete flagging")');
  $this
    ->assertSession()
    ->addressEquals($this->node
    ->toUrl()
    ->getInternalPath());
}