From ff8470ed1425241c5953fde0b0fec7f1a373ce95 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Mon, 14 May 2018 09:56:46 +0200 Subject: [PATCH] dev #72845 add migration patch --- cosmogramme/sql/patch/patch_345.php | 2 + library/Class/AdminVar/CVS.php | 2 +- .../Class/Migration/DigitalResource/CVS.php | 48 +++ library/Class/UserGroup.php | 3 - library/Class/Users.php | 5 - .../digital_resources/CVS/tests/CVSTest.php | 402 ++++++++++++++++++ .../controllers/NoticeAjaxControllerTest.php | 182 -------- .../controllers/RechercheControllerTest.php | 117 ----- tests/db/UpgradeDBTest.php | 12 +- .../Migration/DigitalResource/CVSTest.php | 119 ++++++ .../Class/Systeme/ModulesMenu/CvsTest.php | 72 ---- 11 files changed, 583 insertions(+), 381 deletions(-) create mode 100644 cosmogramme/sql/patch/patch_345.php create mode 100644 library/Class/Migration/DigitalResource/CVS.php create mode 100644 library/digital_resources/CVS/tests/CVSTest.php create mode 100644 tests/library/Class/Migration/DigitalResource/CVSTest.php delete mode 100644 tests/library/Class/Systeme/ModulesMenu/CvsTest.php diff --git a/cosmogramme/sql/patch/patch_345.php b/cosmogramme/sql/patch/patch_345.php new file mode 100644 index 00000000000..d86b055bc3d --- /dev/null +++ b/cosmogramme/sql/patch/patch_345.php @@ -0,0 +1,2 @@ +<?php +(new Class_Migration_DigitalResource_CVS)->run(); \ No newline at end of file diff --git a/library/Class/AdminVar/CVS.php b/library/Class/AdminVar/CVS.php index 5d721f51931..67a5f6e8814 100644 --- a/library/Class/AdminVar/CVS.php +++ b/library/Class/AdminVar/CVS.php @@ -26,7 +26,7 @@ class Class_AdminVar_CVS { $user = Class_Users::getIdentity(); if ($user) - return $user->hasRightAccesCVS(); + return false; return trim(Class_AdminVar::get('CVS_LOGINTEST')) > ''; } diff --git a/library/Class/Migration/DigitalResource/CVS.php b/library/Class/Migration/DigitalResource/CVS.php new file mode 100644 index 00000000000..e1b17f0a891 --- /dev/null +++ b/library/Class/Migration/DigitalResource/CVS.php @@ -0,0 +1,48 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Migration_DigitalResource_CVS extends Class_Migration_DigitalResource_Abstract { + + protected function _getOldRightToken() { + return 4; + } + + + protected function _getAdminVarMapping() { + return []; + } + + + protected function _getConfig() { + return CVS_Config::getInstance(); + } + + + protected function _getOldMenuName() { + return 'CVS'; + } + + + protected function _getOldBatchName() { + return 'CVS'; + } +} \ No newline at end of file diff --git a/library/Class/UserGroup.php b/library/Class/UserGroup.php index 68f95e9daf6..394687195a4 100644 --- a/library/Class/UserGroup.php +++ b/library/Class/UserGroup.php @@ -133,7 +133,6 @@ class Class_UserGroup extends Storm_Model_Abstract { const RIGHT_DIRIGER_ACTIVITY = 1; const RIGHT_ACCES_ARTEVOD = 2; const RIGHT_ACCES_NUMILOG = 3; - const RIGHT_ACCES_CVS = 4; const RIGHT_ACCES_VODECLIC = 5; const RIGHT_ACCES_TOUTAPPRENDRE = 6; const RIGHT_ACCES_NUMERIQUEPREMIUM = 20; @@ -178,7 +177,6 @@ class Class_UserGroup extends Storm_Model_Abstract { self::RIGHT_ACCES_ARTEVOD => 'Bibliothèque numérique: accéder à ARTE VOD', self::RIGHT_ACCES_NUMILOG => 'Bibliothèque numérique: accéder à Numilog', self::RIGHT_ACCES_CYBERLIBRIS => 'Bibliothèque numérique: accéder à Cyberlibris', - self::RIGHT_ACCES_CVS => 'Bibliothèque numérique: accéder à CVS', self::RIGHT_ACCES_VODECLIC => 'Bibliothèque numérique: accéder à Vodéclic', self::RIGHT_ACCES_TOUTAPPRENDRE => 'Bibliothèque numérique: accéder à Tout Apprendre', self::RIGHT_ACCES_NUMERIQUEPREMIUM => 'Bibliothèque numérique: accéder à Numérique Premium', @@ -229,7 +227,6 @@ class Class_UserGroup extends Storm_Model_Abstract { $mapping = ['Activity' => [Class_UserGroup::RIGHT_SUIVRE_ACTIVITY, Class_UserGroup::RIGHT_DIRIGER_ACTIVITY], 'ArteVod' => [Class_UserGroup::RIGHT_ACCES_ARTEVOD], - 'CVS' => [Class_UserGroup::RIGHT_ACCES_CVS], 'Numilog' => [Class_UserGroup::RIGHT_ACCES_NUMILOG], 'Vodeclic' => [Class_UserGroup::RIGHT_ACCES_VODECLIC], 'ToutApprendre' => [Class_UserGroup::RIGHT_ACCES_TOUTAPPRENDRE], diff --git a/library/Class/Users.php b/library/Class/Users.php index 8e0e53213d5..9a882f0b3d0 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -920,11 +920,6 @@ class Class_Users extends Storm_Model_Abstract { } - public function hasRightAccesCVS() { - return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCES_CVS); - } - - public function hasRightAccesVodeclic() { return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCES_VODECLIC); } diff --git a/library/digital_resources/CVS/tests/CVSTest.php b/library/digital_resources/CVS/tests/CVSTest.php new file mode 100644 index 00000000000..ed7e12d3f08 --- /dev/null +++ b/library/digital_resources/CVS/tests/CVSTest.php @@ -0,0 +1,402 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class CVSDashboardTest extends Admin_AbstractControllerTestCase { + + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + $this->dispatch('/CVS_Plugin/index', true); + } + + + /** @test */ + public function shouldDisplayDigitalResourceCVS() { + $this->assertXpathContentContains('//h1', 'CVS'); + } +} + + + + +class CVSModuleMenuTest extends Storm_Test_ModelTestCase { + public function setUp() { + parent::setUp(); + RessourcesNumeriquesFixtures::activate(); + $this->menu = new Class_Systeme_ModulesMenu_CVS(); + $this->user = $this->fixture('Class_Users', [ + 'id'=> 34 , + 'password' => 'toto' , + 'login' => '34', + 'idabon' => 34, + 'pseudo' => 'toto', + 'date_debut' => '1999-02-10', + 'date_fin' => '2025-09-12', + 'user_groups' => [$this->fixture('Class_UserGroup', [ + 'id' => 20, + 'libelle' => 'Cvs' + ])->addRight(4)]//Class_UserGroup::RIGHT_ACCES_CVS)] + ])->beAbonneSIGB(); + + ZendAfi_Auth::getInstance()->logUser($this->user); + Zend_Registry::get('translate')->setLocale('fr'); + } + + + /** @test */ + public function withUserNotInGroupShouldReturnJsAlert() { + $this->user->setUserGroups([]); + $this->menu->getDynamiqueUrl(); + $this->assertContains('Merci de contacter la médiathèque', $this->menu->getMessage()); + } + + + /** @test */ + public function withUserNotInGroupAndDocIdSetUrlForUserShouldBeEmpty() { + $this->user->setUserGroups([]); + $url = $this->menu + ->setDocId(1234) + ->urlForUser($this->user); + $this->assertEmpty($url, $url); + } + + + /** @test */ + public function urlWithAbonnementInvalidShouldBeJSAlertAbonnementInvalid() { + $this->user->setDateFin('2000-03-01'); + $url = $this->menu->getDynamiqueUrl(); + $this->assertContains('Votre abonnement ne permet pas', $this->menu->getMessage()); + } +} + + + + + + +abstract class CVSNoticeAjaxControllerCvsSearchTestCase extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setup() { + parent::setup(); + RessourcesNumeriquesFixtures::activateCVS(); + Class_AdminVar::newInstanceWithId('CVS_LOGINTEST', + ['valeur' => '']); + + $group_cvs = $this->fixture('Class_UserGroup', ['id' => 20 , + 'libelle' => 'CVS acces']) + ->addRight(4); //Class_UserGroup::RIGHT_ACCES_CVS); + + $polo= $this->fixture('Class_Users', ['id' => 15, + 'login' => 'polo', + 'password' => '456', + 'pseudo' => 'polo', + 'user_groups' => [$group_cvs]]) + ->beAbonneSIGB(); + + + ZendAfi_Auth::getInstance()->logUser($polo); + } +} + + + + +class CVSNoticeAjaxControllerCvsSearchFromGooglebotTest extends CVSNoticeAjaxControllerCvsSearchTestCase { + protected $_backup_useragent; + + public function setUp() { + parent::setUp(); + $_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1'; + } + + + + /** @test */ + public function responseShouldBeEmpty() { + $this->dispatch('/opac/noticeajax/cvs-search/expressionRecherche/Cuisson', true); + $this->assertEmpty($this->_response->getBody()); + } + + + public function tearDown() { + unset($_SERVER['HTTP_USER_AGENT']); + parent::tearDown(); + } +} + + + + +class CVSNoticeAjaxControllerCvsSearchWithNoRecordTest extends CVSNoticeAjaxControllerCvsSearchTestCase { + + public function setUp() { + parent::setUp(); + + $mock_cvs = Storm_Test_ObjectWrapper::mock(); + + Storm_Test_ObjectWrapper::mock() + ->whenCalled('forUser') + ->answers($this->mock_cvs); + $mock_cvs + ->whenCalled('searchNotices') + ->answers([]); + + Class_Profil::getCurrentProfil()->setCfgModules(['recherche' => ['resultat' => []]]); + $this->dispatch('/opac/noticeajax/cvs-search/expressionRecherche/Cuisson/page/2', true); + } + + + /** @test */ + public function resultShouldReturnEmptyMessage() { + $this->assertXPathContentContains('//div[@id="cvs_result"]/span','Aucun document trouv',$this->_response->getBody()); + } +} + + + + +abstract class CVSNoticeAjaxControllerCvsWithRecordsSearchWithResultTestCase extends CVSNoticeAjaxControllerCvsSearchTestCase { + protected $_http_client; + + public function setUp() { + parent::setUp(); + + Class_Profil::getCurrentProfil() + ->setCfgModules(['recherche' => + ['resultatsimple' => [ 'cvs_display_position' => '1', + 'liste_format' => 3, + 'cvs_nb_result' => 2]]]); + + RessourcesNumeriquesFixtures::activateCVS(); + + $this->_http_client = $this->mock(); + + Class_CVSLink::setTimeSource((new TimeSourceForTest)->setTime(1369640315)); + Class_WebService_Abstract::setDefaultHttpClient($this->_http_client); + RessourcesNumeriquesFixtures::activateCVS(); + + $this->_http_client + ->whenCalled('postData') + ->answers($this->_returnedXML()); + + } +} + + + + +class CVSNoticeAjaxControllerCvsWithRecordsSearchPhotographTest extends CVSNoticeAjaxControllerCvsWithRecordsSearchWithResultTestCase { + public function setUp() { + parent::setUp(); + + $record = $this->fixture('Class_Notice',['id'=> 10, + 'titre_principal' => 'Le photographe', + 'auteur_principal' => 'Guibert']); + + $this->dispatch('/opac/noticeajax/cvs-search/expressionRecherche/Cuisson/page/1', true); + } + + + protected function _returnedXML() { + return file_get_contents(realpath(dirname(__FILE__)). '/../../../../fixtures/cvs_search_ecole.xml'); + } + + + /** @test */ + public function pageShouldContainsDivCvsResult() { + $this->assertXPath('//div[@id="cvs_result"]//div[@class="cvs_record_list"]'); + } + + + /** @test **/ + public function resultFormatShouldBeVignetteMode() { + $this->assertXPath('//div[@class="liste_vignettes"]'); + } + + + /** @test **/ + public function cvsSearchRequestShouldHaveNbParPage2() { + $xml= base64_decode(strtr($this->_http_client->getAttributesForLastCallOn('postData')[1]['xml'], '-_', '+/')); + $xpath = new Storm_Test_XPathXML(); + $xpath->assertXPath($xml,'//nombre_par_page[contains(text(),2)]'); + } +} + + + + + +class CVSNoticeAjaxControllerCvsWithRecordsSearchDelpyTest extends CVSNoticeAjaxControllerCvsWithRecordsSearchWithResultTestCase { + public function setUp() { + parent::setUp(); + + $record = $this->fixture('Class_Notice',['id'=> 10, + 'titre_principal' => 'Musique', + 'auteur_principal' => 'Delpy']); + Class_CVSLink::forUser($record); + + $this->dispatch('/opac/noticeajax/cvs-search/expressionRecherche/Delpy/page/1', true); + } + + + protected function _returnedXML() { + return file_get_contents(realpath(dirname(__FILE__)). '/../../../../fixtures/cvs_search_delpy.xml'); + } + + + /** @test */ + public function pageShouldContainsDivCvsResult() { + $this->assertXPath('//div[@id="cvs_result"]//div[@class="cvs_record_list"]'); + } + + + /** @test */ + public function resultShouldContainsRecordTwoDaysInNewYork() { + $this->assertXPathContentContains('//div[@class="cvs_record_list"]//div[@class="vignette_titre"]/a', + '2 Days In New York'); + } +} + + + + +require_once 'RechercheControllerTest.php'; + + +class CVSRechercheControllerSimpleActionWithCvsActivatedTest extends RechercheControllerSimpleActionTestCase { + + protected $_cvs; + + public function setUp() { + parent::setUp(); + $this->dispatch('/recherche/simple/expressionRecherche/potter/facettes/T1/facette/B1/page/2', true); + + Class_Profil::getCurrentProfil() + ->setCfgModules(['recherche' => + ['resultatsimple' => [ 'cvs_autres_resultats' => 'Results from opac', + 'cvs_resultat_titre' => 'CVS Ressources', + 'cvs_nb_result' => '5', + 'cvs_display_position' => '1']]]); + + RessourcesNumeriquesFixtures::activateCVS(); + $group_cvs = $this->fixture('Class_UserGroup', ['id' => 20 , + 'libelle' => 'CVS acces']) + ->addRight(4); //Class_UserGroup::RIGHT_ACCES_CVS); + + $polo = $this->fixture('Class_Users', ['id' => 15, + 'login' => 'polo', + 'password' => '456', + 'pseudo' => 'polo', + 'date_fin' => '2025-04-26']) + ->beAbonneSIGB() + ->setUserGroups([$group_cvs]); + + ZendAfi_Auth::getInstance()->logUser($polo); + $record = $this->fixture('Class_Notice',['id'=> 10, + 'titre_principal' => 'Le photographe', + 'auteur_principal' => 'Guibert']); + $this->_cvs = Class_CVSLink::forUser($record); + $http_client = Storm_Test_ObjectWrapper::mock(); + + Class_WebService_Abstract::setDefaultHttpClient($http_client); + RessourcesNumeriquesFixtures::activateCVS(); + + $http_client + ->whenCalled('postData') + ->answers($this->_returnedXML()); + + $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/alpha_auteur',true); + + } + + protected function _returnedXML() { + $xml = file_get_contents(realpath(dirname(__FILE__)). '/../../../../fixtures/cvs_search_ecole.xml'); + return $xml; + } + + + /** @test **/ + public function titleResultFromOpacShouldBeDiplay() { + $this->assertXPathContentContains('//h1','Results from opac'); + } + + + /** @test */ + public function simpleContentShouldContainsCVSDiv() { + $this->assertXPath('//div[@class="conteneur_simple"]//div[contains(@class,"cvs_container")]', $this->_response->getBody()); + } + + + /** @test **/ + public function cvsBoiteShouldHaveTitreCVSRessources() { + $this->assertXPathContentContains('//div[@class="conteneur_simple"]//div[contains(@class,"cvs_container")]//h1', 'CVS Ressources', $this->_response->getBody()); + } + + + /** @test **/ + public function cvsBoiteClassShouldHavePosition1() { + $this->assertXPath('//div[@class="conteneur_simple"]//div[@class="cvs_container position_1"]', $this->_response->getBody()); + } +} + + + +class RechercheControllerSimpleActionWithCvsActivatedAndPreferencesHiddenTest extends RechercheControllerSimpleActionTestCase { + public function setUp() { + parent::setUp(); + + Class_Profil::getCurrentProfil() + ->setCfgModules(['recherche' => + ['resultatsimple' => [ 'cvs_display_position' => '0']]]); + $zork = $this->fixture('Class_Users', + ['id' => 4, + 'login' => 'zork_sigb', + 'role_level' => 2, + 'idabon' => '98475', + 'id_site' => 2, + 'password' => 'xzy']); + $group_multimedia = $this->fixture('Class_UserGroup', + ['id' => 20, + 'libelle' => 'Multimedia']) + ->addRight(4); //Class_UserGroup::RIGHT_ACCES_CVS); + + + $zork->beAbonneSIGB() + ->setUserGroups([$this->group_multimedia]) + ->save(); + ZendAfi_Auth::getInstance()->logUser($zork); + RessourcesNumeriquesFixtures::activateCVS(); + + $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/alpha_auteur',true); + + } + + + /** @test */ + public function simpleContentShouldNotContainsCVSDiv() { + $this->assertNotXPath('//div[@class="conteneur_simple"]//div[contains(@class,"cvs_container")]'); + } + +} diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php index de2bc3231f4..c4fe0a575bb 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php @@ -1803,154 +1803,6 @@ class NoticeAjaxControllerNoticeWithAvisAvisTest extends NoticeAjaxControllerNot -abstract class NoticeAjaxControllerCvsSearchTestCase extends AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; - - public function setup() { - parent::setup(); - RessourcesNumeriquesFixtures::activateCVS(); - Class_AdminVar::newInstanceWithId('CVS_LOGINTEST', - ['valeur' => '']); - - $group_cvs = $this->fixture('Class_UserGroup', ['id' => 20 , - 'libelle' => 'CVS acces']) - ->addRight(Class_UserGroup::RIGHT_ACCES_CVS); - - $polo= $this->fixture('Class_Users', ['id' => 15, - 'login' => 'polo', - 'password' => '456', - 'pseudo' => 'polo', - 'user_groups' => [$group_cvs]]) - ->beAbonneSIGB(); - - - ZendAfi_Auth::getInstance()->logUser($polo); - } -} - - - - -class NoticeAjaxControllerCvsSearchFromGooglebotTest extends NoticeAjaxControllerCvsSearchTestCase { - protected $_backup_useragent; - - public function setUp() { - parent::setUp(); - $_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1'; - } - - - - /** @test */ - public function responseShouldBeEmpty() { - $this->dispatch('/opac/noticeajax/cvs-search/expressionRecherche/Cuisson', true); - $this->assertEmpty($this->_response->getBody()); - } - - - public function tearDown() { - unset($_SERVER['HTTP_USER_AGENT']); - parent::tearDown(); - } -} - - - - -class NoticeAjaxControllerCvsSearchWithNoRecordTest extends NoticeAjaxControllerCvsSearchTestCase { - - public function setUp() { - parent::setUp(); - - $mock_cvs = Storm_Test_ObjectWrapper::mock(); - - Storm_Test_ObjectWrapper::mock() - ->whenCalled('forUser') - ->answers($this->mock_cvs); - $mock_cvs - ->whenCalled('searchNotices') - ->answers([]); - - Class_Profil::getCurrentProfil()->setCfgModules(['recherche' => ['resultat' => []]]); - $this->dispatch('/opac/noticeajax/cvs-search/expressionRecherche/Cuisson/page/2', true); - } - - - /** @test */ - public function resultShouldReturnEmptyMessage() { - $this->assertXPathContentContains('//div[@id="cvs_result"]/span','Aucun document trouv',$this->_response->getBody()); - } -} - - - - -abstract class NoticeAjaxControllerCvsWithRecordsSearchWithResultTestCase extends NoticeAjaxControllerCvsSearchTestCase { - protected $_http_client; - - public function setUp() { - parent::setUp(); - - Class_Profil::getCurrentProfil() - ->setCfgModules(['recherche' => - ['resultatsimple' => [ 'cvs_display_position' => '1', - 'liste_format' => 3, - 'cvs_nb_result' => 2]]]); - - RessourcesNumeriquesFixtures::activateCVS(); - - $this->_http_client = $this->mock(); - - Class_CVSLink::setTimeSource((new TimeSourceForTest)->setTime(1369640315)); - Class_WebService_Abstract::setDefaultHttpClient($this->_http_client); - RessourcesNumeriquesFixtures::activateCVS(); - - $this->_http_client - ->whenCalled('postData') - ->answers($this->_returnedXML()); - - } -} - - - - -class NoticeAjaxControllerCvsWithRecordsSearchPhotographTest extends NoticeAjaxControllerCvsWithRecordsSearchWithResultTestCase { - public function setUp() { - parent::setUp(); - - $record = $this->fixture('Class_Notice',['id'=> 10, - 'titre_principal' => 'Le photographe', - 'auteur_principal' => 'Guibert']); - - $this->dispatch('/opac/noticeajax/cvs-search/expressionRecherche/Cuisson/page/1', true); - } - - - protected function _returnedXML() { - return file_get_contents(realpath(dirname(__FILE__)). '/../../../../fixtures/cvs_search_ecole.xml'); - } - - - /** @test */ - public function pageShouldContainsDivCvsResult() { - $this->assertXPath('//div[@id="cvs_result"]//div[@class="cvs_record_list"]'); - } - - - /** @test **/ - public function resultFormatShouldBeVignetteMode() { - $this->assertXPath('//div[@class="liste_vignettes"]'); - } - - - /** @test **/ - public function cvsSearchRequestShouldHaveNbParPage2() { - $xml= base64_decode(strtr($this->_http_client->getAttributesForLastCallOn('postData')[1]['xml'], '-_', '+/')); - $xpath = new Storm_Test_XPathXML(); - $xpath->assertXPath($xml,'//nombre_par_page[contains(text(),2)]'); - } -} @@ -1970,40 +1822,6 @@ class NoticeAjaxControllerErrorTagsTest extends AbstractControllerTestCase { -class NoticeAjaxControllerCvsWithRecordsSearchDelpyTest extends NoticeAjaxControllerCvsWithRecordsSearchWithResultTestCase { - public function setUp() { - parent::setUp(); - - $record = $this->fixture('Class_Notice',['id'=> 10, - 'titre_principal' => 'Musique', - 'auteur_principal' => 'Delpy']); - Class_CVSLink::forUser($record); - - $this->dispatch('/opac/noticeajax/cvs-search/expressionRecherche/Delpy/page/1', true); - } - - - protected function _returnedXML() { - return file_get_contents(realpath(dirname(__FILE__)). '/../../../../fixtures/cvs_search_delpy.xml'); - } - - - /** @test */ - public function pageShouldContainsDivCvsResult() { - $this->assertXPath('//div[@id="cvs_result"]//div[@class="cvs_record_list"]'); - } - - - /** @test */ - public function resultShouldContainsRecordTwoDaysInNewYork() { - $this->assertXPathContentContains('//div[@class="cvs_record_list"]//div[@class="vignette_titre"]/a', - '2 Days In New York'); - } -} - - - - abstract class NoticeAjaxControllerBiographieTestCase extends AbstractControllerTestCase { public function setUp() { parent::setUp(); diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php index 13cd4d2015e..bbe5d6ca027 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php @@ -2875,123 +2875,6 @@ class RechercheControllerViewNoticeWhichIsInMyPanier extends RechercheController -class RechercheControllerSimpleActionWithCvsActivatedTest extends RechercheControllerSimpleActionTestCase { - - protected $_cvs; - - public function setUp() { - parent::setUp(); - $this->dispatch('/recherche/simple/expressionRecherche/potter/facettes/T1/facette/B1/page/2', true); - - Class_Profil::getCurrentProfil() - ->setCfgModules(['recherche' => - ['resultatsimple' => [ 'cvs_autres_resultats' => 'Results from opac', - 'cvs_resultat_titre' => 'CVS Ressources', - 'cvs_nb_result' => '5', - 'cvs_display_position' => '1']]]); - - RessourcesNumeriquesFixtures::activateCVS(); - $group_cvs = $this->fixture('Class_UserGroup', ['id' => 20 , - 'libelle' => 'CVS acces']) - ->addRight(Class_UserGroup::RIGHT_ACCES_CVS); - - $polo = $this->fixture('Class_Users', ['id' => 15, - 'login' => 'polo', - 'password' => '456', - 'pseudo' => 'polo', - 'date_fin' => '2025-04-26']) - ->beAbonneSIGB() - ->setUserGroups([$group_cvs]); - - ZendAfi_Auth::getInstance()->logUser($polo); - $record = $this->fixture('Class_Notice',['id'=> 10, - 'titre_principal' => 'Le photographe', - 'auteur_principal' => 'Guibert']); - $this->_cvs = Class_CVSLink::forUser($record); - $http_client = Storm_Test_ObjectWrapper::mock(); - - Class_WebService_Abstract::setDefaultHttpClient($http_client); - RessourcesNumeriquesFixtures::activateCVS(); - - $http_client - ->whenCalled('postData') - ->answers($this->_returnedXML()); - - $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/alpha_auteur',true); - - } - - protected function _returnedXML() { - $xml = file_get_contents(realpath(dirname(__FILE__)). '/../../../../fixtures/cvs_search_ecole.xml'); - return $xml; - } - - - /** @test **/ - public function titleResultFromOpacShouldBeDiplay() { - $this->assertXPathContentContains('//h1','Results from opac'); - } - - - /** @test */ - public function simpleContentShouldContainsCVSDiv() { - $this->assertXPath('//div[@class="conteneur_simple"]//div[contains(@class,"cvs_container")]', $this->_response->getBody()); - } - - - /** @test **/ - public function cvsBoiteShouldHaveTitreCVSRessources() { - $this->assertXPathContentContains('//div[@class="conteneur_simple"]//div[contains(@class,"cvs_container")]//h1', 'CVS Ressources', $this->_response->getBody()); - } - - - /** @test **/ - public function cvsBoiteClassShouldHavePosition1() { - $this->assertXPath('//div[@class="conteneur_simple"]//div[@class="cvs_container position_1"]', $this->_response->getBody()); - } -} - - - -class RechercheControllerSimpleActionWithCvsActivatedAndPreferencesHiddenTest extends RechercheControllerSimpleActionTestCase { - public function setUp() { - parent::setUp(); - - Class_Profil::getCurrentProfil() - ->setCfgModules(['recherche' => - ['resultatsimple' => [ 'cvs_display_position' => '0']]]); - $zork = $this->fixture('Class_Users', - ['id' => 4, - 'login' => 'zork_sigb', - 'role_level' => 2, - 'idabon' => '98475', - 'id_site' => 2, - 'password' => 'xzy']); - $group_multimedia = $this->fixture('Class_UserGroup', - ['id' => 20, - 'libelle' => 'Multimedia']) - ->addRight(Class_UserGroup::RIGHT_ACCES_CVS); - - - $zork->beAbonneSIGB() - ->setUserGroups([$this->group_multimedia]) - ->save(); - ZendAfi_Auth::getInstance()->logUser($zork); - RessourcesNumeriquesFixtures::activateCVS(); - - $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/alpha_auteur',true); - - } - - - /** @test */ - public function simpleContentShouldNotContainsCVSDiv() { - $this->assertNotXPath('//div[@class="conteneur_simple"]//div[contains(@class,"cvs_container")]'); - } - -} - - class RechercheControllerSuggestAjaxActionTest extends RechercheControllerNoticeTestCase { /** @test */ diff --git a/tests/db/UpgradeDBTest.php b/tests/db/UpgradeDBTest.php index b1fbc82faa1..19ad2bdbefd 100644 --- a/tests/db/UpgradeDBTest.php +++ b/tests/db/UpgradeDBTest.php @@ -2066,4 +2066,14 @@ class UpgradeDB_344_Test extends UpgradeDBTestCase { public function fieldsShouldExists($field, $type) { $this->assertFieldType('search_form', $field, $type); } -} \ No newline at end of file +} + + + + +class UpgradeDB_345_Test extends UpgradeDBTestCase { + public function prepare() {} + + /** @test */ + public function placeholderForCVSMigrationPatch() {} +} diff --git a/tests/library/Class/Migration/DigitalResource/CVSTest.php b/tests/library/Class/Migration/DigitalResource/CVSTest.php new file mode 100644 index 00000000000..b96432bc752 --- /dev/null +++ b/tests/library/Class/Migration/DigitalResource/CVSTest.php @@ -0,0 +1,119 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Migration_DigitialResource_CVSTest extends ModelTestCase { + protected + $_storm_default_to_volatile = true, + $_migration; + + public function setUp() { + parent::setUp(); + Class_DigitalResource::resetInstance(); + + $cfg_menus = ['H' => ['libelle' => 'Menu horizontal', + 'picto' => 'vide.gif', + 'menus' => [ + ['type_menu' => 'MENU', + 'libelle' => 'Pratique', + 'picto' => 'bookmark.png', + 'preferences' => [], + 'sous_menus' => [ + ['type_menu' => 'ACCUEIL', + 'libelle' => 'Accueil', + 'picto' => 'vide.gif', + 'preferences' => [], + 'sous_menus' => ''], + + ['type_menu' => 'CVS', + 'libelle' => 'Lien vers CVS', + 'preferences' => [], + 'picto' => 'vide.gif'] ]]]]]; + + $cfg_menus_without_CVS = ['H' => ['libelle' => 'Menu horizontal', + 'picto' => 'vide.gif', + 'menus' => [ + ['type_menu' => 'MENU', + 'libelle' => 'Pratique', + 'picto' => 'bookmark.png', + 'preferences' => [], + 'sous_menus' => [ + ['type_menu' => 'ACCUEIL', + 'libelle' => 'Accueil', + 'picto' => 'vide.gif', + 'preferences' => [], + 'sous_menus' => ''] ]]]]]; + + + $profil_adulte = $this->fixture('Class_Profil', + ['id' => 22, + 'parent_id' => null]) + ->setBrowser('opac') + ->setLibelle('Profil Adulte') + ->setCfgMenus($cfg_menus); + + $profil_without_CVS = $this->fixture('Class_Profil', + ['id' => 23, + 'rewrite_url' => 'adulte']) + ->setBrowser('opac') + ->setLibelle('Profil Adulte') + ->setCfgMenus($cfg_menus_without_CVS); + + + Class_Profil::setCurrentProfil($profil_adulte); + + $this->fixture('Class_UserGroup', + ['id' => 2, + 'libelle' => 'team ONE', + 'rights_token' => pow(2, 4)]); + + $this->_migration = (new Class_Migration_DigitalResource_CVS()) + ->setMemoryCleaner(function(){}) + ->run(); + } + + + public function tearDown() { + Class_DigitalResource::resetInstance(); + parent::tearDown(); + } + + + + /** @test */ + public function profilMenuWithAssimilShouldContainsCVS() { + $this->assertEquals('CVS', Class_Profil::find(22)->getCfgMenusAsArray()['H']['menus'][0]['sous_menus'][1]['type_menu']); + } + + + /** @test */ + public function teamOneShouldHavePermissionOnCVS() { + if (!$permissions = Class_UserGroup::find(2)->getPermissions()) + return $this->fail(); + $this->assertEquals('CVS', array_shift($permissions)->getCode()); + } + + + /** @test */ + public function teamOneRightsShouldBeCleaned() { + $this->assertEmpty(Class_UserGroup::find(2)->getRightsToken()); + } +} diff --git a/tests/library/Class/Systeme/ModulesMenu/CvsTest.php b/tests/library/Class/Systeme/ModulesMenu/CvsTest.php deleted file mode 100644 index 5c195797d26..00000000000 --- a/tests/library/Class/Systeme/ModulesMenu/CvsTest.php +++ /dev/null @@ -1,72 +0,0 @@ -<?php -/** - * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. - * - * BOKEH 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). - * - * BOKEH 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 BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - -class Class_Systeme_ModulesMenu_CvsTest extends Storm_Test_ModelTestCase { - public function setUp() { - parent::setUp(); - RessourcesNumeriquesFixtures::activate(); - $this->menu = new Class_Systeme_ModulesMenu_CVS(); - $this->user = $this->fixture('Class_Users', [ - 'id'=> 34 , - 'password' => 'toto' , - 'login' => '34', - 'idabon' => 34, - 'pseudo' => 'toto', - 'date_debut' => '1999-02-10', - 'date_fin' => '2025-09-12', - 'user_groups' => [$this->fixture('Class_UserGroup', [ - 'id' => 20, - 'libelle' => 'Cvs' - ])->addRight(Class_UserGroup::RIGHT_ACCES_CVS)] - ])->beAbonneSIGB(); - - ZendAfi_Auth::getInstance()->logUser($this->user); - Zend_Registry::get('translate')->setLocale('fr'); - } - - - /** @test */ - public function withUserNotInGroupShouldReturnJsAlert() { - $this->user->setUserGroups([]); - $this->menu->getDynamiqueUrl(); - $this->assertContains('Merci de contacter la médiathèque', $this->menu->getMessage()); - } - - - /** @test */ - public function withUserNotInGroupAndDocIdSetUrlForUserShouldBeEmpty() { - $this->user->setUserGroups([]); - $url = $this->menu - ->setDocId(1234) - ->urlForUser($this->user); - $this->assertEmpty($url, $url); - } - - - /** @test */ - public function urlWithAbonnementInvalidShouldBeJSAlertAbonnementInvalid() { - $this->user->setDateFin('2000-03-01'); - $url = $this->menu->getDynamiqueUrl(); - $this->assertContains('Votre abonnement ne permet pas', $this->menu->getMessage()); - } -} -?> \ No newline at end of file -- GitLab