You are here

protected function MultilingualTest::overrideJsonDataAttributes in Entity Share 8.3

Override attributes of entity's JSON:API data.

Parameters

array $overrides: Manipulations to do on attributes.

array $attributes: Original attributes of JSON:API data of an entity.

Return value

array Altered attributes of JSON:API data of an entity.

1 call to MultilingualTest::overrideJsonDataAttributes()
MultilingualTest::expectedState in modules/entity_share_client/tests/src/Functional/MultilingualTest.php
Helper function.

File

modules/entity_share_client/tests/src/Functional/MultilingualTest.php, line 230

Class

MultilingualTest
General functional test class for multilingual scenarios.

Namespace

Drupal\Tests\entity_share_client\Functional

Code

protected function overrideJsonDataAttributes(array $overrides, array $attributes) {
  foreach ($overrides as $override_type) {
    switch ($override_type) {
      case 'fast_forward_changed_time':

        // Sets the 'changed' time of JSON data to one hour in the future.
        $resource_type = $this->resourceTypeRepository
          ->get(static::$entityTypeId, static::$entityBundleId);

        // Determine public name of 'changed'.
        $changed_public_name = FALSE;
        if ($resource_type
          ->hasField('changed')) {
          $changed_public_name = $resource_type
            ->getPublicName('changed');
        }
        $changed = $attributes[$changed_public_name] ?? FALSE;
        if ($changed !== FALSE) {
          $changed_timestamp = EntityShareUtility::convertChangedTime($changed);
          $attributes['changed'] = (string) ($changed_timestamp + 3600);
        }
        break;
    }
  }
  return $attributes;
}