You are here

protected function EntityShareClientFunctionalTestBase::checkCreatedEntities 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::checkCreatedEntities()

Helper function that test that the entities had been recreated.

15 calls to EntityShareClientFunctionalTestBase::checkCreatedEntities()
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.
BasicFieldsTest::testBasicPull in modules/entity_share_client/tests/src/Functional/BasicFieldsTest.php
Test basic pull feature.
BlockFieldTest::testBlockFieldBlockContentImporterPlugin in modules/entity_share_client/tests/src/Functional/BlockFieldTest.php
Test behavior when plugin "Block field block content" is not enabled.
ChangedRemovedTest::testBasicPull in modules/entity_share_client/tests/src/Functional/ChangedRemovedTest.php
Test basic pull feature.

... See full list

File

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

Class

EntityShareClientFunctionalTestBase
Base class for Entity Share Client functional tests.

Namespace

Drupal\Tests\entity_share_client\Functional

Code

protected function checkCreatedEntities() {
  $entities_data = $this
    ->getEntitiesData();
  foreach ($entities_data as $entity_type_id => $data_per_languages) {
    $entity_storage = $this->entityTypeManager
      ->getStorage($entity_type_id);
    foreach ($data_per_languages as $language_id => $entity_data) {
      foreach ($entity_data as $entity_uuid => $entity_data_per_field) {

        /** @var \Drupal\Core\Entity\ContentEntityInterface[] $recreated_entities */
        $recreated_entities = $entity_storage
          ->loadByProperties([
          'uuid' => $entity_uuid,
        ]);

        // Check that the entity has been recreated.
        $this
          ->assertTrue(!empty($recreated_entities), 'The ' . $entity_type_id . ' with UUID ' . $entity_uuid . ' has been recreated.');

        // Check the values.
        if (!empty($recreated_entities)) {
          $recreated_entity = array_shift($recreated_entities);
          $entity_translation = $recreated_entity
            ->getTranslation($language_id);
          foreach ($entity_data_per_field as $field_machine_name => $data) {

            // Some data are dynamic.
            if (isset($data['value_callback'])) {
              $data['value'] = call_user_func($data['value_callback']);
            }

            // When additional keys in field data are created by Drupal. We
            // need to filter this structure.
            if ($data['checker_callback'] == 'getFilteredStructureValues') {

              // Assume that also for single value fields, the data will be
              // set using an array of values.
              $structure = array_keys($data['value'][0]);
              $this
                ->assertEquals($data['value'], $this
                ->getFilteredStructureValues($entity_translation, $field_machine_name, $structure), 'The data of the field ' . $field_machine_name . ' has been recreated.');
            }
            else {
              $this
                ->assertEquals($data['value'], $this
                ->{$data['checker_callback']}($entity_translation, $field_machine_name), 'The data of the field ' . $field_machine_name . ' has been recreated.');
            }
          }
        }
      }
    }
  }
}