You are here

class ImportQueueItemTest in Acquia Content Hub 8

PHPUnit test for the ImportQueueItem.

@coversDefaultClass Drupal\acquia_contenthub\QueueItem\ImportQueueItem

@group acquia_contenthub

Hierarchy

Expanded class hierarchy of ImportQueueItemTest

File

tests/src/Unit/QueueItem/ImportQueueItemTest.php, line 17

Namespace

Drupal\Tests\acquia_contenthub\Unit\QueueItem
View 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

Namesort descending Modifiers Type Description Overrides
ImportQueueItemTest::createContainer public function Build a container before the class.
ImportQueueItemTest::provideAuthorItems public function Provides a series of queue items with dependencies.
ImportQueueItemTest::provideDependencyItems public function Provides a series of queue items with dependencies.
ImportQueueItemTest::provideStatusItems public function Provides a series of queue items with dependencies.
ImportQueueItemTest::provideUuidItems public function Provides a series of queue items.
ImportQueueItemTest::testDependencies public function Ensure an expected dependency can be retrieved from the ImportQueueItem.
ImportQueueItemTest::testGetAuthor public function Ensure an expected author can be retrieved from the ImportQueueItem.
ImportQueueItemTest::testGetStatus public function Ensure an expected status can be retrieved from the ImportQueueItem.
ImportQueueItemTest::testGetUuid public function Ensure an expected UUID can be retrieved from the ImportQueueItem.
ImportQueueItemTest::testImportWithQueue public function Test Import with Queue.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340