From cfdabaffd920e258a254c99948c9c4826abfa8a3 Mon Sep 17 00:00:00 2001 From: adiouf <adiouf@git-test.afi-sa.fr> Date: Wed, 23 Oct 2013 07:53:18 +0000 Subject: [PATCH] =?UTF-8?q?Import=20Abonne=20SIGB=20pour=20AFI-Multimedia,?= =?UTF-8?q?=20data=20crypt=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 2 + .../push/controllers/MultimediaController.php | 16 + .../Connector/GeneratorRendering.php | 104 ++++++ .../Class/Multimedia/Connector/Multimedia.php | 96 ++++++ .../Class/Multimedia/Connector/Webkiosk.php | 98 ++---- .../Class/Multimedia/PushAllUsersRequest.php | 2 +- .../Multimedia/PushUsersModifiedRequest.php | 13 +- library/Class/Multimedia/PushUsersRequest.php | 2 +- library/Class/Users.php | 24 -- .../controllers/MultimediaControllerTest.php | 317 ++++++++++++++++++ .../controllers/WebkioskControllerTest.php | 8 +- 11 files changed, 571 insertions(+), 111 deletions(-) create mode 100644 library/Class/Multimedia/Connector/GeneratorRendering.php create mode 100644 library/Class/Multimedia/Connector/Multimedia.php diff --git a/.gitattributes b/.gitattributes index ff5aa4227b4..06de51d30a2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1867,6 +1867,8 @@ library/Class/MultiUpload/HandlerForm.php -text library/Class/MultiUpload/HandlerXhr.php -text library/Class/Multimedia.php -text library/Class/Multimedia/AuthenticateRequest.php -text +library/Class/Multimedia/Connector/GeneratorRendering.php -text +library/Class/Multimedia/Connector/Multimedia.php -text library/Class/Multimedia/Connector/Renderer/Encrypt.php -text library/Class/Multimedia/Connector/Renderer/Json.php -text library/Class/Multimedia/Connector/Webkiosk.php -text diff --git a/application/modules/push/controllers/MultimediaController.php b/application/modules/push/controllers/MultimediaController.php index a52b81f4237..1a8b4b639ac 100644 --- a/application/modules/push/controllers/MultimediaController.php +++ b/application/modules/push/controllers/MultimediaController.php @@ -74,5 +74,21 @@ class Push_MultimediaController extends Zend_Controller_Action { foreach($postes_to_delete as $poste) $poste->delete(); } + + + + public function getAllBorrowersAction(){ + $attributes = ['idabon', 'login', 'password', 'nom', 'prenom', 'mail', + 'dateNaissanceIso8601', 'dateFin', 'dateDebut']; + + + $this->getHelper('ViewRenderer')->setNoRender(); + $response = Class_Multimedia_PushAllUsersRequest::newWith( + Class_Multimedia_Connector_Multimedia::getInstance() + ->initAttributes($attributes)) + ->getResponse($this->_request); + + $this->_response->setBody($response); + } } ?> \ No newline at end of file diff --git a/library/Class/Multimedia/Connector/GeneratorRendering.php b/library/Class/Multimedia/Connector/GeneratorRendering.php new file mode 100644 index 00000000000..6736d94b5bc --- /dev/null +++ b/library/Class/Multimedia/Connector/GeneratorRendering.php @@ -0,0 +1,104 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class Class_Multimedia_Connector_GeneratorRendering { + + + + protected $_response; + protected $_attributes; + protected $_currentDate = null; + + /** Listes des objets renders dans l'ordre à effectuer sur les datas */ + protected $_renderers = array(); + + public function __construct() { + $this->_response = new StdClass(); + $this->_response->data = []; + $this->_response->error = ''; + $this->_response->date_export = ''; + + $this->_renderers = [new Class_Multimedia_Connector_Renderer_Json(), new Class_Multimedia_Connector_Renderer_Encrypt(), new Class_Multimedia_Connector_Renderer_Json()]; + } + + + public function initAttributes($attributes){ + $this->_attributes = $attributes; + return $this; + } + public function setRenderers($renderers){ + $this->_renderers = $renderers; + } + + public function renderResponse() { + $this->initializeDateExport(); + foreach ($this->_renderers as $renderer) + $this->_response = $renderer->render($this->_response); + return $this->_response; + } + + + public function render($request, $itemsClosure) { + if (!$this->_renderers) + return ''; + + $itemsClosure(); + return $this->renderResponse(); + } + + public function newItem($item) { + $this->_response->data[] = $this->stdClassFrom($item); + } + + public function stdClassFrom($item) { + $data = new StdClass(); + foreach ($this->_attributes as $attribute) { + $method = 'get' . ucfirst($attribute); + $data->$attribute = $item->$method(); + } + return $data; + } + + + public function prepareResponseError($msg){ + $this->_response->error = $msg; + } + + public function initializeDateExport(){ + $this->_response->date_export = $this->getCurrentDate()->format('c'); + } + + private function getCurrentDate(){ + if(null !== $this->_currentDate) + return $this->_currentDate; + return new DateTime(); + } + + public function setCurrentDate($currentDate){ + $this->_currentDate = new DateTime($currentDate); + } + + public function addFullImportInResponse($value){ + $this->_response->fullImport = $value; + } + +} +?> diff --git a/library/Class/Multimedia/Connector/Multimedia.php b/library/Class/Multimedia/Connector/Multimedia.php new file mode 100644 index 00000000000..4572bba4b2d --- /dev/null +++ b/library/Class/Multimedia/Connector/Multimedia.php @@ -0,0 +1,96 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +class Class_Multimedia_Connector_Multimedia{ + const DATA_SEPARATOR = '--@--'; + + /** @category testing */ + protected static $_instance; + + protected $_generatorRendering; + + public function __construct() { + $this->_generatorRendering = new Class_Multimedia_Connector_GeneratorRendering(); + } + + /** @category testing */ + public static function setInstance($instance) { + self::$_instance = $instance; + } + + + public static function getInstance(){ + if (null !== self::$_instance) + return self::$_instance; + return new self(); + } + + public function getGeneratorRendering(){ + return $this->_generatorRendering; + } + + public function initAttributes($attributes){ + $this->_generatorRendering->initAttributes($attributes); + return $this; + } + + public function generateRenderer($request, $itemClosure){ + if (!$this->isValid($request)) + return $this->_generatorRendering->renderResponse(); + + return $this->_generatorRendering->render($request, $itemClosure); + } + + public function isValid($request) { + if (!($sign = $request->getParam('sign'))) { + $this->_generatorRendering->prepareResponseError('NO_PARAMETERS'); + return false; + } + + if(!Class_AdminVar::isMultimediaEnabled()){ + $this->_generatorRendering->prepareResponseError('MULTIMEDIA_DISABLED'); + return false; + } + + $openssl = new Class_Multimedia_Utils_OpensslUtil(); + $isValidated =$openssl->opensslVerify( + $this->dataFor($request->getActionName()), + base64_decode($sign), + Class_AdminVar::get('MULTIMEDIA_KEY')); + restore_error_handler(); + + if($isValidated == -1){ + $this->_generatorRendering->prepareResponseError('ERROR_CHECKING_SIGNATURE'); + return false; + } + + if($isValidated == 0){ + $this->_generatorRendering->prepareResponseError('INVALID_SIGNATURE'); + return false; + } + + return true; + } + + public function dataFor($data) { + return $data . self::DATA_SEPARATOR . date('Ymd'); + } + +} \ No newline at end of file diff --git a/library/Class/Multimedia/Connector/Webkiosk.php b/library/Class/Multimedia/Connector/Webkiosk.php index 632ff4ca5f1..12c070b61a6 100644 --- a/library/Class/Multimedia/Connector/Webkiosk.php +++ b/library/Class/Multimedia/Connector/Webkiosk.php @@ -25,13 +25,15 @@ class Class_Multimedia_Connector_Webkiosk { /** @category testing */ protected static $_instance; - protected $_currentDate = null; - protected $_response; - protected $_attributes; + protected $_generatorRendering; + - /** Listes des objets renders dans l'ordre à effectuer sur les datas */ - protected $_renderers = array(); + public function __construct() { + $this->_generatorRendering = new Class_Multimedia_Connector_GeneratorRendering(); + } + + public static function getInstance(){ if (null !== self::$_instance) return self::$_instance; @@ -40,91 +42,41 @@ class Class_Multimedia_Connector_Webkiosk { /** @category testing */ public static function setInstance($instance) { - self::$_instance = $instance; - } - - public function __construct() { - $this->_response = new StdClass(); - $this->_response->data = []; - $this->_response->error = ''; - $this->_response->date_export = ''; - - $this->_renderers = [new Class_Multimedia_Connector_Renderer_Json(), new Class_Multimedia_Connector_Renderer_Encrypt(), new Class_Multimedia_Connector_Renderer_Json()]; + self::$_instance = $instance; } - + public function initAttributes($attributes){ - $this->_attributes = $attributes; + $this->_generatorRendering->initAttributes($attributes); return $this; } - public function setRenderers($renderers){ - $this->_renderers = $renderers; - } - - public function render($request, $itemsClosure) { - if (!$this->_renderers) - return ''; - - - $this->initializeDateExport(); - - if (!$this->isValid($request)) - return $this->renderResponse(); - - $itemsClosure(); - return $this->renderResponse(); - } - public function renderResponse() { - foreach ($this->_renderers as $renderer) - $this->_response = $renderer->render($this->_response); - return $this->_response; + public function getGeneratorRendering(){ + return $this->_generatorRendering; } public function flagImportIncrementialOnFull(){ - $this->_response->fullImport = true; + $this->_generatorRendering->addFullImportInResponse(true); } public function intFlagImportIncremential(){ - $this->_response->fullImport = false; - } - - public function newItem($item) { - $this->_response->data[] = $this->stdClassFrom($item); - } - - public function initializeDateExport(){ - $this->_response->date_export = $this->getCurrentDate()->format('c'); - } - - private function getCurrentDate(){ - if(null !== $this->_currentDate) - return $this->_currentDate; - return new DateTime(); - } - - public function setCurrentDate($currentDate){ - $this->_currentDate = new DateTime($currentDate); + $this->_generatorRendering->addFullImportInResponse(false); } - - public function stdClassFrom($item) { - $data = new StdClass(); - foreach ($this->_attributes as $attribute) { - $method = 'get' . ucfirst($attribute); - $data->$attribute = $item->$method(); - } - return $data; + public function generateRenderer($request, $itemClosure){ + if (!$this->isValid($request)) + return $this->_generatorRendering->renderResponse(); + + return $this->_generatorRendering->render($request, $itemClosure); } - public function isValid($request) { if (!($sign = $request->getParam('sign'))) { - $this->prepareResponseError('NO_PARAMETERS'); + $this->_generatorRendering->prepareResponseError('NO_PARAMETERS'); return false; } if(!Class_AdminVar::isWebkioskEnabled()){ - $this->prepareResponseError('WEBKIOSK_DISABLED'); + $this->_generatorRendering->prepareResponseError('WEBKIOSK_DISABLED'); return false; } @@ -137,12 +89,12 @@ class Class_Multimedia_Connector_Webkiosk { // openssl_free_key($public_key); if($isValidated == -1){ - $this->prepareResponseError('ERROR_CHECKING_SIGNATURE'); + $this->_generatorRendering->prepareResponseError('ERROR_CHECKING_SIGNATURE'); return false; } if($isValidated == 0){ - $this->prepareResponseError('INVALID_SIGNATURE'); + $this->_generatorRendering->prepareResponseError('INVALID_SIGNATURE'); return false; } @@ -152,8 +104,4 @@ class Class_Multimedia_Connector_Webkiosk { public function dataFor($data) { return $data . self::DATA_SEPARATOR . date('Ymd'); } - - public function prepareResponseError($msg){ - $this->_response->error = $msg; - } } \ No newline at end of file diff --git a/library/Class/Multimedia/PushAllUsersRequest.php b/library/Class/Multimedia/PushAllUsersRequest.php index 0d4949ae214..6a3feb0ef0b 100644 --- a/library/Class/Multimedia/PushAllUsersRequest.php +++ b/library/Class/Multimedia/PushAllUsersRequest.php @@ -26,7 +26,7 @@ class Class_Multimedia_PushAllUsersRequest extends Class_Multimedia_PushUsersReq } public function getResponse($request) { - return $this->_connector->render($request, function () { + return $this->_connector->generateRenderer($request, function () { $this->withBorrowersDo(); }); } diff --git a/library/Class/Multimedia/PushUsersModifiedRequest.php b/library/Class/Multimedia/PushUsersModifiedRequest.php index 9653aacd201..0cc3716aa44 100644 --- a/library/Class/Multimedia/PushUsersModifiedRequest.php +++ b/library/Class/Multimedia/PushUsersModifiedRequest.php @@ -27,18 +27,21 @@ class Class_Multimedia_PushUsersModifiedRequest extends Class_Multimedia_PushUse public function getResponse($request) { if (!($dateMaj = $request->getParam('dateMaj'))) { - $this->_connector->prepareResponseError('NO_PARAMETERS_LAST_DATE_UPDATED'); - return $this->_connector->renderResponse(); + $this->_connector->getGeneratorRendering()->prepareResponseError('NO_PARAMETERS_LAST_DATE_UPDATED'); + return $this->_connector->getGeneratorRendering()->renderResponse(); } $this->_connector->intFlagImportIncremential(); - if(!(Class_AdminVar::isBeforeDateLastFullIntegrationUsers(new DateTime($dateMaj)->format('Y-m-d H:i:s')))){ + $date = new DateTime($dateMaj); + if(!(Class_AdminVar::isBeforeDateLastFullIntegrationUsers( + $date->format('Y-m-d H:i:s')))){ $this->_connector->flagImportIncrementialOnFull(); } - return $this->_connector->render($request, function () use ($request) { - $this->withBorrowersDo(new DateTime($dateMaj)->format('Y-m-d H:i:s')); + return $this->_connector->generateRenderer($request, function () use ($request) { + $date = new DateTime($request->getParam('dateMaj')); + $this->withBorrowersDo($date->format('Y-m-d H:i:s')); }); } diff --git a/library/Class/Multimedia/PushUsersRequest.php b/library/Class/Multimedia/PushUsersRequest.php index 463b9ba17c4..778df551e63 100644 --- a/library/Class/Multimedia/PushUsersRequest.php +++ b/library/Class/Multimedia/PushUsersRequest.php @@ -29,7 +29,7 @@ abstract class Class_Multimedia_PushUsersRequest { public function withUsersDo($users) { foreach ($users as $user) - $this->_connector->newItem($user); + $this->_connector->getGeneratorRendering()->newItem($user); } public function getResponse($request) {} diff --git a/library/Class/Users.php b/library/Class/Users.php index 7e7f2dfb9ad..1cd8da66409 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -232,7 +232,6 @@ class Class_Users extends Storm_Model_Abstract { 'referenced_in' => 'id_site'), 'zone' => array('through' => 'bib')); -<<<<<<< HEAD protected $_default_attribute_values = ['id_site' => 0, 'login' => '', 'role' => 'invite', @@ -255,29 +254,6 @@ class Class_Users extends Storm_Model_Abstract { 'is_contact_sms' => 0, 'is_contact_mail' => 0, 'ordreabon' => '']; -======= - protected $_default_attribute_values = array('id_site' => 0, - 'login' => '', - 'role' => 'invite', - 'role_level' => 0, - 'idabon' => '', - 'date_fin' => '', - 'naissance' => '', - 'date_debut' => 0, - 'telephone' => '', - 'mail' => '', - 'nom' => '', - 'prenom' => '', - 'adresse' => '', - 'code_postal' => '', - 'ville' => '', - 'id_sigb' => null, - 'password' => '', - 'is_contact_sms' => 0, - 'is_contact_mail' => 0 - ); ->>>>>>> export user opac pour les multimedia : ajout d'un parametre retour la date d'export - protected $_translate; protected $_fiche_sigb; diff --git a/tests/application/modules/push/controllers/MultimediaControllerTest.php b/tests/application/modules/push/controllers/MultimediaControllerTest.php index ffe29fdf64f..3f7028de3cd 100644 --- a/tests/application/modules/push/controllers/MultimediaControllerTest.php +++ b/tests/application/modules/push/controllers/MultimediaControllerTest.php @@ -252,4 +252,321 @@ class Push_MultimediaControllerValidConfigTest extends AbstractControllerTestCas $this->assertEquals($this->_device_to_delete, Class_Multimedia_Device::getFirstAttributeForLastCallOn('delete')); } +} + + +abstract class AllBorrowersMultimediaControllerTestCase extends AbstractControllerTestCase { + protected + $_resp, + $_private_key ="-----BEGIN RSA PRIVATE KEY----- +MIICWwIBAAKBgQCm1hgee4LI7ji06BkuV8O4XpxHe59n80Gge/r3uROj+Tuxx2AO +Sk9gX7e4JNVsdfw22ft+xVqwAii8qu4/fYuicrrZl66WXceACmsgGWEdHMB7ZPUd +4HqR5bdE1Xnr1Q0Z9IIku6Naxt/yy0P5Gv+ZlW7U287hF3sdh2dp7UgguQIDAQAB +AoGAUQv+aYh8r1myqId7/Bxckws7BirS9G+iuPChqYf6N5US37lIO4jz6JB3MniK +SYdDf+4DE8GR3aEe4xBybttxYi9JSG28LxSMvUCv13AOpj8GT34cDxDgwczDI9nb +549/hdGpRF+vW0imfA1lguyuteoQHRMUImoHdl8ZRzPXlaUCQQDWEThzawIlbjah +v5uEQ5OjHIJfDECDyV4IIBGfwcpsiCH98Rb4SzcFRvoIJ7HtmNuHT6/fR5JQmnQG +0Vn6qTw3AkEAx4Rk4e/uLSxdDrsqI3rXg+mSNUAXc1IlHUJpRvoktbpfxTwRjwxO +Pp7HmcaApw5RuJ0nOnNGE0J4GBjEAglyjwJAKJ+p+9VB2gKZYYawJ6B/YwPlBc6Y +a6oKKzaSwaOQG5qWANAA0OvNLDY0+tk1neZVOs93i8LUVHGLNUQDdFsrbwJATEXi +wzUUGpThJmaK33Fwvm8mg9DyphV7NspSsN2j9w0+24nxNHyB1RKiP7lRKYwh1a/O +dVvoKCi6/ItLM3QlJQJAEyvWEfvqKnFH13ID5oe/GVOih7O6VzgecEgd3ZawBVWd +dsZ77MnSRzIyzrfJ3LlluaXhJl2qJBITE7X8y5RTKw== +-----END RSA PRIVATE KEY-----", + + $_public_key = "-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCm1hgee4LI7ji06BkuV8O4XpxH +e59n80Gge/r3uROj+Tuxx2AOSk9gX7e4JNVsdfw22ft+xVqwAii8qu4/fYuicrrZ +l66WXceACmsgGWEdHMB7ZPUd4HqR5bdE1Xnr1Q0Z9IIku6Naxt/yy0P5Gv+ZlW7U +287hF3sdh2dp7UgguQIDAQAB +-----END PUBLIC KEY-----", + + + $_invalid_public_key = "-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC6Q3TAOV6nWuS720NH4uas8Wdn +NMBZnbqsshKYeCzCCvqZJfwAyHMcSDQVvbqN452cqsZGKmxUbsRQMtcIml0gablf +Eq5k1SeviSt8OtxkK+pzJHrsC2GBlZuppoKsS9zwwlTEPttY9EgEY53mCSLF4IGD +yIuUs1qpg+Vx0R+3VwIDAQAB +-----END PUBLIC KEY-----"; + + /** + * @param $url string + * @return stdClass + */ + public function getResponseJsonDecode($url) { + $this->dispatch('/push/multimedia/'.$url, true); + return json_decode($this->_response->getBody()); + } + + public function getPublicKey(){ + return $this->_public_key; + } + + public function signUrl($action){ + $connector = new Class_Multimedia_Connector_Webkiosk(); + openssl_sign($connector->dataFor($action), + $sign, + $this->_private_key); + return base64_encode($sign); + } +} + +abstract class AllBorrowersMultimediaControllerJsonEncodeOnlyTestCase extends AllBorrowersMultimediaControllerTestCase { + public function setUp() { + parent::setUp(); + $connector = new Class_Multimedia_Connector_Multimedia(); + $connector->getGeneratorRendering()->setRenderers([new Class_Multimedia_Connector_Renderer_Json()]); + $connector->getGeneratorRendering()->setCurrentDate('2013-10-15 16:26:23'); + Class_Multimedia_Connector_Multimedia::setInstance($connector); + } +} + +class AllBorrowersMultimediaControllerGetAllBorrowersValidationTest extends AllBorrowersMultimediaControllerJsonEncodeOnlyTestCase { + public function setUp() { + parent::setUp(); + $this->_resp = $this->getResponseJsonDecode('get-all-borrowers'); + } + + + /** @test */ + public function responseShouldNotBeARedirect() { + $this->assertNotRedirect(); + } + + + /** @test */ + public function controllerActionShouldBeMultimediaAllBorrowers() { + $this->assertController('multimedia', $this->_response->getBody()); + $this->assertAction('get-all-borrowers'); + } + +} + + +class AllBorrowersMultimediaControllerNoParameterTest extends AllBorrowersMultimediaControllerJsonEncodeOnlyTestCase { + + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getAllBorrowers') + ->answers([AbonneMultimediaControllerMultimediaUsersFixtures::getLoas(), + AbonneMultimediaControllerMultimediaUsersFixtures::getAmadou()]); + + Class_AdminVar::getLoader() + ->newInstanceWithId('MULTIMEDIA_KEY') + ->setValeur($this->getPublicKey()); + + $sign = $this->signUrl('get-all-borrowers'); + $this->_resp = $this->getResponseJsonDecode('get-all-borrowers'); + } + + + /** @test */ + public function shouldHaveNumberDataZero() { + $this->assertEquals(0, count($this->_resp->data)); + } + + /** @test */ + public function shouldBeReturnedNoParameters() { + $this->assertEquals('NO_PARAMETERS', $this->_resp->error); + } +} + +class AllBorrowersMultimediaControllerWebkioskDisabledTest extends AllBorrowersMultimediaControllerJsonEncodeOnlyTestCase { + + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getAllBorrowers') + ->answers([AbonneMultimediaControllerMultimediaUsersFixtures::getLoas(), + AbonneMultimediaControllerMultimediaUsersFixtures::getAmadou()]); + + Class_AdminVar::getLoader() + ->newInstanceWithId('MULTIMEDIA_KEY') + ->setValeur(''); + + $sign = $this->signUrl('get-all-borrowers'); + $this->_resp = $this->getResponseJsonDecode('get-all-borrowers?sign=' . urlencode($sign)); + } + + + /** @test */ + public function shouldHaveNumberDataZero() { + $this->assertEquals(0, count($this->_resp->data)); + } + + /** @test */ + public function shouldBeReturnedWebKioskDesabled() { + $this->assertEquals('MULTIMEDIA_DISABLED', $this->_resp->error); + } +} + + + +class AllBorrowersMultimediaControllerInvalidSignatureTest extends AllBorrowersMultimediaControllerJsonEncodeOnlyTestCase { + + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getAllBorrowers') + ->answers([AbonneMultimediaControllerMultimediaUsersFixtures::getLoas(), + AbonneMultimediaControllerMultimediaUsersFixtures::getAmadou()]); + + Class_AdminVar::getLoader() + ->newInstanceWithId('MULTIMEDIA_KEY') + ->setValeur($this->_invalid_public_key); + + $sign = $this->signUrl('get-all-borrowers'); + $this->_resp = $this->getResponseJsonDecode('get-all-borrowers?sign=' . urlencode($sign)); + } + + + /** @test */ + public function shouldHaveNumberDataZero() { + $this->assertEquals(0, count($this->_resp->data)); + } + + /** @test */ + public function shouldBeReturnedInvalidSignature() { + $this->assertEquals('INVALID_SIGNATURE', $this->_resp->error); + } +} + + + +class AllBorrowersMultimediaControllerErrorCheckingSignatureTest extends AllBorrowersMultimediaControllerJsonEncodeOnlyTestCase { + + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getAllBorrowers') + ->answers([AbonneMultimediaControllerMultimediaUsersFixtures::getLoas(), + AbonneMultimediaControllerMultimediaUsersFixtures::getAmadou()]); + + Class_AdminVar::getLoader() + ->newInstanceWithId('MULTIMEDIA_KEY') + ->setValeur('"-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCm1hgee4LI +-----END PUBLIC KEY-----"'); + + $sign = $this->signUrl('get-all-borrowers'); + $this->_resp = $this->getResponseJsonDecode('get-all-borrowers?sign=' . urlencode($sign)); + } + + + /** @test */ + public function shouldHaveNumberDataZero() { + $this->assertEquals(0, count($this->_resp->data)); + } + + /** @test */ + public function shouldBeReturnedErrorCheckingSignature() { + $this->assertEquals('ERROR_CHECKING_SIGNATURE', $this->_resp->error); + } +} + + +class AllBorrowersMultimediaControllerGetAllBorrowersNumberOfOccurencesReturnedTest extends AllBorrowersMultimediaControllerJsonEncodeOnlyTestCase { + + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getAllBorrowers') + ->answers([AbonneMultimediaControllerMultimediaUsersFixtures::getLoas(), + AbonneMultimediaControllerMultimediaUsersFixtures::getAmadou()]); + + Class_AdminVar::getLoader() + ->newInstanceWithId('MULTIMEDIA_KEY') + ->setValeur($this->getPublicKey()); + + $sign = $this->signUrl('get-all-borrowers'); + $this->_resp = $this->getResponseJsonDecode('get-all-borrowers?sign=' . urlencode($sign)); + } + + /** @test */ + public function shouldHave2Borrowers() { + $this->assertEquals(2, count($this->_resp->data)); + } + + /** @test */ + public function shouldHaveDateExportEqual2013_01_13() { + $date = new DateTime('2013-10-15 16:26:23'); + $this->assertEquals($date->format('c'),$this->_resp->date_export); + } +} + + +class AllBorrowersMultimediaControllerFirstBorrowerReturnedIsLoasTest extends AllBorrowersMultimediaControllerJsonEncodeOnlyTestCase { + + + public function setUp() { + parent::setUp(); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getAllBorrowers') + ->answers([AbonneMultimediaControllerMultimediaUsersFixtures::getLoas(), + AbonneMultimediaControllerMultimediaUsersFixtures::getAmadou()]); + + Class_AdminVar::getLoader() + ->newInstanceWithId('MULTIMEDIA_KEY') + ->setValeur($this->getPublicKey()); + + $sign = $this->signUrl('get-all-borrowers'); + $this->_resp = $this->getResponseJsonDecode('get-all-borrowers?sign=' . urlencode($sign)); + } + + /** @test */ + public function shouldReturnedNameFisrtBorrowerIsLoas() { + $this->assertEquals('Loas', $this->_resp->data[0]->nom); + } + + + /** @test */ + public function shouldReturnedPasswordFisrtBorrowerIsLoas42Pat() { + $this->assertEquals('loas42Pat', $this->_resp->data[0]->password); + } + + /** @test */ + public function roleLevelShouldNotBePresent() { + $this->assertFalse( property_exists($this->_resp->data[0],'roleLevel')); + } + +} + + +class AbonneMultimediaControllerMultimediaUsersFixtures { + public static function getLoas() { + return Class_Users::getLoader()->newInstanceWithId(12) + ->beAbonneSIGB() + ->setLogin("loas") + ->setPassword("loas42Pat") + ->setNom('Loas') + ->setPrenom('Ghislain') + ->setRoleLevel(2) + ->setIdabon('all1') + ->setNaissance('1978-02-17') + ->setDateFin('2030-01-01') + ->setDateDebut('2022-01-01') + ->setEmail('loas@mail.fr'); + } + + + public static function getAmadou() { + return Class_Users::getLoader()->newInstanceWithId(13) + ->beAbonneSIGB() + ->setLogin("ama") + ->setPassword("ama") + ->setNom('Amadou') + ->setPrenom('DIOUF') + ->setRoleLevel(2) + ->setIdabon('all2') + ->setNaissance('1980-02-17') + ->setDateFin('2030-01-01') + ->setDateDebut('2029-01-01') + ->setEmail('loas@mail.fr'); + } } \ No newline at end of file diff --git a/tests/application/modules/push/controllers/WebkioskControllerTest.php b/tests/application/modules/push/controllers/WebkioskControllerTest.php index 971b8754ab6..877ad7e6fd3 100644 --- a/tests/application/modules/push/controllers/WebkioskControllerTest.php +++ b/tests/application/modules/push/controllers/WebkioskControllerTest.php @@ -83,8 +83,8 @@ abstract class WebkioskControllerJsonEncodeOnlyTestCase extends WebkioskControll public function setUp() { parent::setUp(); $connector = new Class_Multimedia_Connector_Webkiosk(); - $connector->setRenderers([new Class_Multimedia_Connector_Renderer_Json()]); - $connector->setCurrentDate('2013-10-15 16:26:23'); + $connector->getGeneratorRendering()->setRenderers([new Class_Multimedia_Connector_Renderer_Json()]); + $connector->getGeneratorRendering()->setCurrentDate('2013-10-15 16:26:23'); Class_Multimedia_Connector_Webkiosk::setInstance($connector); } } @@ -259,8 +259,6 @@ class WebkioskControllerGetAllBorrowersNumberOfOccurencesReturnedTest extends We /** @test */ public function shouldHave2Borrowers() { - $connector = new Class_Multimedia_Connector_Webkiosk(); - $this->assertEquals(2, count($this->_resp->data)); } @@ -314,7 +312,7 @@ abstract class WebkioskControllerJsonEncryptedTestCase extends WebkioskControlle public function setUp() { parent::setUp(); $connector = new Class_Multimedia_Connector_Webkiosk(); - $connector->setRenderers([new Class_Multimedia_Connector_Renderer_Json(), new Class_Multimedia_Connector_Renderer_Encrypt(), new Class_Multimedia_Connector_Renderer_Json()]); + $connector->getGeneratorRendering()->setRenderers([new Class_Multimedia_Connector_Renderer_Json(), new Class_Multimedia_Connector_Renderer_Encrypt(), new Class_Multimedia_Connector_Renderer_Json()]); Class_Multimedia_Connector_Webkiosk::setInstance($connector); } } -- GitLab