View source
<?php
namespace Drupal\Tests\purge_ui\Functional\Form;
use Drupal\purge_ui\Form\QueuerAddForm;
class QueuerAddFormTest extends AjaxFormTestBase {
public static $modules = [
'purge_ui',
'purge_queuer_test',
];
protected $formClass = QueuerAddForm::class;
protected $route = 'purge_ui.queuer_add_form';
protected $routeTitle = 'Which queuer would you like to add?';
public function testRouteConditionalAccess() : void {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->statusCodeEquals(200);
$this
->initializeQueuersService([
'a',
'b',
'c',
]);
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->statusCodeEquals(200);
$this
->initializeQueuersService([
'a',
'b',
'c',
'withform',
'purge_ui_block_queuer',
]);
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->statusCodeEquals(404);
}
public function testAddPresence() : void {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->getPath());
$this
->initializeQueuersService([
'a',
'b',
]);
$this
->assertSession()
->responseContains('Add');
$this
->assertSession()
->responseNotContains('Queuer A');
$this
->assertSession()
->responseNotContains('Queuer B');
$this
->assertSession()
->responseContains('Queuer C');
$this
->assertSession()
->responseContains('Queuer with form');
$this
->assertSame(TRUE, count($this->purgeQueuers
->getPluginsEnabled()) === 2);
$this
->assertSame(TRUE, in_array('a', $this->purgeQueuers
->getPluginsEnabled()));
$this
->assertSame(TRUE, in_array('b', $this->purgeQueuers
->getPluginsEnabled()));
$this
->assertSame(FALSE, in_array('c', $this->purgeQueuers
->getPluginsEnabled()));
$this
->assertSame(FALSE, in_array('withform', $this->purgeQueuers
->getPluginsEnabled()));
}
public function testCancelPresence() : void {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->getPath());
$this
->assertActionExists('edit-cancel', 'Cancel');
}
public function testCancelSubmit() : void {
$this
->drupalLogin($this->adminUser);
$ajax = $this
->postAjaxForm([], 'Cancel');
$this
->assertAjaxCommandCloseModalDialog($ajax);
$this
->assertAjaxCommandsTotal($ajax, 1);
}
public function testAddSubmit() : void {
$this
->drupalLogin($this->adminUser);
$this
->initializeQueuersService([
'a',
'b',
]);
$ajax = $this
->postAjaxForm([
'id' => 'c',
], 'Add');
$this
->assertAjaxCommandCloseModalDialog($ajax);
$this
->assertAjaxCommandReloadConfigForm($ajax);
$this
->assertAjaxCommandsTotal($ajax, 2);
$this->purgeQueuers
->reload();
$this
->assertSame(TRUE, in_array('c', $this->purgeQueuers
->getPluginsEnabled()));
}
}