PurgerDeleteFormTest.php in Purge 8.3
File
modules/purge_ui/tests/src/Functional/Form/PurgerDeleteFormTest.php
View source
<?php
namespace Drupal\Tests\purge_ui\Functional\Form;
use Drupal\purge_ui\Form\PurgerDeleteForm;
class PurgerDeleteFormTest extends AjaxFormTestBase {
public static $modules = [
'purge_ui',
'purge_purger_test',
];
protected $formClass = PurgerDeleteForm::class;
protected $route = 'purge_ui.purger_delete_form';
protected $routeParameters = [
'id' => 'id0',
];
protected $routeParametersInvalid = [
'id' => 'doesnotexist',
];
protected $routeTitle = 'Are you sure you want to delete Purger A?';
public function setUp($switch_to_memory_queue = TRUE) : void {
parent::setUp($switch_to_memory_queue);
$this
->initializePurgersService([
'a',
]);
}
public function testNoPresence() : void {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->responseContains('No');
}
public function testNoSubmit() : void {
$this
->drupalLogin($this->adminUser);
$ajax = $this
->postAjaxForm([], 'No');
$this
->assertAjaxCommandCloseModalDialog($ajax);
$this
->assertAjaxCommandsTotal($ajax, 1);
}
public function testDeletePurger() : void {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->responseContains('Yes, delete this purger!');
$this
->assertSame([
'id0' => 'a',
], $this->purgePurgers
->getPluginsEnabled());
$ajax = $this
->postAjaxForm([], 'Yes, delete this purger!');
$this
->assertAjaxCommandReloadConfigForm($ajax);
$this
->assertAjaxCommandCloseModalDialog($ajax);
$this
->assertAjaxCommandsTotal($ajax, 2);
$this->purgePurgers
->reload();
$this
->assertSame(TRUE, is_array($this->purgePurgers
->getPluginsEnabled()));
$this
->assertEmpty($this->purgePurgers
->getPluginsEnabled());
}
public function testDeletePurgerWhichDoesNotExist() : void {
$this
->drupalLogin($this->adminUser);
$ajax = $this
->postAjaxForm([], 'Yes, delete this purger!', $this->routeParametersInvalid);
$this
->assertAjaxCommandCloseModalDialog($ajax);
$this
->assertAjaxCommandsTotal($ajax, 1);
}
public function testRouteAccess() : void {
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->statusCodeEquals(403);
$path = $this
->getPath($this->routeParametersInvalid);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($path);
$this
->assertSession()
->statusCodeEquals(200);
}
}