ModalFormTest.php in Flag 8.4
File
tests/src/FunctionalJavascript/ModalFormTest.php
View source
<?php
namespace Drupal\Tests\flag\FunctionalJavascript;
use Drupal\Core\Url;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\flag\Traits\FlagCreateTrait;
class ModalFormTest extends WebDriverTestBase {
use FlagCreateTrait;
protected $defaultTheme = 'classy';
public static $modules = [
'flag',
'node',
'user',
];
protected $flag;
protected $flagService;
protected $node;
protected $admin;
protected $webUser;
protected function setUp() {
parent::setUp();
$this->flag = $this
->createFlag('node', [], 'confirm');
$this->flagService = $this->container
->get('flag');
$this->admin = $this
->createUser([], NULL, TRUE);
$type = $this
->createContentType();
$this->node = $this
->createNode([
'type' => $type
->id(),
'uid' => $this->admin
->id(),
]);
$this->webUser = $this
->createUser(array_keys($this->flag
->actionPermissions()));
$this
->drupalLogin($this->webUser);
}
public function testModalOption() {
$this
->drupalGet($this->node
->toUrl());
$this
->clickLink($this->flag
->getShortText('flag'));
$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());
$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());
$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();
$this
->assertSession()
->addressEquals($this->node
->toUrl()
->getInternalPath());
$this
->assertSession()
->buttonExists(t('Create flagging'));
$this
->click('button:contains("Create flagging")');
$this
->assertSession()
->addressEquals($this->node
->toUrl()
->getInternalPath());
$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());
}
}