diff --git a/VERSIONS_WIP/88526 b/VERSIONS_WIP/88526 new file mode 100644 index 0000000000000000000000000000000000000000..7b1f0738ee507e0903f1f5d3769e3b0e0d2c8166 --- /dev/null +++ b/VERSIONS_WIP/88526 @@ -0,0 +1 @@ + - ticket #88526 : intégration Nanook/Bokeh: possibilité d'accéder directement à une notice Bokeh depuis Nanook \ No newline at end of file diff --git a/application/modules/opac/controllers/ErrorController.php b/application/modules/opac/controllers/ErrorController.php index 2452352b84437e958b7c90a535ec08bf35a33ee7..8f01967fe020bd3fccc3ba1ac8c498c96427816f 100644 --- a/application/modules/opac/controllers/ErrorController.php +++ b/application/modules/opac/controllers/ErrorController.php @@ -28,7 +28,9 @@ class ErrorController extends ZendAfi_Controller_Action { if (isset($errors->exception) && (404 == $errors->exception->getCode())) return $this->_renderPageNotFound($errors->exception); - $this->_response->setHttpResponseCode(500); + $this->_response->setHttpResponseCode($this->_isHTTPErrorCode($errors->exception->getCode()) + ? $errors->exception->getCode() + : 500); $this->_response->clearBody(); if (($this->_request->getServer('HTTP_HOST') == 'localhost') @@ -51,4 +53,88 @@ class ErrorController extends ZendAfi_Controller_Action { $this->view->exception = $exception; $this->renderScript('error/404.phtml'); } + + + protected function _isHTTPErrorCode($code) { + $http_codes = [ + 100 => 'Continue', + 101 => 'Switching Protocols', + 102 => 'Processing', // WebDAV; RFC 2518 + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', // since HTTP/1.1 + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + 207 => 'Multi-Status', // WebDAV; RFC 4918 + 208 => 'Already Reported', // WebDAV; RFC 5842 + 226 => 'IM Used', // RFC 3229 + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', + 303 => 'See Other', // since HTTP/1.1 + 304 => 'Not Modified', + 305 => 'Use Proxy', // since HTTP/1.1 + 306 => 'Switch Proxy', + 307 => 'Temporary Redirect', // since HTTP/1.1 + 308 => 'Permanent Redirect', // approved as experimental RFC + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed', + 418 => 'I\'m a teapot', // RFC 2324 + 419 => 'Authentication Timeout', // not in RFC 2616 + 420 => 'Enhance Your Calm', // Twitter + 420 => 'Method Failure', // Spring Framework + 422 => 'Unprocessable Entity', // WebDAV; RFC 4918 + 423 => 'Locked', // WebDAV; RFC 4918 + 424 => 'Failed Dependency', // WebDAV; RFC 4918 + 424 => 'Method Failure', // WebDAV) + 425 => 'Unordered Collection', // Internet draft + 426 => 'Upgrade Required', // RFC 2817 + 428 => 'Precondition Required', // RFC 6585 + 429 => 'Too Many Requests', // RFC 6585 + 431 => 'Request Header Fields Too Large', // RFC 6585 + 444 => 'No Response', // Nginx + 449 => 'Retry With', // Microsoft + 450 => 'Blocked by Windows Parental Controls', // Microsoft + 451 => 'Redirect', // Microsoft + 451 => 'Unavailable For Legal Reasons', // Internet draft + 494 => 'Request Header Too Large', // Nginx + 495 => 'Cert Error', // Nginx + 496 => 'No Cert', // Nginx + 497 => 'HTTP to HTTPS', // Nginx + 499 => 'Client Closed Request', // Nginx + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported', + 506 => 'Variant Also Negotiates', // RFC 2295 + 507 => 'Insufficient Storage', // WebDAV; RFC 4918 + 508 => 'Loop Detected', // WebDAV; RFC 5842 + 509 => 'Bandwidth Limit Exceeded', // Apache bw/limited extension + 510 => 'Not Extended', // RFC 2774 + 511 => 'Network Authentication Required', // RFC 6585 + 598 => 'Network read timeout error', // Unknown + 599 => 'Network connect timeout error']; + + return isset($http_codes[$code]); + } } \ No newline at end of file diff --git a/application/modules/opac/controllers/RechercheController.php b/application/modules/opac/controllers/RechercheController.php index a6a23fd5fbd8d581b5b30c1ee9e19dc4cfd7fb32..3f50fd04b4df6fb5fc27e829b1fbcae916bc428f 100644 --- a/application/modules/opac/controllers/RechercheController.php +++ b/application/modules/opac/controllers/RechercheController.php @@ -300,10 +300,47 @@ class RechercheController extends ZendAfi_Controller_Action { } + protected function _isViewNoticeRequestFromSIGB() { + return $this->_getParam('id_sigb') || $this->_getParam('id_site'); + } + + + protected function _handleViewNoticeRequestFromSIGB() { + if (!$id_sigb = $this->_getParam('id_sigb')) + return $this->_badRequestError($this->_('Paramètre id_sigb obligatoire')); + + if (!$id_site = $this->_getParam('id_site')) + return $this->_badRequestError($this->_('Paramètre id_site obligatoire')); + + if (!$annex = Class_CodifAnnexe::findFirstBy(['id_origine' => $id_site])) + return $this->_recordDoesNotExistsError(); + + if (!$item = Class_Exemplaire::findFirstBy(['id_origine' => $id_sigb, + 'id_bib' => $annex->getIdBib()])) + return $this->_recordDoesNotExistsError(); + + return $this->_redirect('/recherche/viewnotice/id/' . $item->getIdNotice()); + } + + + protected function _badRequestError($message) { + throw new Zend_Controller_Action_Exception($message, 400); + } + + + protected function _recordDoesNotExistsError() { + throw new Zend_Controller_Action_Exception($this->view->_('Désolé, aucun document ne correspond aux critères transmis'), + 404); + } + + public function viewnoticeAction() { if ($authority_record = $this->_authorityFromParams()) return $this->_redirect('/opac/recherche/viewnotice/id/' . $authority_record->getId()); + if ($this->_isViewNoticeRequestFromSIGB()) + return $this->_handleViewNoticeRequestFromSIGB(); + $id_notice = (int)$this->_getParam('id'); $clef_alpha = (string)$this->_getParam('clef'); diff --git a/application/modules/opac/views/scripts/error/error.phtml b/application/modules/opac/views/scripts/error/error.phtml index 630218acd5cde4ab4c239c327f0becaa8e6a7074..3130e8f24de1fff667bdd0163b09fee26a9f6762 100644 --- a/application/modules/opac/views/scripts/error/error.phtml +++ b/application/modules/opac/views/scripts/error/error.phtml @@ -1,2 +1,2 @@ -<h1>Une erreur est survenue</h1> -<?php echo $this->error($this->errors);?> \ No newline at end of file +<h1><?php echo $this->_('Une erreur est survenue') ?></h1> +<?php echo $this->error($this->errors);?> diff --git a/tests/application/modules/opac/controllers/ErrorControllerTest.php b/tests/application/modules/opac/controllers/ErrorControllerTest.php index bfba19a68f7f883cdfe2fde9601b09d434917fd3..096ec44451b8f55e5a0ebf5540d1ee0248be60fb 100644 --- a/tests/application/modules/opac/controllers/ErrorControllerTest.php +++ b/tests/application/modules/opac/controllers/ErrorControllerTest.php @@ -37,4 +37,10 @@ class ErrorControllerTest extends AbstractControllerTestCase { public function actionShouldBeError() { $this->assertAction('error'); } + + + /** @test */ + public function httpStatusCodeShouldBe404() { + $this->assertResponseCode(404); + } } diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php index 891958c5cab3797e626c2606afd4951afa2af64a..df8befcbedaeb0b0cf88a27f6f17eb76b0e5a98a 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php @@ -82,13 +82,15 @@ abstract class RechercheControllerNoticeTestCase extends AbstractControllerTestC 'facettes' => 'A123 F2 G1 P4 Y2 B1 Lfre M1 Z3 D1', 'date_creation' => '2013-12-31', 'unimarc' => file_get_contents(ROOT_PATH . 'tests/fixtures/bernard_genin.uni')]) - ->setExemplaires([Class_Exemplaire::getLoader()->newInstanceWithId(34) - ->setIdBib('456') - ->setIdOrigine('12') - ->setCodeBarres('12256663233656') - ->setSigbExemplaire($this->mock() - ->whenCalled('isReservable') - ->answers(true))]); + ->setExemplaires([$this->fixture('Class_Exemplaire', + ['id' => 34, + 'id_bib' => 456, + 'id_origine' => 12, + 'code_barres' => '12256663233656', + 'sigb_exemplaire' => ($this->mock() + ->whenCalled('isReservable') + ->answers(true)) + ])]); } } @@ -604,6 +606,54 @@ class RechercheControllerViewNoticeTest extends RechercheControllerNoticeTestCas +class RechercheControllerViewNoticeByIdSigbTest extends RechercheControllerNoticeTestCase { + public function setUp() { + parent::setUp(); + $this->fixture('Class_CodifAnnexe', + ['id' => 1, + 'id_bib' => 456, + 'id_origine' => 2]); + } + + + /** @test */ + public function withRightIdsResponseShouldRedirectToViewNoticeId345() { + $this->dispatch('/recherche/viewnotice/id_sigb/12/id_site/2'); + $this->assertRedirectTo('/recherche/viewnotice/id/345'); + } + + + /** @test */ + public function withUnknownIdSiteShouldThrow404() { + $this->dispatch('/recherche/viewnotice/id_sigb/12/id_site/3', false); + $this->assertResponseCode(404); + } + + + /** @test */ + public function withUnknownIdSigbShouldThrow404() { + $this->dispatch('/recherche/viewnotice/id_sigb/66/id_site/2', false); + $this->assertResponseCode(404); + } + + + /** @test */ + public function withNoIdSigbShouldThrow400() { + $this->dispatch('/recherche/viewnotice/id_site/2', false); + $this->assertResponseCode(400); + } + + + /** @test */ + public function withNoIdSiteShouldThrow400() { + $this->dispatch('/recherche/viewnotice/id_sigb/12', false); + $this->assertResponseCode(400); + } +} + + + + class RechercheControllerViewNoticeMetasTest extends RechercheControllerNoticeTestCase { public function setUp() { parent::setUp();