From 8db4c553f7babe4c9bdf570d0c6a486dca1a58e1 Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Wed, 30 Oct 2024 13:10:08 -0400 Subject: [PATCH] Add Drupal 11 support (#83) * Add Drupal 11 support * Update build-3.x.yml * verbose no longer support in phpunit * Remove drupal/core dependency * Drop <=10.2 support * compatible with Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize * Remove installSchema per https://www.drupal.org/node/3349345 * Add Drupal 11 getSupportedTypes on normalizers --- .github/workflows/build-3.x.yml | 10 +++++-- composer.json | 3 +- jsonld.info.yml | 2 +- .../JsonldContextGenerator.php | 14 +++++----- src/Controller/JsonldContextController.php | 6 ++-- src/Normalizer/ContentEntityNormalizer.php | 24 ++++++++++++---- .../EntityReferenceItemNormalizer.php | 27 ++++++++++++------ src/Normalizer/FieldItemNormalizer.php | 19 +++++++++---- src/Normalizer/FieldNormalizer.php | 13 +++++++-- src/Normalizer/FileEntityNormalizer.php | 28 +++++++++++++------ src/Normalizer/NormalizerBase.php | 4 +-- src/Utils/JsonldNormalizerUtils.php | 2 +- tests/json_alter_normalize_hooks.info.yml | 2 +- tests/src/Kernel/JsonldHookTest.php | 2 +- tests/src/Kernel/JsonldKernelTestBase.php | 6 ++-- .../src/Kernel/JsonldTestEntityGenerator.php | 2 +- .../JsonldContentEntityNormalizerTest.php | 10 +++---- 17 files changed, 114 insertions(+), 60 deletions(-) diff --git a/.github/workflows/build-3.x.yml b/.github/workflows/build-3.x.yml index 6850f13..2759ce2 100644 --- a/.github/workflows/build-3.x.yml +++ b/.github/workflows/build-3.x.yml @@ -22,8 +22,12 @@ jobs: strategy: matrix: php-versions: ["8.1", "8.2", "8.3"] - drupal-version: ["10.2.x", "10.3.x", "10.4.x-dev"] - + drupal-version: ["10.3.x", "10.4.x-dev", "11.0.x"] + exclude: + - drupal-version: "11.0.x" + php-versions: "8.1" + - drupal-version: "11.0.x" + php-versions: "8.2" env: DRUPAL_VERSION: ${{ matrix.drupal-version }} SCRIPT_DIR: ${{ github.workspace }}/islandora_ci @@ -108,4 +112,4 @@ jobs: - name: PHPUNIT tests run: | cd $DRUPAL_DIR/web/core - $DRUPAL_DIR/vendor/bin/phpunit --verbose --debug + $DRUPAL_DIR/vendor/bin/phpunit --debug diff --git a/composer.json b/composer.json index ed38a9d..7a57292 100644 --- a/composer.json +++ b/composer.json @@ -23,9 +23,8 @@ "islandora/jsonld": "self.version" }, "require" : { - "drupal/core": "^10", "drupal/hal": "^1||^2", - "drupal/rdf": "^2.1" + "drupal/rdf": "^3.0@beta" }, "require-dev": { "phpunit/phpunit": "^8", diff --git a/jsonld.info.yml b/jsonld.info.yml index 8fd21d4..6d4101e 100644 --- a/jsonld.info.yml +++ b/jsonld.info.yml @@ -2,7 +2,7 @@ name: 'JSON-LD' type: module description: 'Serializes entities to JSON-LD / LDP for the Islandora Project' package: Web services -core_version_requirement: ^10 +core_version_requirement: ^10.3 || ^11 dependencies: - drupal:serialization - hal:hal diff --git a/src/ContextGenerator/JsonldContextGenerator.php b/src/ContextGenerator/JsonldContextGenerator.php index b0ccc7e..a18a284 100644 --- a/src/ContextGenerator/JsonldContextGenerator.php +++ b/src/ContextGenerator/JsonldContextGenerator.php @@ -2,14 +2,14 @@ namespace Drupal\jsonld\ContextGenerator; -use Drupal\Core\Entity\EntityFieldManagerInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Entity\EntityFieldManagerInterface; +use Drupal\Core\Entity\EntityTypeBundleInfoInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\FieldDefinitionInterface; -use Drupal\rdf\RdfMappingInterface; use Drupal\rdf\Entity\RdfMapping; +use Drupal\rdf\RdfMappingInterface; use Psr\Log\LoggerInterface; /** @@ -206,7 +206,7 @@ public function getFieldsRdf(RdfMappingInterface $rdfMapping, $field_name, Field // Now we start overriding from config entity defined mappings. // Assume all non defined mapping types as "property". - $reltype = isset($fieldRDFMapping['mapping_type']) ? $fieldRDFMapping['mapping_type'] : 'property'; + $reltype = $fieldRDFMapping['mapping_type'] ?? 'property'; if (isset($fieldRDFMapping['datatype']) && ($reltype == 'property')) { $termDefinition = ['@type' => $fieldRDFMapping['datatype']]; @@ -277,7 +277,7 @@ protected function writeCache(RdfMappingInterface $rdfMapping, $cid) { * And array with the entity type and the bundle id */ protected function entityBundleIdsSplitter($ids) { - list($entity_type_id, $bundle_id) = explode(".", $ids, 2); + [$entity_type_id, $bundle_id] = explode(".", $ids, 2); return ['entityTypeId' => $entity_type_id, 'bundleId' => $bundle_id]; } @@ -297,7 +297,7 @@ protected function entityBundleIdsSplitter($ids) { */ protected function parseCompactedIri($iri) { // As naive as it gets. - list($prefix, $rest) = array_pad(explode(":", $iri, 2), 2, ''); + [$prefix, $rest] = array_pad(explode(":", $iri, 2), 2, ''); if ((substr($rest, 0, 2) == "//") || ($prefix == $iri)) { // Means this was never a compacted IRI. return ['prefix' => NULL, 'term' => $iri]; diff --git a/src/Controller/JsonldContextController.php b/src/Controller/JsonldContextController.php index 8cd8b6e..6566712 100644 --- a/src/Controller/JsonldContextController.php +++ b/src/Controller/JsonldContextController.php @@ -2,15 +2,15 @@ namespace Drupal\jsonld\Controller; +use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableJsonResponse; +use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Controller\ControllerBase; use Drupal\jsonld\ContextGenerator\JsonldContextGeneratorInterface; +use Drupal\rdf\Entity\RdfMapping; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Drupal\rdf\Entity\RdfMapping; -use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; /** * Controller for retrieving jsonld contexts. diff --git a/src/Normalizer/ContentEntityNormalizer.php b/src/Normalizer/ContentEntityNormalizer.php index bd8ce60..b57e5ee 100644 --- a/src/Normalizer/ContentEntityNormalizer.php +++ b/src/Normalizer/ContentEntityNormalizer.php @@ -3,6 +3,7 @@ namespace Drupal\jsonld\Normalizer; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\hal\LinkManager\LinkManagerInterface; @@ -63,10 +64,12 @@ class ContentEntityNormalizer extends NormalizerBase { * @param \Drupal\Jsonld\Utils\JsonldNormalizerUtilsInterface $normalizer_utils * The json-ld normalizer utilities. */ - public function __construct(LinkManagerInterface $link_manager, - EntityTypeManagerInterface $entity_manager, - ModuleHandlerInterface $module_handler, - JsonldNormalizerUtilsInterface $normalizer_utils) { + public function __construct( + LinkManagerInterface $link_manager, + EntityTypeManagerInterface $entity_manager, + ModuleHandlerInterface $module_handler, + JsonldNormalizerUtilsInterface $normalizer_utils, + ) { $this->linkManager = $link_manager; $this->entityManager = $entity_manager; @@ -77,7 +80,7 @@ public function __construct(LinkManagerInterface $link_manager, /** * {@inheritdoc} */ - public function normalize($entity, $format = NULL, array $context = []) { + public function normalize($entity, $format = NULL, array $context = []): array|bool|string|int|float|null|\ArrayObject { // We need to make sure that this only runs for JSON-LD. // @todo check $format before going RDF crazy @@ -195,7 +198,7 @@ public function normalize($entity, $format = NULL, array $context = []) { /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = NULL, array $context = []) { + public function denormalize(mixed $data, string $class, ?string $format = NULL, array $context = []) : mixed { // Get type, necessary for determining which bundle to create. if (!isset($data['_links']['type'])) { @@ -304,4 +307,13 @@ protected function getTypedDataIds(array $types, array $context = []) { return $typed_data_ids; } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + ContentEntityInterface::class => TRUE, + ]; + } + } diff --git a/src/Normalizer/EntityReferenceItemNormalizer.php b/src/Normalizer/EntityReferenceItemNormalizer.php index e504661..a88bfee 100644 --- a/src/Normalizer/EntityReferenceItemNormalizer.php +++ b/src/Normalizer/EntityReferenceItemNormalizer.php @@ -3,6 +3,7 @@ namespace Drupal\jsonld\Normalizer; use Drupal\Core\Entity\FieldableEntityInterface; +use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem; use Drupal\hal\LinkManager\LinkManagerInterface; use Drupal\jsonld\ContextGenerator\JsonldContextGeneratorInterface; use Drupal\serialization\EntityResolver\EntityResolverInterface; @@ -44,9 +45,11 @@ class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidR * @param \Drupal\jsonld\ContextGenerator\JsonldContextGeneratorInterface $jsonld_context * The Json-Ld context service. */ - public function __construct(LinkManagerInterface $link_manager, - EntityResolverInterface $entity_Resolver, - JsonldContextGeneratorInterface $jsonld_context) { + public function __construct( + LinkManagerInterface $link_manager, + EntityResolverInterface $entity_Resolver, + JsonldContextGeneratorInterface $jsonld_context, + ) { parent::__construct($jsonld_context); $this->linkManager = $link_manager; $this->entityResolver = $entity_Resolver; @@ -55,7 +58,7 @@ public function __construct(LinkManagerInterface $link_manager, /** * {@inheritdoc} */ - public function normalize($field_item, $format = NULL, array $context = []) { + public function normalize($field_item, $format = NULL, array $context = []): array|bool|string|int|float|null|\ArrayObject { /** @var \Drupal\Core\Field\FieldItemInterface $field_item */ $target_entity = $field_item->get('entity')->getValue(); @@ -68,7 +71,7 @@ public function normalize($field_item, $format = NULL, array $context = []) { // If the parent entity passed in a langcode, unset it before normalizing // the target entity. Otherwise, untranslatable fields of the target entity // will include the langcode. - $langcode = isset($context['langcode']) ? $context['langcode'] : NULL; + $langcode = $context['langcode'] ?? NULL; unset($context['langcode']); // Limiting to uuid makes sure that we only get one child from base entity // if not we could end traversing forever since there is no way @@ -90,15 +93,14 @@ public function normalize($field_item, $format = NULL, array $context = []) { $field_item->getParent() ->getName() ); - $field_keys = isset($field_mappings['properties']) ? - $field_mappings['properties'] : + $field_keys = $field_mappings['properties'] ?? [$field_item->getParent()->getName()]; // Value in this case is the target entity, so if a callback exists // it should work against that. if (!empty($field_mappings['datatype_callback'])) { $callback = $field_mappings['datatype_callback']['callable']; - $arguments = isset($field_mappings['datatype_callback']['arguments']) ? $field_mappings['datatype_callback']['arguments'] : NULL; + $arguments = $field_mappings['datatype_callback']['arguments'] ?? NULL; $transformed_value = call_user_func($callback, $target_entity, $arguments); // If the config says it is an @id, we'll save it as an @id. if (!empty($field_mappings['datatype']) && $field_mappings['datatype'] == '@id') { @@ -178,4 +180,13 @@ public function getUuid($data) { } } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + EntityReferenceItem::class => TRUE, + ]; + } + } diff --git a/src/Normalizer/FieldItemNormalizer.php b/src/Normalizer/FieldItemNormalizer.php index efaecd5..d5405e5 100644 --- a/src/Normalizer/FieldItemNormalizer.php +++ b/src/Normalizer/FieldItemNormalizer.php @@ -38,7 +38,7 @@ public function __construct(JsonldContextGeneratorInterface $jsonld_context) { /** * {@inheritdoc} */ - public function normalize($field_item, $format = NULL, array $context = []) { + public function normalize($field_item, $format = NULL, array $context = []): array|bool|string|int|float|null|\ArrayObject { // @todo Understand Drupal complex fields to RDF mapping // Fields can be complex, with multiple subfields @@ -57,14 +57,14 @@ public function normalize($field_item, $format = NULL, array $context = []) { } else { // Set the uri here, and then convert it to '@id' later on. - $values_clean['@value'] = isset($values['value']) ? $values['value'] : $values['uri']; + $values_clean['@value'] = $values['value'] ?? $values['uri']; if (isset($context['current_entity_rdf_mapping'])) { // So why i am passing the whole rdf mapping object and not // only the predicate? Well because i hope i will be able // to MAP to RDF also sub fields of a complex field someday // and somehow. $field_mappings = $context['current_entity_rdf_mapping']->getPreparedFieldMapping($field->getName()); - $field_keys = isset($field_mappings['properties']) ? $field_mappings['properties'] : [$field->getName()]; + $field_keys = $field_mappings['properties'] ?? [$field->getName()]; if (!empty($field_mappings['datatype'])) { $values_clean['@type'] = $field_mappings['datatype']; @@ -76,7 +76,7 @@ public function normalize($field_item, $format = NULL, array $context = []) { // For now this is a dirty solution. if (!empty($field_mappings['datatype_callback'])) { $callback = $field_mappings['datatype_callback']['callable']; - $arguments = isset($field_mappings['datatype_callback']['arguments']) ? $field_mappings['datatype_callback']['arguments'] : NULL; + $arguments = $field_mappings['datatype_callback']['arguments'] ?? NULL; $values_clean['@value'] = call_user_func($callback, $values, $arguments); } $field_context = $this->jsonldContextgenerator->getFieldsRdf( @@ -138,7 +138,7 @@ public function normalize($field_item, $format = NULL, array $context = []) { /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = NULL, array $context = []) { + public function denormalize(mixed $data, string $class, ?string $format = NULL, array $context = []) : mixed { if (!isset($context['target_instance'])) { throw new InvalidArgumentException('$context[\'target_instance\'] must be set to denormalize with the FieldItemNormalizer'); @@ -210,4 +210,13 @@ protected function createTranslatedInstance(FieldItemInterface $item, $langcode) return $entity_translation->get($field_name)->appendItem(); } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + FieldItemInterface::class => TRUE, + ]; + } + } diff --git a/src/Normalizer/FieldNormalizer.php b/src/Normalizer/FieldNormalizer.php index e2a8eaf..ad58d1e 100644 --- a/src/Normalizer/FieldNormalizer.php +++ b/src/Normalizer/FieldNormalizer.php @@ -21,7 +21,7 @@ class FieldNormalizer extends NormalizerBase { /** * {@inheritdoc} */ - public function normalize($field, $format = NULL, array $context = []) { + public function normalize($field, $format = NULL, array $context = []): array|bool|string|int|float|null|\ArrayObject { $normalized_field_items = []; @@ -62,7 +62,7 @@ public function normalize($field, $format = NULL, array $context = []) { /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = NULL, array $context = []) { + public function denormalize(mixed $data, string $class, ?string $format = NULL, array $context = []) : mixed { if (!isset($context['target_instance'])) { throw new InvalidArgumentException('$context[\'target_instance\'] must be set to denormalize with the FieldNormalizer'); @@ -110,4 +110,13 @@ protected function normalizeFieldItems(FieldItemListInterface $field, $format, a return $normalized_field_items; } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + FieldItemListInterface::class => TRUE, + ]; + } + } diff --git a/src/Normalizer/FileEntityNormalizer.php b/src/Normalizer/FileEntityNormalizer.php index 356f169..d5e006a 100644 --- a/src/Normalizer/FileEntityNormalizer.php +++ b/src/Normalizer/FileEntityNormalizer.php @@ -5,6 +5,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\File\FileSystemInterface; +use Drupal\file\FileInterface; use Drupal\hal\LinkManager\LinkManagerInterface; use Drupal\jsonld\Utils\JsonldNormalizerUtilsInterface; use GuzzleHttp\ClientInterface; @@ -51,12 +52,14 @@ class FileEntityNormalizer extends ContentEntityNormalizer { * @param \Drupal\jsonld\Utils\JsonldNormalizerUtilsInterface $normalizer_utils * The json-ld normalizer utils. */ - public function __construct(EntityTypeManagerInterface $entity_manager, - ClientInterface $http_client, - LinkManagerInterface $link_manager, - ModuleHandlerInterface $module_handler, - FileSystemInterface $file_system, - JsonldNormalizerUtilsInterface $normalizer_utils) { + public function __construct( + EntityTypeManagerInterface $entity_manager, + ClientInterface $http_client, + LinkManagerInterface $link_manager, + ModuleHandlerInterface $module_handler, + FileSystemInterface $file_system, + JsonldNormalizerUtilsInterface $normalizer_utils, + ) { parent::__construct($link_manager, $entity_manager, $module_handler, $normalizer_utils); @@ -67,7 +70,7 @@ public function __construct(EntityTypeManagerInterface $entity_manager, /** * {@inheritdoc} */ - public function normalize($entity, $format = NULL, array $context = []) { + public function normalize($entity, $format = NULL, array $context = []): array|bool|string|int|float|null|\ArrayObject { $data = parent::normalize($entity, $format, $context); // Replace the file url with a full url for the file. @@ -79,7 +82,7 @@ public function normalize($entity, $format = NULL, array $context = []) { /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = NULL, array $context = []) { + public function denormalize(mixed $data, string $class, ?string $format = NULL, array $context = []) : mixed { $file_data = (string) $this->httpClient->get($data['uri'][0]['value'])->getBody(); @@ -89,4 +92,13 @@ public function denormalize($data, $class, $format = NULL, array $context = []) return $this->entityManager->getStorage('file')->create($data); } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + FileInterface::class => TRUE, + ]; + } + } diff --git a/src/Normalizer/NormalizerBase.php b/src/Normalizer/NormalizerBase.php index 65802fb..64c794c 100644 --- a/src/Normalizer/NormalizerBase.php +++ b/src/Normalizer/NormalizerBase.php @@ -20,7 +20,7 @@ abstract class NormalizerBase extends SerializationNormalizerBase implements Den /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = NULL, array $context = []): bool { + public function supportsNormalization(mixed $data, ?string $format = NULL, array $context = []): bool { return in_array($format, $this->formats) && parent::supportsNormalization($data, $format); } @@ -28,7 +28,7 @@ public function supportsNormalization($data, string $format = NULL, array $conte /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = NULL, array $context = []): bool { + public function supportsDenormalization($data, string $type, ?string $format = NULL, array $context = []): bool { if (in_array($format, $this->formats) && (class_exists($this->supportedInterfaceOrClass) || interface_exists($this->supportedInterfaceOrClass))) { $target = new \ReflectionClass($type); diff --git a/src/Utils/JsonldNormalizerUtils.php b/src/Utils/JsonldNormalizerUtils.php index 66b291f..24cb000 100644 --- a/src/Utils/JsonldNormalizerUtils.php +++ b/src/Utils/JsonldNormalizerUtils.php @@ -51,7 +51,7 @@ class JsonldNormalizerUtils implements JsonldNormalizerUtilsInterface { public function __construct( ConfigFactoryInterface $config_factory, LanguageManagerInterface $language_manager, - RouteProviderInterface $route_provider + RouteProviderInterface $route_provider, ) { $this->config = $config_factory->get(JsonLdSettingsForm::CONFIG_NAME); $this->languageManager = $language_manager; diff --git a/tests/json_alter_normalize_hooks.info.yml b/tests/json_alter_normalize_hooks.info.yml index 5b4d1d0..4630f27 100644 --- a/tests/json_alter_normalize_hooks.info.yml +++ b/tests/json_alter_normalize_hooks.info.yml @@ -1,6 +1,6 @@ name: 'Jsonld hook tests' type: module package: Testing -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8 || ^9 || ^10 || ^11 dependencies: - jsonld diff --git a/tests/src/Kernel/JsonldHookTest.php b/tests/src/Kernel/JsonldHookTest.php index ccfc17b..a837e42 100644 --- a/tests/src/Kernel/JsonldHookTest.php +++ b/tests/src/Kernel/JsonldHookTest.php @@ -37,7 +37,7 @@ public function setUp() : void { */ public function testAlterNormalizedJsonld() { - list($entity, $expected) = JsonldTestEntityGenerator::create()->generateNewEntity(); + [$entity, $expected] = JsonldTestEntityGenerator::create()->generateNewEntity(); $expected['@graph'][] = [ "@id" => "json_alter_normalize_hooks", "http://purl.org/dc/elements/1.1/title" => "The hook is tested.", diff --git a/tests/src/Kernel/JsonldKernelTestBase.php b/tests/src/Kernel/JsonldKernelTestBase.php index 13d05b4..f0c28c9 100644 --- a/tests/src/Kernel/JsonldKernelTestBase.php +++ b/tests/src/Kernel/JsonldKernelTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\jsonld\Kernel; +use Drupal\KernelTests\KernelTestBase; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\jsonld\Encoder\JsonldEncoder; @@ -10,11 +11,10 @@ use Drupal\jsonld\Normalizer\FieldItemNormalizer; use Drupal\jsonld\Normalizer\FieldNormalizer; use Drupal\jsonld\Utils\JsonldNormalizerUtils; -use Drupal\KernelTests\KernelTestBase; +use Drupal\language\Entity\ConfigurableLanguage; use Drupal\serialization\EntityResolver\ChainEntityResolver; use Drupal\serialization\EntityResolver\TargetIdResolver; use Symfony\Component\Serializer\Serializer; -use Drupal\language\Entity\ConfigurableLanguage; /** * Base class for Json-LD Kernel tests. @@ -116,8 +116,6 @@ protected function setUp() : void { $class = get_parent_class($class); } - $this->installSchema('system', ['sequences']); - $types = ['schema:Thing']; $created_mapping = [ 'properties' => ['schema:dateCreated'], diff --git a/tests/src/Kernel/JsonldTestEntityGenerator.php b/tests/src/Kernel/JsonldTestEntityGenerator.php index 13fca31..a632936 100644 --- a/tests/src/Kernel/JsonldTestEntityGenerator.php +++ b/tests/src/Kernel/JsonldTestEntityGenerator.php @@ -2,8 +2,8 @@ namespace Drupal\Tests\jsonld\Kernel; -use Drupal\entity_test\Entity\EntityTest; use Drupal\Tests\RandomGeneratorTrait; +use Drupal\entity_test\Entity\EntityTest; use Drupal\user\Entity\User; /** diff --git a/tests/src/Kernel/Normalizer/JsonldContentEntityNormalizerTest.php b/tests/src/Kernel/Normalizer/JsonldContentEntityNormalizerTest.php index 1a9cce6..fff0176 100644 --- a/tests/src/Kernel/Normalizer/JsonldContentEntityNormalizerTest.php +++ b/tests/src/Kernel/Normalizer/JsonldContentEntityNormalizerTest.php @@ -33,7 +33,7 @@ protected function setUp() :void { */ public function testSimpleNormalizeJsonld() { - list($entity, $expected) = JsonldTestEntityGenerator::create()->generateNewEntity(); + [$entity, $expected] = JsonldTestEntityGenerator::create()->generateNewEntity(); $normalized = $this->serializer->normalize($entity, $this->format); $this->assertEquals($expected, $normalized, "Did not normalize correctly."); @@ -52,7 +52,7 @@ public function testSimpleNormalizeJsonld() { */ public function testLocalizedNormalizeJsonld() { - list($entity, $expected) = JsonldTestEntityGenerator::create()->generateNewEntity(); + [$entity, $expected] = JsonldTestEntityGenerator::create()->generateNewEntity(); $existing_entity_values = $entity->toArray(); $target_entity_tl_id = $existing_entity_values['field_test_entity_reference'][0]['target_id']; @@ -96,7 +96,7 @@ public function testLocalizedNormalizeJsonld() { */ public function testDeduplicateEntityReferenceMappings(): void { - list($entity, $expected) = JsonldTestEntityGenerator::create()->makeDuplicateReferenceMapping()->generateNewEntity(); + [$entity, $expected] = JsonldTestEntityGenerator::create()->makeDuplicateReferenceMapping()->generateNewEntity(); $normalized = $this->serializer->normalize($entity, $this->format); @@ -108,7 +108,7 @@ public function testDeduplicateEntityReferenceMappings(): void { */ public function testDeduplicateEntityReferenceIds(): void { - list($entity, $expected) = JsonldTestEntityGenerator::create()->makeDuplicateReference()->generateNewEntity(); + [$entity, $expected] = JsonldTestEntityGenerator::create()->makeDuplicateReference()->generateNewEntity(); $normalized = $this->serializer->normalize($entity, $this->format); @@ -122,7 +122,7 @@ public function testDeduplicateEntityReferenceIds(): void { * - sharing the same RDF mapping. */ public function testDuplicateEntityReferenceAndMappings(): void { - list($entity, $expected) = JsonldTestEntityGenerator::create()->makeDuplicateReference()->makeDuplicateReferenceMapping() + [$entity, $expected] = JsonldTestEntityGenerator::create()->makeDuplicateReference()->makeDuplicateReferenceMapping() ->generateNewEntity(); $normalized = $this->serializer->normalize($entity, $this->format);