Browse Source

coder_fixes (#797)

Co-authored-by: ajstanley <alanjarlathstanle@gmail.com>
pull/801/head
Alan Stanley 4 years ago committed by GitHub
parent
commit
a3d7a55bdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php
  2. 2
      modules/islandora_text_extraction/src/Controller/MediaSourceController.php
  3. 2
      src/Commands/IslandoraCommands.php
  4. 2
      src/Controller/MediaSourceController.php
  5. 2
      src/EventSubscriber/JwtEventSubscriber.php
  6. 2
      src/EventSubscriber/LinkHeaderSubscriber.php
  7. 2
      src/EventSubscriber/MediaLinkHeaderSubscriber.php
  8. 2
      src/EventSubscriber/NodeLinkHeaderSubscriber.php
  9. 3
      src/Flysystem/Adapter/FedoraAdapter.php
  10. 26
      src/IslandoraUtils.php
  11. 2
      src/Plugin/Condition/EntityBundle.php
  12. 62
      tests/src/Functional/IslandoraFunctionalTestBase.php
  13. 2
      tests/src/Functional/IslandoraSettingsFormTest.php
  14. 2
      tests/src/Functional/JsonldTypeAlterReactionTest.php
  15. 21
      tests/src/Functional/NodeHasTermTest.php
  16. 151
      tests/src/Kernel/FedoraAdapterTest.php
  17. 2
      tests/src/Kernel/GeminiClientFactoryTest.php
  18. 9
      tests/src/Kernel/GeminiLookupTest.php

2
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 {

2
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 {

2
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);
}
/**

2
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
*/

2
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
*/

2
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
*/

2
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
*/

2
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
*/

3
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 {

26
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,
]);
}
/**

2
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);
}
/**

62
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 = <<<EOD
@ -113,7 +116,9 @@ EOLIc/4JOdONrJKWYpWIjDhHLL8BacjLoh2bDY0KdYa69AfYvW4=
-----END RSA PRIVATE KEY-----
EOD;
$key = $this->container->get('entity_type.manager')->getStorage('key')->create([
$key = $this->container->get('entity_type.manager')
->getStorage('key')
->create([
'id' => 'test',
'label' => 'Test',
'key_type' => 'jwt_rs',
@ -127,14 +132,17 @@ EOD;
]);
$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([
$hello_world = $this->container->get('entity_type.manager')
->getStorage('action')
->create([
'id' => 'hello_world',
'label' => 'Hello World',
'type' => 'system',
@ -146,20 +154,26 @@ EOD;
$hello_world->save();
// Create a vocabulary.
$this->testVocabulary = $this->container->get('entity_type.manager')->getStorage('taxonomy_vocabulary')->create([
$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([
$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 = $this->container->get('entity_type.manager')
->getStorage('field_config')
->create([
'field_storage' => $fieldStorage,
'bundle' => $this->testVocabulary->id(),
'settings' => [
@ -170,7 +184,9 @@ EOD;
$field->save();
// Create a test content type.
$this->testType = $this->container->get('entity_type.manager')->getStorage('node_type')->create([
$this->testType = $this->container->get('entity_type.manager')
->getStorage('node_type')
->create([
'type' => 'test_type',
'name' => 'Test Type',
]);
@ -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,7 +235,9 @@ EOD;
*/
protected function createImageTag() {
// 'Image' tag.
$this->imageTerm = $this->container->get('entity_type.manager')->getStorage('taxonomy_term')->create([
$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"]],
@ -233,7 +252,9 @@ EOD;
*/
protected function createPreservationMasterTag() {
// 'Preservation Master' tag.
$this->preservationMasterTerm = $this->container->get('entity_type.manager')->getStorage('taxonomy_term')->create([
$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"]],
@ -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,7 +414,9 @@ EOD;
*/
protected function makeMediaAndFile(AccountInterface $account) {
// Make a file for the Media.
$file = $this->container->get('entity_type.manager')->getStorage('file')->create([
$file = $this->container->get('entity_type.manager')
->getStorage('file')
->create([
'uid' => $account->id(),
'uri' => "public://test_file.txt",
'filename' => "test_file.txt",
@ -400,7 +430,9 @@ EOD;
$source_field = $type_configuration['source_field'];
// Make the media for the referencer.
$media = $this->container->get('entity_type.manager')->getStorage('media')->create([
$media = $this->container->get('entity_type.manager')
->getStorage('media')
->create([
'bundle' => $this->testMediaType->id(),
'name' => 'Media',
"$source_field" => [$file->id()],

2
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

2
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

21
tests/src/Functional/NodeHasTermTest.php

@ -30,7 +30,9 @@ class NodeHasTermTest extends IslandoraFunctionalTestBase {
public function testNodeHasTerm() {
// Create a new node with the tag.
$node = $this->container->get('entity_type.manager')->getStorage('node')->create([
$node = $this->container->get('entity_type.manager')
->getStorage('node')
->create([
'type' => 'test_type',
'title' => 'Test Node',
'field_tags' => [$this->imageTerm->id()],
@ -48,7 +50,9 @@ 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([
$node = $this->container->get('entity_type.manager')
->getStorage('node')
->create([
'type' => 'test_type',
'title' => 'Test Node',
]);
@ -57,7 +61,9 @@ class NodeHasTermTest extends IslandoraFunctionalTestBase {
$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([
$node = $this->container->get('entity_type.manager')
->getStorage('node')
->create([
'type' => 'test_type',
'title' => 'Test Node',
'field_tags' => [$this->preservationMasterTerm->id()],
@ -90,10 +96,15 @@ 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([
$node = $this->container->get('entity_type.manager')
->getStorage('node')
->create([
'type' => 'test_type',
'title' => 'Test Node',
'field_tags' => [$this->imageTerm->id(), $this->preservationMasterTerm->id()],
'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");

151
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(['<http://www.w3.org/ns/ldp#Resource>;rel="type"', '<http://www.w3.org/ns/ldp#NonRDFSource>;rel="type"']);
$prophecy->getHeader('Last-Modified')
->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]);
$prophecy->getHeader('Link')
->willReturn([
'<http://www.w3.org/ns/ldp#Resource>;rel="type"',
'<http://www.w3.org/ns/ldp#NonRDFSource>;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(['<http://www.w3.org/ns/ldp#Resource>;rel="type"', '<http://www.w3.org/ns/ldp#RDFSource>;rel="type"']);
$prophecy->getHeader('Last-Modified')
->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]);
$prophecy->getHeader('Link')
->willReturn([
'<http://www.w3.org/ns/ldp#Resource>;rel="type"',
'<http://www.w3.org/ns/ldp#RDFSource>;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);
}
@ -91,12 +104,18 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$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(['<http://www.w3.org/ns/ldp#Resource>;rel="type"', '<http://www.w3.org/ns/ldp#NonRDFSource>;rel="type"']);
$prophecy->getHeader('Last-Modified')
->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]);
$prophecy->getHeader('Link')
->willReturn([
'<http://www.w3.org/ns/ldp#Resource>;rel="type"',
'<http://www.w3.org/ns/ldp#NonRDFSource>;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(['<http://www.w3.org/ns/ldp#Resource>;rel="type"', '<http://www.w3.org/ns/ldp#RDFSource>;rel="type"']);
$prophecy->getHeader('Last-Modified')
->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]);
$prophecy->getHeader('Link')
->willReturn([
'<http://www.w3.org/ns/ldp#Resource>;rel="type"',
'<http://www.w3.org/ns/ldp#RDFSource>;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('<some-path-to-a-tombstone>; rel="hasTombstone"');
$head_prophecy->getHeader('Link')
->willReturn('<some-path-to-a-tombstone>; 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('<some-path-to-a-tombstone>; rel="hasTombstone"');
$head_prophecy->getHeader('Link')
->willReturn('<some-path-to-a-tombstone>; 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(['<http://www.w3.org/ns/ldp#Resource>;rel="type"', '<http://www.w3.org/ns/ldp#NonRDFSource>;rel="type"']);
$prophecy->getHeader('Last-Modified')
->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]);
$prophecy->getHeader('Link')
->willReturn([
'<http://www.w3.org/ns/ldp#Resource>;rel="type"',
'<http://www.w3.org/ns/ldp#NonRDFSource>;rel="type"',
]);
$prophecy->getHeader('Content-Type')->willReturn(['text/plain']);
$prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]);
$prophecy->getBody()->willReturn(PSR7\stream_for("DERP"));
@ -577,17 +628,23 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$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(['<http://www.w3.org/ns/ldp#Resource>;rel="type"', '<http://www.w3.org/ns/ldp#NonRDFSource>;rel="type"']);
$prophecy->getHeader('Last-Modified')
->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]);
$prophecy->getHeader('Link')->willReturn([
'<http://www.w3.org/ns/ldp#Resource>;rel="type"',
'<http://www.w3.org/ns/ldp#NonRDFSource>;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);
}

2
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

9
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();
}

Loading…
Cancel
Save