InfiniteLoopTest.php in Entity Share 8.3
File
modules/entity_share_client/tests/src/Functional/InfiniteLoopTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\entity_share_client\Functional;
use Drupal\node\NodeInterface;
class InfiniteLoopTest extends EntityShareClientFunctionalTestBase {
protected static $entityTypeId = 'node';
protected static $entityBundleId = 'es_test';
protected static $entityLangcode = 'en';
protected function setUp() : void {
parent::setUp();
$this
->postSetupFixture();
}
protected function prepareContent() {
$node_storage = $this->entityTypeManager
->getStorage('node');
$node_1 = $node_storage
->create([
'uuid' => 'es_test_content_reference_one',
'type' => static::$entityBundleId,
'title' => $this
->randomString(),
'status' => NodeInterface::PUBLISHED,
]);
$node_1
->save();
$node_2 = $node_storage
->create([
'uuid' => 'es_test_content_reference_two',
'type' => static::$entityBundleId,
'title' => $this
->randomString(),
'status' => NodeInterface::PUBLISHED,
'field_es_test_content_reference' => $node_1
->id(),
]);
$node_2
->save();
$node_1
->set('field_es_test_content_reference', $node_2
->id());
$node_1
->save();
$this->entities = [
'node' => [
'es_test_content_reference_one' => $node_1,
'es_test_content_reference_two' => $node_2,
],
];
}
protected function getEntitiesDataArray() {
return [];
}
public function testInfiniteLoop() {
$selected_entities = [
'es_test_content_reference_one',
];
$this
->infiniteLoopTestHelper($selected_entities);
$this
->resetImportedContent();
$selected_entities = [
'es_test_content_reference_two',
];
$this
->infiniteLoopTestHelper($selected_entities);
}
protected function populateRequestService() {
parent::populateRequestService();
$selected_entities = [
'es_test_content_reference_one',
];
$prepared_url = $this
->prepareUrlFilteredOnUuids($selected_entities, 'node_es_test_en');
$this
->discoverJsonApiEndpoints($prepared_url);
$selected_entities = [
'es_test_content_reference_two',
];
$prepared_url = $this
->prepareUrlFilteredOnUuids($selected_entities, 'node_es_test_en');
$this
->discoverJsonApiEndpoints($prepared_url);
}
protected function infiniteLoopTestHelper(array $selected_entities) {
$this
->importSelectedEntities($selected_entities);
$uuids = [
'es_test_content_reference_one',
'es_test_content_reference_two',
];
foreach ($uuids as $uuid) {
$node = $this
->loadEntity('node', $uuid);
$this
->assertTrue($node instanceof NodeInterface, 'The node with the uuid ' . $uuid . ' has been recreated.');
}
}
}
Classes
Name |
Description |
InfiniteLoopTest |
Functional test class for infinite loop in content entity reference field. |