You are here

class ContentHubImportQueueBaseTest in Acquia Content Hub 8

Test for Content Hub Import Queue Base.

@coversDefaultClass \Drupal\acquia_contenthub\Plugin\QueueWorker\ContentHubImportQueueBase

@group acquia_contenthub

Hierarchy

Expanded class hierarchy of ContentHubImportQueueBaseTest

File

tests/src/Unit/Plugin/QueueWorker/ContentHubImportQueueBaseTest.php, line 17

Namespace

Drupal\Tests\acquia_contenthub\Unit\Plugin\QueueWorker
View source
class ContentHubImportQueueBaseTest extends UnitTestCase {

  /**
   * Provide QueueItems for the queue process.
   */
  public function provideQueueItems() {
    $data = [];
    $data[] = [
      [
        new ImportQueueItem('00000000-0000-0000-0000-000000000000'),
      ],
      [
        [
          '00000000-0000-0000-0000-000000000000',
          TRUE,
          TRUE,
          0,
        ],
      ],
    ];
    $data[] = [
      [
        new ImportQueueItem('00000000-0000-0000-0000-000000000000'),
        new ImportQueueItem('00000000-0001-0000-0000-000000000000', FALSE),
        new ImportQueueItem('00000000-0002-0000-0000-000000000000', TRUE, TRUE, 1),
      ],
      [
        [
          '00000000-0000-0000-0000-000000000000',
          TRUE,
          TRUE,
          0,
        ],
        [
          '00000000-0001-0000-0000-000000000000',
          FALSE,
          TRUE,
          0,
        ],
        [
          '00000000-0002-0000-0000-000000000000',
          TRUE,
          TRUE,
          1,
        ],
      ],
    ];
    $data[] = [
      (object) [
        'data' => [
          new ImportQueueItem('00000000-0000-0000-0000-000000000000'),
        ],
      ],
      [
        [
          '00000000-0000-0000-0000-000000000000',
          TRUE,
          TRUE,
          0,
        ],
      ],
    ];
    return $data;
  }

  /**
   * Ensure that the queue can process given entities.
   *
   * @param mixed $item
   *   Some items to test.
   * @param array $expected
   *   An array of expected items.
   *
   * @dataProvider provideQueueItems
   */
  public function testProcessItem($item = [], array $expected = []) {
    $import_entity_manager = $this
      ->getMockBuilder(ImportEntityManager::class)
      ->disableOriginalConstructor()
      ->setMethods([
      'importRemoteEntity',
    ])
      ->getMock();
    foreach ($expected as $index => $values) {

      // @codingStandardsIgnoreStart

      /**
       * @var string $uuid
       * @var bool $deps
       * @var bool $author
       * @var int $status
       */

      // @codingStandardsIgnoreEnd
      $values = array_combine([
        'uuid',
        'deps',
        'author',
        'status',
      ], $values);
      extract($values);
      $import_entity_manager
        ->expects($this
        ->at($index))
        ->method('importRemoteEntity')
        ->with($uuid, $deps, $author, $status);
    }
    $worker = $this
      ->getMockBuilder(ContentHubImportQueue::class)
      ->disableOriginalConstructor()
      ->setMethods([
      'getEntityManager',
    ])
      ->getMock();
    $worker
      ->expects($this
      ->any())
      ->method('getEntityManager')
      ->willReturn($import_entity_manager);
    $worker
      ->processItem($item);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentHubImportQueueBaseTest::provideQueueItems public function Provide QueueItems for the queue process.
ContentHubImportQueueBaseTest::testProcessItem public function Ensure that the queue can process given entities.
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