View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\entity_share_client\Functional;
use Drupal\Core\Url;
class BlockFieldTest extends EntityShareClientFunctionalTestBase {
public static $modules = [
'jsonapi_extras',
];
protected static $entityTypeId = 'node';
protected static $entityBundleId = 'es_test';
protected static $entityLangcode = 'en';
protected function setUp() : void {
parent::setUp();
$this->entityTypeManager
->getStorage('jsonapi_resource_config')
->create([
'id' => 'node--es_test',
'disabled' => FALSE,
'path' => 'node/es_test',
'resourceType' => 'node--es_test',
'resourceFields' => [
'field_es_test_block' => [
'fieldName' => 'field_es_test_block',
'publicName' => 'field_es_test_block',
'enhancer' => [
'id' => 'entity_share_block_field',
],
'disabled' => FALSE,
],
],
])
->save();
$this
->postSetupFixture();
}
protected function getImportConfigProcessorSettings() {
$processors = parent::getImportConfigProcessorSettings();
$processors['block_field_block_content_importer'] = [
'max_recursion_depth' => -1,
'weights' => [
'prepare_importable_entity_data' => 20,
],
];
return $processors;
}
protected function getEntitiesDataArray() {
return [
'block_content' => [
'en' => [
'block_content_test' => $this
->getCompleteBlockInfos([]),
],
],
'node' => [
'en' => [
'es_test_block' => $this
->getCompleteNodeInfos([
'field_es_test_block' => [
'value_callback' => function () {
return [
[
'plugin_id' => 'system_powered_by_block',
'settings' => [
'id' => 'system_powered_by_block',
'label' => 'Powered by Drupal',
'provider' => 'system',
'label_display' => 'visible',
],
],
[
'plugin_id' => 'block_content:block_content_test',
'settings' => [
'id' => 'block_content:block_content_test',
'label' => 'Test',
'provider' => 'block_content',
'label_display' => 'visible',
'status' => TRUE,
'info' => '',
'view_mode' => 'full',
],
],
];
},
'checker_callback' => 'getFilteredStructureValues',
],
]),
],
],
];
}
public function testBlockFieldBlockContentImporterPlugin() {
$this
->pullEveryChannels();
$this
->checkCreatedEntities();
$this
->removePluginFromImportConfig('block_field_block_content_importer');
$recreated_node = $this
->loadEntity('node', 'es_test_block');
$recreated_node
->delete();
$recreated_block_entity = $this
->loadEntity('block_content', 'block_content_test');
$recreated_block_entity
->delete();
$this
->pullEveryChannels();
$recreated_node = $this
->loadEntity('node', 'es_test_block');
$this
->assertNotNull($recreated_node, 'The node with UUID es_test_block has been recreated.');
$recreated_block_entity = $this
->loadEntity('block_content', 'block_content_test');
$this
->assertNull($recreated_block_entity, 'The block_content with UUID block_content_test has not been recreated.');
}
protected function populateRequestService() {
parent::populateRequestService();
$route_name = sprintf('jsonapi.%s--%s.individual', 'block_content', 'es_test');
$url = Url::fromRoute($route_name, [
'entity' => 'block_content_test',
])
->setOption('language', $this->container
->get('language_manager')
->getLanguage('en'))
->setOption('absolute', TRUE);
$this->remoteManager
->jsonApiRequest($this->remote, 'GET', $url
->toString());
}
}