diff --git a/application/modules/admin/controllers/UploadController.php b/application/modules/admin/controllers/UploadController.php index 267c7b6bcb84e2ec4b4b63d10f1f17993f446134..0bec56076751eef4cb743761821f53bda56b1f1c 100644 --- a/application/modules/admin/controllers/UploadController.php +++ b/application/modules/admin/controllers/UploadController.php @@ -71,6 +71,11 @@ $(document).ready(function () { public function vignetteNoticeAction() { + if ($this->getRequest()->isPost()) { + Class_WebService_AllServices::uploadVignetteForNotice($this->_getParam('url_vignette'), + $this->_getParam('id')); + } + $this->_helper->getHelper('viewRenderer')->setLayoutScript('empty.phtml'); $this->view->form = new ZendAfi_Form_VignetteNotice(); } diff --git a/library/Class/CosmoVar.php b/library/Class/CosmoVar.php index e30b90f7579442520769d2792fc2b4a22c195ae2..e2666407a7457cf661ea5c18df742849e5800708 100644 --- a/library/Class/CosmoVar.php +++ b/library/Class/CosmoVar.php @@ -23,16 +23,12 @@ class Class_CosmoVar extends Storm_Model_Abstract { protected $_table_name = 'variables'; protected $_table_primary = 'clef'; - public static function getLoader() { - return self::getLoaderFor(__CLASS__); - } - /** * @param string $name * @return mixed */ public static function get($name) { - $var = self::getLoader()->find($name); + $var = self::find($name); if ($var == null) return null; return $var->getValeur(); diff --git a/library/Class/Notice.php b/library/Class/Notice.php index af0a64557ed25e1e3df477e962742b6f9231ca7d..e92a99b63ef61d3bb4091e3682705ad01262c575 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -1163,6 +1163,14 @@ class Class_Notice extends Storm_Model_Abstract { public function getLinksAsTarget() { return Class_FRBR_Link::getLinksForTarget($this->getClefAlpha()); } + + + /** + * return int identifiant type doc codifié Pergame + */ + public function getTypeDocPergame() { + return Class_TypeDoc::find($this->getTypeDoc())->toPergame(); + } } ?> \ No newline at end of file diff --git a/library/Class/TypeDoc.php b/library/Class/TypeDoc.php index 1046ca59461d1de3d9f91bedf414fd7bf64c93d0..685cfaeab8e4365c7d5de220330a1066fdd5a107 100644 --- a/library/Class/TypeDoc.php +++ b/library/Class/TypeDoc.php @@ -119,6 +119,7 @@ class Class_TypeDoc extends Storm_Model_Abstract { protected $_loader_class = 'TypeDocLoader'; const LIVRE = 1; const PERIODIQUE = 2; + const DISQUE = 3; const DVD = 4; const LIVRE_NUM = 100; const DIAPORAMA = 101; @@ -148,14 +149,6 @@ class Class_TypeDoc extends Storm_Model_Abstract { } - /** - * @return Storm_Model_Loader - */ - public static function getLoader() { - return self::getLoaderFor(__CLASS__); - } - - /** * @param Array types_docs * @return array @@ -190,6 +183,14 @@ class Class_TypeDoc extends Storm_Model_Abstract { } return $for_album; } + + + /** + * return int identifiant type doc codifié Pergame + */ + public function toPergame() { + return $this->getId(); + } } ?> \ No newline at end of file diff --git a/library/Class/WebService/AllServices.php b/library/Class/WebService/AllServices.php index e854a3c394515ec901f95c02bd5266edabde3617..0f4a1aa22132a0bad0ca0d4fbccb25abc96e11ff 100644 --- a/library/Class/WebService/AllServices.php +++ b/library/Class/WebService/AllServices.php @@ -110,11 +110,29 @@ class Class_WebService_AllServices { return self::runServiceAfi(7, $args); } + static function runServiceAfiUploadVignette($args) { + return self::runServiceAfi(12, $args); + } + static function setHttpClient($client) { self::$_http_client = $client; } + static function uploadVignetteForNotice($url, $id) { + $notice = Class_Notice::find($id); + $result = static::runServiceAfiUploadVignette(['isbn' => $notice->getIsbn(), + 'type_doc' => $notice->getTypeDocPergame(), + 'titre' => $notice->getTitrePrincipal(), + 'auteur' => $notice->getAuteurPrincipal(), + 'image' => $url]); + $notice + ->setUrlVignette($result['vignette']) + ->setUrlImage($result['image']) + ->save(); + } + + static function httpGet($url, $args) { if (!isset(self::$_http_client)) self::$_http_client = new Class_WebService_SimpleWebClient(); diff --git a/tests/application/modules/admin/controllers/UploadControllerTest.php b/tests/application/modules/admin/controllers/UploadControllerTest.php index 56ba373bbba02eb56a727817396eaf393b90380e..0ca25ea68acb06a0fb9a67b96cabf3bdd02c3e01 100644 --- a/tests/application/modules/admin/controllers/UploadControllerTest.php +++ b/tests/application/modules/admin/controllers/UploadControllerTest.php @@ -147,9 +147,10 @@ class UploadControllerVignetteNoticeActionTest extends AbstractControllerTestCas public function setUp() { parent::setUp(); - $this->dispatch('/admin/upload/vignette-notice', true); + $this->dispatch('/admin/upload/vignette-notice/id/12345', true); } + /** @test */ public function formShouldHaveInputUrlVignette() { $this->assertXPath('//form//input[@type="url"][@name="url_vignette"][contains(@placeholder, "ex: http://upload")]'); @@ -162,4 +163,65 @@ class UploadControllerVignetteNoticeActionTest extends AbstractControllerTestCas } } + + + +class UploadControllerVignetteNoticeActionPostValidUrlTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') + ->whenCalled('save') + ->answers(true); + + + Class_Notice::newInstanceWithId(12345) + ->setIsbn('0123456789') + ->setTypeDoc(Class_TypeDoc::LIVRE) + ->setTitrePrincipal('Harry Potter') + ->setAuteurPrincipal('J.K.Rowling'); + + Class_CosmoVar::newInstanceWithId('url_services')->setValeur('http://cache.org'); + + Class_WebService_AllServices::setHttpClient($http_client = Storm_Test_ObjectWrapper::mock() + ->whenCalled('open_url') + ->with('http://cache.org?isbn=0123456789' + .'&type_doc=1' + .'&titre='.urlencode('Harry Potter') + .'&auteur='.urlencode('J.K.Rowling') + .'&image='.urlencode('http://upload.wikimedia.org/potter.jpg') + .'&src='.Class_WebService_AllServices::createSecurityKey() + .'&action=12' + ) + ->answers(json_encode(['vignette' => 'http://cache.org/potter_thumb.jpg', + 'image' => 'http://cache.org/potter.jpg', + 'statut' => 'ok']) + ) + ->beStrict() + ); + + $this->postDispatch('/admin/upload/vignette-notice/id/12345', + ['url_vignette' => 'http://upload.wikimedia.org/potter.jpg'], + true); + } + + + public function tearDown() { + Class_WebService_AllServices::setHttpClient(null); + } + + + /** @test */ + public function noticeShouldHaveBeenSaved() { + $this->assertEquals('0123456789', Class_Notice::getFirstAttributeForLastCallOn('save')->getIsbn()); + } + + + /** @test */ + public function noticeUrlVignetteShouldBePotterThumbDotJpg() { + $this->assertEquals('http://cache.org/potter_thumb.jpg', Class_Notice::find(12345)->getUrlVignette()); + } + +} + ?> \ No newline at end of file