From 316917a12c0cafceb2d757e382ecc6c68b0bb5be Mon Sep 17 00:00:00 2001 From: elizoller Date: Tue, 25 Aug 2020 21:20:05 +0000 Subject: [PATCH] improve header check in the case that it fails and update tests since they now make another fedora call --- src/Flysystem/Adapter/FedoraAdapter.php | 3 ++- tests/src/Kernel/FedoraAdapterTest.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Flysystem/Adapter/FedoraAdapter.php b/src/Flysystem/Adapter/FedoraAdapter.php index 6946117b..bd0a0331 100644 --- a/src/Flysystem/Adapter/FedoraAdapter.php +++ b/src/Flysystem/Adapter/FedoraAdapter.php @@ -253,7 +253,8 @@ class FedoraAdapter implements AdapterInterface { $headers = [ 'Content-Type' => $this->mimeTypeGuesser->guess($path), ]; - if ($this->has($path)) { + $heads_response = $this->fedora->getResourceHeaders($path); + if (isset($heads_response) && $heads_response->getStatusCode() == 200) { $fedora_url = $path; $date = new DateTime(); $timestamp = $date->format("D, d M Y H:i:s O"); diff --git a/tests/src/Kernel/FedoraAdapterTest.php b/tests/src/Kernel/FedoraAdapterTest.php index abff8eea..5d17814d 100644 --- a/tests/src/Kernel/FedoraAdapterTest.php +++ b/tests/src/Kernel/FedoraAdapterTest.php @@ -84,6 +84,10 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { protected function createAdapterForWrite() { $fedora_prophecy = $this->prophesize(IFedoraApi::class); + $prophecy = $this->prophesize(Response::class); + $prophecy->getStatusCode()->willReturn(201); + $fedora_prophecy->createVersion('', Argument::any(), NULL, + Argument::any())->willReturn($prophecy->reveal()); $prophecy = $this->prophesize(Response::class); $prophecy->getStatusCode()->willReturn(201); @@ -111,6 +115,9 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { */ protected function createAdapterForWriteFail() { $fedora_prophecy = $this->prophesize(IFedoraApi::class); + $prophecy = $this->prophesize(Response::class); + $prophecy->getStatusCode()->willReturn(500); + $fedora_prophecy->getResourceHeaders('')->willReturn($prophecy->reveal()); $prophecy = $this->prophesize(Response::class); $prophecy->getStatusCode()->willReturn(500); @@ -562,6 +569,14 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $prophecy->getStatusCode()->willReturn(201); $response = $prophecy->reveal(); + $date = new \DateTime(); + $timestamp = $date->format("D, d M Y H:i:s O"); + $fedora_prophecy->createVersion('', + Argument::any(), NULL, + 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); $prophecy = $this->prophesize(Response::class);