diff --git a/tests/functional/QueueTest.php b/tests/functional/QueueTest.php index 53005be32a..dab8bdc3bf 100644 --- a/tests/functional/QueueTest.php +++ b/tests/functional/QueueTest.php @@ -11,64 +11,6 @@ class QueueTest extends CommandUnishTestCase { use TestModuleHelperTrait; - public function testQueue() - { - if (!$this->isDrupalGreaterThanOrEqualTo('10.0.0')) { - $this->markTestSkipped('testQueue uses aggregator module, which has been removed in Drupal 10'); - } - - $expected = 'aggregator_feeds,%items,"Drupal\Core\Queue\DatabaseQueue"'; - $sites = $this->setUpDrupal(1, true); - - // Enable aggregator since it declares a queue. - $this->drush('pm-enable', ['aggregator']); - - $this->drush('queue-list'); - $output = $this->getOutput(); - $this->assertStringContainsString('aggregator_feeds', $output, 'Queue list shows the declared queue.'); - - // We need user to own to the feed. - $this->drush('user-create', ['example'], ['password' => 'password', 'mail' => "example@example.com"]); - $this->drush('php-script', ['queue_script'], ['script-path' => __DIR__ . '/resources']); - $this->drush('queue-list', [], ['format' => 'csv']); - $output = $this->getOutputAsList(); - $this->assertEquals(str_replace('%items', 1, $expected), array_pop($output), 'Item was successfully added to the queue.'); - - $this->drush('queue-run', ['aggregator_feeds']); - $this->drush('queue-list', [], ['format' => 'csv']); - $output = $this->getOutputAsList(); - $this->assertEquals(str_replace('%items', 0, $expected), array_pop($output), 'Queue item processed.'); - } - - /** - * Tests the queue-delete command. - */ - public function testQueueDelete() - { - if (!$this->isDrupalGreaterThanOrEqualTo('10.0.0')) { - $this->markTestSkipped('testQueueDelete uses aggregator module, which has been removed in Drupal 10'); - } - - $expected = 'aggregator_feeds,%items,"Drupal\Core\Queue\DatabaseQueue"'; - - $sites = $this->setUpDrupal(1, true); - - // Enable aggregator since it declares a queue. - $this->drush('pm-enable', ['aggregator']); - - // Add another item to the queue and make sure it was deleted. - $this->drush('php-script', ['queue_script'], ['script-path' => __DIR__ . '/resources']); - $this->drush('queue-list', [], ['format' => 'csv']); - $output = $this->getOutputAsList(); - $this->assertEquals(str_replace('%items', 1, $expected), array_pop($output), 'Item was successfully added to the queue.'); - - $this->drush('queue-delete', ['aggregator_feeds']); - - $this->drush('queue-list', [], ['format' => 'csv']); - $output = $this->getOutputAsList(); - $this->assertEquals(str_replace('%items', 0, $expected), array_pop($output), 'Queue was successfully deleted.'); - } - /** * Tests the RequeueException. */ @@ -81,18 +23,17 @@ public function testRequeueException() // Enable woot module, which contains a queue worker that throws a // RequeueException. - $this->drush('pm-enable', ['woot'], [], null, null, self::EXIT_SUCCESS); + $this->drush('pm:enable', ['woot'], [], null, null, self::EXIT_SUCCESS); // Add an item to the queue. - $this->drush('php-script', ['requeue_script'], ['script-path' => __DIR__ . '/resources']); + $this->drush('php:script', ['requeue_script'], ['script-path' => __DIR__ . '/resources']); // Check that the queue exists and it has one item in it. - $expected = 'woot_requeue_exception,%items,"Drupal\Core\Queue\DatabaseQueue"'; - $this->drush('queue-list', [], ['format' => 'csv']); - $output = $this->getOutput(); - $this->assertStringContainsString(str_replace('%items', 1, $expected), $output, 'Item was successfully added to the queue.'); + $this->drush('queue:list', [], ['format' => 'json']); + $output = $this->getOutputFromJSON('woot_requeue_exception'); + $this->assertStringContainsString(1, $output['items'], 'Item was successfully added to the queue.'); // Process the queue. - $this->drush('queue-run', ['woot_requeue_exception']); + $this->drush('queue:run', ['woot_requeue_exception']); // Check that the item was processed after being requeued once. // Here is the detailed workflow of what the above command did. @@ -105,15 +46,15 @@ public function testRequeueException() // RequeueException this time (see below). // 6. Drush removes the item from the queue. // 7. Command finishes. The queue is empty. - $this->drush('queue-list', [], ['format' => 'csv']); - $output = $this->getOutput(); - $this->assertStringContainsString(str_replace('%items', 0, $expected), $output, 'Queue item processed after being requeued.'); + $this->drush('queue:list', [], ['format' => 'json']); + $output = $this->getOutputFromJSON('woot_requeue_exception'); + $this->assertStringContainsString(0, $output['items'], 'Queue item processed after being requeued.'); } /** - * Tests that CustomExceptions do not hold up the queue. + * Tests that CustomExceptions do not hold up the queue. Also queue:run, queue:list, queue:delete */ - public function testCustomException() + public function testCustomExceptionAndCommands() { $this->setUpDrupal(1, true); @@ -122,19 +63,18 @@ public function testCustomException() // Enable woot module, which contains a queue worker that throws a // custom exception. - $this->drush('pm-enable', ['woot'], [], null, null, self::EXIT_SUCCESS); + $this->drush('pm:enable', ['woot'], [], null, null, self::EXIT_SUCCESS); // Add a couple of items to the queue. - $this->drush('php-script', ['queue_custom_exception_script'], ['script-path' => __DIR__ . '/resources']); + $this->drush('php:script', ['queue_custom_exception_script'], ['script-path' => __DIR__ . '/resources']); // Check that the queue exists and it has two items in it. - $expected = 'woot_custom_exception,%items,"Drupal\Core\Queue\DatabaseQueue"'; - $this->drush('queue-list', [], ['format' => 'csv']); - $output = $this->getOutput(); - $this->assertStringContainsString(str_replace('%items', 2, $expected), $output, 'Items were successfully added to the queue.'); + $this->drush('queue-list', [], ['format' => 'json']); + $output = $this->getOutputFromJSON('woot_custom_exception'); + $this->assertStringContainsString(2, $output['items'], 'Items were successfully added to the queue.'); // Process the queue. - $this->drush('queue-run', ['woot_custom_exception']); + $this->drush('queue:run', ['woot_custom_exception']); // Check that the item was processed after being requeued once. // Here is the detailed workflow of what the above command did. Note @@ -149,8 +89,13 @@ public function testCustomException() // 6. Drush removes the second item from the queue. // 7. Command finishes. The queue is left with the first item, which was // skipped. - $this->drush('queue-list', [], ['format' => 'csv']); - $output = $this->getOutput(); - $this->assertStringContainsString(str_replace('%items', 1, $expected), $output, 'Last queue item processed after first threw custom exception.'); + $this->drush('queue:list', [], ['format' => 'json']); + $output = $this->getOutputFromJSON('woot_custom_exception'); + $this->assertStringContainsString(1, $output['items'], 'Last queue item processed after first threw custom exception.'); + + $this->drush('queue:delete', ['woot_custom_exception']); + $this->drush('queue:list', [], ['format' => 'json']); + $output = $this->getOutputFromJSON('woot_custom_exception'); + $this->assertEquals(0, $output['items'], 'Queue was successfully deleted.'); } }