diff --git a/.gitattributes b/.gitattributes index 5f9fb482635902b85764e6001a01570fe18d37b8..d2eb9f40b4a610d4f10791b6e46109adac7f4ef4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -521,6 +521,7 @@ application/modules/admin/views/scripts/systeme/phpinfo.phtml -text application/modules/admin/views/scripts/systeme/webservices.phtml -text application/modules/admin/views/scripts/upload/multiple.phtml -text application/modules/admin/views/scripts/upload/vignette-notice.phtml -text +application/modules/admin/views/scripts/upload/vignette-uploaded.phtml -text application/modules/admin/views/scripts/usergroup/_form.phtml -text application/modules/admin/views/scripts/usergroup/_usergroup.phtml -text application/modules/admin/views/scripts/usergroup/editmembers.phtml -text diff --git a/application/modules/admin/controllers/UploadController.php b/application/modules/admin/controllers/UploadController.php index 0bec56076751eef4cb743761821f53bda56b1f1c..97bfc1abd6a75e344213d61cf428cc4949708296 100644 --- a/application/modules/admin/controllers/UploadController.php +++ b/application/modules/admin/controllers/UploadController.php @@ -71,12 +71,14 @@ $(document).ready(function () { public function vignetteNoticeAction() { + $this->_helper->getHelper('viewRenderer')->setLayoutScript('empty.phtml'); + if ($this->getRequest()->isPost()) { - Class_WebService_AllServices::uploadVignetteForNotice($this->_getParam('url_vignette'), - $this->_getParam('id')); + if (!$this->view->error = Class_WebService_AllServices::uploadVignetteForNotice($this->_getParam('url_vignette'), + $this->_getParam('id'))) + $this->renderScript('upload/vignette-uploaded.phtml'); } - $this->_helper->getHelper('viewRenderer')->setLayoutScript('empty.phtml'); $this->view->form = new ZendAfi_Form_VignetteNotice(); } } diff --git a/application/modules/admin/views/scripts/upload/vignette-notice.phtml b/application/modules/admin/views/scripts/upload/vignette-notice.phtml index 2e55e706a8c1be64eb9926ab9417c4f4efc547db..5bbc86c61b0a631352afafcd8f08af293e674e35 100644 --- a/application/modules/admin/views/scripts/upload/vignette-notice.phtml +++ b/application/modules/admin/views/scripts/upload/vignette-notice.phtml @@ -1 +1,5 @@ -<?php echo $this->form; ?> \ No newline at end of file +<?php +if ($this->error) + echo '<div class="error">'.$this->_('Erreur: ').$this->error.'</div>'; +echo $this->form; +?> \ No newline at end of file diff --git a/application/modules/admin/views/scripts/upload/vignette-uploaded.phtml b/application/modules/admin/views/scripts/upload/vignette-uploaded.phtml new file mode 100644 index 0000000000000000000000000000000000000000..2616a4005452792f0b52eb57c169e592e4adb0b9 --- /dev/null +++ b/application/modules/admin/views/scripts/upload/vignette-uploaded.phtml @@ -0,0 +1,5 @@ +<p> +<?php +echo $this->_('La vignette a bien été transférée'); +?> +</p> \ No newline at end of file diff --git a/library/Class/WebService/AllServices.php b/library/Class/WebService/AllServices.php index 0f4a1aa22132a0bad0ca0d4fbccb25abc96e11ff..4e7b4fc460717580132da4c47099596c497bb737 100644 --- a/library/Class/WebService/AllServices.php +++ b/library/Class/WebService/AllServices.php @@ -126,6 +126,10 @@ class Class_WebService_AllServices { 'titre' => $notice->getTitrePrincipal(), 'auteur' => $notice->getAuteurPrincipal(), 'image' => $url]); + + if ('ok' !== $result['statut']) + return $result['message']; + $notice ->setUrlVignette($result['vignette']) ->setUrlImage($result['image']) diff --git a/tests/application/modules/admin/controllers/UploadControllerTest.php b/tests/application/modules/admin/controllers/UploadControllerTest.php index 0ca25ea68acb06a0fb9a67b96cabf3bdd02c3e01..285cd01224b2e7f60ee96d96f18680623ad6b48b 100644 --- a/tests/application/modules/admin/controllers/UploadControllerTest.php +++ b/tests/application/modules/admin/controllers/UploadControllerTest.php @@ -166,7 +166,7 @@ class UploadControllerVignetteNoticeActionTest extends AbstractControllerTestCas -class UploadControllerVignetteNoticeActionPostValidUrlTest extends AbstractControllerTestCase { +abstract class UploadControllerVignetteNoticeActionPostTestCase extends AbstractControllerTestCase { public function setUp() { parent::setUp(); @@ -182,7 +182,15 @@ class UploadControllerVignetteNoticeActionPostValidUrlTest extends AbstractContr ->setAuteurPrincipal('J.K.Rowling'); Class_CosmoVar::newInstanceWithId('url_services')->setValeur('http://cache.org'); + } +} + + + +class UploadControllerVignetteNoticeActionPostValidUrlTest extends UploadControllerVignetteNoticeActionPostTestCase { + public function setUp() { + parent::setUp(); Class_WebService_AllServices::setHttpClient($http_client = Storm_Test_ObjectWrapper::mock() ->whenCalled('open_url') ->with('http://cache.org?isbn=0123456789' @@ -222,6 +230,42 @@ class UploadControllerVignetteNoticeActionPostValidUrlTest extends AbstractContr $this->assertEquals('http://cache.org/potter_thumb.jpg', Class_Notice::find(12345)->getUrlVignette()); } + + /** @test */ + public function pageShouldDisplayVignetteTransferee() { + $this->assertXPathContentContains('//p', 'La vignette a bien été transférée'); + } +} + + + + +class UploadControllerVignetteNoticePostServeurCacheErrorTest extends UploadControllerVignetteNoticeActionPostTestCase { + public function setUp() { + parent::setUp(); + + Class_WebService_AllServices::setHttpClient($http_client = Storm_Test_ObjectWrapper::mock() + ->whenCalled('open_url') + ->answers(json_encode(['statut' => 'erreur', 'message' => 'Image indisponible']))); + + + $this->postDispatch('/admin/upload/vignette-notice/id/12345', + ['url_vignette' => 'http://upload.wikimedia.org/potter.jpg'], + true); + } + + + /** @test */ + public function pageShouldDisplayErrorMessageImageIndisponible() { + $this->assertXPathContentContains('//div[@class="error"]', 'Erreur: Image indisponible'); + } + + + /** @test */ + public function noticeShouldNotHaveBeenSaved() { + $this->assertFalse(Class_Notice::methodHasBeenCalled('save')); + } + } ?> \ No newline at end of file