View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\entity_share_client\Functional;
use Drupal\Component\Serialization\Json;
use Drupal\entity_share\EntityShareUtility;
use Drupal\entity_share_client\ImportContext;
use Drupal\node\NodeInterface;
use Drupal\Tests\key\Functional\KeyTestTrait;
abstract class AuthenticationTestBase extends EntityShareClientFunctionalTestBase {
use KeyTestTrait;
public static $modules = [
'key',
];
protected static $entityTypeId = 'node';
protected static $entityBundleId = 'es_test';
protected static $entityLangcode = 'en';
protected static $filesData = [
'private_file' => [
'filename' => 'test_private.txt',
'filemime' => 'text/plain',
'uri' => 'private://test_private.txt',
'file_content' => 'Drupal',
],
];
protected function getImportConfigProcessorSettings() {
$processors = parent::getImportConfigProcessorSettings();
$processors['physical_file'] = [
'rename' => FALSE,
'weights' => [
'process_entity' => 0,
],
];
return $processors;
}
protected function postSetupFixture() {
$this
->prepareContent();
$this
->populateRequestService();
foreach (static::$filesData as $file_data) {
$this->fileSystem
->delete($file_data['uri']);
}
$this
->deleteContent();
}
protected function getEntitiesDataArray() {
return [
'file' => [
'en' => $this
->preparePhysicalFilesAndFileEntitiesData(),
],
'node' => [
'en' => [
'es_test_node_import_published' => $this
->getCompleteNodeInfos([
'status' => [
'value' => NodeInterface::PUBLISHED,
'checker_callback' => 'getValue',
],
'field_es_test_file' => [
'value_callback' => function () {
return [
[
'target_id' => $this
->getEntityId('file', 'private_file'),
],
];
},
'checker_callback' => 'getFilteredStructureValues',
],
]),
'es_test_node_import_not_published' => $this
->getCompleteNodeInfos([
'status' => [
'value' => NodeInterface::NOT_PUBLISHED,
'checker_callback' => 'getValue',
],
]),
],
],
];
}
protected function resetRemoteCaches() {
$this->remoteManager
->resetRemoteInfos();
$this->remoteManager
->resetHttpClientsCache('json_api');
$this->remoteManager
->resetResponseMapping();
}
protected function reimportChannel(array $channel_infos, string $channel_id = NULL) {
if (empty($channel_id)) {
$channel_id = static::$entityTypeId . '_' . static::$entityBundleId . '_' . static::$entityLangcode;
}
$channel_url = $channel_infos[$channel_id]['url'];
$response = $this->remoteManager
->jsonApiRequest($this->remote, 'GET', $channel_url);
$json = Json::decode((string) $response
->getBody());
$this
->deleteContent();
$this->entities = [];
$import_context = new ImportContext($this->remote
->id(), $channel_id, $this::IMPORT_CONFIG_ID);
$this->importService
->prepareImport($import_context);
$this->importService
->importEntityListData(EntityShareUtility::prepareData($json['data']));
}
}