diff --git a/VERSIONS_WIP/159589 b/VERSIONS_WIP/159589 new file mode 100644 index 0000000000000000000000000000000000000000..e5da8b2016b72b19dad1daab36d15ec9df5a8c3c --- /dev/null +++ b/VERSIONS_WIP/159589 @@ -0,0 +1 @@ + - fonctionnalité #159589 : Amélioration de la gestion du paramètre d'url render/ajax. \ No newline at end of file diff --git a/application/modules/opac/controllers/BibController.php b/application/modules/opac/controllers/BibController.php index e12bd3d0f9d934676401de8d0a7fc4184c559dc8..1868b9b668cf4b2d17a499fabaf8032faa266622 100644 --- a/application/modules/opac/controllers/BibController.php +++ b/application/modules/opac/controllers/BibController.php @@ -232,9 +232,6 @@ class BibController extends ZendAfi_Controller_Action { public function widgetPageAction() { $viewRenderer = $this->getHelper('ViewRenderer'); - if ($this->_getParam('render') === 'ajax') - $viewRenderer->setLayoutScript('empty.phtml'); - $id_module = (int)$this->_getParam('id_module'); $id_division = (int)$this->_getParam('id_division'); $page = (int)$this->_getParam('page'); @@ -260,14 +257,7 @@ class BibController extends ZendAfi_Controller_Action { $preferences['ID_MODULE'] = $id_module; $this->view->titre = $preferences['titre']; - $this->view->content = $this->view->librariesWidget($preferences); - - if (!$this->_getParam('render') === 'ajax') - return; - - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($this->view->content); } @@ -281,14 +271,7 @@ class BibController extends ZendAfi_Controller_Action { $preferences['ID_MODULE'] = $id_module; $this->view->titre = $preferences['titre']; - $this->view->content = $this->view->librariesWidgetForAjax($preferences); - - if (!$this->_getParam('render') === 'ajax') - return; - - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($this->view->content); } diff --git a/application/modules/opac/controllers/CmsController.php b/application/modules/opac/controllers/CmsController.php index 3422f8cf9edf17b0529dd5838761afd63e46f9d5..29e019cdda258227b4045c45c5c43161c6194ab5 100644 --- a/application/modules/opac/controllers/CmsController.php +++ b/application/modules/opac/controllers/CmsController.php @@ -246,37 +246,26 @@ class CmsController extends ZendAfi_Controller_Action { public function calendarAction() { $this->_initCalendarAndPreferences(); - if ($this->_getParam('render') !== 'ajax') - return; - $cache_key = [$this->_request->getParams(), Class_Profil::getCurrentProfil()->getId(), __CLASS__, __FUNCTION__]; - $content = (new Storm_Cache()) + + $this->view->content = (new Storm_Cache) ->memoize($cache_key, function() { return $this->view->calendarContent($this->view->calendar, $this->view->preferences); }); - - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($content); } public function renderAllAction() { $this->_initCalendarAndPreferences(); - if (!$this->_getParam('render') === 'ajax') - return; - - $content = $this->view->calendarContentForAjax($this->view->calendar, - $this->view->preferences); - - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($content); + $this->view->content = $this->view->calendarContentForAjax($this->view->calendar, + $this->view->preferences); } diff --git a/application/modules/opac/controllers/RechercheController.php b/application/modules/opac/controllers/RechercheController.php index 166d9863bae0bf1f69e15a2b363a6bc2c1312aa8..df23656a12aa56cb4721a5a449d3ecd998201bf1 100644 --- a/application/modules/opac/controllers/RechercheController.php +++ b/application/modules/opac/controllers/RechercheController.php @@ -88,10 +88,6 @@ class RechercheController extends ZendAfi_Controller_Action { throw new Zend_Controller_Action_Exception($this->view->_('Exemplaire non trouvé'), 404); $this->view->content = $this->view->itemShelf(new Class_Exemplaire_Shelf($item)); - - if ('ajax' === $this->_getParam('render')) - $this->_helper->getHelper('HTMLAjaxResponse') - ->htmlAjaxResponseWithScript($this->view->content); } diff --git a/application/modules/opac/views/scripts/bib/render-all.phtml b/application/modules/opac/views/scripts/bib/render-all.phtml new file mode 100644 index 0000000000000000000000000000000000000000..ff71d31e883048cb05ea7b632370dd47b1fe1517 --- /dev/null +++ b/application/modules/opac/views/scripts/bib/render-all.phtml @@ -0,0 +1,2 @@ +<?php +echo $this->content; diff --git a/application/modules/opac/views/scripts/cms/calendar.phtml b/application/modules/opac/views/scripts/cms/calendar.phtml index b82d04aa41e331c9249b5b33e3ac62953a7ecfab..ff71d31e883048cb05ea7b632370dd47b1fe1517 100644 --- a/application/modules/opac/views/scripts/cms/calendar.phtml +++ b/application/modules/opac/views/scripts/cms/calendar.phtml @@ -1,2 +1,2 @@ <?php -echo $this->calendarContent($this->calendar, $this->preferences); +echo $this->content; diff --git a/application/modules/opac/views/scripts/cms/render-all.phtml b/application/modules/opac/views/scripts/cms/render-all.phtml new file mode 100644 index 0000000000000000000000000000000000000000..ff71d31e883048cb05ea7b632370dd47b1fe1517 --- /dev/null +++ b/application/modules/opac/views/scripts/cms/render-all.phtml @@ -0,0 +1,2 @@ +<?php +echo $this->content; diff --git a/library/ZendAfi/Controller/Action.php b/library/ZendAfi/Controller/Action.php index 1191dff1ebbdf3c693f1f3011895413b98a38e76..b3e4007cd0cd69ff8034f8717fb53e57311995ba 100644 --- a/library/ZendAfi/Controller/Action.php +++ b/library/ZendAfi/Controller/Action.php @@ -97,6 +97,12 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { } + public function switchToAjaxMode() : self { + $this->_getHelperViewRenderer()->beRenderAjax(); + return $this; + } + + public function isPopupRequest() { return ('popup' == $this->_request->getParam('render')); } @@ -107,6 +113,11 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { } + public function isAjaxRequest() { + return ('ajax' == $this->_request->getParam('render')); + } + + public function preDispatch() { $this->view->plugins = $this->_getActionPlugins(); @@ -116,6 +127,9 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { if ($this->isIframeRequest()) $this->switchToIframeMode(); + if ($this->isAjaxRequest()) + $this->switchToAjaxMode(); + if (ZendAfi_Controller_Plugin_DefineURLs::ADMIN != $this->_request->getModuleName()) return; diff --git a/library/ZendAfi/Controller/Action/Helper/ViewRenderer.php b/library/ZendAfi/Controller/Action/Helper/ViewRenderer.php index f1a1c6e6be4ecc68f26b69a638624366678a19cc..c8050fd431593a34a1ffdb430802f2d9a1de115d 100644 --- a/library/ZendAfi/Controller/Action/Helper/ViewRenderer.php +++ b/library/ZendAfi/Controller/Action/Helper/ViewRenderer.php @@ -25,6 +25,8 @@ class ZendAfi_Controller_Action_Helper_ViewRenderer extends Zend_Controller_Acti $_layoutScript = 'module.phtml', $_render_popup = false; + protected bool $_render_ajax = false; + public function __construct() { $options['viewSuffix'] = 'phtml'; @@ -135,6 +137,18 @@ class ZendAfi_Controller_Action_Helper_ViewRenderer extends Zend_Controller_Acti } + public function beRenderAjax() : self { + $this->_render_ajax = true; + $this->setLayoutScript('empty.phtml'); + return $this; + } + + + protected function _isRenderAjax() : bool { + return $this->_render_ajax; + } + + public function renderScript($script, $name = null) { $this->view->actionScript = $script; $layoutScript = $this->getLayoutScript(); @@ -142,6 +156,10 @@ class ZendAfi_Controller_Action_Helper_ViewRenderer extends Zend_Controller_Acti $this->getResponse()->appendBody($layoutContent, $this->getResponseSegment()); $this->setNoRender(); + if ($this->_isRenderAjax()) + return $this->_actionController->getHelper('HTMLAjaxResponse') + ->htmlAjaxResponseWithScript($this->getResponse()->getBody()); + if ($this->_render_popup) { $result = ['result' => 'CONTENT', 'title' => $this->view->getMainTitle(), diff --git a/tests/application/modules/opac/controllers/BibControllerTest.php b/tests/application/modules/opac/controllers/BibControllerTest.php index 15776b62f3cbd9aa1083121bf0cc8ea988c7e479..9cfdfc97eb27f296c928093ad2f4924db9ce5cf6 100644 --- a/tests/application/modules/opac/controllers/BibControllerTest.php +++ b/tests/application/modules/opac/controllers/BibControllerTest.php @@ -1430,12 +1430,19 @@ class BibControllerWidgetPageAsAdminTest extends BibControllerWithThreeBibTestCa 'id_site' => 1]); $admin_bib->beAdminBib(); ZendAfi_Auth::getInstance()->logUser($admin_bib); - $this->dispatch('/bib/widget-page/id_module/1/id_division/2', true); } /** @test */ public function editBibShouldBePresent() { + $this->dispatch('/bib/widget-page/id_module/1/id_division/2'); + $this->assertXPath('//a[contains(@href,"admin/bib/edit/id/1")]'); + } + + + /** @test */ + public function editBibShouldBePresentInAjax() { + $this->dispatch('/bib/widget-page/id_module/1/id_division/2/render/ajax'); $this->assertXPath('//a[contains(@href,"admin/bib/edit/id/1")]'); } } diff --git a/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php b/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php index 1bd0cccd1b42db344b5db34eb4e81baf2e671883..4d12360c7c03a864d2b183f306fc01f354119a5c 100644 --- a/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php +++ b/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php @@ -132,21 +132,33 @@ class CmsControllerCalendarActionCacheTest extends CmsControllerCalendarActionTe class CmsControllerCalendarActionLanguageEnTest extends CmsControllerCalendarActionTestCase { - public function setUp() { - parent::setUp(); + + /** @test */ + function ajaxCalendarWithLocaleEnMonthShouldBeFebruary() { $this->dispatch('/cms/calendar/id_profil/3/id_module/1/select_id_categorie/2/date/2011-02/language/en/render/ajax'); + $this->assertXPathContentContains('//td[@class="calendar_title_month"]/a', "february"); + } + + + /** @test **/ + function ajaxCalendarShouldContains6AwithClassCalendarTitleMonthClickable() { + $this->dispatch('/cms/calendar/id_profil/3/id_module/1/select_id_categorie/2/date/2011-02/language/en/render/ajax'); + $this->assertXPathCount('//a[@class="calendar_title_month_clickable"]', 6); } /** @test */ - function withLocaleEnMonthShouldBeFebruary() { - $this->assertXPathContentContains('//td[@class="calendar_title_month"]/a', "february"); + function calendarWithLocaleEnMonthShouldBeFebruary() { + $this->dispatch('/cms/calendar/id_profil/3/id_module/1/select_id_categorie/2/date/2011-02/language/en'); + $this->assertXPathContentContains('//div[@class="colContenu layout-division"]//td[@class="calendar_title_month"]/a', "february"); } /** @test **/ function calendarShouldContains6AwithClassCalendarTitleMonthClickable() { - $this->assertXPathCount('//a[@class="calendar_title_month_clickable"]', 6, $this->_response->getBody()); + $this->dispatch('/cms/calendar/id_profil/3/id_module/1/select_id_categorie/2/date/2011-02/language/en'); + $this->assertXPathCount('//div[@class="colContenu layout-division"]//a[@class="calendar_title_month_clickable"]', + 6); } } @@ -1476,7 +1488,7 @@ class CmsControllerCalendarActionWithOutDateTest extends AbstractControllerTestC /** @test */ - public function calendarContentShouldBeCached() { + public function ajaxCalendarContentShouldBeCached() { $this->bootstrap(); Class_Article::getLoader() ->clearAllRedirections() diff --git a/tests/application/modules/opac/controllers/IndexControllerRenderAjaxTest.php b/tests/application/modules/opac/controllers/IndexControllerRenderAjaxTest.php new file mode 100644 index 0000000000000000000000000000000000000000..97e2a5de288e4bf3e378b0d79a487e2c1d09ffa7 --- /dev/null +++ b/tests/application/modules/opac/controllers/IndexControllerRenderAjaxTest.php @@ -0,0 +1,34 @@ +<?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 IndexControllerRenderAjaxDispatchTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/index/index/render/ajax'); + } + + + /** @test */ + public function responseShouldContainsAjaxScripts() { + $this->assertXPathContentContains('//script', 'setTimeout(function(){setupAnchorsTarget();}, 5);'); + } +} diff --git a/tests/scenarios/ShelfNavigation/ShelfNavigationTest.php b/tests/scenarios/ShelfNavigation/ShelfNavigationTest.php index 0e5afbf52bdd1b0786b01716d16e7a2c822009ca..6c5d33cd1596a0b290014a5590d9c31a4d058380 100644 --- a/tests/scenarios/ShelfNavigation/ShelfNavigationTest.php +++ b/tests/scenarios/ShelfNavigation/ShelfNavigationTest.php @@ -257,7 +257,6 @@ class ShelfNavigationSearchShelfAtStartTest public function setUp() { parent::setUp(); - $this->dispatch('/recherche/shelf/item_id/2'); } @@ -297,7 +296,6 @@ class ShelfNavigationSearchShelfRenderAjaxTest public function setUp() { parent::setUp(); - $this->dispatch('/recherche/shelf/item_id/4/render/ajax'); } diff --git a/tests/scenarios/Templates/TemplatesAgendaTest.php b/tests/scenarios/Templates/TemplatesAgendaTest.php index 9c7ee244fe14a512d88d9ce84e4a2f9357545342..352829dabb4ae4de86659e064e257d859c38399d 100644 --- a/tests/scenarios/Templates/TemplatesAgendaTest.php +++ b/tests/scenarios/Templates/TemplatesAgendaTest.php @@ -20,19 +20,12 @@ */ abstract class TemplatesAgendaTestCase extends AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; public function setUp() { parent::setUp(); - - Class_AdminVar::set('TEMPLATING', 1); ZendAfi_Auth::getInstance()->clearIdentity(); - - $profile = $this->fixture(Class_Profil::class, - ['id' => 34, - 'template' => 'MUSCLE']); - - $profile->beCurrentProfil(); + $profile = $this->_buildTemplateProfil(['id' => 34, + 'template' => 'MUSCLE']); $profile_patcher = (new Class_Template_ProfilePatcher(null)) ->setProfile($profile); @@ -96,15 +89,14 @@ class TemplatesAgendaWidgetRenderAllTest extends TemplatesAgendaTestCase { public function setUp() { parent::setUp(); - $this->dispatch('/opac/widget/render-all/profile_id/34/widget_id/1'); } /** @test */ public function linksUrlShouldUseCmsRenderAll() { - $this->assertXPath('//div[@class="calendar"]//a[contains(@href, "/cms/render-all/")]', - $this->_response->getBody()); + $this->assertXPathContentContains('//div[@class="calendar"]//a[@href="/cms/render-all/id_module/1"]', + 'Tous'); } } @@ -709,3 +701,22 @@ class TemplatesAgendaWallModeSelectedMonthIsCurrentMonthArticleWithoutEndDateTes $this->assertNotXPathContentContains('//div[@class="calendar"]//span', 'à 00:00'); } } + + + + +class TemplatesAgendaRenderAllTest extends TemplatesAgendaTestCase { + + /** @test */ + public function ajaxShouldContainsTwoClickableMonths() { + $this->dispatch('/opac/cms/render-all/id_module/1/render/ajax'); + $this->assertXPathCount('//div[@class="calendar"]//a[@class="calendar_title_month_clickable text-secondary"]', 2); + } + + + /** @test */ + public function shouldContainsTwoClickableMonths() { + $this->dispatch('/opac/cms/render-all/id_module/1'); + $this->assertXPathCount('//div[@class="calendar"]//a[@class="calendar_title_month_clickable text-secondary"]', 2); + } +} \ No newline at end of file diff --git a/tests/scenarios/Templates/TemplatesLibraryTest.php b/tests/scenarios/Templates/TemplatesLibraryTest.php index 6229c981f4fd2b969b3e8ea1325a1068fedff6f1..b916f299c0b666877f158ce691a829d9e2a39c4b 100644 --- a/tests/scenarios/Templates/TemplatesLibraryTest.php +++ b/tests/scenarios/Templates/TemplatesLibraryTest.php @@ -927,14 +927,16 @@ class TemplatesLibraryWithCarouselDataInHTMLCustomFieldTest class TemplatesLibraryBibWidgetDispatchTest extends TemplatesLibraryTestCase { - public function setUp() { - parent::setUp(); - $this->dispatch('bib/widget/id_module/1/render/ajax'); + /** @test */ + public function htmlShouldContainsLibraryAnnecy() { + $this->dispatch('/bib/widget/id_module/1'); + $this->assertXPathContentContains('//div[@class="ajax_content"]//div[@class="card-deck"]//div[@class="card-title card_title card_title_Intonation_Library_View_Wrapper_Library"]//a', 'Annecy'); } /** @test */ - public function htmlShouldContainsLibraryAnnecy() { + public function ajaxHtmlShouldContainsLibraryAnnecy() { + $this->dispatch('/bib/widget/id_module/1/render/ajax'); $this->assertXPathContentContains('//div[@class="ajax_content"]//div[@class="card-deck"]//div[@class="card-title card_title card_title_Intonation_Library_View_Wrapper_Library"]//a', 'Annecy'); } } @@ -943,14 +945,17 @@ class TemplatesLibraryBibWidgetDispatchTest extends TemplatesLibraryTestCase { class TemplatesLibraryBibRenderAllDispatchTest extends TemplatesLibraryTestCase { - public function setUp() { - parent::setUp(); - $this->dispatch('bib/render-all/id_module/1/render/ajax'); + + /** @test */ + public function ajaxHtmlShouldContainsLibraryAnnecy() { + $this->dispatch('/bib/render-all/id_module/1/render/ajax'); + $this->assertXPathContentContains('//div[@class="ajax_content"]//div[@class="list-group bg-transparent no_border"]//div[@class="card-title card_title card_title_Intonation_Library_View_Wrapper_Library"]//a', 'Annecy'); } /** @test */ public function htmlShouldContainsLibraryAnnecy() { + $this->dispatch('/bib/render-all/id_module/1'); $this->assertXPathContentContains('//div[@class="ajax_content"]//div[@class="list-group bg-transparent no_border"]//div[@class="card-title card_title card_title_Intonation_Library_View_Wrapper_Library"]//a', 'Annecy'); } } \ No newline at end of file