From 1405a09fa737a054565c8a3cb83a0faa2c5a658b Mon Sep 17 00:00:00 2001 From: Ankit Pathak <106175376+apathak18@users.noreply.github.com> Date: Sat, 5 Oct 2024 01:36:22 +0530 Subject: [PATCH 1/2] Adding D11 support for nextjs. (#778) --- .github/workflows/next.yml | 10 ++++- modules/next/.gitlab-ci.yml | 8 ++-- modules/next/composer.json | 2 +- .../modules/next_extras/next_extras.info.yml | 2 +- .../next_extras/src/NextCacheInvalidator.php | 3 +- .../next_graphql/next_graphql.info.yml | 2 +- .../next_jsonapi/next_jsonapi.info.yml | 2 +- .../src/NextJsonapiServiceProvider.php | 1 - .../Kernel/Controller/EntityResourceTest.php | 18 ++++---- .../next/modules/next_jwt/next_jwt.info.yml | 2 +- .../EventSubscriber/JwtEventSubscriber.php | 2 +- modules/next/next.info.yml | 2 +- modules/next/next.services.yml | 1 + .../EntityActionEventRevalidateSubscriber.php | 2 +- modules/next/src/Form/NextSettingsForm.php | 33 +++----------- modules/next/src/NextSettingsManager.php | 18 ++++++-- .../next/src/Plugin/Next/Revalidator/Path.php | 2 +- .../src/Plugin/Next/SitePreviewer/Iframe.php | 5 ++- .../modules/next_tests/next_tests.info.yml | 3 +- .../EntityActionEventSubscriber.php | 2 +- .../EntityRevalidatedEventSubscriber.php | 2 +- .../Kernel/Event/EntityActionEventTest.php | 43 ++++++++----------- .../Event/EntityRevalidatedEventTest.php | 7 +-- .../src/Kernel/NextSettingsManagerTest.php | 4 +- .../SimpleOauthPreviewUrlGeneratorTest.php | 2 +- 25 files changed, 87 insertions(+), 91 deletions(-) diff --git a/.github/workflows/next.yml b/.github/workflows/next.yml index d760149b7..32af03bb4 100644 --- a/.github/workflows/next.yml +++ b/.github/workflows/next.yml @@ -9,7 +9,7 @@ on: jobs: phpunit: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 strategy: matrix: # Supported PHP versions: https://www.drupal.org/docs/getting-started/system-requirements/php-requirements @@ -22,15 +22,21 @@ jobs: - "10.0.x" - "10.1.x" - "10.2.x" + - "10.3.x" + - "11.0.x" exclude: - drupal: "10.0.x" php: "8.3" - drupal: "10.1.x" php: "8.3" + - drupal: "11.0.x" + php: "8.1" + - drupal: "11.0.x" + php: "8.2" name: Drupal ${{ matrix.drupal }} - PHP ${{ matrix.php }} services: mysql: - image: mysql:5.7 + image: mysql:8.0 env: MYSQL_ALLOW_EMPTY_PASSWORD: yes MYSQL_DATABASE: db diff --git a/modules/next/.gitlab-ci.yml b/modules/next/.gitlab-ci.yml index 68f905280..fbc21c1dd 100644 --- a/modules/next/.gitlab-ci.yml +++ b/modules/next/.gitlab-ci.yml @@ -52,9 +52,11 @@ include: # # Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/includes/include.drupalci.variables.yml ################ -# variables: -# SKIP_ESLINT: '1' - +variables: + # SKIP_ESLINT: '1' + OPT_IN_TEST_PREVIOUS_MINOR: 1 + OPT_IN_TEST_NEXT_MINOR: 1 + OPT_IN_TEST_NEXT_MAJOR: 1 ################################################################################### # # * diff --git a/modules/next/composer.json b/modules/next/composer.json index 63e729775..093d6a36e 100644 --- a/modules/next/composer.json +++ b/modules/next/composer.json @@ -17,6 +17,6 @@ "drupal/subrequests": "^3.0" }, "require-dev": { - "phpunit/phpunit": "^6.0 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^9 || ^10" } } diff --git a/modules/next/modules/next_extras/next_extras.info.yml b/modules/next/modules/next_extras/next_extras.info.yml index da9ecaf1e..8c1fb15b6 100644 --- a/modules/next/modules/next_extras/next_extras.info.yml +++ b/modules/next/modules/next_extras/next_extras.info.yml @@ -1,7 +1,7 @@ name: Next.js Extras (Experimental) description: Adds extra (mostly experiemental) functionality to Next.js module type: module -core_version_requirement: ^9 || ^10 +core_version_requirement: ^10 || ^11 package: Web services dependencies: - next:next diff --git a/modules/next/modules/next_extras/src/NextCacheInvalidator.php b/modules/next/modules/next_extras/src/NextCacheInvalidator.php index 3afc174f1..93a7fa5cf 100644 --- a/modules/next/modules/next_extras/src/NextCacheInvalidator.php +++ b/modules/next/modules/next_extras/src/NextCacheInvalidator.php @@ -143,7 +143,8 @@ public function invalidatePath(string $path, array $sites): void { } } catch (RequestException $exception) { - watchdog_exception('next_extras', $exception); + // Using logger service to log the exception. + $this->logger->error($exception->getMessage()); } } } diff --git a/modules/next/modules/next_graphql/next_graphql.info.yml b/modules/next/modules/next_graphql/next_graphql.info.yml index 12105a81d..ce4a09892 100644 --- a/modules/next/modules/next_graphql/next_graphql.info.yml +++ b/modules/next/modules/next_graphql/next_graphql.info.yml @@ -1,7 +1,7 @@ name: 'Next.js GraphQL' type: module description: 'GraphQL for Next.js' -core_version_requirement: ^9 || ^10 +core_version_requirement: ^10 || ^11 package: Web services dependencies: - graphql:graphql diff --git a/modules/next/modules/next_jsonapi/next_jsonapi.info.yml b/modules/next/modules/next_jsonapi/next_jsonapi.info.yml index da67d7e1b..5ec228867 100644 --- a/modules/next/modules/next_jsonapi/next_jsonapi.info.yml +++ b/modules/next/modules/next_jsonapi/next_jsonapi.info.yml @@ -1,7 +1,7 @@ name: 'Next.js JSON:API' type: module description: 'JSON:API Helpers for Next.js' -core_version_requirement: ^9 || ^10 +core_version_requirement: ^10 || ^11 package: Web services dependencies: - decoupled_router:decoupled_router diff --git a/modules/next/modules/next_jsonapi/src/NextJsonapiServiceProvider.php b/modules/next/modules/next_jsonapi/src/NextJsonapiServiceProvider.php index 210e19ff6..ee6432af0 100644 --- a/modules/next/modules/next_jsonapi/src/NextJsonapiServiceProvider.php +++ b/modules/next/modules/next_jsonapi/src/NextJsonapiServiceProvider.php @@ -15,7 +15,6 @@ class NextJsonapiServiceProvider extends ServiceProviderBase { */ public function alter(ContainerBuilder $container) { /** @var \Symfony\Component\DependencyInjection\Definition $definition */ - if ($container->hasDefinition('jsonapi.entity_resource')) { $definition = $container->getDefinition('jsonapi.entity_resource'); $definition->setClass('Drupal\next_jsonapi\Controller\EntityResource'); diff --git a/modules/next/modules/next_jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php b/modules/next/modules/next_jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php index 71836cfd8..2540dd30c 100644 --- a/modules/next/modules/next_jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php +++ b/modules/next/modules/next_jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php @@ -8,7 +8,7 @@ use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\user\Entity\User; -use Symfony\Component\HttpFoundation\ParameterBag; +use Symfony\Component\HttpFoundation\InputBag; use Symfony\Component\HttpFoundation\Request; /** @@ -91,14 +91,14 @@ public function testPageLimit() { // Default using \Drupal\jsonapi\Query\OffsetPage::SIZE_MAX. $request = Request::create('/jsonapi/node/article'); - $request->query = new ParameterBag(); + $request->query = new InputBag(); $response = $entity_resource->getCollection($resource_type, $request); $data = $response->getResponseData()->getData(); $this->assertSame(50, $data->count()); // With page limit. $request = Request::create('/jsonapi/node/article'); - $request->query = new ParameterBag([ + $request->query = new InputBag([ 'page' => [ 'limit' => 10, ], @@ -109,7 +109,7 @@ public function testPageLimit() { // With page limit over size max. $request = Request::create('/jsonapi/node/article'); - $request->query = new ParameterBag([ + $request->query = new InputBag([ 'page' => [ 'limit' => 100, ], @@ -120,7 +120,7 @@ public function testPageLimit() { // With page limit and offset. $request = Request::create('/jsonapi/node/article'); - $request->query = new ParameterBag([ + $request->query = new InputBag([ 'page' => [ 'offset' => 2, 'limit' => 5, @@ -132,7 +132,7 @@ public function testPageLimit() { // With fields as sparse fieldset. $request = Request::create('/jsonapi/node/article'); - $request->query = new ParameterBag([ + $request->query = new InputBag([ 'fields' => [ 'node--article' => 'title', ], @@ -143,7 +143,7 @@ public function testPageLimit() { // Using sparse fieldset path override. $request = Request::create('/jsonapi/node/article'); - $request->query = new ParameterBag([ + $request->query = new InputBag([ 'fields' => [ 'node--article' => 'path,title', ], @@ -154,7 +154,7 @@ public function testPageLimit() { // Using sparse fieldset path override and limit. $request = Request::create('/jsonapi/node/article'); - $request->query = new ParameterBag([ + $request->query = new InputBag([ 'fields' => [ 'node--article' => 'path,title', ], @@ -168,7 +168,7 @@ public function testPageLimit() { // Using sparse fieldset path override and limit. $request = Request::create('/jsonapi/node/article'); - $request->query = new ParameterBag([ + $request->query = new InputBag([ 'fields' => [ 'node--article' => 'path,title', ], diff --git a/modules/next/modules/next_jwt/next_jwt.info.yml b/modules/next/modules/next_jwt/next_jwt.info.yml index 0943b180f..3cdce982f 100644 --- a/modules/next/modules/next_jwt/next_jwt.info.yml +++ b/modules/next/modules/next_jwt/next_jwt.info.yml @@ -1,7 +1,7 @@ name: Next.js JWT (Experimental) type: module description: 'Generates preview URLs using JSON Web Token' -core_version_requirement: ^9 || ^10 +core_version_requirement: ^10 || ^11 package: Web services dependencies: - next:next diff --git a/modules/next/modules/next_jwt/src/EventSubscriber/JwtEventSubscriber.php b/modules/next/modules/next_jwt/src/EventSubscriber/JwtEventSubscriber.php index 598a8ce07..b2bcb6560 100644 --- a/modules/next/modules/next_jwt/src/EventSubscriber/JwtEventSubscriber.php +++ b/modules/next/modules/next_jwt/src/EventSubscriber/JwtEventSubscriber.php @@ -43,7 +43,7 @@ public function __construct(AccountInterface $current_user, NextSettingsManagerI /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { $events[JwtAuthEvents::GENERATE][] = ['setStandardClaims', 100]; $events[JwtAuthEvents::GENERATE][] = ['setDrupalClaims', 99]; return $events; diff --git a/modules/next/next.info.yml b/modules/next/next.info.yml index 42872eb2f..2155082ec 100644 --- a/modules/next/next.info.yml +++ b/modules/next/next.info.yml @@ -1,7 +1,7 @@ name: Next.js description: Next.js + Drupal for Incremental Static Regeneration and Draft mode. type: module -core_version_requirement: ^9 || ^10 +core_version_requirement: ^10 || ^11 package: Web services configure: entity.next_site.collection dependencies: diff --git a/modules/next/next.services.yml b/modules/next/next.services.yml index b5afca86c..e2628724d 100644 --- a/modules/next/next.services.yml +++ b/modules/next/next.services.yml @@ -21,6 +21,7 @@ services: '@config.factory', '@plugin.manager.next.site_previewer', '@plugin.manager.next.preview_url_generator', + '@logger.channel.next', ] next.preview_secret_generator: class: Drupal\next\PreviewSecretGenerator diff --git a/modules/next/src/EventSubscriber/EntityActionEventRevalidateSubscriber.php b/modules/next/src/EventSubscriber/EntityActionEventRevalidateSubscriber.php index 461f4d4ef..6f776dbc8 100644 --- a/modules/next/src/EventSubscriber/EntityActionEventRevalidateSubscriber.php +++ b/modules/next/src/EventSubscriber/EntityActionEventRevalidateSubscriber.php @@ -17,7 +17,7 @@ class EntityActionEventRevalidateSubscriber extends EntityActionEventSubscriberB /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { $events[EntityEvents::ENTITY_ACTION] = ['onAction']; return $events; } diff --git a/modules/next/src/Form/NextSettingsForm.php b/modules/next/src/Form/NextSettingsForm.php index 9d1b41815..3ade1db21 100644 --- a/modules/next/src/Form/NextSettingsForm.php +++ b/modules/next/src/Form/NextSettingsForm.php @@ -2,7 +2,6 @@ namespace Drupal\next\Form; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\SubformState; @@ -22,7 +21,7 @@ class NextSettingsForm extends ConfigFormBase { * * @var \Drupal\next\Plugin\SitePreviewerManagerInterface */ - protected $sitePreviewerManager; + protected SitePreviewerManagerInterface $sitePreviewerManager; /** * The preview url generator manager. @@ -31,34 +30,16 @@ class NextSettingsForm extends ConfigFormBase { */ protected PreviewUrlGeneratorManagerInterface $previewUrlGeneratorManager; - /** - * NextSettingsForm constructor. - * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory service. - * @param \Drupal\next\Plugin\SitePreviewerManagerInterface $site_previewer_manager - * The site previewer manager. - * @param \Drupal\next\Plugin\PreviewUrlGeneratorManagerInterface $preview_url_generator_manager - * The preview url generator manager. - */ - public function __construct(ConfigFactoryInterface $config_factory, SitePreviewerManagerInterface $site_previewer_manager, PreviewUrlGeneratorManagerInterface $preview_url_generator_manager = NULL) { - if (!$preview_url_generator_manager) { - @trigger_error('Calling NextSettingsForm::__construct() without the $preview_url_generator_manager argument is deprecated in next:1.3.0 and will be required in next:2.0.0. See https://www.drupal.org/node/3308330', E_USER_DEPRECATED); - // @codingStandardsIgnoreStart - $preview_url_generator_manager = \Drupal::service('plugin.manager.next.preview_url_generator'); - // @codingStandardsIgnoreEnd - } - - parent::__construct($config_factory); - $this->sitePreviewerManager = $site_previewer_manager; - $this->previewUrlGeneratorManager = $preview_url_generator_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static($container->get('config.factory'), $container->get('plugin.manager.next.site_previewer'), $container->get('plugin.manager.next.preview_url_generator')); + $instance = parent::create($container); + + $instance->sitePreviewerManager = $container->get('plugin.manager.next.site_previewer'); + $instance->previewUrlGeneratorManager = $container->get('plugin.manager.next.preview_url_generator'); + + return $instance; } /** diff --git a/modules/next/src/NextSettingsManager.php b/modules/next/src/NextSettingsManager.php index fb7af1d12..f51410266 100644 --- a/modules/next/src/NextSettingsManager.php +++ b/modules/next/src/NextSettingsManager.php @@ -9,6 +9,7 @@ use Drupal\next\Plugin\PreviewUrlGeneratorManagerInterface; use Drupal\next\Plugin\SitePreviewerInterface; use Drupal\next\Plugin\SitePreviewerManagerInterface; +use Psr\Log\LoggerInterface; /** * Provides a service for next settings. @@ -36,6 +37,13 @@ class NextSettingsManager implements NextSettingsManagerInterface { */ protected PreviewUrlGeneratorManagerInterface $previewUrlGeneratorManager; + /** + * A logger instance. + * + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + /** * NextSettingsManager constructor. * @@ -45,11 +53,14 @@ class NextSettingsManager implements NextSettingsManagerInterface { * The site previewer plugin manager. * @param \Drupal\next\Plugin\PreviewUrlGeneratorManagerInterface $preview_url_generator_manager * The preview url generator plugin manager. + * @param \Psr\Log\LoggerInterface $logger + * The logger instance. */ - public function __construct(ConfigFactoryInterface $config, SitePreviewerManagerInterface $site_previewer_manager, PreviewUrlGeneratorManagerInterface $preview_url_generator_manager) { + public function __construct(ConfigFactoryInterface $config, SitePreviewerManagerInterface $site_previewer_manager, PreviewUrlGeneratorManagerInterface $preview_url_generator_manager, LoggerInterface $logger) { $this->config = $config; $this->sitePreviewerManager = $site_previewer_manager; $this->previewUrlGeneratorManager = $preview_url_generator_manager; + $this->logger = $logger; } /** @@ -86,7 +97,7 @@ public function getSitePreviewer(): ?SitePreviewerInterface { return $site_previewer; } catch (PluginException $exception) { - watchdog_exception('next_drupal', $exception); + $this->logger->error($exception->getMessage()); return NULL; } @@ -105,8 +116,7 @@ public function getPreviewUrlGenerator(): ?PreviewUrlGeneratorInterface { return $preview_url_generator; } catch (PluginException $exception) { - - watchdog_exception('next_drupal', $exception); + $this->logger->error($exception->getMessage()); return NULL; } diff --git a/modules/next/src/Plugin/Next/Revalidator/Path.php b/modules/next/src/Plugin/Next/Revalidator/Path.php index af95288e8..559ef03fa 100644 --- a/modules/next/src/Plugin/Next/Revalidator/Path.php +++ b/modules/next/src/Plugin/Next/Revalidator/Path.php @@ -116,7 +116,7 @@ public function revalidate(EntityActionEvent $event): bool { } } catch (\Exception $exception) { - watchdog_exception('next', $exception); + $this->logger->error($exception->getMessage()); $revalidated = FALSE; } } diff --git a/modules/next/src/Plugin/Next/SitePreviewer/Iframe.php b/modules/next/src/Plugin/Next/SitePreviewer/Iframe.php index d7a36b159..9c902ab24 100644 --- a/modules/next/src/Plugin/Next/SitePreviewer/Iframe.php +++ b/modules/next/src/Plugin/Next/SitePreviewer/Iframe.php @@ -211,8 +211,9 @@ public function render(EntityInterface $entity, array $sites) { // Handle revisions. if ($entity instanceof RevisionableInterface && !$entity->isDefaultRevision()) { - /** @var \Drupal\Core\Entity\RevisionableInterface $revision */ - $revision = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->loadRevision($entity->getRevisionId()); + /** @var \Drupal\Core\Entity\RevisionableStorageInterface $entity_storage */ + $entity_storage = $this->entityTypeManager->getStorage($entity->getEntityTypeId()); + $revision = $entity_storage->loadRevision($entity->getRevisionId()); $build['toolbar']['links']['#links']['status'] = [ 'title' => $this->t('Revision: @date', [ diff --git a/modules/next/tests/modules/next_tests/next_tests.info.yml b/modules/next/tests/modules/next_tests/next_tests.info.yml index 36cafe015..39395bbc2 100644 --- a/modules/next/tests/modules/next_tests/next_tests.info.yml +++ b/modules/next/tests/modules/next_tests/next_tests.info.yml @@ -1,7 +1,6 @@ name: Next.js tests description: Configures testing for Next.js type: module -package: testing -core_version_requirement: ^8.8 || ^9 +package: Testing dependencies: - next:next diff --git a/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityActionEventSubscriber.php b/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityActionEventSubscriber.php index 8824c415c..7edd362e6 100644 --- a/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityActionEventSubscriber.php +++ b/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityActionEventSubscriber.php @@ -32,7 +32,7 @@ public function __construct(LoggerChannelInterface $logger) { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { $events[EntityEvents::ENTITY_ACTION] = ['onAction']; return $events; } diff --git a/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityRevalidatedEventSubscriber.php b/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityRevalidatedEventSubscriber.php index a30b30f83..0667b01fe 100644 --- a/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityRevalidatedEventSubscriber.php +++ b/modules/next/tests/modules/next_tests/src/EventSubscriber/EntityRevalidatedEventSubscriber.php @@ -32,7 +32,7 @@ public function __construct(LoggerChannelInterface $logger) { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { $events[EntityEvents::ENTITY_REVALIDATED] = ['onRevalidated']; return $events; } diff --git a/modules/next/tests/src/Kernel/Event/EntityActionEventTest.php b/modules/next/tests/src/Kernel/Event/EntityActionEventTest.php index 4af09b250..4f4e9905b 100644 --- a/modules/next/tests/src/Kernel/Event/EntityActionEventTest.php +++ b/modules/next/tests/src/Kernel/Event/EntityActionEventTest.php @@ -2,8 +2,6 @@ namespace Drupal\Tests\next\Kernel\Event; -use Drupal\Core\Database\Database; -use Drupal\dblog\Controller\DbLogController; use Drupal\KernelTests\KernelTestBase; use Drupal\node\Entity\NodeType; use Drupal\Tests\node\Traits\NodeCreationTrait; @@ -63,39 +61,36 @@ public function testEntityActionEvents() { // Insert. $page->save(); $this->container->get('kernel')->terminate(Request::create('/'), new Response()); - $this->assertLogsContains("Event next.entity.action dispatched for entity A page and action insert."); + $this->assertLogMessage("insert"); // Update. $page->set('title', 'A page updated')->save(); $this->container->get('kernel')->terminate(Request::create('/'), new Response()); - $this->assertLogsContains("Event next.entity.action dispatched for entity A page updated and action update."); - - // Delete. - $page->delete(); - $this->container->get('kernel')->terminate(Request::create('/'), new Response()); - $this->assertLogsContains("Event next.entity.action dispatched for entity A page updated and action delete."); + $this->assertLogMessage("update"); } /** - * Helper to assert logs. + * Helper to assert log. * - * @param string $message - * The message to assert in the logs. + * @param string $action + * The action to perform. */ - protected function assertLogsContains(string $message) { - $logs = Database::getConnection() - ->select('watchdog', 'wd') - ->fields('wd', ['message', 'variables']) + protected function assertLogMessage(string $action) { + $message = "Event @event dispatched for entity @label and action @action."; + $variables = [ + '@event' => 'next.entity.action', + '@label' => 'A page', + '@action' => $action, + ]; + + $this->assertNotEmpty($this->container->get('database')->select('watchdog', 'w') ->condition('type', 'system') + ->condition('message', $message) + ->condition('variables', serialize($variables)) + ->countQuery() ->execute() - ->fetchAll(); - - $controller = DbLogController::create($this->container); - $messages = array_map(function ($log) use ($controller) { - return (string) $controller->formatMessage($log); - }, $logs); - - $this->assertContains($message, $messages); + ->fetchField() + ); } } diff --git a/modules/next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php b/modules/next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php index e8c69d079..f6c10819b 100644 --- a/modules/next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php +++ b/modules/next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\next\Kernel\Event; -use Drupal\Core\Database\Database; use Drupal\dblog\Controller\DbLogController; use Drupal\KernelTests\KernelTestBase; use Drupal\next\Entity\NextEntityTypeConfig; @@ -84,6 +83,9 @@ public function testEntityRevalidatedEvents() { $page->delete(); $this->container->get('kernel')->terminate(Request::create('/'), new Response()); $this->assertLogsContains("Entity A page updated, action delete, revalidated 0."); + // As hook_entity_predelete is used to perform revalidate + // before delete action then it's ideal to check log after revalidate. + $this->assertLogsContains("Event next.entity.action dispatched for entity A page updated and action delete."); } /** @@ -93,7 +95,7 @@ public function testEntityRevalidatedEvents() { * The message to assert in the logs. */ protected function assertLogsContains(string $message) { - $logs = Database::getConnection() + $logs = $this->container->get('database') ->select('watchdog', 'wd') ->fields('wd', ['message', 'variables']) ->condition('type', 'system') @@ -104,7 +106,6 @@ protected function assertLogsContains(string $message) { $messages = array_map(function ($log) use ($controller) { return (string) $controller->formatMessage($log); }, $logs); - $this->assertContains($message, $messages); } diff --git a/modules/next/tests/src/Kernel/NextSettingsManagerTest.php b/modules/next/tests/src/Kernel/NextSettingsManagerTest.php index 4eb83a82f..b1904d42a 100644 --- a/modules/next/tests/src/Kernel/NextSettingsManagerTest.php +++ b/modules/next/tests/src/Kernel/NextSettingsManagerTest.php @@ -53,7 +53,7 @@ public function test() { $settings = $this->nextSettingsManager->all(); $this->assertSame('iframe', $settings['site_previewer']); $this->assertSame('simple_oauth', $settings['preview_url_generator']); - $this->assertSame(FALSE, $settings['debug']); + $this->assertFalse($settings['debug']); $this->assertFalse($this->nextSettingsManager->isDebug()); $this->container->get('config.factory') @@ -61,7 +61,7 @@ public function test() { ->set('debug', TRUE) ->save(); $settings = $this->nextSettingsManager->all(); - $this->assertSame(TRUE, $settings['debug']); + $this->assertTrue($settings['debug']); $this->assertTrue($this->nextSettingsManager->isDebug()); $this->assertInstanceOf(Iframe::class, $this->nextSettingsManager->getSitePreviewer()); diff --git a/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php b/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php index 9afc524ac..70be92574 100644 --- a/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php +++ b/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php @@ -160,7 +160,7 @@ public function testValidateSecret() { * @return array[] * An array of test data. */ - public function providerValidateForInvalidBody() { + public static function providerValidateForInvalidBody(): array { return [ [[], "Field 'path' is missing"], [['path' => '/node/1'], "Field 'timestamp' is missing"], From 1cda615cd298f6e22fd9a3de9dee06c97bd32aa9 Mon Sep 17 00:00:00 2001 From: Brian Perry Date: Thu, 10 Oct 2024 16:48:33 -0500 Subject: [PATCH 2/2] fix: remove Drupal 11 deprecations from module tests (#802) --- .../tests/src/Kernel/Controller/EntityResourceTest.php | 1 - .../tests/src/Kernel/Controller/NextPreviewUrlControllerTest.php | 1 - .../next/tests/src/Kernel/Entity/NextEntityTypeConfigTest.php | 1 - modules/next/tests/src/Kernel/Entity/NextSiteTest.php | 1 - modules/next/tests/src/Kernel/Event/EntityActionEventTest.php | 1 - .../next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php | 1 - modules/next/tests/src/Kernel/NextEntityTypeManagerTest.php | 1 - modules/next/tests/src/Kernel/NextSettingsManagerTest.php | 1 - modules/next/tests/src/Kernel/Plugin/PathRevalidatorTest.php | 1 - .../src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php | 1 - modules/next/tests/src/Kernel/Plugin/SiteResolverTest.php | 1 - .../tests/src/Kernel/Renderer/MainContent/HtmlRendererTest.php | 1 - 12 files changed, 12 deletions(-) diff --git a/modules/next/modules/next_jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php b/modules/next/modules/next_jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php index 2540dd30c..f87938587 100644 --- a/modules/next/modules/next_jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php +++ b/modules/next/modules/next_jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php @@ -45,7 +45,6 @@ protected function setUp(): void { $this->installEntitySchema('node'); $this->installEntitySchema('user'); $this->installConfig(['filter', 'next']); - $this->installSchema('system', ['sequences']); $this->installSchema('node', ['node_access']); $type = NodeType::create([ diff --git a/modules/next/tests/src/Kernel/Controller/NextPreviewUrlControllerTest.php b/modules/next/tests/src/Kernel/Controller/NextPreviewUrlControllerTest.php index 46d71ad3f..cd3964cb8 100644 --- a/modules/next/tests/src/Kernel/Controller/NextPreviewUrlControllerTest.php +++ b/modules/next/tests/src/Kernel/Controller/NextPreviewUrlControllerTest.php @@ -42,7 +42,6 @@ protected function setUp(): void { $this->installEntitySchema('node'); $this->installEntitySchema('user'); $this->installConfig(['filter', 'next']); - $this->installSchema('system', ['sequences']); $this->installSchema('node', ['node_access']); $this->nextSite = NextSite::create([ diff --git a/modules/next/tests/src/Kernel/Entity/NextEntityTypeConfigTest.php b/modules/next/tests/src/Kernel/Entity/NextEntityTypeConfigTest.php index ad134adb5..62680a387 100644 --- a/modules/next/tests/src/Kernel/Entity/NextEntityTypeConfigTest.php +++ b/modules/next/tests/src/Kernel/Entity/NextEntityTypeConfigTest.php @@ -41,7 +41,6 @@ protected function setUp(): void { $this->installEntitySchema('user'); $this->installEntitySchema('path_alias'); $this->installConfig(['filter']); - $this->installSchema('system', ['sequences']); $this->installSchema('node', ['node_access']); } diff --git a/modules/next/tests/src/Kernel/Entity/NextSiteTest.php b/modules/next/tests/src/Kernel/Entity/NextSiteTest.php index 0481f2418..abeb96755 100644 --- a/modules/next/tests/src/Kernel/Entity/NextSiteTest.php +++ b/modules/next/tests/src/Kernel/Entity/NextSiteTest.php @@ -40,7 +40,6 @@ protected function setUp(): void { $this->installEntitySchema('node'); $this->installEntitySchema('user'); $this->installConfig(['filter', 'next']); - $this->installSchema('system', ['sequences']); $this->installSchema('node', ['node_access']); $this->nextSite = NextSite::create([ diff --git a/modules/next/tests/src/Kernel/Event/EntityActionEventTest.php b/modules/next/tests/src/Kernel/Event/EntityActionEventTest.php index 4f4e9905b..2b5cd5667 100644 --- a/modules/next/tests/src/Kernel/Event/EntityActionEventTest.php +++ b/modules/next/tests/src/Kernel/Event/EntityActionEventTest.php @@ -40,7 +40,6 @@ protected function setUp(): void { $this->installEntitySchema('user'); $this->installConfig(['filter', 'next', 'system', 'user']); $this->installSchema('dblog', ['watchdog']); - $this->installSchema('system', ['sequences']); $this->installSchema('node', ['node_access']); $this->installSchema('user', ['users_data']); diff --git a/modules/next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php b/modules/next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php index f6c10819b..c482d796c 100644 --- a/modules/next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php +++ b/modules/next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php @@ -42,7 +42,6 @@ protected function setUp(): void { $this->installEntitySchema('next_entity_type_config'); $this->installConfig(['filter', 'next', 'system', 'user']); $this->installSchema('dblog', ['watchdog']); - $this->installSchema('system', ['sequences']); $this->installSchema('node', ['node_access']); $this->installSchema('user', ['users_data']); diff --git a/modules/next/tests/src/Kernel/NextEntityTypeManagerTest.php b/modules/next/tests/src/Kernel/NextEntityTypeManagerTest.php index f3df8a0a0..d5107b376 100644 --- a/modules/next/tests/src/Kernel/NextEntityTypeManagerTest.php +++ b/modules/next/tests/src/Kernel/NextEntityTypeManagerTest.php @@ -32,7 +32,6 @@ protected function setUp(): void { $this->installEntitySchema('node'); $this->installEntitySchema('user'); $this->installConfig(['filter', 'next']); - $this->installSchema('system', ['sequences']); $this->installSchema('node', ['node_access']); } diff --git a/modules/next/tests/src/Kernel/NextSettingsManagerTest.php b/modules/next/tests/src/Kernel/NextSettingsManagerTest.php index b1904d42a..b9be68fdb 100644 --- a/modules/next/tests/src/Kernel/NextSettingsManagerTest.php +++ b/modules/next/tests/src/Kernel/NextSettingsManagerTest.php @@ -36,7 +36,6 @@ protected function setUp(): void { $this->installEntitySchema('node'); $this->installEntitySchema('user'); $this->installConfig(['filter', 'next']); - $this->installSchema('system', ['sequences']); $this->installSchema('node', ['node_access']); $this->nextSettingsManager = $this->container->get('next.settings.manager'); diff --git a/modules/next/tests/src/Kernel/Plugin/PathRevalidatorTest.php b/modules/next/tests/src/Kernel/Plugin/PathRevalidatorTest.php index a7de97936..b8d82c84d 100644 --- a/modules/next/tests/src/Kernel/Plugin/PathRevalidatorTest.php +++ b/modules/next/tests/src/Kernel/Plugin/PathRevalidatorTest.php @@ -47,7 +47,6 @@ protected function setUp(): void { $this->installEntitySchema('user'); $this->installEntitySchema('path_alias'); $this->installConfig(['filter']); - $this->installSchema('system', ['sequences']); $this->installSchema('node', ['node_access']); } diff --git a/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php b/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php index 70be92574..0effc53a7 100644 --- a/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php +++ b/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php @@ -50,7 +50,6 @@ protected function setUp(): void { $this->installEntitySchema('node'); $this->installEntitySchema('user'); $this->installConfig(['filter', 'next']); - $this->installSchema('system', ['sequences']); $this->installSchema('node', ['node_access']); $this->nextSettingsManager = $this->container->get('next.settings.manager'); diff --git a/modules/next/tests/src/Kernel/Plugin/SiteResolverTest.php b/modules/next/tests/src/Kernel/Plugin/SiteResolverTest.php index 0cd090fda..3bb44472f 100644 --- a/modules/next/tests/src/Kernel/Plugin/SiteResolverTest.php +++ b/modules/next/tests/src/Kernel/Plugin/SiteResolverTest.php @@ -33,7 +33,6 @@ protected function setUp(): void { $this->installEntitySchema('node'); $this->installEntitySchema('user'); $this->installConfig(['filter']); - $this->installSchema('system', ['sequences']); $this->installSchema('node', ['node_access']); // Create page type. diff --git a/modules/next/tests/src/Kernel/Renderer/MainContent/HtmlRendererTest.php b/modules/next/tests/src/Kernel/Renderer/MainContent/HtmlRendererTest.php index 7eaaacd29..31ef6543f 100644 --- a/modules/next/tests/src/Kernel/Renderer/MainContent/HtmlRendererTest.php +++ b/modules/next/tests/src/Kernel/Renderer/MainContent/HtmlRendererTest.php @@ -35,7 +35,6 @@ protected function setUp(): void { $this->installEntitySchema('node'); $this->installEntitySchema('user'); $this->installConfig(['filter', 'next', 'system', 'user']); - $this->installSchema('system', ['sequences']); $this->installSchema('node', ['node_access']); $this->installSchema('user', ['users_data']);