From 0b34a1141c731dc0a9141baec727d2c0b79c6ddc Mon Sep 17 00:00:00 2001 From: adiouf <adiouf@afi-sa.fr> Date: Tue, 2 Dec 2014 15:17:18 +0100 Subject: [PATCH] rel #18020 : fix test failure and not received device deletion --- .../push/controllers/MultimediaController.php | 25 ++++---- .../controllers/MultimediaControllerTest.php | 57 +++++++++---------- 2 files changed, 39 insertions(+), 43 deletions(-) diff --git a/application/modules/push/controllers/MultimediaController.php b/application/modules/push/controllers/MultimediaController.php index d5dc7eaac1f..5b3b1ad4838 100644 --- a/application/modules/push/controllers/MultimediaController.php +++ b/application/modules/push/controllers/MultimediaController.php @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Push_MultimediaController extends Zend_Controller_Action { public function configAction() { $multimedia = Class_Multimedia::getInstance(); $log = $multimedia->getLog(); $log->info('Push multimedia start'); - + $this->_helper->getHelper('viewRenderer')->setNoRender(); if (null == ($json = $this->_getParam('json'))) { @@ -35,12 +35,12 @@ class Push_MultimediaController extends Zend_Controller_Action { $log->err('Missing sign parameter'); return; } - + if (!($groups = json_decode($json))) { $log->err('Invalid json'); return; } - + if (!$multimedia->isValidHash($sign, $this->_getParam('json'))) { $log->err('Sign check failure'); return; @@ -68,16 +68,17 @@ class Push_MultimediaController extends Zend_Controller_Action { public function deleteAllPostesFromSiteWithoutIdOrigine($id_site, $id_origine_postes) { - $postes_to_delete = Class_Multimedia_Device::findAllBy(['where' => sprintf('id_origine not in(%s) and id_origine like \'%s-%%\'', - implode(',', array_map(function($id){return '\''.$id.'\'';}, - $id_origine_postes)), - $id_site)]); - foreach($postes_to_delete as $poste) - $poste->delete(); + Class_Multimedia_Device::deleteBy(['id_origine not' => $id_origine_postes]); } - - + + public function deleteAllGpPosteFromSiteWithoutPoste(){ + $listGposte = Class_Multimedia_DeviceGroup::findAll(); + + } + + + public function getAllBorrowersAction() { $this->getHelper('ViewRenderer')->setNoRender(); diff --git a/tests/application/modules/push/controllers/MultimediaControllerTest.php b/tests/application/modules/push/controllers/MultimediaControllerTest.php index a2ca35a4b76..4b7d75587d6 100644 --- a/tests/application/modules/push/controllers/MultimediaControllerTest.php +++ b/tests/application/modules/push/controllers/MultimediaControllerTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'AbstractControllerTestCase.php'; @@ -35,7 +35,7 @@ abstract class Push_MultimediaControllerTestCase extends AbstractControllerTestC class Push_MultimediaControllerInvalidConfigTest extends Push_MultimediaControllerTestCase { public function setUp() { - parent::setUp(); + parent::setUp(); $this->_log ->whenCalled('err')->answers(null) ->whenCalled('info')->answers(null); @@ -48,14 +48,14 @@ class Push_MultimediaControllerInvalidConfigTest extends Push_MultimediaControll [['json' => '{}'], 'Missing sign parameter'], [['json' => 'it is invalid', 'sign' => 'iu/-@+uieiucrc'], 'Invalid json'], [['json' => '[{"libelle":"Groupe 1", "id":1, "site":{"id":1,"libelle":"Site 1"}, "postes":[{"id":1, "libelle":"Poste 1", "os":"Windows XP", "maintenance":"1"}, {"id":2, "libelle":"Poste 2", "os":"Ubuntu Lucid Lynx", "maintenance":"0"}]}]', - 'sign' => 'iu/-@+uieiucrc'], + 'sign' => 'iu/-@+uieiucrc'], 'Sign check failure'] ]; } - /** - * @test + /** + * @test * @dataProvider datas */ public function withParamsShouldHaveError($params, $message) { @@ -112,13 +112,7 @@ l66WXceACmsgGWEdHMB7ZPUd4HqR5bdE1Xnr1Q0Z9IIku6Naxt/yy0P5Gv+ZlW7U Class_Multimedia_Location::beVolatile(); Class_Multimedia_DeviceGroup::beVolatile(); - - $this->_device_wrapper = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_Device') - ->whenCalled('findAllBy') - ->with(['where' => 'id_origine not in(\'1-1\',\'1-2\') and id_origine like \'1-%\'']) - ->answers([ - $this->fixture('Class_Multimedia_Device', - ['id' => 34, 'id_origine' => '1-34'])]); + $this->fixture('Class_Multimedia_Device', ['id' => 34, 'id_origine' => '1-34']); $datas = '[{"libelle":"Groupe 1", "id":1, "site":{"id":1,"libelle":"Site 1","admin_url":"192.168.2.92"}, "postes":[{"id":1, "libelle":"Poste 1", "os":"Windows XP", "maintenance":"1"}, {"id":2, "libelle":"Poste 2", "os":"Ubuntu Lucid Lynx", "maintenance":"0"}]}]'; @@ -137,7 +131,7 @@ l66WXceACmsgGWEdHMB7ZPUd4HqR5bdE1Xnr1Q0Z9IIku6Naxt/yy0P5Gv+ZlW7U return base64_encode($sign); } - + /** @test */ public function deviceGroupLibelleShouldBeGroupeOne() { $this->assertEquals('Groupe 1', $this->_group->getLibelle()); @@ -171,6 +165,7 @@ l66WXceACmsgGWEdHMB7ZPUd4HqR5bdE1Xnr1Q0Z9IIku6Naxt/yy0P5Gv+ZlW7U /** @test */ public function firstDeviceLibelleShouldBePoste1() { + $this->assertEquals('Poste 1', $this->_devices[0]->getLibelle()); } @@ -190,7 +185,7 @@ l66WXceACmsgGWEdHMB7ZPUd4HqR5bdE1Xnr1Q0Z9IIku6Naxt/yy0P5Gv+ZlW7U /** @test */ public function firstDeviceGroupShouldBeGroupe1() { $this->assertEquals($this->_group, $this->_devices[0]->getGroup()); - } + } /** @test */ @@ -216,7 +211,7 @@ l66WXceACmsgGWEdHMB7ZPUd4HqR5bdE1Xnr1Q0Z9IIku6Naxt/yy0P5Gv+ZlW7U $this->assertEquals('1-2', $this->_devices[1]->getIdOrigine()); } - + /** @test */ public function secondDeviceShouldNotBeDisabled() { $this->assertFalse($this->_devices[1]->isDisabled()); @@ -231,7 +226,7 @@ l66WXceACmsgGWEdHMB7ZPUd4HqR5bdE1Xnr1Q0Z9IIku6Naxt/yy0P5Gv+ZlW7U abstract class AllBorrowersMultimediaControllerTestCase extends AbstractControllerTestCase { - protected + protected $_resp, $_private_key ="-----BEGIN RSA PRIVATE KEY----- MIICWwIBAAKBgQCm1hgee4LI7ji06BkuV8O4XpxHe59n80Gge/r3uROj+Tuxx2AO @@ -276,18 +271,18 @@ yIuUs1qpg+Vx0R+3VwIDAQAB public function getPublicKey(){ return $this->_public_key; } - + public function signUrl($action){ $connector = new Class_Multimedia_Connector_Multimedia(); - openssl_sign($connector->dataFor($action), - $sign, + openssl_sign($connector->dataFor($action), + $sign, $this->_private_key); return base64_encode($sign); } } -abstract class AllBorrowersMultimediaControllerJsonEncodeOnlyTestCase +abstract class AllBorrowersMultimediaControllerJsonEncodeOnlyTestCase extends AllBorrowersMultimediaControllerTestCase { public function setUp() { parent::setUp(); @@ -300,7 +295,7 @@ extends AllBorrowersMultimediaControllerTestCase { } -class AllBorrowersMultimediaControllerGetAllBorrowersValidationTest +class AllBorrowersMultimediaControllerGetAllBorrowersValidationTest extends AllBorrowersMultimediaControllerJsonEncodeOnlyTestCase { public function setUp() { parent::setUp(); @@ -309,7 +304,7 @@ extends AllBorrowersMultimediaControllerJsonEncodeOnlyTestCase { /** @test */ - public function responseShouldNotBeARedirect() { + public function responseShouldNotBeARedirect() { $this->assertNotRedirect(); } @@ -335,7 +330,7 @@ class AllBorrowersMultimediaControllerNoParameterTest extends AllBorrowersMultim $this->_resp = $this->getResponseJsonDecode('get-all-borrowers'); } - + /** @test */ public function shouldHaveNumberDataZero() { $this->assertEquals(0, count($this->_resp->data)); @@ -361,7 +356,7 @@ class AllBorrowersMultimediaControllerDisabledTest extends AllBorrowersMultimedi $this->_resp = $this->getResponseJsonDecode('get-all-borrowers?sign=' . urlencode($sign)); } - + /** @test */ public function shouldHaveNumberDataZero() { $this->assertEquals(0, count($this->_resp->data)); @@ -388,7 +383,7 @@ class AllBorrowersMultimediaControllerInvalidSignatureTest extends AllBorrowersM $this->_resp = $this->getResponseJsonDecode('get-all-borrowers?sign=' . urlencode($sign)); } - + /** @test */ public function shouldHaveNumberDataZero() { $this->assertEquals(0, count($this->_resp->data)); @@ -417,7 +412,7 @@ MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCm1hgee4LI $this->_resp = $this->getResponseJsonDecode('get-all-borrowers?sign=' . urlencode($sign)); } - + /** @test */ public function shouldHaveNumberDataZero() { $this->assertEquals(0, count($this->_resp->data)); @@ -439,7 +434,7 @@ class AllBorrowersMultimediaControllerGetAllBorrowersNumberOfOccurencesReturnedT ->whenCalled('countBorrowers') ->answers(2) ->whenCalled('getBorrowersByPage') - ->answers([AbonneMultimediaControllerMultimediaUsersFixtures::getLoas(), + ->answers([AbonneMultimediaControllerMultimediaUsersFixtures::getLoas(), AbonneMultimediaControllerMultimediaUsersFixtures::getAmadou()]); Class_AdminVar::getLoader() @@ -457,7 +452,7 @@ class AllBorrowersMultimediaControllerGetAllBorrowersNumberOfOccurencesReturnedT /** @test */ public function shouldHaveDateExportEqual2013_01_13() { - $date = new DateTime('2013-10-15 16:26:23'); + $date = new DateTime('2013-10-15 16:26:23'); $this->assertEquals($date->format('c'),$this->_resp->date_export); } } @@ -471,7 +466,7 @@ class AllBorrowersMultimediaControllerFirstBorrowerReturnedIsLoasTest extends Al ->whenCalled('countBorrowers') ->answers(2) ->whenCalled('getBorrowersByPage') - ->answers([AbonneMultimediaControllerMultimediaUsersFixtures::getLoas(), + ->answers([AbonneMultimediaControllerMultimediaUsersFixtures::getLoas(), AbonneMultimediaControllerMultimediaUsersFixtures::getAmadou()]); Class_AdminVar::getLoader() @@ -487,7 +482,7 @@ class AllBorrowersMultimediaControllerFirstBorrowerReturnedIsLoasTest extends Al $this->assertEquals('Loas', $this->_resp->data[0]->nom); } - + /** @test */ public function shouldReturnedPasswordFisrtBorrowerIsLoas42Pat() { $this->assertEquals('loas42Pat', $this->_resp->data[0]->password); @@ -516,7 +511,7 @@ class AbonneMultimediaControllerMultimediaUsersFixtures { ->setEmail('loas@mail.fr'); } - + public static function getAmadou() { return Class_Users::getLoader()->newInstanceWithId(13) ->beAbonneSIGB() -- GitLab