EnqueueFormTest.php in Warmer 8
File
modules/warmer_entity/tests/src/Functional/EnqueueFormTest.php
View source
<?php
namespace Drupal\Tests\warmer_entity\Functional;
use Drupal\Core\Queue\QueueInterface;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\node\NodeInterface;
use Drupal\Tests\BrowserTestBase;
class EnqueueFormTest extends BrowserTestBase {
protected static $modules = [
'node',
'warmer',
'warmer_entity',
];
private $adminUser;
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->createUser([
'administer site configuration',
]);
NodeType::create([
'type' => 'article',
])
->save();
}
public function testEnqueueForm() {
$this
->createTestContent();
$this
->config('warmer.settings')
->set('warmers', [
'entity' => [
'id' => 'entity',
'frequency' => 1,
'batchSize' => 1,
'entity_types' => [
'node:article' => 'node:article',
],
],
])
->save();
$this
->drupalLogin($this->adminUser);
$this
->drupalGet(Url::fromRoute('warmer.enqueue'));
$this
->submitForm([
'warmers[entity]' => true,
], 'Warm Caches');
$elements = $this
->cssSelect('div.messages');
$element = reset($elements);
$this
->assertEquals($element
->getText(), 'Status message 1 items enqueued for cache warming.');
$queue = \Drupal::service('queue')
->get('warmer');
assert($queue instanceof QueueInterface);
$this
->assertSame(1, $queue
->numberOfItems(), 'Correct number of batches in the queue.');
}
public function testEmptyEnqueueForm() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet(Url::fromRoute('warmer.enqueue'));
$assertions = $this
->assertSession();
$assertions
->buttonExists('Warm Caches');
$elements = $this
->xpath('//table[@id="edit-warmers"]/tbody/tr');
$this
->assertCount(1, $elements);
$this
->click('#edit-submit');
$elements = $this
->cssSelect('div.messages');
$element = reset($elements);
$this
->assertEquals($element
->getText(), 'Status message 0 items enqueued for cache warming.');
}
private function createTestContent() {
Node::create([
'type' => 'article',
'title' => 'Test Article 1',
'status' => NodeInterface::PUBLISHED,
])
->save();
}
}