Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Merge pull request #85 from openeuropa/EWPP-2997
Browse files Browse the repository at this point in the history
EWPP-2997: Drupal 10 compatibility.
  • Loading branch information
brummbar authored Mar 10, 2023
2 parents 1a6d2ef + ec12ec5 commit 3f54e91
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 87 deletions.
36 changes: 11 additions & 25 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,14 @@ services:
- NODE_MAX_SESSION=5

pipeline:
composer-install-lowest:
composer-install:
group: prepare
image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
volumes:
- /cache:/cache
- /cache/${DRONE_REPO_NAME}:/cache
commands:
- composer self-update --2
- composer update --prefer-lowest --prefer-stable --ansi --no-progress
when:
matrix:
COMPOSER_BOUNDARY: lowest

composer-install-highest:
group: prepare
image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
volumes:
- /cache:/cache
commands:
- composer self-update --2
- composer install --ansi --no-progress
when:
matrix:
COMPOSER_BOUNDARY: highest
- composer self-update --2
- composer require drupal/core:~${CORE_VERSION} drupal/core-composer-scaffold:~${CORE_VERSION} drupal/core-dev:~${CORE_VERSION} --update-with-all-dependencies --ansi --no-progress --no-interaction

site-install:
image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
Expand All @@ -78,9 +63,10 @@ pipeline:
- ./vendor/bin/phpunit

