ContentEntityReferenceTest.php in Entity Share 8.2
File
modules/entity_share_client/tests/src/Functional/ContentEntityReferenceTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\entity_share_client\Functional;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\entity_share\EntityShareUtility;
use Drupal\node\NodeInterface;
class ContentEntityReferenceTest extends EntityShareClientFunctionalTestBase {
protected static $entityTypeId = 'node';
protected static $entityBundleId = 'es_test';
protected static $entityLangcode = 'en';
protected function setUp() {
parent::setUp();
$this
->postSetupFixture();
}
protected function getEntitiesDataArray() {
return [
'node' => [
'en' => [
'es_test_to_be_referenced' => $this
->getCompleteNodeInfos([
'status' => [
'value' => NodeInterface::PUBLISHED,
'checker_callback' => 'getValue',
],
]),
'es_test_content_reference' => $this
->getCompleteNodeInfos([
'field_es_test_content_reference' => [
'value_callback' => function () {
return [
[
'target_id' => $this
->getEntityId('node', 'es_test_to_be_referenced'),
],
];
},
'checker_callback' => 'getExpectedContentReferenceValue',
],
]),
],
],
];
}
public function testReferenceEntityValue() {
$this
->pullEveryChannels();
$this
->checkCreatedEntities();
}
public function testReferencedEntityCreated() {
$selected_entities = [
'es_test_content_reference',
];
$prepared_url = $this
->prepareUrlFilteredOnUuids($selected_entities, 'node_es_test_en');
$this->jsonapiHelper
->setRemote($this->remote);
$http_client = $this->remoteManager
->prepareJsonApiClient($this->remote);
$response = $this->requestService
->request($http_client, 'GET', $prepared_url);
$json = Json::decode((string) $response
->getBody());
$this->jsonapiHelper
->importEntityListData(EntityShareUtility::prepareData($json['data']));
$this
->checkCreatedEntities();
}
protected function getExpectedContentReferenceValue(ContentEntityInterface $entity, string $field_name) {
return [
[
'target_id' => $this
->getEntityId('node', 'es_test_to_be_referenced'),
],
];
}
protected function populateRequestService() {
parent::populateRequestService();
$selected_entities = [
'es_test_content_reference',
];
$prepared_url = $this
->prepareUrlFilteredOnUuids($selected_entities, 'node_es_test_en');
$this->jsonapiHelper
->setRemote($this->remote);
$http_client = $this->remoteManager
->prepareJsonApiClient($this->remote);
$this
->discoverJsonApiEndpoints($http_client, $prepared_url);
}
}