From a3d7a55bdf71040082ae6f40b8361dc64cd3f250 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Tue, 22 Sep 2020 15:43:58 -0300 Subject: [PATCH] coder_fixes (#797) Co-authored-by: ajstanley --- .../src/Form/IslandoraIIIFConfigForm.php | 2 +- .../src/Controller/MediaSourceController.php | 2 +- src/Commands/IslandoraCommands.php | 2 +- src/Controller/MediaSourceController.php | 2 +- src/EventSubscriber/JwtEventSubscriber.php | 2 +- src/EventSubscriber/LinkHeaderSubscriber.php | 2 +- .../MediaLinkHeaderSubscriber.php | 2 +- .../NodeLinkHeaderSubscriber.php | 2 +- src/Flysystem/Adapter/FedoraAdapter.php | 3 +- src/IslandoraUtils.php | 26 ++- src/Plugin/Condition/EntityBundle.php | 2 +- .../IslandoraFunctionalTestBase.php | 170 +++++++++++------- .../Functional/IslandoraSettingsFormTest.php | 2 +- .../JsonldTypeAlterReactionTest.php | 2 +- tests/src/Functional/NodeHasTermTest.php | 49 +++-- tests/src/Kernel/FedoraAdapterTest.php | 155 +++++++++++----- tests/src/Kernel/GeminiClientFactoryTest.php | 2 +- tests/src/Kernel/GeminiLookupTest.php | 9 +- 18 files changed, 276 insertions(+), 160 deletions(-) diff --git a/modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php b/modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php index 5bb73de4..fd349b39 100644 --- a/modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php +++ b/modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php @@ -8,7 +8,7 @@ use Drupal\Component\Utility\UrlHelper; use GuzzleHttp\Exception\ClientException; /** - * Class IslandoraIIIFConfigForm. + * Form to configure IslandoraIIIF. */ class IslandoraIIIFConfigForm extends ConfigFormBase { diff --git a/modules/islandora_text_extraction/src/Controller/MediaSourceController.php b/modules/islandora_text_extraction/src/Controller/MediaSourceController.php index da934ea5..576f2a43 100644 --- a/modules/islandora_text_extraction/src/Controller/MediaSourceController.php +++ b/modules/islandora_text_extraction/src/Controller/MediaSourceController.php @@ -10,7 +10,7 @@ use Symfony\Component\HttpFoundation\Response; use Drupal\Core\File\FileSystem; /** - * Class MediaSourceController. + * Controller for Media Source. */ class MediaSourceController extends ControllerBase { diff --git a/src/Commands/IslandoraCommands.php b/src/Commands/IslandoraCommands.php index 262b4518..c13f3623 100644 --- a/src/Commands/IslandoraCommands.php +++ b/src/Commands/IslandoraCommands.php @@ -38,7 +38,7 @@ class IslandoraCommands extends DrushCommands { * @hook validate migrate:import */ public function validateUserImport(CommandData $commandData) { - $this->validateUser($commandData);; + $this->validateUser($commandData); } /** diff --git a/src/Controller/MediaSourceController.php b/src/Controller/MediaSourceController.php index 374d0f8b..c32b8079 100644 --- a/src/Controller/MediaSourceController.php +++ b/src/Controller/MediaSourceController.php @@ -21,7 +21,7 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\HttpException; /** - * Class MediaSourceController. + * Controller for MediaSource. * * @package Drupal\islandora\Controller */ diff --git a/src/EventSubscriber/JwtEventSubscriber.php b/src/EventSubscriber/JwtEventSubscriber.php index 4ea049c4..438bfb4b 100644 --- a/src/EventSubscriber/JwtEventSubscriber.php +++ b/src/EventSubscriber/JwtEventSubscriber.php @@ -13,7 +13,7 @@ use Drupal\Core\Session\AccountInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** - * Class JwtEventSubscriber. + * Subscribes to Jwt Events. * * @package Drupal\islandora\EventSubscriber */ diff --git a/src/EventSubscriber/LinkHeaderSubscriber.php b/src/EventSubscriber/LinkHeaderSubscriber.php index a25b506c..78aa7b62 100644 --- a/src/EventSubscriber/LinkHeaderSubscriber.php +++ b/src/EventSubscriber/LinkHeaderSubscriber.php @@ -17,7 +17,7 @@ use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; /** - * Class LinkHeaderSubscriber. + * Abstract class to subscribe to LinkHeader Event. * * @package Drupal\islandora\EventSubscriber */ diff --git a/src/EventSubscriber/MediaLinkHeaderSubscriber.php b/src/EventSubscriber/MediaLinkHeaderSubscriber.php index 5df879f0..3cebbbaa 100644 --- a/src/EventSubscriber/MediaLinkHeaderSubscriber.php +++ b/src/EventSubscriber/MediaLinkHeaderSubscriber.php @@ -8,7 +8,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; /** - * Class MediaLinkHeaderSubscriber. + * Subscribes to MediaLinkHeader Event. * * @package Drupal\islandora\EventSubscriber */ diff --git a/src/EventSubscriber/NodeLinkHeaderSubscriber.php b/src/EventSubscriber/NodeLinkHeaderSubscriber.php index 92eac804..e00533f7 100644 --- a/src/EventSubscriber/NodeLinkHeaderSubscriber.php +++ b/src/EventSubscriber/NodeLinkHeaderSubscriber.php @@ -8,7 +8,7 @@ use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** - * Class NodeLinkHeaderSubscriber. + * Subcribes to NodeLinkHeader. * * @package Drupal\islandora\EventSubscriber */ diff --git a/src/Flysystem/Adapter/FedoraAdapter.php b/src/Flysystem/Adapter/FedoraAdapter.php index 783a9ed0..0cc95044 100644 --- a/src/Flysystem/Adapter/FedoraAdapter.php +++ b/src/Flysystem/Adapter/FedoraAdapter.php @@ -11,7 +11,6 @@ use GuzzleHttp\Psr7; use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\StreamWrapper; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface; -use DateTime; /** * Fedora adapter for Flysystem. @@ -255,7 +254,7 @@ class FedoraAdapter implements AdapterInterface { ]; if ($this->has($path)) { $fedora_url = $path; - $date = new DateTime(); + $date = new \DateTime(); $timestamp = $date->format("D, d M Y H:i:s O"); // Create version in Fedora. try { diff --git a/src/IslandoraUtils.php b/src/IslandoraUtils.php index 56422515..87f0021b 100644 --- a/src/IslandoraUtils.php +++ b/src/IslandoraUtils.php @@ -4,8 +4,8 @@ namespace Drupal\islandora; use Drupal\context\ContextManager; use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\Query\QueryException; use Drupal\Core\Entity\Query\QueryFactory; @@ -15,9 +15,9 @@ use Drupal\Core\Site\Settings; use Drupal\Core\Url; use Drupal\file\FileInterface; use Drupal\flysystem\FlysystemFactory; -use Drupal\islandora\ContextProvider\NodeContextProvider; -use Drupal\islandora\ContextProvider\MediaContextProvider; use Drupal\islandora\ContextProvider\FileContextProvider; +use Drupal\islandora\ContextProvider\MediaContextProvider; +use Drupal\islandora\ContextProvider\NodeContextProvider; use Drupal\islandora\ContextProvider\TermContextProvider; use Drupal\media\MediaInterface; use Drupal\node\NodeInterface; @@ -29,7 +29,9 @@ use Drupal\taxonomy\TermInterface; class IslandoraUtils { const EXTERNAL_URI_FIELD = 'field_external_uri'; + const MEDIA_OF_FIELD = 'field_media_of'; + const MEDIA_USAGE_FIELD = 'field_media_use'; /** @@ -151,10 +153,13 @@ class IslandoraUtils { * Calling getStorage() throws if the storage handler couldn't be loaded. */ public function getMedia(NodeInterface $node) { - if (!$this->entityTypeManager->getStorage('field_storage_config')->load('media.' . self::MEDIA_OF_FIELD)) { + if (!$this->entityTypeManager->getStorage('field_storage_config') + ->load('media.' . self::MEDIA_OF_FIELD)) { return []; } - $mids = $this->entityQuery->get('media')->condition(self::MEDIA_OF_FIELD, $node->id())->execute(); + $mids = $this->entityQuery->get('media') + ->condition(self::MEDIA_OF_FIELD, $node->id()) + ->execute(); if (empty($mids)) { return []; } @@ -217,7 +222,8 @@ class IslandoraUtils { $query->condition($condition, $fid); } - return $this->entityTypeManager->getStorage('media')->loadMultiple($query->execute()); + return $this->entityTypeManager->getStorage('media') + ->loadMultiple($query->execute()); } /** @@ -261,7 +267,8 @@ class IslandoraUtils { return NULL; } - return $this->entityTypeManager->getStorage('taxonomy_term')->load(reset($results)); + return $this->entityTypeManager->getStorage('taxonomy_term') + ->load(reset($results)); } /** @@ -587,7 +594,10 @@ class IslandoraUtils { */ public function getDownloadUrl(FileInterface $file) { $undefined = $this->languageManager->getLanguage('und'); - return $file->url('canonical', ['absolute' => TRUE, 'language' => $undefined]); + return $file->url('canonical', [ + 'absolute' => TRUE, + 'language' => $undefined, + ]); } /** diff --git a/src/Plugin/Condition/EntityBundle.php b/src/Plugin/Condition/EntityBundle.php index bd42df54..80e866e6 100644 --- a/src/Plugin/Condition/EntityBundle.php +++ b/src/Plugin/Condition/EntityBundle.php @@ -44,7 +44,7 @@ class EntityBundle extends ConditionPluginBase { '#default_value' => $this->configuration['bundles'], ]; - return parent::buildConfigurationForm($form, $form_state);; + return parent::buildConfigurationForm($form, $form_state); } /** diff --git a/tests/src/Functional/IslandoraFunctionalTestBase.php b/tests/src/Functional/IslandoraFunctionalTestBase.php index 9a50fb05..8cee2ba7 100644 --- a/tests/src/Functional/IslandoraFunctionalTestBase.php +++ b/tests/src/Functional/IslandoraFunctionalTestBase.php @@ -80,7 +80,10 @@ class IslandoraFunctionalTestBase extends BrowserTestBase { parent::setUp(); // Delete the node rest config that's bootstrapped with Drupal. - $this->container->get('entity_type.manager')->getStorage('rest_resource_config')->load('entity.node')->delete(); + $this->container->get('entity_type.manager') + ->getStorage('rest_resource_config') + ->load('entity.node') + ->delete(); // Set up JWT stuff. $key_value = <<container->get('entity_type.manager')->getStorage('key')->create([ - 'id' => 'test', - 'label' => 'Test', - 'key_type' => 'jwt_rs', - 'key_type_settings' => [ - 'algorithm' => 'RS256', - ], - 'key_provider' => 'config', - 'key_provider_settings' => [ - 'key_value' => $key_value, - ], - ]); + $key = $this->container->get('entity_type.manager') + ->getStorage('key') + ->create([ + 'id' => 'test', + 'label' => 'Test', + 'key_type' => 'jwt_rs', + 'key_type_settings' => [ + 'algorithm' => 'RS256', + ], + 'key_provider' => 'config', + 'key_provider_settings' => [ + 'key_value' => $key_value, + ], + ]); $key->save(); - $jwt_config = $this->container->get('config.factory')->getEditable('jwt.config'); + $jwt_config = $this->container->get('config.factory') + ->getEditable('jwt.config'); $jwt_config->set('algorithm', 'RS256'); $jwt_config->set('key_id', 'test'); $jwt_config->save(TRUE); // Make some bundles and field by hand so hooks fire. // Create an action that dsm's "Hello World!". - $hello_world = $this->container->get('entity_type.manager')->getStorage('action')->create([ - 'id' => 'hello_world', - 'label' => 'Hello World', - 'type' => 'system', - 'plugin' => 'action_message_action', - 'configuration' => [ - 'message' => 'Hello World!', - ], - ]); + $hello_world = $this->container->get('entity_type.manager') + ->getStorage('action') + ->create([ + 'id' => 'hello_world', + 'label' => 'Hello World', + 'type' => 'system', + 'plugin' => 'action_message_action', + 'configuration' => [ + 'message' => 'Hello World!', + ], + ]); $hello_world->save(); // Create a vocabulary. - $this->testVocabulary = $this->container->get('entity_type.manager')->getStorage('taxonomy_vocabulary')->create([ - 'name' => 'Test Vocabulary', - 'vid' => 'test_vocabulary', - ]); + $this->testVocabulary = $this->container->get('entity_type.manager') + ->getStorage('taxonomy_vocabulary') + ->create([ + 'name' => 'Test Vocabulary', + 'vid' => 'test_vocabulary', + ]); $this->testVocabulary->save(); // Create an external_uri field for taxonomy terms. - $fieldStorage = $this->container->get('entity_type.manager')->getStorage('field_storage_config')->create([ - 'field_name' => 'field_external_uri', - 'entity_type' => 'taxonomy_term', - 'type' => 'link', - ]); + $fieldStorage = $this->container->get('entity_type.manager') + ->getStorage('field_storage_config') + ->create([ + 'field_name' => 'field_external_uri', + 'entity_type' => 'taxonomy_term', + 'type' => 'link', + ]); $fieldStorage->save(); - $field = $this->container->get('entity_type.manager')->getStorage('field_config')->create([ - 'field_storage' => $fieldStorage, - 'bundle' => $this->testVocabulary->id(), - 'settings' => [ - 'title' => 'External URI', - 'link_type' => LinkItemInterface::LINK_EXTERNAL, - ], - ]); + $field = $this->container->get('entity_type.manager') + ->getStorage('field_config') + ->create([ + 'field_storage' => $fieldStorage, + 'bundle' => $this->testVocabulary->id(), + 'settings' => [ + 'title' => 'External URI', + 'link_type' => LinkItemInterface::LINK_EXTERNAL, + ], + ]); $field->save(); // Create a test content type. - $this->testType = $this->container->get('entity_type.manager')->getStorage('node_type')->create([ - 'type' => 'test_type', - 'name' => 'Test Type', - ]); + $this->testType = $this->container->get('entity_type.manager') + ->getStorage('node_type') + ->create([ + 'type' => 'test_type', + 'name' => 'Test Type', + ]); $this->testType->save(); $this->createEntityReferenceField('node', 'test_type', 'field_member_of', 'Member Of', 'node', 'default', [], 2); $this->createEntityReferenceField('node', 'test_type', 'field_tags', 'Tags', 'taxonomy_term', 'default', [], 2); @@ -192,7 +208,8 @@ EOD; $destination->write($name, $source->read($name)); } - $media_settings = $this->container->get('config.factory')->getEditable('media.settings'); + $media_settings = $this->container->get('config.factory') + ->getEditable('media.settings'); $media_settings->set('standalone_url', TRUE); $media_settings->save(TRUE); @@ -218,11 +235,13 @@ EOD; */ protected function createImageTag() { // 'Image' tag. - $this->imageTerm = $this->container->get('entity_type.manager')->getStorage('taxonomy_term')->create([ - 'name' => 'Image', - 'vid' => $this->testVocabulary->id(), - 'field_external_uri' => [['uri' => "http://purl.org/coar/resource_type/c_c513"]], - ]); + $this->imageTerm = $this->container->get('entity_type.manager') + ->getStorage('taxonomy_term') + ->create([ + 'name' => 'Image', + 'vid' => $this->testVocabulary->id(), + 'field_external_uri' => [['uri' => "http://purl.org/coar/resource_type/c_c513"]], + ]); $this->imageTerm->save(); } @@ -233,11 +252,13 @@ EOD; */ protected function createPreservationMasterTag() { // 'Preservation Master' tag. - $this->preservationMasterTerm = $this->container->get('entity_type.manager')->getStorage('taxonomy_term')->create([ - 'name' => 'Preservation Master', - 'vid' => $this->testVocabulary->id(), - 'field_external_uri' => [['uri' => "http://pcdm.org/use#PreservationMasterFile"]], - ]); + $this->preservationMasterTerm = $this->container->get('entity_type.manager') + ->getStorage('taxonomy_term') + ->create([ + 'name' => 'Preservation Master', + 'vid' => $this->testVocabulary->id(), + 'field_external_uri' => [['uri' => "http://pcdm.org/use#PreservationMasterFile"]], + ]); $this->preservationMasterTerm->save(); } @@ -245,7 +266,11 @@ EOD; * Creates a test context. */ protected function createContext($label, $name) { - $this->drupalPostForm('admin/structure/context/add', ['label' => $label, 'name' => $name], t('Save')); + $this->drupalPostForm('admin/structure/context/add', [ + 'label' => $label, + 'name' => $name, + ], + t('Save')); $this->assertSession()->statusCodeEquals(200); } @@ -263,7 +288,10 @@ EOD; */ protected function addPresetReaction($context_id, $reaction_type, $action_id) { $this->drupalGet("admin/structure/context/$context_id/reaction/add/$reaction_type"); - $this->getSession()->getPage()->findById("edit-reactions-$reaction_type-actions")->selectOption($action_id); + $this->getSession() + ->getPage() + ->findById("edit-reactions-$reaction_type-actions") + ->selectOption($action_id); $this->getSession()->getPage()->pressButton(t('Save and continue')); $this->assertSession()->statusCodeEquals(200); } @@ -386,13 +414,15 @@ EOD; */ protected function makeMediaAndFile(AccountInterface $account) { // Make a file for the Media. - $file = $this->container->get('entity_type.manager')->getStorage('file')->create([ - 'uid' => $account->id(), - 'uri' => "public://test_file.txt", - 'filename' => "test_file.txt", - 'filemime' => "text/plain", - 'status' => FILE_STATUS_PERMANENT, - ]); + $file = $this->container->get('entity_type.manager') + ->getStorage('file') + ->create([ + 'uid' => $account->id(), + 'uri' => "public://test_file.txt", + 'filename' => "test_file.txt", + 'filemime' => "text/plain", + 'status' => FILE_STATUS_PERMANENT, + ]); $file->save(); // Get the source field for the media. @@ -400,11 +430,13 @@ EOD; $source_field = $type_configuration['source_field']; // Make the media for the referencer. - $media = $this->container->get('entity_type.manager')->getStorage('media')->create([ - 'bundle' => $this->testMediaType->id(), - 'name' => 'Media', - "$source_field" => [$file->id()], - ]); + $media = $this->container->get('entity_type.manager') + ->getStorage('media') + ->create([ + 'bundle' => $this->testMediaType->id(), + 'name' => 'Media', + "$source_field" => [$file->id()], + ]); $media->save(); return [$file, $media]; diff --git a/tests/src/Functional/IslandoraSettingsFormTest.php b/tests/src/Functional/IslandoraSettingsFormTest.php index 2e724be4..bdf15d29 100644 --- a/tests/src/Functional/IslandoraSettingsFormTest.php +++ b/tests/src/Functional/IslandoraSettingsFormTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\islandora\Functional; /** - * Class IslandoraSettingsFormTest. + * Tests Islandora Settings Form. * * @package Drupal\Tests\islandora\Functional * @group islandora diff --git a/tests/src/Functional/JsonldTypeAlterReactionTest.php b/tests/src/Functional/JsonldTypeAlterReactionTest.php index d983e36d..6e838126 100644 --- a/tests/src/Functional/JsonldTypeAlterReactionTest.php +++ b/tests/src/Functional/JsonldTypeAlterReactionTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\islandora\Functional; /** - * Class JsonldTypeAlterReactionTest. + * Tests Jsonld Alter Reaction. * * @package Drupal\Tests\islandora\Functional * @group islandora diff --git a/tests/src/Functional/NodeHasTermTest.php b/tests/src/Functional/NodeHasTermTest.php index 7d336de0..1d4dd44c 100644 --- a/tests/src/Functional/NodeHasTermTest.php +++ b/tests/src/Functional/NodeHasTermTest.php @@ -30,11 +30,13 @@ class NodeHasTermTest extends IslandoraFunctionalTestBase { public function testNodeHasTerm() { // Create a new node with the tag. - $node = $this->container->get('entity_type.manager')->getStorage('node')->create([ - 'type' => 'test_type', - 'title' => 'Test Node', - 'field_tags' => [$this->imageTerm->id()], - ]); + $node = $this->container->get('entity_type.manager') + ->getStorage('node') + ->create([ + 'type' => 'test_type', + 'title' => 'Test Node', + 'field_tags' => [$this->imageTerm->id()], + ]); // Create and execute the condition. $condition_manager = $this->container->get('plugin.manager.condition'); @@ -48,20 +50,24 @@ class NodeHasTermTest extends IslandoraFunctionalTestBase { $this->assertTrue($condition->execute(), "Condition should pass if node has the term"); // Create a new node without the tag. - $node = $this->container->get('entity_type.manager')->getStorage('node')->create([ - 'type' => 'test_type', - 'title' => 'Test Node', - ]); + $node = $this->container->get('entity_type.manager') + ->getStorage('node') + ->create([ + 'type' => 'test_type', + 'title' => 'Test Node', + ]); $condition->setContextValue('node', $node); $this->assertFalse($condition->execute(), "Condition should fail if the node does not have any terms"); // Create a new node with the wrong tag. - $node = $this->container->get('entity_type.manager')->getStorage('node')->create([ - 'type' => 'test_type', - 'title' => 'Test Node', - 'field_tags' => [$this->preservationMasterTerm->id()], - ]); + $node = $this->container->get('entity_type.manager') + ->getStorage('node') + ->create([ + 'type' => 'test_type', + 'title' => 'Test Node', + 'field_tags' => [$this->preservationMasterTerm->id()], + ]); $condition->setContextValue('node', $node); $this->assertFalse($condition->execute(), "Condition should fail if the node has terms, but not the one we want."); @@ -90,11 +96,16 @@ class NodeHasTermTest extends IslandoraFunctionalTestBase { $this->assertTrue($condition->execute(), "Condition should pass if has one of two terms using OR logic."); // Create a node with both tags and try it with OR. - $node = $this->container->get('entity_type.manager')->getStorage('node')->create([ - 'type' => 'test_type', - 'title' => 'Test Node', - 'field_tags' => [$this->imageTerm->id(), $this->preservationMasterTerm->id()], - ]); + $node = $this->container->get('entity_type.manager') + ->getStorage('node') + ->create([ + 'type' => 'test_type', + 'title' => 'Test Node', + 'field_tags' => [ + $this->imageTerm->id(), + $this->preservationMasterTerm->id(), + ], + ]); $condition->setContextValue('node', $node); $this->assertTrue($condition->execute(), "Condition should pass if node has both terms using OR logic"); diff --git a/tests/src/Kernel/FedoraAdapterTest.php b/tests/src/Kernel/FedoraAdapterTest.php index 5d17814d..522321c4 100644 --- a/tests/src/Kernel/FedoraAdapterTest.php +++ b/tests/src/Kernel/FedoraAdapterTest.php @@ -2,9 +2,9 @@ namespace Drupal\Tests\islandora\Kernel; +use Drupal\islandora\Flysystem\Adapter\FedoraAdapter; use GuzzleHttp\Psr7; use GuzzleHttp\Psr7\Response; -use Drupal\islandora\Flysystem\Adapter\FedoraAdapter; use Islandora\Chullo\IFedoraApi; use League\Flysystem\Config; use Prophecy\Argument; @@ -31,7 +31,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $prophecy->getResource('')->willReturn($response); $api = $prophecy->reveal(); - $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)->reveal(); + $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) + ->reveal(); return new FedoraAdapter($api, $mime_guesser); } @@ -42,8 +43,13 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { protected function createAdapterForFile() { $prophecy = $this->prophesize(Response::class); $prophecy->getStatusCode()->willReturn(200); - $prophecy->getHeader('Last-Modified')->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); - $prophecy->getHeader('Link')->willReturn([';rel="type"', ';rel="type"']); + $prophecy->getHeader('Last-Modified') + ->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); + $prophecy->getHeader('Link') + ->willReturn([ + ';rel="type"', + ';rel="type"', + ]); $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); $prophecy->getBody()->willReturn(PSR7\stream_for("DERP")); @@ -54,7 +60,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $prophecy->getResource('')->willReturn($response); $api = $prophecy->reveal(); - $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)->reveal(); + $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) + ->reveal(); return new FedoraAdapter($api, $mime_guesser); } @@ -65,15 +72,21 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { protected function createAdapterForDirectory() { $prophecy = $this->prophesize(Response::class); $prophecy->getStatusCode()->willReturn(200); - $prophecy->getHeader('Last-Modified')->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); - $prophecy->getHeader('Link')->willReturn([';rel="type"', ';rel="type"']); + $prophecy->getHeader('Last-Modified') + ->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); + $prophecy->getHeader('Link') + ->willReturn([ + ';rel="type"', + ';rel="type"', + ]); $response = $prophecy->reveal(); $prophecy = $this->prophesize(IFedoraApi::class); $prophecy->getResourceHeaders('')->willReturn($response); $api = $prophecy->reveal(); - $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)->reveal(); + $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) + ->reveal(); return new FedoraAdapter($api, $mime_guesser); } @@ -87,16 +100,22 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $prophecy = $this->prophesize(Response::class); $prophecy->getStatusCode()->willReturn(201); $fedora_prophecy->createVersion('', Argument::any(), NULL, - Argument::any())->willReturn($prophecy->reveal()); + Argument::any())->willReturn($prophecy->reveal()); $prophecy = $this->prophesize(Response::class); $prophecy->getStatusCode()->willReturn(201); - $fedora_prophecy->saveResource('', '', Argument::any())->willReturn($prophecy->reveal()); + $fedora_prophecy->saveResource('', '', Argument::any()) + ->willReturn($prophecy->reveal()); $prophecy = $this->prophesize(Response::class); $prophecy->getStatusCode()->willReturn(200); - $prophecy->getHeader('Last-Modified')->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); - $prophecy->getHeader('Link')->willReturn([';rel="type"', ';rel="type"']); + $prophecy->getHeader('Last-Modified') + ->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); + $prophecy->getHeader('Link') + ->willReturn([ + ';rel="type"', + ';rel="type"', + ]); $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); $prophecy->getBody()->willReturn(PSR7\stream_for("DERP")); @@ -105,7 +124,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $api = $fedora_prophecy->reveal(); - $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)->reveal(); + $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) + ->reveal(); return new FedoraAdapter($api, $mime_guesser); } @@ -122,11 +142,13 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $prophecy = $this->prophesize(Response::class); $prophecy->getStatusCode()->willReturn(500); - $fedora_prophecy->saveResource('', '', Argument::any())->willReturn($prophecy->reveal()); + $fedora_prophecy->saveResource('', '', Argument::any()) + ->willReturn($prophecy->reveal()); $api = $fedora_prophecy->reveal(); - $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)->reveal(); + $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) + ->reveal(); return new FedoraAdapter($api, $mime_guesser); } @@ -144,14 +166,20 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $prophecy = $this->prophesize(Response::class); $prophecy->getStatusCode()->willReturn(200); - $prophecy->getHeader('Last-Modified')->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); - $prophecy->getHeader('Link')->willReturn([';rel="type"', ';rel="type"']); + $prophecy->getHeader('Last-Modified') + ->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); + $prophecy->getHeader('Link') + ->willReturn([ + ';rel="type"', + ';rel="type"', + ]); $fedora_prophecy->getResourceHeaders('')->willReturn($prophecy->reveal()); $api = $fedora_prophecy->reveal(); - $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)->reveal(); + $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) + ->reveal(); return new FedoraAdapter($api, $mime_guesser); } @@ -169,7 +197,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $fedora_prophecy->getResourceHeaders('')->willReturn($prophecy->reveal()); $api = $fedora_prophecy->reveal(); - $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)->reveal(); + $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) + ->reveal(); return new FedoraAdapter($api, $mime_guesser); } @@ -187,7 +216,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $api = $fedora_prophecy->reveal(); - $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)->reveal(); + $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) + ->reveal(); return new FedoraAdapter($api, $mime_guesser); } @@ -203,18 +233,22 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $head_prophecy = $this->prophesize(Response::class); $head_prophecy->getStatusCode()->willReturn(410); - $head_prophecy->getHeader('Link')->willReturn('; rel="hasTombstone"'); + $head_prophecy->getHeader('Link') + ->willReturn('; rel="hasTombstone"'); $tombstone_prophecy = $this->prophesize(Response::class); $tombstone_prophecy->getStatusCode()->willReturn(204); $fedora_prophecy->deleteResource('')->willReturn($prophecy->reveal()); - $fedora_prophecy->getResourceHeaders('')->willReturn($head_prophecy->reveal()); - $fedora_prophecy->deleteResource('some-path-to-a-tombstone')->willReturn($tombstone_prophecy->reveal()); + $fedora_prophecy->getResourceHeaders('') + ->willReturn($head_prophecy->reveal()); + $fedora_prophecy->deleteResource('some-path-to-a-tombstone') + ->willReturn($tombstone_prophecy->reveal()); $api = $fedora_prophecy->reveal(); - $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)->reveal(); + $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) + ->reveal(); return new FedoraAdapter($api, $mime_guesser); } @@ -230,18 +264,22 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $head_prophecy = $this->prophesize(Response::class); $head_prophecy->getStatusCode()->willReturn(410); - $head_prophecy->getHeader('Link')->willReturn('; rel="hasTombstone"'); + $head_prophecy->getHeader('Link') + ->willReturn('; rel="hasTombstone"'); $tombstone_prophecy = $this->prophesize(Response::class); $tombstone_prophecy->getStatusCode()->willReturn(500); $fedora_prophecy->deleteResource('')->willReturn($prophecy->reveal()); - $fedora_prophecy->getResourceHeaders('')->willReturn($head_prophecy->reveal()); - $fedora_prophecy->deleteResource('some-path-to-a-tombstone')->willReturn($tombstone_prophecy->reveal()); + $fedora_prophecy->getResourceHeaders('') + ->willReturn($head_prophecy->reveal()); + $fedora_prophecy->deleteResource('some-path-to-a-tombstone') + ->willReturn($tombstone_prophecy->reveal()); $api = $fedora_prophecy->reveal(); - $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)->reveal(); + $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) + ->reveal(); return new FedoraAdapter($api, $mime_guesser); } @@ -414,7 +452,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { public function testWriteFail() { $adapter = $this->createAdapterForWriteFail(); - $this->assertTrue($adapter->write('', '', $this->prophesize(Config::class)->reveal()) == FALSE, "write() must return FALSE on non-201 or non-204"); + $this->assertTrue($adapter->write('', '', $this->prophesize(Config::class) + ->reveal()) == FALSE, "write() must return FALSE on non-201 or non-204"); } /** @@ -423,7 +462,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { public function testWrite() { $adapter = $this->createAdapterForWrite(); - $metadata = $adapter->write('', '', $this->prophesize(Config::class)->reveal()); + $metadata = $adapter->write('', '', $this->prophesize(Config::class) + ->reveal()); $this->assertFileMetadata($metadata); } @@ -433,7 +473,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { public function testWriteStreamFail() { $adapter = $this->createAdapterForWriteFail(); - $this->assertTrue($adapter->writeStream('', '', $this->prophesize(Config::class)->reveal()) == FALSE, "writeStream() must return FALSE on non-201 or non-204"); + $this->assertTrue($adapter->writeStream('', '', $this->prophesize(Config::class) + ->reveal()) == FALSE, "writeStream() must return FALSE on non-201 or non-204"); } /** @@ -442,7 +483,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { public function testWriteStream() { $adapter = $this->createAdapterForWrite(); - $metadata = $adapter->writeStream('', '', $this->prophesize(Config::class)->reveal()); + $metadata = $adapter->writeStream('', '', $this->prophesize(Config::class) + ->reveal()); $this->assertFileMetadata($metadata); } @@ -452,7 +494,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { public function testUpdateFail() { $adapter = $this->createAdapterForWriteFail(); - $this->assertTrue($adapter->update('', '', $this->prophesize(Config::class)->reveal()) == FALSE, "write() must return FALSE on non-201 or non-204"); + $this->assertTrue($adapter->update('', '', $this->prophesize(Config::class) + ->reveal()) == FALSE, "write() must return FALSE on non-201 or non-204"); } /** @@ -461,7 +504,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { public function testUpdate() { $adapter = $this->createAdapterForWrite(); - $metadata = $adapter->update('', '', $this->prophesize(Config::class)->reveal()); + $metadata = $adapter->update('', '', $this->prophesize(Config::class) + ->reveal()); $this->assertFileMetadata($metadata); } @@ -471,7 +515,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { public function testUpdateStreamFail() { $adapter = $this->createAdapterForWriteFail(); - $this->assertTrue($adapter->updateStream('', '', $this->prophesize(Config::class)->reveal()) == FALSE, "writeStream() must return FALSE on non-201 or non-204"); + $this->assertTrue($adapter->updateStream('', '', $this->prophesize(Config::class) + ->reveal()) == FALSE, "writeStream() must return FALSE on non-201 or non-204"); } /** @@ -480,7 +525,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { public function testUpdateStream() { $adapter = $this->createAdapterForWrite(); - $metadata = $adapter->updateStream('', '', $this->prophesize(Config::class)->reveal()); + $metadata = $adapter->updateStream('', '', $this->prophesize(Config::class) + ->reveal()); $this->assertFileMetadata($metadata); } @@ -555,8 +601,13 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { public function testRename() { $prophecy = $this->prophesize(Response::class); $prophecy->getStatusCode()->willReturn(200); - $prophecy->getHeader('Last-Modified')->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); - $prophecy->getHeader('Link')->willReturn([';rel="type"', ';rel="type"']); + $prophecy->getHeader('Last-Modified') + ->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); + $prophecy->getHeader('Link') + ->willReturn([ + ';rel="type"', + ';rel="type"', + ]); $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); $prophecy->getBody()->willReturn(PSR7\stream_for("DERP")); @@ -573,21 +624,27 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $timestamp = $date->format("D, d M Y H:i:s O"); $fedora_prophecy->createVersion('', Argument::any(), NULL, - Argument::any())->willReturn($prophecy->reveal()); + Argument::any())->willReturn($prophecy->reveal()); $prophecy = $this->prophesize(Response::class); $prophecy->getStatusCode()->willReturn(201); - $fedora_prophecy->saveResource(Argument::any(), Argument::any(), Argument::any())->willReturn($response); + $fedora_prophecy->saveResource(Argument::any(), Argument::any(), Argument::any()) + ->willReturn($response); $prophecy = $this->prophesize(Response::class); $prophecy->getStatusCode()->willReturn(200); - $prophecy->getHeader('Last-Modified')->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); - $prophecy->getHeader('Link')->willReturn([';rel="type"', ';rel="type"']); + $prophecy->getHeader('Last-Modified') + ->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); + $prophecy->getHeader('Link')->willReturn([ + ';rel="type"', + ';rel="type"', + ]); $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); $response = $prophecy->reveal(); - $fedora_prophecy->getResourceHeaders(Argument::any())->willReturn($response); + $fedora_prophecy->getResourceHeaders(Argument::any()) + ->willReturn($response); $prophecy = $this->prophesize(Response::class); $prophecy->getStatusCode()->willReturn(204); @@ -597,7 +654,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $api = $fedora_prophecy->reveal(); - $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)->reveal(); + $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) + ->reveal(); $adapter = new FedoraAdapter($api, $mime_guesser); @@ -616,11 +674,13 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $api = $fedora_prophecy->reveal(); - $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)->reveal(); + $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) + ->reveal(); $adapter = new FedoraAdapter($api, $mime_guesser); - $this->assertTrue($adapter->createDir('', $this->prophesize(Config::class)->reveal()) == FALSE, "createDir() must return FALSE on fail"); + $this->assertTrue($adapter->createDir('', $this->prophesize(Config::class) + ->reveal()) == FALSE, "createDir() must return FALSE on fail"); } /** @@ -629,7 +689,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { public function testCreateDir() { $adapter = $this->createAdapterForCreateDir(); - $metadata = $adapter->createDir('', $this->prophesize(Config::class)->reveal()); + $metadata = $adapter->createDir('', $this->prophesize(Config::class) + ->reveal()); $this->assertDirMetadata($metadata); } diff --git a/tests/src/Kernel/GeminiClientFactoryTest.php b/tests/src/Kernel/GeminiClientFactoryTest.php index 1bbd8e75..68fca748 100644 --- a/tests/src/Kernel/GeminiClientFactoryTest.php +++ b/tests/src/Kernel/GeminiClientFactoryTest.php @@ -10,7 +10,7 @@ use Prophecy\Argument; use Psr\Log\LoggerInterface; /** - * Class GeminiClientFactoryTest. + * Tests GeminiClientFactory. * * @package Drupal\Tests\islandora\Kernel * @group islandora diff --git a/tests/src/Kernel/GeminiLookupTest.php b/tests/src/Kernel/GeminiLookupTest.php index 15edc2e8..e15f4303 100644 --- a/tests/src/Kernel/GeminiLookupTest.php +++ b/tests/src/Kernel/GeminiLookupTest.php @@ -4,10 +4,10 @@ namespace Drupal\Tests\islandora\Kernel; use Drupal\Core\Entity\EntityInterface; use Drupal\file\FileInterface; -use Drupal\media\MediaInterface; use Drupal\islandora\GeminiLookup; use Drupal\islandora\MediaSource\MediaSourceService; use Drupal\jwt\Authentication\Provider\JwtAuth; +use Drupal\media\MediaInterface; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Response; use Islandora\Crayfish\Commons\Client\GeminiClient; @@ -16,7 +16,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** - * Class GeminiLookupTest. + * Tests Gemini Lookup. * * @group islandora * @coversDefaultClass \Drupal\islandora\GeminiLookup @@ -125,7 +125,10 @@ class GeminiLookupTest extends IslandoraKernelTestBase { private function mockGeminiClientForSuccess() { $prophecy = $this->prophesize(GeminiClient::class); $prophecy->getUrls(Argument::any(), Argument::any()) - ->willReturn(['drupal' => '', 'fedora' => 'http://localhost:8080/fcrepo/rest/abc123']); + ->willReturn([ + 'drupal' => '', + 'fedora' => 'http://localhost:8080/fcrepo/rest/abc123', + ]); $this->geminiClient = $prophecy->reveal(); }