View source
<?php
namespace Drupal\Tests\purge_ui\Functional\Form;
use Drupal\purge_ui\Form\PurgerAddForm;
class PurgerAddFormTest extends AjaxFormTestBase {
public static $modules = [
'purge_ui',
'purge_purger_test',
];
protected $route = 'purge_ui.purger_add_form';
protected $formClass = PurgerAddForm::class;
protected $routeTitle = 'Which purger would you like to add?';
public function testRouteConditionalAccess() : void {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->statusCodeEquals(200);
$this
->initializePurgersService([
'a',
'b',
'c',
]);
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->statusCodeEquals(200);
$this
->initializePurgersService([
'a',
'b',
'c',
'withform',
'good',
]);
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->statusCodeEquals(404);
}
public function testAddPresence() : void {
$this
->initializePurgersService([
'a',
'withform',
'good',
]);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->responseContains('Add');
$this
->assertSame(TRUE, count($this->purgePurgers
->getPluginsEnabled()) === 3);
}
public function testAddSubmit() : void {
$this
->drupalLogin($this->adminUser);
$this
->initializePurgersService([
'a',
'withform',
'good',
]);
$ajax = $this
->postAjaxForm([
'plugin_id' => 'c',
], 'Add');
$this
->assertAjaxCommandCloseModalDialog($ajax);
$this
->assertAjaxCommandReloadConfigForm($ajax);
$this
->assertAjaxCommandsTotal($ajax, 2);
$this->purgePurgers
->reload();
$this
->assertSame(TRUE, in_array('c', $this->purgePurgers
->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 testTwoAvailablePurgers() : void {
$this
->initializePurgersService([
'c',
'withform',
]);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->fieldExists('edit-plugin-id-a');
$this
->assertSession()
->fieldExists('edit-plugin-id-b');
$this
->assertSession()
->fieldExists('edit-plugin-id-good');
$this
->assertSession()
->pageTextContains('Purger A');
$this
->assertSession()
->pageTextContains('Purger B');
$this
->assertSession()
->pageTextContains('Good Purger');
$this
->assertSession()
->pageTextNotContains('Configurable purger');
$this
->assertActionExists('edit-cancel', 'Cancel');
$this
->assertActionExists('edit-submit', 'Add');
}
}