QueueEmptyFormTest.php in Purge 8.3
File
modules/purge_ui/tests/src/Functional/Form/QueueEmptyFormTest.php
View source
<?php
namespace Drupal\Tests\purge_ui\Functional\Form;
use Drupal\purge_ui\Form\QueueEmptyForm;
class QueueEmptyFormTest extends AjaxFormTestBase {
public static $modules = [
'purge_ui',
'purge_queuer_test',
'purge_purger_test',
];
protected $formClass = QueueEmptyForm::class;
protected $route = 'purge_ui.queue_empty_form';
protected $routeTitle = 'Are you sure you want to empty the queue?';
protected $queuer;
public function setUp($switch_to_memory_queue = TRUE) : void {
parent::setUp($switch_to_memory_queue);
$this
->initializeQueuersService();
$this->queuer = $this->purgeQueuers
->get('a');
}
public function testPresence() : void {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->titleEquals("Are you sure you want to empty the queue? | Drupal");
$this
->assertSession()
->pageTextContains("This action cannot be undone.");
$this
->assertSession()
->pageTextContains('Yes, throw everything away!');
}
public function testNo() : void {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->responseContains('No');
$ajax = $this
->postAjaxForm([], 'No');
$this
->assertAjaxCommandCloseModalDialog($ajax);
$this
->assertAjaxCommandsTotal($ajax, 1);
}
public function testConfirm() : void {
$this
->initializeQueueService('file');
$this->purgeQueue
->add($this->queuer, $this
->getInvalidations(7, 'tag', 'test'));
$this->purgeQueue
->reload();
$this
->assertSame(7, $this->purgeQueue
->numberOfItems());
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->getPath());
$ajax = $this
->postAjaxForm([], 'Yes, throw everything away!');
$this
->assertAjaxCommandCloseModalDialog($ajax);
$this
->assertAjaxCommandsTotal($ajax, 1);
$this
->assertSame(0, $this->purgeQueue
->numberOfItems());
}
}