View source
<?php
namespace Drupal\Tests\queue_example\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Tests\BrowserTestBase;
class QueueExampleTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'queue_example',
];
protected $profile = 'minimal';
public function testQueueExampleBasic() {
$this
->drupalGet('examples/queue_example');
for ($i = 1; $i <= 5; $i++) {
$edit = [
'queue_name' => 'queue_example_first_queue',
'string_to_add' => 'boogie' . $i,
];
$this
->drupalPostForm(NULL, $edit, 'Insert into queue');
$this
->assertText((string) new FormattableMarkup('There are now @number items in the queue', [
'@number' => $i,
]));
}
for ($i = 1; $i <= 5; $i++) {
$edit = [
'queue_name' => 'queue_example_first_queue',
'claim_time' => 0,
];
$this
->drupalPostForm(NULL, $edit, 'Claim the next item from the queue');
$this
->assertPattern((string) new FormattableMarkup('%Claimed item id=.*string=@string for 0 seconds.%', [
'@string' => 'boogie' . $i,
]));
}
$edit = [
'queue_name' => 'queue_example_first_queue',
'claim_time' => 0,
];
$this
->drupalPostForm(NULL, $edit, 'Claim the next item from the queue');
$this
->assertText('There were no items in the queue available to claim');
sleep(1);
$this
->drupalPostForm(NULL, [], 'Run cron manually to expire claims');
for ($i = 1; $i <= 5; $i++) {
$edit = [
'queue_name' => 'queue_example_first_queue',
'claim_time' => 0,
];
$this
->drupalPostForm(NULL, $edit, 'Claim the next item and delete it');
$this
->assertPattern((string) new FormattableMarkup('%Claimed and deleted item id=.*string=@string for 0 seconds.%', [
'@string' => 'boogie' . $i,
]));
}
$edit = [
'queue_name' => 'queue_example_first_queue',
'claim_time' => 0,
];
$this
->drupalPostForm(NULL, $edit, 'Claim the next item from the queue');
$this
->assertText('There were no items in the queue available to claim');
}
}