QueueBrowserFormTest.php in Purge 8.3
File
modules/purge_ui/tests/src/Functional/Form/QueueBrowserFormTest.php
View source
<?php
namespace Drupal\Tests\purge_ui\Functional\Form;
use Drupal\purge_ui\Form\QueueBrowserForm;
class QueueBrowserFormTest extends AjaxFormTestBase {
public static $modules = [
'purge_ui',
'purge_queuer_test',
'purge_purger_test',
];
protected $formClass = QueueBrowserForm::class;
protected $route = 'purge_ui.queue_browser_form';
protected $routeTitle = 'Purge queue browser';
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("Purge queue browser | Drupal");
$this
->assertSession()
->pageTextContains("Your queue is empty.");
$this
->assertSession()
->fieldNotExists('edit-1');
}
public function testClose() : void {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->pageTextContains("Close");
$ajax = $this
->postAjaxForm([], 'Close');
$this
->assertAjaxCommandCloseModalDialog($ajax);
$this
->assertAjaxCommandsTotal($ajax, 1);
}
public function testData() : void {
$this
->drupalLogin($this->adminUser);
$this
->initializeInvalidationFactoryService();
$this
->initializePurgersService([
'id' => 'good',
]);
$this
->initializeQueueService('database');
$tags = $needles = [];
for ($i = 1; $i <= 30; $i++) {
$needles[$i] = "node:{$i}";
$tags[] = $this->purgeInvalidationFactory
->get('tag', $needles[$i]);
}
$this->purgeQueue
->add($this->queuer, $tags);
$this
->assertEquals(15, count($this->purgeQueue
->selectPage()));
$this
->assertEquals(50, $this->purgeQueue
->selectPageLimit(50));
$this
->assertEquals(30, count($this->purgeQueue
->selectPage()));
$this->purgeQueue
->reload();
$this
->drupalGet($this
->getPath());
$this
->assertSession()
->pageTextContains("Type");
$this
->assertSession()
->pageTextContains("State");
$this
->assertSession()
->pageTextContains("Expression");
$this
->assertSession()
->pageTextContains("New");
$this
->assertActionExists('edit-1', '1');
$this
->assertActionExists('edit-2', '2');
$this
->assertActionNotExists('edit-3', '3');
foreach ($needles as $i => $needle) {
$needle = "<td>{$needle}</td>";
if ($i >= 16) {
$this
->assertSession()
->responseContains($needle);
}
else {
$this
->assertSession()
->responseNotContains($needle);
}
}
}
}