-
Notifications
You must be signed in to change notification settings - Fork 1
/
QueueRunnerTraitTest.php
87 lines (73 loc) · 1.85 KB
/
QueueRunnerTraitTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace DrupalTest\QueueRunnerTrait\Tests;
use weitzman\DrupalTestTraits\ExistingSiteBase;
use DrupalTest\QueueRunnerTrait\QueueRunnerTrait;
/**
* @coversDefaultClass \DrupalTest\QueueRunnerTrait\QueueRunnerTrait
*/
class QueueRunnerTraitTest extends ExistingSiteBase
{
use QueueRunnerTrait;
/**
* The queue to test with.
*
* @var \Drupal\Core\Queue\QueueInterface
*/
protected $queue;
/**
* The queue to test with.
*
* @var string
*/
protected $queueName = 'media_entity_thumbnail';
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
// The core media module has a queue to test with.
$this->container->get('module_installer')->install(['media']);
/** @var \Drupal\Core\Queue\QueueInterface $queue */
$this->queue = $this->container->get('queue')->get($this->queueName);
}
/**
* {@inheritdoc}
*/
public function tearDown()
{
$this->clearQueue($this->queueName);
parent::tearDown();
}
/**
* @covers ::clearQueue
*/
public function testClearQueue()
{
$this->addQueueItem();
$this->clearQueue($this->queueName);
$this->assertEquals(0, $this->queue->numberOfItems());
}
/**
* @covers ::runQueue
*/
public function testRunQueue()
{
$this->addQueueItem();
$this->runQueue($this->queueName);
$this->assertEquals(0, $this->queue->numberOfItems());
}
/**
* Adds an item to the queue.
*/
protected function addQueueItem()
{
// Add an item to a queue.
$item = [
'id' => 'dummy_id',
];
$this->queue->createItem($item);
// Verify the item is in the queue.
$this->assertEquals(1, $this->queue->numberOfItems());
}
}