diff --git a/.github/workflows/build-2.x.yml b/.github/workflows/build-2.x.yml index 230e247..17a6726 100644 --- a/.github/workflows/build-2.x.yml +++ b/.github/workflows/build-2.x.yml @@ -21,8 +21,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ["7.4", "8.0", "8.1"] - drupal-version: ["9.3.x", "9.4.x", "9.5.x-dev"] + php-versions: ["8.0", "8.1"] + drupal-version: ["9.5.x"] env: DRUPAL_VERSION: ${{ matrix.drupal-version }} diff --git a/.github/workflows/build-3.x.yml b/.github/workflows/build-3.x.yml new file mode 100644 index 0000000..eb70911 --- /dev/null +++ b/.github/workflows/build-3.x.yml @@ -0,0 +1,111 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the action will run. +on: + # Triggers the workflow on push or pull request events but only for the 8.x branch + push: + branches: [ 3.x ] + pull_request: + branches: [ 3.x ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: ["8.1"] + drupal-version: ["10.0.x", "10.1.x-dev"] + + env: + DRUPAL_VERSION: ${{ matrix.drupal-version }} + SCRIPT_DIR: ${{ github.workspace }}/islandora_ci + DRUPAL_DIR: /opt/drupal + DRUPAL_WEB_ROOT: /opt/drupal/web + PHPUNIT_FILE: ${{ github.workspace }}/build_dir/phpunit.xml + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: drupal + ports: + - 3306:3306 + activemq: + image: webcenter/activemq:5.14.3 + ports: + - 8161:8161 + - 61616:61616 + - 61613:61613 + + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - name: Checkout code + uses: actions/checkout@v2 + with: + path: build_dir + + - name: Checkout islandora_ci + uses: actions/checkout@v2 + with: + repository: islandora/islandora_ci + ref: github-actions + path: islandora_ci + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + tools: composer:v2 + + - name: Setup Mysql client + run: | + sudo apt-get update + sudo apt-get install -y mysql-client + + - name: Cache Composer dependencies + uses: actions/cache@v2 + with: + path: /tmp/composer-cache + key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} + + - name: Setup Drupal + run: | + mkdir $DRUPAL_DIR + $SCRIPT_DIR/travis_setup_drupal.sh + cd $DRUPAL_DIR + chmod -R u+w web/sites/default + mkdir -p web/sites/simpletest/browser_output + + - name: Setup composer paths + run: | + git -C "$GITHUB_WORKSPACE/build_dir" checkout -b github-testing + cd $DRUPAL_DIR + composer config repositories.local path "$GITHUB_WORKSPACE/build_dir" + composer config minimum-stability dev + composer require "islandora/jsonld:dev-github-testing as dev-2.x" --prefer-source -W + + - name: Install modules + run: | + cd $DRUPAL_DIR/web + drush --uri=127.0.0.1:8282 en -y user jsonld + + - name: Copy PHPunit file + run: cp $PHPUNIT_FILE $DRUPAL_DIR/web/core/phpunit.xml + + - name: Test scripts + run: $SCRIPT_DIR/travis_scripts.sh + + # Unit test config is defined in the module's phpunit.xml file. + - name: PHPUNIT tests + run: | + cd $DRUPAL_DIR/web/core + $DRUPAL_DIR/vendor/bin/phpunit --verbose --debug diff --git a/README.md b/README.md index bca292d..fe82c04 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,9 @@ ## Introduction -JSON-LD Serializer for Drupal 8 and Islandora. +JSON-LD Serializer for Drupal 10 and Islandora. + +NOTE: This 3.x branch is compatible with Drupal 10. For progress in D10 compatibility with the rest of Islandora, see [ticket](https://github.com/Islandora/documentation/issues/2235). This module adds a simple Drupal entity to JSON-LD `normalizer/serializer/unserializer` service provider and a few supporting diff --git a/composer.json b/composer.json index 3d1a93f..652a24e 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,9 @@ } ], "require" : { - "php": ">=7.4" + "php": ">=7.4", + "drupal/hal": "^1||^2", + "drupal/rdf": "^2.1" }, "require-dev": { "phpunit/phpunit": "^8", diff --git a/jsonld.info.yml b/jsonld.info.yml index 53e9b62..8fd21d4 100644 --- a/jsonld.info.yml +++ b/jsonld.info.yml @@ -2,8 +2,8 @@ name: 'JSON-LD' type: module description: 'Serializes entities to JSON-LD / LDP for the Islandora Project' package: Web services -core_version_requirement: ^9 +core_version_requirement: ^10 dependencies: - - hal - - serialization - - rdf + - drupal:serialization + - hal:hal + - rdf:rdf diff --git a/src/ContextGenerator/JsonldContextGenerator.php b/src/ContextGenerator/JsonldContextGenerator.php index f9a2cc8..b0ccc7e 100644 --- a/src/ContextGenerator/JsonldContextGenerator.php +++ b/src/ContextGenerator/JsonldContextGenerator.php @@ -333,9 +333,8 @@ protected function getTermContextFromField($field_type) { // yet for this instance. if (empty($this->fieldMappings)) { // Cribbed from rdf module's rdf_get_namespaces. - foreach (\Drupal::moduleHandler()->getImplementations(self::FIELD_MAPPPINGS_HOOK) as $module) { - $function = $module . '_' . self::FIELD_MAPPPINGS_HOOK; - foreach ($function() as $field => $mapping) { + \Drupal::moduleHandler()->invokeAllWith(self::FIELD_MAPPPINGS_HOOK, function (callable $hook, string $module) { + foreach ($hook() as $field => $mapping) { if (array_key_exists($field, $this->fieldMappings)) { $this->logger->warning( t('Tried to map @field_type to @new_type, but @field_type is already mapped to @orig_type.', [ @@ -349,7 +348,7 @@ protected function getTermContextFromField($field_type) { $this->fieldMappings[$field] = $mapping; } } - } + }); } return array_key_exists($field_type, $this->fieldMappings) ? $this->fieldMappings[$field_type] : $default_mapping; } diff --git a/src/Encoder/JsonldEncoder.php b/src/Encoder/JsonldEncoder.php index 72e8537..aee2ec0 100644 --- a/src/Encoder/JsonldEncoder.php +++ b/src/Encoder/JsonldEncoder.php @@ -22,7 +22,7 @@ class JsonldEncoder extends SymfonyJsonEncoder { /** * {@inheritdoc} */ - public function supportsEncoding($format) { + public function supportsEncoding(string $format): bool { return $format == $this->format; } @@ -30,7 +30,7 @@ public function supportsEncoding($format) { /** * {@inheritdoc} */ - public function supportsDecoding($format) { + public function supportsDecoding(string $format): bool { return $format == $this->format; } diff --git a/src/Normalizer/NormalizerBase.php b/src/Normalizer/NormalizerBase.php index b8a40ac..65802fb 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, $format = NULL) { + public function supportsNormalization($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, $format = NULL) { /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = NULL) { + 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/tests/src/Functional/JsonldContextGeneratorTest.php b/tests/src/Functional/JsonldContextGeneratorTest.php index 649e4f3..3f9e0f9 100644 --- a/tests/src/Functional/JsonldContextGeneratorTest.php +++ b/tests/src/Functional/JsonldContextGeneratorTest.php @@ -94,7 +94,7 @@ public function testJsonldcontextContentypeheaderResponseIsValid() { ); $this->drupalGet($url); $this->assertSession()->statusCodeEquals(200); - $this->assertEquals($this->drupalGetHeader('Content-Type'), 'application/ld+json', 'Correct JSON-LD mime type was returned'); + $this->assertEquals($this->getSession()->getResponseHeader('Content-Type'), 'application/ld+json', 'Correct JSON-LD mime type was returned'); } /** @@ -121,7 +121,7 @@ public function testJsonldcontextResponseIsValid() { $this->drupalGet($url); $this->assertSession()->statusCodeEquals(200); $jsonldarray = json_decode($this->getSession()->getPage()->getContent(), TRUE); - $this->verbose($jsonldarray); + dump($jsonldarray); $this->assertEquals($expected, $jsonldarray, "Returned @context matches expected response."); } diff --git a/tests/src/Kernel/JsonldContextGeneratorTest.php b/tests/src/Kernel/JsonldContextGeneratorTest.php index 85d5c99..ecbafe3 100644 --- a/tests/src/Kernel/JsonldContextGeneratorTest.php +++ b/tests/src/Kernel/JsonldContextGeneratorTest.php @@ -17,7 +17,7 @@ class JsonldContextGeneratorTest extends JsonldKernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'entity_test', 'hal', 'jsonld', diff --git a/tests/src/Kernel/JsonldHookTest.php b/tests/src/Kernel/JsonldHookTest.php index b7ae0b7..ccfc17b 100644 --- a/tests/src/Kernel/JsonldHookTest.php +++ b/tests/src/Kernel/JsonldHookTest.php @@ -13,7 +13,7 @@ class JsonldHookTest extends JsonldKernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'entity_test', 'hal', 'jsonld', diff --git a/tests/src/Kernel/JsonldKernelTestBase.php b/tests/src/Kernel/JsonldKernelTestBase.php index 24c8e8f..13d05b4 100644 --- a/tests/src/Kernel/JsonldKernelTestBase.php +++ b/tests/src/Kernel/JsonldKernelTestBase.php @@ -24,7 +24,7 @@ abstract class JsonldKernelTestBase extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'system', 'user', 'field', diff --git a/tests/src/Kernel/JsonldTestEntityGenerator.php b/tests/src/Kernel/JsonldTestEntityGenerator.php index 8d5c4f1..13fca31 100644 --- a/tests/src/Kernel/JsonldTestEntityGenerator.php +++ b/tests/src/Kernel/JsonldTestEntityGenerator.php @@ -158,7 +158,7 @@ public function makeDuplicateReferenceMapping(): JsonldTestEntityGenerator { * Error saving the entity. */ public function generateNewEntity(): array { - $dt = new \DateTime(NULL, new \DateTimeZone('UTC')); + $dt = new \DateTime('now', new \DateTimeZone('UTC')); $created = $dt->format("U"); $created_iso = $dt->format(\DateTime::W3C); // Create an entity.