public function ContentHubExportQueueControllerTest::testEnqueueExportEntities in Acquia Content Hub 8
Test the enqueueExportEntities method.
@covers ::enqueueExportEntities
File
- tests/
src/ Unit/ Controller/ ContentHubExportQueueControllerTest.php, line 122
Class
- ContentHubExportQueueControllerTest
- PHPUnit test for the ContentHubExportQueueController class.
Namespace
Drupal\Tests\acquia_contenthub\Unit\ControllerCode
public function testEnqueueExportEntities() {
$queued_items = [
$this
->createQueueItem('node', 1, '00000000-0000-0000-0000-000000000000'),
$this
->createQueueItem('node', 2, '00000000-0000-1111-0000-000000000000'),
$this
->createQueueItem('node', 3, '00000000-0000-2222-0000-000000000000'),
$this
->createQueueItem('node', 4, '00000000-0000-3333-0000-000000000000'),
$this
->createQueueItem('node', 5, '00000000-0000-4444-0000-000000000000'),
$this
->createQueueItem('node', 6, '00000000-0000-5555-0000-000000000000'),
$this
->createQueueItem('node', 7, '00000000-0000-6666-0000-000000000000'),
];
// Defining the queue.
$queue = $this
->createMock('Drupal\\Core\\Queue\\QueueInterface');
$queue
->method('numberOfItems')
->willReturn(100);
$queue
->expects($this
->at(0))
->method('createItem')
->willReturnCallback(function ($item) use ($queued_items) {
$item = (array) $item;
$queued_item = (array) $queued_items[0];
$this
->assertEquals($item, $queued_item);
return $item == $queued_item ? 1 : FALSE;
});
$queue
->expects($this
->at(1))
->method('createItem')
->willReturnCallback(function ($item) use ($queued_items) {
$item = (array) $item;
$queued_item = (array) $queued_items[1];
$this
->assertEquals($item, $queued_item);
return $item == $queued_item ? 1 : FALSE;
});
$queue
->expects($this
->at(2))
->method('createItem')
->willReturnCallback(function ($item) use ($queued_items) {
$item = (array) $item;
$queued_item = (array) $queued_items[2];
$this
->assertEquals($item, $queued_item);
return $item == $queued_item ? 1 : FALSE;
});
$queue
->expects($this
->at(3))
->method('createItem')
->willReturnCallback(function ($item) use ($queued_items) {
$item = (array) $item;
$queued_item = (array) $queued_items[3];
$this
->assertEquals($item, $queued_item);
return $item == $queued_item ? 1 : FALSE;
});
$queue
->expects($this
->at(4))
->method('createItem')
->willReturnCallback(function ($item) use ($queued_items) {
$item = (array) $item;
$queued_item = (array) $queued_items[4];
$this
->assertEquals($item, $queued_item);
return $item == $queued_item ? 1 : FALSE;
});
$queue
->expects($this
->at(5))
->method('createItem')
->willReturnCallback(function ($item) use ($queued_items) {
$item = (array) $item;
$queued_item = (array) $queued_items[5];
$this
->assertEquals($item, $queued_item);
return $item == $queued_item ? 1 : FALSE;
});
$queue
->expects($this
->at(6))
->method('createItem')
->willReturnCallback(function ($item) use ($queued_items) {
$item = (array) $item;
$queued_item = (array) $queued_items[6];
$this
->assertEquals($item, $queued_item);
return $item == $queued_item ? 1 : FALSE;
});
$this->queueFactory
->method('get')
->with('acquia_contenthub_export_queue')
->willReturn($queue);
// Defining candidate entities.
$candidate_entities = [
'00000000-0000-0000-0000-000000000000' => $this
->createMockForContentEntity('node', 1, '00000000-0000-0000-0000-000000000000'),
'00000000-0000-1111-0000-000000000000' => $this
->createMockForContentEntity('node', 2, '00000000-0000-1111-0000-000000000000'),
'00000000-0000-2222-0000-000000000000' => $this
->createMockForContentEntity('node', 3, '00000000-0000-2222-0000-000000000000'),
'00000000-0000-3333-0000-000000000000' => $this
->createMockForContentEntity('node', 4, '00000000-0000-3333-0000-000000000000'),
'00000000-0000-4444-0000-000000000000' => $this
->createMockForContentEntity('node', 5, '00000000-0000-4444-0000-000000000000'),
'00000000-0000-5555-0000-000000000000' => $this
->createMockForContentEntity('node', 6, '00000000-0000-5555-0000-000000000000'),
'00000000-0000-6666-0000-000000000000' => $this
->createMockForContentEntity('node', 7, '00000000-0000-6666-0000-000000000000'),
];
// Enqueue entities.
$this->contentHubExportQueueController
->enqueueExportEntities($candidate_entities);
}