You are here

protected function EntityShareClientFunctionalTestBase::prepareContent in Entity Share 8.3

Same name and namespace in other branches
  1. 8.2 modules/entity_share_client/tests/src/Functional/EntityShareClientFunctionalTestBase.php \Drupal\Tests\entity_share_client\Functional\EntityShareClientFunctionalTestBase::prepareContent()

Helper function to create the content required for the tests.

13 calls to EntityShareClientFunctionalTestBase::prepareContent()
AuthenticationBasicAuthTest::testImport in modules/entity_share_client/tests/src/Functional/AuthenticationBasicAuthTest.php
Test that correct entities are created with different authentications.
AuthenticationOAuthTest::testImport in modules/entity_share_client/tests/src/Functional/AuthenticationOAuthTest.php
Test that correct entities are created with different authentications.
AuthenticationTestBase::postSetupFixture in modules/entity_share_client/tests/src/Functional/AuthenticationTestBase.php
Helper function.
EmbeddedEntityTest::postSetupFixture in modules/entity_share_client/tests/src/Functional/EmbeddedEntityTest.php
Helper function.
EntityShareClientFunctionalTestBase::postSetupFixture in modules/entity_share_client/tests/src/Functional/EntityShareClientFunctionalTestBase.php
Helper function.

... See full list

1 method overrides EntityShareClientFunctionalTestBase::prepareContent()
InfiniteLoopTest::prepareContent in modules/entity_share_client/tests/src/Functional/InfiniteLoopTest.php
Helper function to create the content required for the tests.

File

modules/entity_share_client/tests/src/Functional/EntityShareClientFunctionalTestBase.php, line 447

Class

EntityShareClientFunctionalTestBase
Base class for Entity Share Client functional tests.

Namespace

Drupal\Tests\entity_share_client\Functional

Code

protected function prepareContent() {
  $entities_data = $this
    ->getEntitiesData();
  foreach ($entities_data as $entity_type_id => $data_per_languages) {
    $entity_storage = $this->entityTypeManager
      ->getStorage($entity_type_id);
    if (!isset($this->entities[$entity_type_id])) {
      $this->entities[$entity_type_id] = [];
    }
    foreach ($data_per_languages as $langcode => $entity_data) {
      foreach ($entity_data as $entity_uuid => $entity_data_per_field) {

        // If the entity has already been created, create a translation.
        if (isset($this->entities[$entity_type_id][$entity_uuid])) {
          $prepared_entity_data = $this
            ->prepareEntityData($entity_data_per_field);
          $entity = $this->entities[$entity_type_id][$entity_uuid];
          $entity
            ->addTranslation($langcode, $prepared_entity_data);
          $entity
            ->save();
        }
        else {
          $entity_data_per_field += [
            'langcode' => [
              'value' => $langcode,
              'checker_callback' => 'getValue',
            ],
            'uuid' => [
              'value' => $entity_uuid,
              'checker_callback' => 'getValue',
            ],
          ];
          $prepared_entity_data = $this
            ->prepareEntityData($entity_data_per_field);
          $entity = $entity_storage
            ->create($prepared_entity_data);
          $entity
            ->save();
        }
        $this->entities[$entity_type_id][$entity_uuid] = $entity;
      }
    }
  }
}