From 06f2a5754eba0dc80db567c2ea7872af359eaa1d Mon Sep 17 00:00:00 2001 From: Rosie Le Faive Date: Fri, 26 May 2023 16:41:10 -0300 Subject: [PATCH] Drupal Rector. --- .../islandora_advanced_search.module | 2 +- .../GenerateAudioDerivativeTest.php | 3 +- .../tests/src/Functional/BreadcrumbsTest.php | 4 +-- .../src/Plugin/views/style/IIIFManifest.php | 34 ++----------------- .../GenerateImageDerivativeTest.php | 3 +- .../src/Controller/MediaSourceController.php | 2 +- .../tests/src/Functional/LoadTest.php | 4 +-- .../GenerateVideoDerivativeTest.php | 3 +- src/EventSubscriber/LinkHeaderSubscriber.php | 6 ++-- .../MediaLinkHeaderSubscriber.php | 4 +-- .../NodeLinkHeaderSubscriber.php | 6 ++-- src/Flysystem/Adapter/FedoraAdapter.php | 14 ++++---- .../AbstractFileSelectionForm.php | 7 +++- tests/src/Functional/AddChildTest.php | 2 +- tests/src/Functional/AddMediaToNodeTest.php | 2 +- .../src/Functional/ContentEntityTypeTest.php | 3 +- tests/src/Functional/DeleteMediaTest.php | 4 +-- .../src/Functional/DerivativeReactionTest.php | 5 +-- .../Functional/GenerateDerivativeTestBase.php | 2 +- tests/src/Functional/IndexingTest.php | 5 +-- .../IslandoraFunctionalTestBase.php | 11 +++--- .../IslandoraImageFormatterTest.php | 2 +- .../Functional/IslandoraSettingsFormTest.php | 17 ++++++---- .../JsonldSelfReferenceReactionTest.php | 13 +++---- .../JsonldTypeAlterReactionTest.php | 14 ++++---- tests/src/Functional/LinkHeaderTest.php | 2 +- .../src/Functional/MediaSourceUpdateTest.php | 2 +- tests/src/Functional/NodeHasTermTest.php | 2 +- .../Functional/ViewModeAlterReactionTest.php | 2 +- .../IntegerWeightTest.php | 2 +- tests/src/Kernel/EventGeneratorTest.php | 2 +- tests/src/Kernel/FedoraAdapterTest.php | 12 ++++--- tests/src/Kernel/IslandoraKernelTestBase.php | 4 +-- tests/src/Kernel/JwtEventSubscriberTest.php | 4 ++- 34 files changed, 102 insertions(+), 102 deletions(-) diff --git a/modules/islandora_advanced_search/islandora_advanced_search.module b/modules/islandora_advanced_search/islandora_advanced_search.module index cbf52667..7bae23cd 100644 --- a/modules/islandora_advanced_search/islandora_advanced_search.module +++ b/modules/islandora_advanced_search/islandora_advanced_search.module @@ -48,7 +48,7 @@ function islandora_advanced_search_theme() { function islandora_advanced_search_library_info_alter(&$libraries, $extension) { if ($extension == 'facets') { // Override facets module javascript with customizations. - $path = '/' . drupal_get_path('module', 'islandora_advanced_search') . '/js/facets'; + $path = '/' . \Drupal::service('extension.list.module')->getPath('islandora_advanced_search') . '/js/facets'; $libraries['soft-limit']['js'] = [ "$path/soft-limit.js" => [], ]; diff --git a/modules/islandora_audio/tests/src/Functional/GenerateAudioDerivativeTest.php b/modules/islandora_audio/tests/src/Functional/GenerateAudioDerivativeTest.php index fc1c6188..766ceac0 100644 --- a/modules/islandora_audio/tests/src/Functional/GenerateAudioDerivativeTest.php +++ b/modules/islandora_audio/tests/src/Functional/GenerateAudioDerivativeTest.php @@ -68,7 +68,8 @@ class GenerateAudioDerivativeTest extends GenerateDerivativeTestBase { 'field_media_of[0][target_id]' => 'Test Node', 'field_tags[0][target_id]' => 'Preservation Master', ]; - $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save')); + $this->drupalGet('media/add/' . $this->testMediaType->id()); + $this->submitForm($values, $this->t('Save')); $expected = [ 'source_uri' => 'test_file.txt', diff --git a/modules/islandora_breadcrumbs/tests/src/Functional/BreadcrumbsTest.php b/modules/islandora_breadcrumbs/tests/src/Functional/BreadcrumbsTest.php index 80f5dbee..ee35a1ed 100644 --- a/modules/islandora_breadcrumbs/tests/src/Functional/BreadcrumbsTest.php +++ b/modules/islandora_breadcrumbs/tests/src/Functional/BreadcrumbsTest.php @@ -20,7 +20,7 @@ class BreadcrumbsTest extends IslandoraFunctionalTestBase { * * @var array */ - public static $modules = [ + protected static $modules = [ 'islandora_breadcrumbs', ]; @@ -56,7 +56,7 @@ class BreadcrumbsTest extends IslandoraFunctionalTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); // Create some nodes. diff --git a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php index 55fe3634..90945664 100644 --- a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php +++ b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php @@ -4,7 +4,6 @@ namespace Drupal\islandora_iiif\Plugin\views\style; use Drupal\views\Plugin\views\style\StylePluginBase; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Url; @@ -92,17 +91,10 @@ class IIIFManifest extends StylePluginBase { */ protected $messenger; - /** - * Module Handler for running hooks. - * - * @var \Drupal\Core\Extention\ModuleHandlerInterface - */ - protected $moduleHandler; - /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, SerializerInterface $serializer, Request $request, ImmutableConfig $iiif_config, EntityTypeManagerInterface $entity_type_manager, FileSystemInterface $file_system, Client $http_client, MessengerInterface $messenger, ModuleHandlerInterface $moduleHandler) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, SerializerInterface $serializer, Request $request, ImmutableConfig $iiif_config, EntityTypeManagerInterface $entity_type_manager, FileSystemInterface $file_system, Client $http_client, MessengerInterface $messenger) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->serializer = $serializer; @@ -112,7 +104,6 @@ class IIIFManifest extends StylePluginBase { $this->fileSystem = $file_system; $this->httpClient = $http_client; $this->messenger = $messenger; - $this->moduleHandler = $moduleHandler; } /** @@ -129,21 +120,10 @@ class IIIFManifest extends StylePluginBase { $container->get('entity_type.manager'), $container->get('file_system'), $container->get('http_client'), - $container->get('messenger'), - $container->get('module_handler') + $container->get('messenger') ); } - /** - * Return the request property. - * - * @return \Symfony\Component\HttpFoundation\Request - * The Symfony request object - */ - public function getRequest() { - return $this->request; - } - /** * {@inheritdoc} */ @@ -190,9 +170,6 @@ class IIIFManifest extends StylePluginBase { $content_type = 'json'; - // Give other modules a chance to alter the manifest. - $this->moduleHandler->alter('islandora_iiif_manifest', $json, $this); - return $this->serializer->serialize($json, $content_type, ['views_style_plugin' => $this]); } @@ -311,13 +288,6 @@ class IIIFManifest extends StylePluginBase { ]; } - // Give other modules a chance to alter the canvas. - $alter_options = [ - 'options' => $this->options, - 'views_plugin' => $this, - ]; - $this->moduleHandler->alter('islandora_iiif_manifest_canvas', $tmp_canvas, $row, $alter_options); - $canvases[] = $tmp_canvas; } } diff --git a/modules/islandora_image/tests/src/Functional/GenerateImageDerivativeTest.php b/modules/islandora_image/tests/src/Functional/GenerateImageDerivativeTest.php index b6e016fc..295eae91 100644 --- a/modules/islandora_image/tests/src/Functional/GenerateImageDerivativeTest.php +++ b/modules/islandora_image/tests/src/Functional/GenerateImageDerivativeTest.php @@ -70,7 +70,8 @@ class GenerateImageDerivativeTest extends GenerateDerivativeTestBase { 'field_media_of[0][target_id]' => 'Test Node', 'field_tags[0][target_id]' => 'Preservation Master', ]; - $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save')); + $this->drupalGet('media/add/' . $this->testMediaType->id()); + $this->submitForm($values, $this->t('Save')); $expected = [ 'source_uri' => 'test_file.txt', diff --git a/modules/islandora_text_extraction/src/Controller/MediaSourceController.php b/modules/islandora_text_extraction/src/Controller/MediaSourceController.php index f15e42d5..5518220d 100644 --- a/modules/islandora_text_extraction/src/Controller/MediaSourceController.php +++ b/modules/islandora_text_extraction/src/Controller/MediaSourceController.php @@ -98,7 +98,7 @@ class MediaSourceController extends ControllerBase { if (!$this->fileSystem->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) { throw new HttpException(500, "The destination directory does not exist, could not be created, or is not writable"); } - $file = file_save_data($contents, $content_location, FileSystemInterface::EXISTS_REPLACE); + $file = \Drupal::service('file.repository')->writeData($contents, $content_location, FileSystemInterface::EXISTS_REPLACE); if ($media->hasField($destination_field)) { $media->{$destination_field}->setValue([ 'target_id' => $file->id(), diff --git a/modules/islandora_text_extraction/tests/src/Functional/LoadTest.php b/modules/islandora_text_extraction/tests/src/Functional/LoadTest.php index 31dca62c..172ae73a 100644 --- a/modules/islandora_text_extraction/tests/src/Functional/LoadTest.php +++ b/modules/islandora_text_extraction/tests/src/Functional/LoadTest.php @@ -17,7 +17,7 @@ class LoadTest extends IslandoraFunctionalTestBase { * * @var array */ - public static $modules = ['islandora_text_extraction']; + protected static $modules = ['islandora_text_extraction']; /** * A user with permission to administer site configuration. @@ -29,7 +29,7 @@ class LoadTest extends IslandoraFunctionalTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); $this->user = $this->drupalCreateUser(['administer site configuration']); $this->drupalLogin($this->user); diff --git a/modules/islandora_video/tests/src/Functional/GenerateVideoDerivativeTest.php b/modules/islandora_video/tests/src/Functional/GenerateVideoDerivativeTest.php index 8714a2f1..17e8bd5b 100644 --- a/modules/islandora_video/tests/src/Functional/GenerateVideoDerivativeTest.php +++ b/modules/islandora_video/tests/src/Functional/GenerateVideoDerivativeTest.php @@ -65,7 +65,8 @@ class GenerateVideoDerivativeTest extends GenerateDerivativeTestBase { 'field_media_of[0][target_id]' => 'Test Node', 'field_tags[0][target_id]' => 'Preservation Master', ]; - $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save')); + $this->drupalGet('media/add/' . $this->testMediaType->id()); + $this->submitForm($values, $this->t('Save')); $expected = [ 'source_uri' => 'test_file.txt', diff --git a/src/EventSubscriber/LinkHeaderSubscriber.php b/src/EventSubscriber/LinkHeaderSubscriber.php index ce33ce2e..f7e5725b 100644 --- a/src/EventSubscriber/LinkHeaderSubscriber.php +++ b/src/EventSubscriber/LinkHeaderSubscriber.php @@ -2,6 +2,7 @@ namespace Drupal\islandora\EventSubscriber; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityInterface; @@ -13,7 +14,6 @@ use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; /** @@ -312,9 +312,9 @@ abstract class LinkHeaderSubscriber implements EventSubscriberInterface { /** * Adds resource-specific link headers to appropriate responses. * - * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event + * @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event * Event containing the response. */ - abstract public function onResponse(FilterResponseEvent $event); + abstract public function onResponse(ResponseEvent $event); } diff --git a/src/EventSubscriber/MediaLinkHeaderSubscriber.php b/src/EventSubscriber/MediaLinkHeaderSubscriber.php index 3cebbbaa..0f406cf5 100644 --- a/src/EventSubscriber/MediaLinkHeaderSubscriber.php +++ b/src/EventSubscriber/MediaLinkHeaderSubscriber.php @@ -2,10 +2,10 @@ namespace Drupal\islandora\EventSubscriber; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Drupal\Core\Url; use Drupal\media\MediaInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; /** * Subscribes to MediaLinkHeader Event. @@ -17,7 +17,7 @@ class MediaLinkHeaderSubscriber extends LinkHeaderSubscriber implements EventSub /** * {@inheritdoc} */ - public function onResponse(FilterResponseEvent $event) { + public function onResponse(ResponseEvent $event) { $response = $event->getResponse(); $media = $this->getObject($response, 'media'); diff --git a/src/EventSubscriber/NodeLinkHeaderSubscriber.php b/src/EventSubscriber/NodeLinkHeaderSubscriber.php index e00533f7..c4cdaea8 100644 --- a/src/EventSubscriber/NodeLinkHeaderSubscriber.php +++ b/src/EventSubscriber/NodeLinkHeaderSubscriber.php @@ -2,9 +2,9 @@ namespace Drupal\islandora\EventSubscriber; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Drupal\node\NodeInterface; use Drupal\islandora\IslandoraUtils; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -17,10 +17,10 @@ class NodeLinkHeaderSubscriber extends LinkHeaderSubscriber implements EventSubs /** * Adds node-specific link headers to appropriate responses. * - * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event + * @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event * Event containing the response. */ - public function onResponse(FilterResponseEvent $event) { + public function onResponse(ResponseEvent $event) { $response = $event->getResponse(); $node = $this->getObject($response, 'node'); diff --git a/src/Flysystem/Adapter/FedoraAdapter.php b/src/Flysystem/Adapter/FedoraAdapter.php index 4ebc61c5..55f8b11d 100644 --- a/src/Flysystem/Adapter/FedoraAdapter.php +++ b/src/Flysystem/Adapter/FedoraAdapter.php @@ -2,6 +2,8 @@ namespace Drupal\islandora\Flysystem\Adapter; +use GuzzleHttp\Psr7\Header; +use function GuzzleHttp\Psr7\parse_header; use Drupal\Core\Logger\LoggerChannelInterface; use Islandora\Chullo\IFedoraApi; use League\Flysystem\AdapterInterface; @@ -159,11 +161,11 @@ class FedoraAdapter implements AdapterInterface { // directory. $type = 'dir'; // phpcs:disable - if (class_exists(\GuzzleHttp\Psr7\Header::class)) { - $links = \GuzzleHttp\Psr7\Header::parse($response->getHeader('Link')); + if (class_exists(Header::class)) { + $links = Header::parse($response->getHeader('Link')); } else { - $links = \GuzzleHttp\Psr7\parse_header($response->getHeader('Link')); + $links = parse_header($response->getHeader('Link')); } // phpcs:enable foreach ($links as $link) { @@ -402,11 +404,11 @@ class FedoraAdapter implements AdapterInterface { if ($response->getStatusCode() == 410) { $return = FALSE; // phpcs:disable - if (class_exists(\GuzzleHttp\Psr7\Header::class)) { - $link_headers = \GuzzleHttp\Psr7\Header::parse($response->getHeader('Link')); + if (class_exists(Header::class)) { + $link_headers = Header::parse($response->getHeader('Link')); } else { - $link_headers = \GuzzleHttp\Psr7\parse_header($response->getHeader('Link')); + $link_headers = parse_header($response->getHeader('Link')); } // phpcs:enable if ($link_headers) { diff --git a/src/Form/AddChildrenWizard/AbstractFileSelectionForm.php b/src/Form/AddChildrenWizard/AbstractFileSelectionForm.php index 6aeed879..cf6ef305 100644 --- a/src/Form/AddChildrenWizard/AbstractFileSelectionForm.php +++ b/src/Form/AddChildrenWizard/AbstractFileSelectionForm.php @@ -37,6 +37,11 @@ abstract class AbstractFileSelectionForm extends FormBase { * @var \Drupal\islandora\Form\AddChildrenWizard\AbstractBatchProcessor|null */ protected ?AbstractBatchProcessor $batchProcessor; + private \static $static; + public function __construct(\static $static) + { + $this->static = $static; + } /** * {@inheritdoc} @@ -49,7 +54,7 @@ abstract class AbstractFileSelectionForm extends FormBase { $instance->entityFieldManager = $container->get('entity_field.manager'); $instance->currentUser = $container->get('current_user'); - $instance->batchProcessor = $container->get(static::BATCH_PROCESSOR); + $instance->batchProcessor = $this->static; return $instance; } diff --git a/tests/src/Functional/AddChildTest.php b/tests/src/Functional/AddChildTest.php index 9fc2f9e2..f27f9db9 100644 --- a/tests/src/Functional/AddChildTest.php +++ b/tests/src/Functional/AddChildTest.php @@ -12,7 +12,7 @@ class AddChildTest extends IslandoraFunctionalTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); $this->parent = diff --git a/tests/src/Functional/AddMediaToNodeTest.php b/tests/src/Functional/AddMediaToNodeTest.php index 32909775..4b0b62c5 100644 --- a/tests/src/Functional/AddMediaToNodeTest.php +++ b/tests/src/Functional/AddMediaToNodeTest.php @@ -31,7 +31,7 @@ class AddMediaToNodeTest extends IslandoraFunctionalTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); $this->node = $this->container->get('entity_type.manager')->getStorage('node')->create([ diff --git a/tests/src/Functional/ContentEntityTypeTest.php b/tests/src/Functional/ContentEntityTypeTest.php index 362ff7fb..5ed22948 100644 --- a/tests/src/Functional/ContentEntityTypeTest.php +++ b/tests/src/Functional/ContentEntityTypeTest.php @@ -52,7 +52,8 @@ class ContentEntityTypeTest extends IslandoraFunctionalTestBase { 'name[0][value]' => 'Test Media', 'files[field_media_file_0]' => __DIR__ . '/../../fixtures/test_file.txt', ]; - $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save')); + $this->drupalGet('media/add/' . $this->testMediaType->id()); + $this->submitForm($values, $this->t('Save')); $this->assertSession()->pageTextNotContains("Hello World!"); } diff --git a/tests/src/Functional/DeleteMediaTest.php b/tests/src/Functional/DeleteMediaTest.php index f112c700..86895dbb 100644 --- a/tests/src/Functional/DeleteMediaTest.php +++ b/tests/src/Functional/DeleteMediaTest.php @@ -16,7 +16,7 @@ class DeleteMediaTest extends IslandoraFunctionalTestBase { * * @var array */ - public static $modules = [ + protected static $modules = [ 'media_test_views', 'context_ui', 'field_ui', @@ -47,7 +47,7 @@ class DeleteMediaTest extends IslandoraFunctionalTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); // Create a test user. diff --git a/tests/src/Functional/DerivativeReactionTest.php b/tests/src/Functional/DerivativeReactionTest.php index e1b1c827..00e0e5ae 100644 --- a/tests/src/Functional/DerivativeReactionTest.php +++ b/tests/src/Functional/DerivativeReactionTest.php @@ -19,7 +19,7 @@ class DerivativeReactionTest extends IslandoraFunctionalTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); $this->node = $this->container->get('entity_type.manager')->getStorage('node')->create([ @@ -52,7 +52,8 @@ class DerivativeReactionTest extends IslandoraFunctionalTestBase { 'files[field_media_file_0]' => __DIR__ . '/../../fixtures/test_file.txt', 'field_media_of[0][target_id]' => 'Test Node', ]; - $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save')); + $this->drupalGet('media/add/' . $this->testMediaType->id()); + $this->submitForm($values, $this->t('Save')); // field_media_of is set and there's a file, so derivatives should fire. $this->assertSession()->pageTextContains("Hello World!"); diff --git a/tests/src/Functional/GenerateDerivativeTestBase.php b/tests/src/Functional/GenerateDerivativeTestBase.php index 0f67d591..c5ec9701 100644 --- a/tests/src/Functional/GenerateDerivativeTestBase.php +++ b/tests/src/Functional/GenerateDerivativeTestBase.php @@ -29,7 +29,7 @@ abstract class GenerateDerivativeTestBase extends IslandoraFunctionalTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); $this->createUserAndLogin(); diff --git a/tests/src/Functional/IndexingTest.php b/tests/src/Functional/IndexingTest.php index e995329d..ff215281 100644 --- a/tests/src/Functional/IndexingTest.php +++ b/tests/src/Functional/IndexingTest.php @@ -12,7 +12,7 @@ class IndexingTest extends IslandoraFunctionalTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); // Create an action that dsm's "Goodbye, Cruel World!". @@ -63,9 +63,10 @@ class IndexingTest extends IslandoraFunctionalTestBase { // Add the Goodbye World reaction. $this->addPresetReaction('test', 'delete', 'goodbye_world'); + $this->drupalGet("$url/delete"); // Delete the node. - $this->drupalPostForm("$url/delete", [], $this->t('Delete')); + $this->submitForm([], $this->t('Delete')); $this->assertSession()->statusCodeEquals(200); // Confirm Goodbye, Cruel World! is printed to the screen. diff --git a/tests/src/Functional/IslandoraFunctionalTestBase.php b/tests/src/Functional/IslandoraFunctionalTestBase.php index 2e4c88e8..2e723561 100644 --- a/tests/src/Functional/IslandoraFunctionalTestBase.php +++ b/tests/src/Functional/IslandoraFunctionalTestBase.php @@ -88,7 +88,7 @@ class IslandoraFunctionalTestBase extends BrowserTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); // Delete the node rest config that's bootstrapped with Drupal. @@ -314,7 +314,8 @@ EOD; * Create a new node by posting its add form. */ protected function postNodeAddForm($bundle_id, $values, $button_text) { - $this->drupalPostForm("node/add/$bundle_id", $values, $this->t('@text', ['@text' => $button_text])); + $this->drupalGet("node/add/$bundle_id"); + $this->submitForm($values, $this->t('@text', ['@text' => $button_text])); $this->assertSession()->statusCodeEquals(200); } @@ -322,7 +323,8 @@ EOD; * Create a new node by posting its add form. */ protected function postTermAddForm($taxomony_id, $values, $button_text) { - $this->drupalPostForm("admin/structure/taxonomy/manage/$taxomony_id/add", $values, $this->t('@text', ['@text' => $button_text])); + $this->drupalGet("admin/structure/taxonomy/manage/$taxomony_id/add"); + $this->submitForm($values, $this->t('@text', ['@text' => $button_text])); $this->assertSession()->statusCodeEquals(200); } @@ -330,7 +332,8 @@ EOD; * Edits a node by posting its edit form. */ protected function postEntityEditForm($entity_url, $values, $button_text) { - $this->drupalPostForm("$entity_url/edit", $values, $this->t('@text', ['@text' => $button_text])); + $this->drupalGet("$entity_url/edit"); + $this->submitForm($values, $this->t('@text', ['@text' => $button_text])); $this->assertSession()->statusCodeEquals(200); } diff --git a/tests/src/Functional/IslandoraImageFormatterTest.php b/tests/src/Functional/IslandoraImageFormatterTest.php index 33f6e1e6..84ea5517 100644 --- a/tests/src/Functional/IslandoraImageFormatterTest.php +++ b/tests/src/Functional/IslandoraImageFormatterTest.php @@ -92,7 +92,7 @@ class IslandoraImageFormatterTest extends IslandoraFunctionalTestBase { ':title' => 'Some Title', ] ); - $this->assertEqual(count($elements), 1, 'Image linked to content formatter displaying points to Node and not Media.'); + $this->assertEquals(count($elements), 1, 'Image linked to content formatter displaying points to Node and not Media.'); } } diff --git a/tests/src/Functional/IslandoraSettingsFormTest.php b/tests/src/Functional/IslandoraSettingsFormTest.php index 92cfc6a2..80a327af 100644 --- a/tests/src/Functional/IslandoraSettingsFormTest.php +++ b/tests/src/Functional/IslandoraSettingsFormTest.php @@ -14,7 +14,7 @@ class IslandoraSettingsFormTest extends IslandoraFunctionalTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); // Create a test user. @@ -36,20 +36,25 @@ class IslandoraSettingsFormTest extends IslandoraFunctionalTestBase { $this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextContains("JWT Expiry"); $this->assertSession()->fieldValueEquals('edit-jwt-expiry', '+2 hour'); + $this->drupalGet('/admin/config/islandora/core'); // Blank is not allowed. - $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => ""], $this->t('Save configuration')); + $this->submitForm(['edit-jwt-expiry' => ""], $this->t('Save configuration')); $this->assertSession()->pageTextContainsOnce('"" is not a valid time or interval expression.'); + $this->drupalGet('/admin/config/islandora/core'); // Negative is not allowed. - $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => "-2 hours"], $this->t('Save configuration')); + $this->submitForm(['edit-jwt-expiry' => "-2 hours"], $this->t('Save configuration')); $this->assertSession()->pageTextContainsOnce('Time or interval expression cannot be negative'); + $this->drupalGet('/admin/config/islandora/core'); // Must include an integer value. - $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => "last hour"], $this->t('Save configuration')); + $this->submitForm(['edit-jwt-expiry' => "last hour"], $this->t('Save configuration')); $this->assertSession()->pageTextContainsOnce('No numeric interval specified, for example "1 day"'); + $this->drupalGet('/admin/config/islandora/core'); // Must have an accepted interval. - $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => "1 fortnight"], $this->t('Save configuration')); + $this->submitForm(['edit-jwt-expiry' => "1 fortnight"], $this->t('Save configuration')); $this->assertSession()->pageTextContainsOnce('No time interval found, please include one of'); + $this->drupalGet('/admin/config/islandora/core'); // Test a valid setting. - $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => "2 weeks"], $this->t('Save configuration')); + $this->submitForm(['edit-jwt-expiry' => "2 weeks"], $this->t('Save configuration')); $this->assertSession()->pageTextContainsOnce('The configuration options have been saved.'); } diff --git a/tests/src/Functional/JsonldSelfReferenceReactionTest.php b/tests/src/Functional/JsonldSelfReferenceReactionTest.php index f3c88271..7ad8f018 100644 --- a/tests/src/Functional/JsonldSelfReferenceReactionTest.php +++ b/tests/src/Functional/JsonldSelfReferenceReactionTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\islandora\Functional; +use function GuzzleHttp\json_decode; /** * Class MappingUriPredicateReactionTest. * @@ -13,7 +14,7 @@ class JsonldSelfReferenceReactionTest extends IslandoraFunctionalTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); $types = ['schema:Thing']; @@ -61,7 +62,7 @@ class JsonldSelfReferenceReactionTest extends IslandoraFunctionalTestBase { $contents = $this->drupalGet($url . '?_format=jsonld'); $this->assertSession()->statusCodeEquals(200); - $json = \GuzzleHttp\json_decode($contents, TRUE); + $json = json_decode($contents, TRUE); $this->assertArrayHasKey('http://purl.org/dc/terms/title', $json['@graph'][0], 'Missing dcterms:title key'); $this->assertEquals( @@ -103,7 +104,7 @@ class JsonldSelfReferenceReactionTest extends IslandoraFunctionalTestBase { drupal_flush_all_caches(); $new_contents = $this->drupalGet($url . '?_format=jsonld'); - $json = \GuzzleHttp\json_decode($new_contents, TRUE); + $json = json_decode($new_contents, TRUE); $this->assertEquals( 'Test Node', $json['@graph'][0]['http://purl.org/dc/terms/title'][0]['@value'], @@ -123,7 +124,7 @@ class JsonldSelfReferenceReactionTest extends IslandoraFunctionalTestBase { $this->assertSession() ->pageTextContains("The context $context_name has been saved"); $new_contents = $this->drupalGet($url . '?_format=jsonld'); - $json = \GuzzleHttp\json_decode($new_contents, TRUE); + $json = json_decode($new_contents, TRUE); $this->assertEquals( 'Test Node', $json['@graph'][0]['http://purl.org/dc/terms/title'][0]['@value'], @@ -161,7 +162,7 @@ class JsonldSelfReferenceReactionTest extends IslandoraFunctionalTestBase { $contents = $this->drupalGet($media_url . '?_format=jsonld'); $this->assertSession()->statusCodeEquals(200); - $json = \GuzzleHttp\json_decode($contents, TRUE); + $json = json_decode($contents, TRUE); $this->assertEquals( "$media_url?_format=jsonld", $json['@graph'][0]['@id'], @@ -186,7 +187,7 @@ class JsonldSelfReferenceReactionTest extends IslandoraFunctionalTestBase { drupal_flush_all_caches(); $new_contents = $this->drupalGet($media_url . '?_format=jsonld'); - $json = \GuzzleHttp\json_decode($new_contents, TRUE); + $json = json_decode($new_contents, TRUE); $this->assertEquals( "$media_url?_format=jsonld", $json['@graph'][0]['http://www.iana.org/assignments/relation/describedby'][0]['@id'], diff --git a/tests/src/Functional/JsonldTypeAlterReactionTest.php b/tests/src/Functional/JsonldTypeAlterReactionTest.php index e5d21abc..58e8bf61 100644 --- a/tests/src/Functional/JsonldTypeAlterReactionTest.php +++ b/tests/src/Functional/JsonldTypeAlterReactionTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\islandora\Functional; +use function GuzzleHttp\json_decode; /** * Tests Jsonld Alter Reaction. * @@ -20,17 +21,18 @@ class JsonldTypeAlterReactionTest extends JsonldSelfReferenceReactionTest { 'administer node fields', ]); $this->drupalLogin($account); + $this->drupalGet('admin/structure/types/manage/test_type/fields/add-field'); // Add the typed predicate we will select in the reaction config. // Taken from FieldUiTestTrait->fieldUIAddNewField. - $this->drupalPostForm('admin/structure/types/manage/test_type/fields/add-field', [ + $this->submitForm([ 'new_storage_type' => 'string', 'label' => 'Typed Predicate', 'field_name' => 'type_predicate', ], $this->t('Save and continue')); - $this->drupalPostForm(NULL, [], $this->t('Save field settings')); - $this->drupalPostForm(NULL, [], $this->t('Save settings')); - $this->assertRaw('field_type_predicate', 'Redirected to "Manage fields" page.'); + $this->submitForm([], $this->t('Save field settings')); + $this->submitForm([], $this->t('Save settings')); + $this->assertSession()->responseContains('field_type_predicate'); // Add the test node. $this->postNodeAddForm('test_type', [ @@ -46,7 +48,7 @@ class JsonldTypeAlterReactionTest extends JsonldSelfReferenceReactionTest { $contents = $this->drupalGet($url . '?_format=jsonld'); $this->assertSession()->statusCodeEquals(200); - $json = \GuzzleHttp\json_decode($contents, TRUE); + $json = json_decode($contents, TRUE); $this->assertArrayHasKey('@type', $json['@graph'][0], 'Missing @type'); $this->assertEquals( @@ -81,7 +83,7 @@ class JsonldTypeAlterReactionTest extends JsonldSelfReferenceReactionTest { // Check for the new @type from the field_type_predicate value. $new_contents = $this->drupalGet($url . '?_format=jsonld'); - $json = \GuzzleHttp\json_decode($new_contents, TRUE); + $json = json_decode($new_contents, TRUE); $this->assertTrue( in_array('http://schema.org/Organization', $json['@graph'][0]['@type']), 'Missing altered @type value of http://schema.org/Organization' diff --git a/tests/src/Functional/LinkHeaderTest.php b/tests/src/Functional/LinkHeaderTest.php index 7cb741d5..98b36c68 100644 --- a/tests/src/Functional/LinkHeaderTest.php +++ b/tests/src/Functional/LinkHeaderTest.php @@ -42,7 +42,7 @@ class LinkHeaderTest extends IslandoraFunctionalTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); $account = $this->createUserAndLogin(); diff --git a/tests/src/Functional/MediaSourceUpdateTest.php b/tests/src/Functional/MediaSourceUpdateTest.php index fdea6aef..3c97c695 100644 --- a/tests/src/Functional/MediaSourceUpdateTest.php +++ b/tests/src/Functional/MediaSourceUpdateTest.php @@ -35,7 +35,7 @@ class MediaSourceUpdateTest extends IslandoraFunctionalTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); // Make a user with appropriate permissions. diff --git a/tests/src/Functional/NodeHasTermTest.php b/tests/src/Functional/NodeHasTermTest.php index eff5b5c3..2b4ee16f 100644 --- a/tests/src/Functional/NodeHasTermTest.php +++ b/tests/src/Functional/NodeHasTermTest.php @@ -13,7 +13,7 @@ class NodeHasTermTest extends IslandoraFunctionalTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); diff --git a/tests/src/Functional/ViewModeAlterReactionTest.php b/tests/src/Functional/ViewModeAlterReactionTest.php index 72cdfe44..19660bda 100644 --- a/tests/src/Functional/ViewModeAlterReactionTest.php +++ b/tests/src/Functional/ViewModeAlterReactionTest.php @@ -26,7 +26,7 @@ class ViewModeAlterReactionTest extends IslandoraFunctionalTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); // Node to be referenced via member of. diff --git a/tests/src/FunctionalJavascript/IntegerWeightTest.php b/tests/src/FunctionalJavascript/IntegerWeightTest.php index ba289aa4..2572c191 100644 --- a/tests/src/FunctionalJavascript/IntegerWeightTest.php +++ b/tests/src/FunctionalJavascript/IntegerWeightTest.php @@ -80,7 +80,7 @@ class IntegerWeightTest extends WebDriverTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); $this->adminUser = $this->drupalCreateUser( diff --git a/tests/src/Kernel/EventGeneratorTest.php b/tests/src/Kernel/EventGeneratorTest.php index c423cda3..a9c1f082 100644 --- a/tests/src/Kernel/EventGeneratorTest.php +++ b/tests/src/Kernel/EventGeneratorTest.php @@ -41,7 +41,7 @@ class EventGeneratorTest extends IslandoraKernelTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); // Create a test user. diff --git a/tests/src/Kernel/FedoraAdapterTest.php b/tests/src/Kernel/FedoraAdapterTest.php index e5161063..d6adecbb 100644 --- a/tests/src/Kernel/FedoraAdapterTest.php +++ b/tests/src/Kernel/FedoraAdapterTest.php @@ -2,6 +2,9 @@ namespace Drupal\Tests\islandora\Kernel; +use Prophecy\PhpUnit\ProphecyTrait; +use GuzzleHttp\Psr7\Utils; +use function GuzzleHttp\Psr7\stream_for; use Drupal\Core\Logger\LoggerChannelInterface; use Drupal\islandora\Flysystem\Adapter\FedoraAdapter; use GuzzleHttp\Psr7\Response; @@ -18,6 +21,7 @@ use Symfony\Component\Mime\MimeTypeGuesserInterface; */ class FedoraAdapterTest extends IslandoraKernelTestBase { + use ProphecyTrait; /** * A mimetype guesser prophecy. * @@ -35,7 +39,7 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); $this->mimeGuesser = $this->prophesize(MimeTypeGuesserInterface::class) ->reveal(); @@ -58,10 +62,10 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); // phpcs:disable - if (class_exists(\GuzzleHttp\Psr7\Utils::class)) { - $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor("DERP")); + if (class_exists(Utils::class)) { + $prophecy->getBody()->willReturn(Utils::streamFor("DERP")); } else { - $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\stream_for("DERP")); + $prophecy->getBody()->willReturn(stream_for("DERP")); } // phpcs:enable return $prophecy; diff --git a/tests/src/Kernel/IslandoraKernelTestBase.php b/tests/src/Kernel/IslandoraKernelTestBase.php index 5a95cb68..1c98db3e 100644 --- a/tests/src/Kernel/IslandoraKernelTestBase.php +++ b/tests/src/Kernel/IslandoraKernelTestBase.php @@ -12,7 +12,7 @@ abstract class IslandoraKernelTestBase extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'system', 'user', 'field', @@ -43,7 +43,7 @@ abstract class IslandoraKernelTestBase extends KernelTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); // Bootstrap minimal Drupal environment to run the tests. diff --git a/tests/src/Kernel/JwtEventSubscriberTest.php b/tests/src/Kernel/JwtEventSubscriberTest.php index f97eab9f..9493ab78 100644 --- a/tests/src/Kernel/JwtEventSubscriberTest.php +++ b/tests/src/Kernel/JwtEventSubscriberTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\islandora\Kernel; +use Prophecy\PhpUnit\ProphecyTrait; use Drupal\jwt\Authentication\Event\JwtAuthGenerateEvent; use Drupal\jwt\Authentication\Event\JwtAuthValidEvent; use Drupal\jwt\Authentication\Event\JwtAuthValidateEvent; @@ -19,6 +20,7 @@ use Drupal\islandora\EventSubscriber\JwtEventSubscriber; */ class JwtEventSubscriberTest extends IslandoraKernelTestBase { + use ProphecyTrait; use UserCreationTrait; /** @@ -31,7 +33,7 @@ class JwtEventSubscriberTest extends IslandoraKernelTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); $this->user = $this->createUser();