matrix:
COMPOSER_BOUNDARY:
- lowest
- highest
PHP_VERSION:
- 8.0
- 8.1
include:
- CORE_VERSION: 9.4.0
PHP_VERSION: 8.0
- CORE_VERSION: 9.4.0
PHP_VERSION: 8.1
- CORE_VERSION: 10.0
PHP_VERSION: 8.1
37 changes: 8 additions & 29 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,17 @@
"require": {
"php": ">=8.0",
"cweagans/composer-patches": "~1.4",
"drupal/core": "^9.4",
"drupal/core": "^9.4 || ^10",
"drupal/remote_stream_wrapper": "^2.0"
},
"require-dev": {
"behat/mink-selenium2-driver": "^1.5",
"composer/installers": "~1.5",
"drupal/core-composer-scaffold": "^9.4",
"drupal/config_devel": "~1.2",
"drupal/drupal-extension": "dev-master as 4.0",
"composer/installers": "^1.11",
"drupal/core-composer-scaffold": "^9.4 || ^10",
"drupal/core-dev": "^9.4 || ^10",
"drush/drush": "^11.1",
"guzzlehttp/guzzle": "^7.0",
"mikey179/vfsstream": "^1.6.10",
"nikic/php-parser": "^4.12.0",
"openeuropa/code-review": "^2.0.0-alpha6",
"openeuropa/task-runner-drupal-project-symlink": "^1.0-beta6",
"phpspec/prophecy-phpunit": "^2",
"symfony/console": "^4.4.30",
"symfony/css-selector": "^4.4.24",
"symfony/dom-crawler": "^4.4.44",
"symfony/finder": "^4.4.30",
"symfony/http-foundation": "^4.4.30",
"symfony/phpunit-bridge": "^6.0",
"symfony/process": "^4.4.30",
"symfony/routing": "^4.4.30",
"symfony/validator": "^4.4.35",
"symfony/yaml": "^4.4.29"
"phpspec/prophecy-phpunit": "^2"
},
"scripts": {
"post-install-cmd": "./vendor/bin/run drupal:site-setup",
Expand Down Expand Up @@ -73,14 +58,7 @@
"locations": {
"web-root": "./build"
}
},
"_readme": [
"Use master branch of drupal/drupal-extension to replace fabpot/goutte with behat/mink-browserkit-driver.",
"Explicit minimum version requirement of symfony/phpunit-bridge to replace drupal/core-dev testing classes and traits.",
"Explicit minimum version requirement of mikey179/vfsstream due to lower versions missing return type on vfsStreamDirectory::getIterator() method.",
"Explicit minimum version requirement of guzzlehttp/guzzle due to lower versions missing return type on CookieJar::getIterator() and CookieJar::count() methods.",
"Explicit minimum version requirement of symfony packages due to lower versions missing return type on various methods being incompatible with PHP 8.1 parent methods."
]
}
},
"config": {
"sort-packages": true,
Expand All @@ -89,7 +67,8 @@
"dealerdirect/phpcodesniffer-composer-installer": true,
"drupal/core-composer-scaffold": true,
"cweagans/composer-patches": true,
"phpro/grumphp": true
"phpro/grumphp": true,
"phpstan/extension-installer": true
}
}
}
2 changes: 1 addition & 1 deletion media_avportal.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'Media AV Portal'
description: 'Media AV Portal adds European Audiovisual Services as a supported media provider.'
type: module
package: Media
core_version_requirement: ^9.4
core_version_requirement: ^9.4 || ^10
dependencies:
- drupal:media
- remote_stream_wrapper:remote_stream_wrapper
8 changes: 4 additions & 4 deletions runner.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ drupal:
# Prepare the instance.
- "./vendor/bin/drush en toolbar -y"
# themes
- "./vendor/bin/drush theme:enable bartik -y"
- "./vendor/bin/drush theme:enable seven -y"
- "./vendor/bin/drush config-set system.theme default bartik -y"
- "./vendor/bin/drush config-set system.theme admin seven -y"
- "./vendor/bin/drush theme:enable olivero -y"
- "./vendor/bin/drush theme:enable claro -y"
- "./vendor/bin/drush config-set system.theme default olivero -y"
- "./vendor/bin/drush config-set system.theme admin claro -y"
- "./vendor/bin/drush config-set node.settings use_admin_theme 1 -y"
# Enable the modules.
- "./vendor/bin/drush en media_avportal -y"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Media AV Portal Mock'
description: 'Provides a middleware for the returning mocked responses from AV Portal. Do not use this in production.'
core_version_requirement: ^9.4
core_version_requirement: ^9.4 || ^10
type: module
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ services:
- { name: http_client_middleware }
media_avportal_mock.client_middleware:
class: Drupal\media_avportal_mock\AvPortalClientMiddleware
arguments: ['@config.factory', '@event_dispatcher']
arguments: ['@config.factory', '@event_dispatcher', '@extension.list.module']
tags:
- { name: http_client_middleware }
media_avportal_mock.event_subscriber:
class: Drupal\media_avportal_mock\EventSubscriber\AvPortalMockEventSubscriber
arguments: ['@extension.list.module']
tags:
- { name: event_subscriber }
17 changes: 14 additions & 3 deletions tests/modules/media_avportal_mock/src/AvPortalClientMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Drupal\media_avportal_mock;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleExtensionList;
use GuzzleHttp\Promise\FulfilledPromise;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Psr7\Response;
Expand Down Expand Up @@ -36,17 +37,27 @@ class AvPortalClientMiddleware {
*/
protected $eventDispatcher;

/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected ModuleExtensionList $moduleExtensionList;

/**
* AvPortalClientMiddleware constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The config factory.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
* The event dispatcher.
* @param \Drupal\Core\Extension\ModuleExtensionList|null $moduleExtensionList
* The module extension list.
*/
public function __construct(ConfigFactoryInterface $configFactory, EventDispatcherInterface $eventDispatcher) {
public function __construct(ConfigFactoryInterface $configFactory, EventDispatcherInterface $eventDispatcher, ModuleExtensionList $moduleExtensionList = NULL) {
$this->configFactory = $configFactory;
$this->eventDispatcher = $eventDispatcher;
$this->moduleExtensionList = $moduleExtensionList ?? \Drupal::service('extension.list.module');
}

/**
Expand All @@ -67,7 +78,7 @@ public function __invoke() {

// AV Portal thumbnails.
if ($uri->getHost() === 'defiris.ec.streamcloud.be' || strpos($uri->getPath(), 'avservices/avs/files/video6/repository/prod/photo/store/')) {
$thumbnail = file_get_contents(drupal_get_path('module', 'media') . '/images/icons/no-thumbnail.png');
$thumbnail = file_get_contents($this->moduleExtensionList->getPath('media') . '/images/icons/no-thumbnail.png');
$response = new Response(200, [], $thumbnail);
return new FulfilledPromise($response);
}
Expand All @@ -93,7 +104,7 @@ public function __invoke() {
protected function createServicePromise(RequestInterface $request): PromiseInterface {
// Dispatch event to gather the JSON data for responses.
$event = new AvPortalMockEvent($request);
$event = $this->eventDispatcher->dispatch(AvPortalMockEvent::AV_PORTAL_MOCK_EVENT, $event);
$event = $this->eventDispatcher->dispatch($event, AvPortalMockEvent::AV_PORTAL_MOCK_EVENT);

$uri = $request->getUri();
$query = $uri->getQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Drupal\media_avportal_mock;

use Symfony\Contracts\EventDispatcher\Event;
use Psr\Http\Message\RequestInterface;
use Symfony\Component\EventDispatcher\Event;

/**
* Event used to collect the mocking JSON data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Drupal\media_avportal_mock\EventSubscriber;

use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\media_avportal_mock\AvPortalMockEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

Expand All @@ -12,6 +13,23 @@
*/
class AvPortalMockEventSubscriber implements EventSubscriberInterface {

/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected ModuleExtensionList $moduleExtensionList;

/**
* Creates a new instance of the class.
*
* @param \Drupal\Core\Extension\ModuleExtensionList $moduleExtensionList
* The module extension list.
*/
public function __construct(ModuleExtensionList $moduleExtensionList) {
$this->moduleExtensionList = $moduleExtensionList;
}

/**
* {@inheritdoc}
*/
Expand All @@ -33,15 +51,15 @@ public static function getSubscribedEvents() {
*/
public function setMockResources(AvPortalMockEvent $event) {
$resources = $event->getResources();
foreach (glob(drupal_get_path('module', 'media_avportal_mock') . '/responses/resources/*.json') as $file) {
foreach (glob($this->moduleExtensionList->getPath('media_avportal_mock') . '/responses/resources/*.json') as $file) {
$ref = str_replace('.json', '', basename($file));
$resources[$ref] = file_get_contents($file);
}

$event->setResources($resources);

$searches = $event->getSearches();
foreach (glob(drupal_get_path('module', 'media_avportal_mock') . '/responses/searches/*.json') as $file) {
foreach (glob($this->moduleExtensionList->getPath('media_avportal_mock') . '/responses/searches/*.json') as $file) {
$ref = str_replace('.json', '', basename($file));
if (!isset($searches[$ref])) {
// We only add the default search if another subscriber did not yet
Expand All @@ -51,13 +69,13 @@ public function setMockResources(AvPortalMockEvent $event) {
}
$event->setSearches($searches);
if (!$event->getDefault('video')) {
$event->setDefault(file_get_contents(drupal_get_path('module', 'media_avportal_mock') . '/responses/video-default.json'), 'video');
$event->setDefault(file_get_contents($this->moduleExtensionList->getPath('media_avportal_mock') . '/responses/video-default.json'), 'video');
}
if (!$event->getDefault('all')) {
$event->setDefault(file_get_contents(drupal_get_path('module', 'media_avportal_mock') . '/responses/all-default.json'), 'all');
$event->setDefault(file_get_contents($this->moduleExtensionList->getPath('media_avportal_mock') . '/responses/all-default.json'), 'all');
}
if (!$event->getDefault('photo')) {
$event->setDefault(file_get_contents(drupal_get_path('module', 'media_avportal_mock') . '/responses/photo-default.json'), 'photo');
$event->setDefault(file_get_contents($this->moduleExtensionList->getPath('media_avportal_mock') . '/responses/photo-default.json'), 'photo');
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'Media AV Portal Responsive Test'
description: 'Test module for the Responsive image style'
type: module
core_version_requirement: ^9.4
core_version_requirement: ^9.4 || ^10
package: Testing

dependencies:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Media AV Portal Test'
description: 'Provides configuration media bundles for testing purpose.'
core_version_requirement: ^9.4
core_version_requirement: ^9.4 || ^10
type: module
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MediaAvPortalCreateContentTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'classy';
protected $defaultTheme = 'starterkit_theme';

/**
* Modules to enable.
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/AvPortalClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AvPortalClientTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
protected function setUp(): void {
parent::setUp();

$this->installConfig(['media_avportal']);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/AvPortalPullMediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AvPortalPullMediaTest extends MediaKernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
protected static $modules = [
'system',
'remote_stream_wrapper',
'media_avportal',
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/AvPortalStreamWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AvPortalStreamWrapperTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
protected function setUp(): void {
parent::setUp();
$this->installConfig(['media_avportal']);
}
Expand Down
17 changes: 6 additions & 11 deletions tests/src/Unit/AvPortalClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AvPortalClientTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
protected function setUp(): void {
parent::setUp();

$this->configFactory = $this->getConfigFactoryStub([
Expand All @@ -52,13 +52,9 @@ protected function setUp() {
],
]);

$this->cacheBackend = $this->getMockBuilder(CacheBackendInterface::class)
->disableOriginalConstructor()
->getMock();
$this->cacheBackend = $this->createMock(CacheBackendInterface::class);

$this->time = $this->getMockBuilder(TimeInterface::class)
->disableOriginalConstructor()
->getMock();
$this->time = $this->createMock(TimeInterface::class);
}

/**
Expand All @@ -74,8 +70,9 @@ protected function setUp() {
*/
public function testQueryOptions(array $input, array $expected): void {
$http_client = $this->getMockBuilder(Client::class)
->setMethods(['request'])
->onlyMethods(['request'])
->getMock();

$http_client
->expects($this->once())
->method('request')
Expand All @@ -98,9 +95,7 @@ public function testQueryOptions(array $input, array $expected): void {
* @dataProvider invalidQueryOptionsDataProvider
*/
public function testInvalidQueryOptions(array $input, string $message) {
$http_client = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->getMock();
$http_client = $this->createMock(Client::class);

$client = new AvPortalClient($http_client, $this->configFactory, $this->cacheBackend, $this->time, FALSE);
$this->expectException(\InvalidArgumentException::class);
Expand Down

0 comments on commit 3f54e91

Please sign in to comment.