diff --git a/VERSIONS_WIP/152400 b/VERSIONS_WIP/152400 new file mode 100644 index 0000000000000000000000000000000000000000..7078743d93c5de55d20f9cd71d290a32c1188252 --- /dev/null +++ b/VERSIONS_WIP/152400 @@ -0,0 +1 @@ + - fonctionnalité #152400 : Enrichissements : Prise en charge de la nouvelle API ELECTRE NG, ATTENTION : la mise à jour des identifiants est requise \ No newline at end of file diff --git a/cosmogramme/sql/patch/patch_428.php b/cosmogramme/sql/patch/patch_428.php new file mode 100644 index 0000000000000000000000000000000000000000..e7d5bf29fb237c6634eebab95cee84d24728da0f --- /dev/null +++ b/cosmogramme/sql/patch/patch_428.php @@ -0,0 +1,8 @@ +<?php +$adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); + +try { + $adapter->query('UPDATE bib_admin_var' + . ' SET valeur=REPLACE(valeur, "electre_rest_2", "electre_ng")' + . ' WHERE clef="PELLICULE_SETTINGS"'); +} catch(Exception $e) {} diff --git a/library/Class/AdminVar/PelliculeSettings.php b/library/Class/AdminVar/PelliculeSettings.php index 73a6d3f3bb7f1c31d9862aa42e4784d343cc6650..c3f85f51fc1122f2c76ad4e7fd9ad41436493b33 100644 --- a/library/Class/AdminVar/PelliculeSettings.php +++ b/library/Class/AdminVar/PelliculeSettings.php @@ -27,7 +27,7 @@ class Class_AdminVar_PelliculeSettings { LOGIN_KEY = 'Login', PASSWORD_KEY = 'Password', - ELECTRE_REST_2 = 'electre_rest_2'; + PROVIDER_ID = 'electre_ng'; protected $_settings; @@ -50,7 +50,7 @@ class Class_AdminVar_PelliculeSettings { ['name' => static::PROVIDER_KEY, 'label' => $this->_('Fournisseur'), 'type' => 'select', - 'options' => [static::ELECTRE_REST_2 => $this->_('Electre v2 REST')], + 'options' => [static::PROVIDER_ID => $this->_('Electre NG')], ], ['name' => static::LOGIN_KEY, 'label' => $this->_('Identifiant')], diff --git a/tests/db/UpgradeDBTest.php b/tests/db/UpgradeDBTest.php index 5b3b2521548af64fcf8aaac3c40b19cda37325dc..9e5afd942ae43333975e5efeb1659a0c0a7538b5 100644 --- a/tests/db/UpgradeDBTest.php +++ b/tests/db/UpgradeDBTest.php @@ -32,14 +32,14 @@ abstract class UpgradeDBTestCase extends PHPUnit_Framework_TestCase { } - public function query($query) { - return Zend_Db_Table::getDefaultAdapter()->query($query); + public function query($query, $bind=[]) { + return Zend_Db_Table::getDefaultAdapter()->query($query, $bind); } - public function silentQuery($query) { + public function silentQuery($query, $bind=[]) { try { - $this->query($query); + $this->query($query, $bind); } catch(Exception $e) {} return $this; @@ -4371,3 +4371,24 @@ class UpgradeDB_427_Test extends UpgradeDBTestCase { $this->assertEquals('PRI', $columns['Key']); } } + + + + +class UpgradeDB_428_Test extends UpgradeDBTestCase { + public function prepare() { + $this->query('replace into bib_admin_var(clef, valeur) values(?, ?)', + ['PELLICULE_SETTINGS', + '{"Provider":["electre_rest_2"],"Login":["api_cat_login"],"Password":["?login@cat_api!"]}']); + } + + + /** @test */ + public function pelliculeProviderShouldBecomeElectreNg() { + $row = $this->query('select valeur from bib_admin_var where clef="PELLICULE_SETTINGS"') + ->fetch(); + + $this->assertEquals('{"Provider":["electre_ng"],"Login":["api_cat_login"],"Password":["?login@cat_api!"]}', + $row['valeur'] ?? ''); + } +} diff --git a/tests/scenarios/Pellicule/PelliculeAdminVarTest.php b/tests/scenarios/Pellicule/PelliculeAdminVarTest.php new file mode 100644 index 0000000000000000000000000000000000000000..8c6f8a7f0e3913f48980afd110bbb00311f5a387 --- /dev/null +++ b/tests/scenarios/Pellicule/PelliculeAdminVarTest.php @@ -0,0 +1,45 @@ +<?php +/** + * Copyright (c) 2012-2022, 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 PelliculeAdminVarTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + Class_AdminVar::set('PELLICULE_SETTINGS', ''); + $this->dispatch('/admin/index/adminvaredit/cle/PELLICULE_SETTINGS'); + } + + + /** @test */ + public function pageShouldContainsIdentifiantAupresDUnFournisseurDeVignettes() { + $this->assertXPathContentContains('//p', + 'Identifiant auprès d\'un fournisseur de vignettes'); + } + + + /** @test */ + public function pageShouldContainsScriptWithTypeElectreNg() { + $this->assertXPathContentContains('//script', ':{"electre_ng":"Electre NG"}'); + } +} diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerPelliculeTest.php b/tests/scenarios/Pellicule/PelliculeNoticeAjaxTest.php similarity index 67% rename from tests/application/modules/opac/controllers/NoticeAjaxControllerPelliculeTest.php rename to tests/scenarios/Pellicule/PelliculeNoticeAjaxTest.php index b0c8b1ad7b66dcf7f1939bdb269eb09d7ad2e480..f9aa9e5f1dd623b6d218b26559498c0e4b6cc9a9 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerPelliculeTest.php +++ b/tests/scenarios/Pellicule/PelliculeNoticeAjaxTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved. + * Copyright (c) 2012-2022, 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 @@ -20,23 +20,24 @@ */ -class NoticeAjaxControllerPelliculeActiveTest extends AbstractControllerTestCase { +class PelliculeNoticeAjaxTest extends AbstractControllerTestCase { protected $_storm_default_to_volatile = true, - $_http_client; + $_http_client, + $_authorization; public function setUp() { parent::setUp(); Class_CosmoVar::setValueOf('url_services', 'http://cache.org'); Class_AdminVar::set('PELLICULE_SETTINGS', - json_encode(['Provider' => [Class_AdminVar_PelliculeSettings::ELECTRE_REST_2], + json_encode(['Provider' => [Class_AdminVar_PelliculeSettings::PROVIDER_ID], 'Login' => ['mylogin'], 'Password' => ['mys3cr3t']])); Class_Exemplaire::clearCache(); Class_Notice::clearCache(); - $this->fixture('Class_Notice', + $this->fixture(Class_Notice::class, ['id' => 1, 'titre' => 'Pomme et Ananas', 'titre_principal' => 'Journey in Satchidananda', @@ -49,7 +50,7 @@ class NoticeAjaxControllerPelliculeActiveTest extends AbstractControllerTestCase 'type_doc' => Class_TypeDoc::LIVRE, 'url_vignette' => '', 'url_image' => '', - 'exemplaires' => [$this->fixture('Class_Exemplaire', + 'exemplaires' => [$this->fixture(Class_Exemplaire::class, ['id' => 2, 'id_origine' => '9939_SSIRTE'])] ]); @@ -60,14 +61,37 @@ class NoticeAjaxControllerPelliculeActiveTest extends AbstractControllerTestCase Class_WebService_Afi::setHttpClient($this->_http_client); $this->dispatch('/noticeajax/notice/id/1'); + $call_params = $this->_http_client->getAttributesForLastCallOn('open_url'); + $this->_authorization = $call_params[1]['headers'][0]['Authorization'] ?? null; } /** @test */ - public function requestShouldContainsAuthorizationHeader() { - $headers = [['Authorization' => "Pellicule eyJwcm92aWRlciI6ImVsZWN0cmVfcmVzdF8yIiwiY2xpZW50X2lkIjoibXlsb2dpbiIsImNsaWVudF9zZWNyZXQiOiJteXMzY3IzdCJ9"]]; + public function authorizationShouldNotBeNull() { + $this->assertNotNull($this->_authorization); + } - $call_params = $this->_http_client->getAttributesForLastCallOn('open_url'); - $this->assertEquals($headers, $call_params[1]['headers']); + + /** @test */ + public function authorizationTypeShouldBePellicule() { + $this->assertEquals('Pellicule ', substr($this->_authorization, 0, 10)); + } + + + public function credentials() { + return [['provider', 'electre_ng'], + ['client_id', 'mylogin'], + ['client_secret', 'mys3cr3t']]; + } + + + /** + * @test + * @dataProvider credentials + */ + public function authorizationCredientialValueShouldBe($key, $value) { + $credentials = json_decode(base64_decode(str_replace('Pellicule ', '', $this->_authorization)), + true); + $this->assertEquals($value, $credentials[$key]); } }