public function ExportTest::setUp in Acquia Content Hub 8.2
Throws
\Exception
Overrides EntityKernelTestBase::setUp
File
- tests/
src/ Kernel/ ExportTest.php, line 136
Class
- ExportTest
- Tests entity exports.
Namespace
Drupal\Tests\acquia_contenthub\KernelCode
public function setUp() {
if (version_compare(\Drupal::VERSION, '9.0', '>=')) {
static::$modules[] = 'path_alias';
}
parent::setUp();
if (version_compare(\Drupal::VERSION, '8.8.0', '>=')) {
$this
->installEntitySchema('path_alias');
}
$this
->installEntitySchema('taxonomy_term');
$this
->installSchema('acquia_contenthub_publisher', [
'acquia_contenthub_publisher_export_tracking',
]);
$this
->installSchema('node', [
'node_access',
]);
$this
->installEntitySchema('file');
$this
->installSchema('file', [
'file_usage',
]);
$this
->installSchema('user', [
'users_data',
]);
$this
->installConfig([
'acquia_contenthub',
'acquia_contenthub_publisher',
'system',
'field',
'node',
'file',
'user',
'taxonomy',
]);
$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');
$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');
$name = 'acquia_contenthub_publish_export';
$this->queueWorker = $queue_worker_manager
->createInstance($name);
$this->queue = $queue_factory
->get($name);
// Add stream wrapper manager service.
$this->streamWrapperManager = \Drupal::service('stream_wrapper_manager');
// Add Content Hub tracker service.
$this->publisherTracker = \Drupal::service('acquia_contenthub_publisher.tracker');
}