class ImportQueueItemTest in Acquia Content Hub 8
PHPUnit test for the ImportQueueItem.
@coversDefaultClass Drupal\acquia_contenthub\QueueItem\ImportQueueItem
@group acquia_contenthub
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\acquia_contenthub\Unit\QueueItem\ImportQueueItemTest
Expanded class hierarchy of ImportQueueItemTest
File
- tests/
src/ Unit/ QueueItem/ ImportQueueItemTest.php, line 17
Namespace
Drupal\Tests\acquia_contenthub\Unit\QueueItemView source
class ImportQueueItemTest extends UnitTestCase {
/**
* Ensure an expected UUID can be retrieved from the ImportQueueItem.
*
* @param \Drupal\acquia_contenthub\QueueItem\ImportQueueItem $item
* A test ImportQueueItem object.
* @param string $expected
* The expected UUID.
*
* @dataProvider provideUuidItems
*/
public function testGetUuid(ImportQueueItem $item, $expected) {
$this
->assertEquals($item
->get('uuid'), $expected);
}
/**
* Ensure an expected dependency can be retrieved from the ImportQueueItem.
*
* @param \Drupal\acquia_contenthub\QueueItem\ImportQueueItem $item
* A test ImportQueueItem object.
* @param string $expected
* The expected dependency status.
*
* @dataProvider provideDependencyItems
*/
public function testDependencies(ImportQueueItem $item, $expected) {
$this
->assertEquals($item
->get('dependencies'), $expected);
}
/**
* Ensure an expected author can be retrieved from the ImportQueueItem.
*
* @param \Drupal\acquia_contenthub\QueueItem\ImportQueueItem $item
* A test ImportQueueItem object.
* @param string $expected
* The expected dependency status.
*
* @dataProvider provideAuthorItems
*/
public function testGetAuthor(ImportQueueItem $item, $expected) {
// var_dump(\Drupal::config('acquia_contenthub.entity_config')->get('import_with_queue'));.
$this
->assertEquals($item
->get('author'), $expected);
}
/**
* Ensure an expected status can be retrieved from the ImportQueueItem.
*
* @param \Drupal\acquia_contenthub\QueueItem\ImportQueueItem $item
* A test ImportQueueItem object.
* @param string $expected
* The expected dependency status.
*
* @dataProvider provideStatusItems
*/
public function testGetStatus(ImportQueueItem $item, $expected) {
$this
->assertEquals($item
->get('status'), $expected);
}
/**
* Test Import with Queue.
*/
public function testImportWithQueue() {
$importEntityManager = $this
->getMockBuilder(ImportEntityManager::class)
->disableOriginalConstructor()
->setMethods([
'addEntityToImportQueue',
])
->getMock();
$container = new ContainerBuilder();
$config = $this
->getConfigFactoryStub([
'acquia_contenthub.entity_config' => [
'import_with_queue' => TRUE,
],
]);
$container
->set('config.factory', $config);
$container
->set('config.factory', $config);
\Drupal::unsetContainer();
\Drupal::setContainer($container);
$import_with_queue = \Drupal::config('acquia_contenthub.entity_config')
->get('import_with_queue');
$this
->assertTrue($import_with_queue);
}
/**
* Provides a series of queue items.
*
* @return array
* An array of queue items.
*/
public function provideUuidItems() {
$data = [];
$data[] = [
new ImportQueueItem('00000000-0000-0000-0000-000000000000'),
'00000000-0000-0000-0000-000000000000',
];
$data[] = [
new ImportQueueItem('00000000-0001-0000-0000-000000000000'),
'00000000-0001-0000-0000-000000000000',
];
$data[] = [
new ImportQueueItem('00000000-0002-0000-0000-000000000000'),
'00000000-0002-0000-0000-000000000000',
];
$data[] = [
new ImportQueueItem('00000000-0003-0000-0000-000000000000'),
'00000000-0003-0000-0000-000000000000',
];
return $data;
}
/**
* Provides a series of queue items with dependencies.
*
* @return array
* An array with queue items with dependencies.
*/
public function provideDependencyItems() {
$data = [];
$data[] = [
new ImportQueueItem('00000000-0000-0000-0000-000000000000', TRUE),
TRUE,
];
$data[] = [
new ImportQueueItem('00000000-0000-0000-0000-000000000000', FALSE),
FALSE,
];
$data[] = [
new ImportQueueItem('00000000-0000-0000-0000-000000000000'),
TRUE,
];
return $data;
}
/**
* Provides a series of queue items with dependencies.
*
* @return array
* A series of queue items with users.
*/
public function provideAuthorItems() {
$this
->createContainer();
$data = [];
$data[] = [
new ImportQueueItem('00000000-0000-0000-0000-000000000000', TRUE, TRUE),
TRUE,
];
$data[] = [
new ImportQueueItem('00000000-0000-0000-0000-000000000000', FALSE, \Drupal::currentUser()),
\Drupal::currentUser(),
];
return $data;
}
/**
* Provides a series of queue items with dependencies.
*
* @return array
* An array of queue items with other data.
*/
public function provideStatusItems() {
$data = [];
$data[] = [
new ImportQueueItem('00000000-0000-0000-0000-000000000000', TRUE, TRUE, 0),
0,
];
$data[] = [
new ImportQueueItem('00000000-0000-0000-0000-000000000000', TRUE, TRUE, 1),
1,
];
return $data;
}
/**
* Build a container before the class.
*/
public function createContainer() {
parent::setup();
\Drupal::unsetContainer();
$container = new ContainerBuilder();
$account = $this
->getMockBuilder('Drupal\\Core\\Session\\AccountProxyInterface')
->disableOriginalConstructor()
->getMock();
$container
->set('current_user', $account);
\Drupal::setContainer($container);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ImportQueueItemTest:: |
public | function | Build a container before the class. | |
ImportQueueItemTest:: |
public | function | Provides a series of queue items with dependencies. | |
ImportQueueItemTest:: |
public | function | Provides a series of queue items with dependencies. | |
ImportQueueItemTest:: |
public | function | Provides a series of queue items with dependencies. | |
ImportQueueItemTest:: |
public | function | Provides a series of queue items. | |
ImportQueueItemTest:: |
public | function | Ensure an expected dependency can be retrieved from the ImportQueueItem. | |
ImportQueueItemTest:: |
public | function | Ensure an expected author can be retrieved from the ImportQueueItem. | |
ImportQueueItemTest:: |
public | function | Ensure an expected status can be retrieved from the ImportQueueItem. | |
ImportQueueItemTest:: |
public | function | Ensure an expected UUID can be retrieved from the ImportQueueItem. | |
ImportQueueItemTest:: |
public | function | Test Import with Queue. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |