You are here

protected function NullifyQueueIdTest::setUp in Acquia Content Hub 8.2

Overrides EntityKernelTestBase::setUp

1 call to NullifyQueueIdTest::setUp()
PublisherTrackerTest::setUp in tests/src/Kernel/PublisherTrackerTest.php
1 method overrides NullifyQueueIdTest::setUp()
PublisherTrackerTest::setUp in tests/src/Kernel/PublisherTrackerTest.php

File

tests/src/Kernel/NullifyQueueIdTest.php, line 88

Class

NullifyQueueIdTest
Tests the NullifyQueueId class.

Namespace

Drupal\Tests\acquia_contenthub\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  if (version_compare(\Drupal::VERSION, '9.0', '>=')) {
    static::$modules[] = 'path_alias';
  }
  elseif (version_compare(\Drupal::VERSION, '8.8.0', '>=')) {
    $this
      ->installEntitySchema('path_alias');
  }
  $this
    ->installSchema('acquia_contenthub_publisher', [
    self::TABLE_NAME,
  ]);
  $this
    ->installEntitySchema('user');
  $this
    ->installSchema('user', [
    'users_data',
  ]);
  $this
    ->installEntitySchema('node');
  $this
    ->installSchema('node', [
    'node_access',
  ]);
  $this
    ->installConfig([
    'acquia_contenthub',
    'acquia_contenthub_publisher',
    'system',
    'user',
  ]);

  // Creates sample node type.
  $this
    ->createNodeType();
  $origin_uuid = '00000000-0000-0001-0000-123456789123';
  $configFactory = $this->container
    ->get('config.factory');
  $config = $configFactory
    ->getEditable('acquia_contenthub.admin_settings');
  $config
    ->set('origin', $origin_uuid);
  $config
    ->set('send_contenthub_updates', TRUE);
  $config
    ->save();

  // Acquia ContentHub export queue service.
  $this->contentHubQueue = $this->container
    ->get('acquia_contenthub_publisher.acquia_contenthub_export_queue');

  // Add Content Hub tracker service.
  $this->publisherTracker = \Drupal::service('acquia_contenthub_publisher.tracker');
  $cdf_object = $this
    ->getMockBuilder(CDFObjectInterface::class)
    ->disableOriginalConstructor()
    ->getMock();
  $cdf_object
    ->method('getOrigin')
    ->willReturn($origin_uuid);

  // Mock Acquia ContentHub Client.
  $response = $this
    ->getMockBuilder('\\Psr\\Http\\Message\\ResponseInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $response
    ->method('getStatusCode')
    ->willReturn(202);
  $contenthub_client = $this
    ->getMockBuilder('\\Acquia\\ContentHubClient\\ContentHubClient')
    ->disableOriginalConstructor()
    ->getMock();
  $contenthub_client
    ->method('putEntities')
    ->with($this
    ->captureArg($this->cdfObject))
    ->willReturn($response);
  $contenthub_client
    ->method('deleteEntity')
    ->willReturn($response);
  $contenthub_client
    ->method('getEntity')
    ->willReturn($cdf_object);
  $contenthub_client_factory = $this
    ->getMockBuilder('\\Drupal\\acquia_contenthub\\Client\\ClientFactory')
    ->disableOriginalConstructor()
    ->getMock();
  $contenthub_client_factory
    ->method('isConfigurationSet')
    ->willReturn(TRUE);
  $contenthub_client_factory
    ->method('getClient')
    ->willReturn($contenthub_client);
  $this->container
    ->set('acquia_contenthub.client.factory', $contenthub_client_factory);
  $contenthub_settings = $this
    ->getMockBuilder('\\Acquia\\ContentHubClient\\Settings')
    ->disableOriginalConstructor()
    ->getMock();
  $contenthub_settings
    ->method('getUuid')
    ->willReturn($origin_uuid);
  $contenthub_client_factory
    ->method('getSettings')
    ->willReturn($contenthub_settings);
  $contenthub_client
    ->method('getSettings')
    ->willReturn($contenthub_settings);
  $common = $this
    ->getMockBuilder(ContentHubCommonActions::class)
    ->setConstructorArgs([
    $this->container
      ->get('event_dispatcher'),
    $this->container
      ->get('entity.cdf.serializer'),
    $this->container
      ->get('entity.dependency.calculator'),
    $this->container
      ->get('acquia_contenthub.client.factory'),
    $this->container
      ->get('logger.factory'),
    $this->container
      ->get('config.factory'),
  ])
    ->setMethods([
    'getUpdateDbStatus',
  ])
    ->getMock();
  $this->container
    ->set('acquia_contenthub_common_actions', $common);

  // Setup queue.
  $queue_factory = $this->container
    ->get('queue');
  $queue_worker_manager = $this->container
    ->get('plugin.manager.queue_worker');
  $this->queueWorker = $queue_worker_manager
    ->createInstance(self::QUEUE_NAME);
  $this->queue = $queue_factory
    ->get(self::QUEUE_NAME);
}