From 16fd5e167f9fbf612e5719ae91e54b9772beb407 Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT <hdlaurent@afi-sa.fr> Date: Tue, 28 Jan 2020 18:32:08 +0100 Subject: [PATCH] hotline#101645: Opac : Fix Link for article in mails generated by bookedmarked Searches --- VERSIONS_HOTLINE/101645 | 1 + library/Class/Notice/MailRenderer.php | 4 +- .../controllers/NewsletterControllerTest.php | 2 +- tests/library/Class/NewsletterMailingTest.php | 10 +- tests/scenarios/bookmarks/SearchTest.php | 132 ++++++++++++++++++ 5 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 VERSIONS_HOTLINE/101645 diff --git a/VERSIONS_HOTLINE/101645 b/VERSIONS_HOTLINE/101645 new file mode 100644 index 00000000000..6fa9facc6f8 --- /dev/null +++ b/VERSIONS_HOTLINE/101645 @@ -0,0 +1 @@ +Hotline #101645 : OPAC : les liens des articles envoyés dans les emails de recherches sauvegardés pointent directement vers ceux-ci \ No newline at end of file diff --git a/library/Class/Notice/MailRenderer.php b/library/Class/Notice/MailRenderer.php index 75c44a1bbb0..0f8c1cbba9b 100644 --- a/library/Class/Notice/MailRenderer.php +++ b/library/Class/Notice/MailRenderer.php @@ -76,9 +76,7 @@ class Class_Notice_MailRenderer { protected function _urlWithoutRouter($record) { - return Class_Url::absolute(['controller' => 'recherche', - 'action' => 'viewnotice', - 'id' => $record->getId()], null, true); + return (new Class_Notice_Permalink())->absoluteFor($record); } diff --git a/tests/application/modules/admin/controllers/NewsletterControllerTest.php b/tests/application/modules/admin/controllers/NewsletterControllerTest.php index c2f7b5e762c..e6f7a8bbb08 100644 --- a/tests/application/modules/admin/controllers/NewsletterControllerTest.php +++ b/tests/application/modules/admin/controllers/NewsletterControllerTest.php @@ -962,7 +962,7 @@ class Admin_NewsletterControllerPreviewActionWithArticlesSelectionTest /** @test */ public function noticeMartineALaPlageUrlShouldBeRechercheViewNotice42() { - $this->assertXPath('//a[@href="' . Class_Url::absolute('/recherche/viewnotice/id/42') . '"]'); + $this->assertXPath('//a[contains(@href,"' . Class_Url::absolute('/recherche/viewnotice/id/42') . '")]', $this->_response->getBody()); } diff --git a/tests/library/Class/NewsletterMailingTest.php b/tests/library/Class/NewsletterMailingTest.php index 1951286af31..50a1afeb2e4 100644 --- a/tests/library/Class/NewsletterMailingTest.php +++ b/tests/library/Class/NewsletterMailingTest.php @@ -363,7 +363,7 @@ class NewsletterMailingConcertsPanierTextTest extends NewsletterMailingTestCase /** @test */ public function shouldContainsURLMillenium() { - $this->assertBodyTextContains(Class_Url::absolute('/recherche/viewnotice/id/345')); + $this->assertBodyTextContains(Class_Url::absolute('/recherche/viewnotice/clef//id/345')); } @@ -381,7 +381,7 @@ class NewsletterMailingConcertsPanierTextTest extends NewsletterMailingTestCase /** @test */ public function shouldContainsURLPotter() { - $this->assertBodyTextContains(Class_Url::absolute("/recherche/viewnotice/id/987")); + $this->assertBodyTextContains(Class_Url::absolute("/recherche/viewnotice/clef//id/987")); } } @@ -397,7 +397,7 @@ class NewsletterMailingConcertsPanierHtmlTest extends NewsletterMailingTestCase /** @test */ public function shouldContainsLinkMillenium() { - $this->assertBodyHTMLContains('<a href="' . Class_Url::absolute('/recherche/viewnotice/id/345')); + $this->assertBodyHTMLContains('<a href="' . Class_Url::absolute('/recherche/viewnotice/clef//id/345')); } @@ -422,7 +422,7 @@ class NewsletterMailingConcertsPanierHtmlTest extends NewsletterMailingTestCase /** @test */ public function shouldContainsPotterLink() { - $this->assertBodyHTMLContains('<a href="' . Class_Url::absolute('/recherche/viewnotice/id/987"')); + $this->assertBodyHTMLContains('<a href="' . Class_Url::absolute('/recherche/viewnotice/clef//id/987"')); } } @@ -630,6 +630,6 @@ class NewsletterMailingRecordAbsoluteUrlTest extends ModelTestCase { protected function _recordUrlOf($id) { - return Class_Url::absolute('/recherche/viewnotice/id/' . $id); + return Class_Url::absolute('/recherche/viewnotice/clef//id/' . $id); } } diff --git a/tests/scenarios/bookmarks/SearchTest.php b/tests/scenarios/bookmarks/SearchTest.php index 8acd88ad415..965d111d6ab 100644 --- a/tests/scenarios/bookmarks/SearchTest.php +++ b/tests/scenarios/bookmarks/SearchTest.php @@ -437,6 +437,8 @@ class Bookmarks_SearchDependentsDeleteTest + + class Bookmarks_SearchCosmogrammePhaseTest extends Class_Cosmogramme_Integration_PhaseTestCase { @@ -598,6 +600,136 @@ class Bookmarks_SearchCosmogrammePhaseTest +class Bookmarks_SearchMailArticlePhaseTest + extends Class_Cosmogramme_Integration_PhaseTestCase { + + protected + $_result, + $_file_system, + $_files_content, + $_mail_transport; + + protected function _getPreviousPhase() { + return (new Class_Cosmogramme_Integration_Phase(17)) + ->beCron(); + } + + + protected function _prepareFixtures() { + $criteres_potter = (new Class_CriteresRecherche) + ->setParams(['expressionRecherche' => 'Harry Potter', + 'page' => 2]); + + $laurel = $this->fixture('Class_Users', + ['id' => 34, + 'login' => 'll', + 'password' => 'needs_hardy', + 'mail' => 'laurel@server.io']); + + $this->fixture('Class_User_BookmarkedSearch', + ['id' => 5, + 'criterias' => serialize($criteres_potter), + 'user' => $laurel, + 'notified' => 1, + 'memory_cleaner' => function(){}]); + + $this->fixture('Class_User_BookmarkedSearch', + ['id' => 8, + 'criterias' => serialize($criteres_potter), + 'user' => $laurel, + 'notified' => 1, + 'label' => 'mega original', + 'memory_cleaner' => function(){}]); + + $this->fixture('Class_Article', + ['id' => 1, + 'titre' => 'Mon POT POTTER', + 'id_user' => 1, + 'indexation' => 1, + 'contenu' => 'Articles are going to be auto indexed !' + ]); + + Class_Article::find(1)->index(); + + $this->fixture('Class_Notice', + ['id' => 1888, + 'clef_alpha' => 'DROITDEVANT--ODAEIICHIRO-15-GLENAT-2013-1', + 'titre_principal' => 'Droit devant']); + + foreach(range(1, Class_User_BookmarkedSearch::NOTIFY_LIMIT + 5) as $index) + $this->fixture('Class_Notice', + ['id' => 2000+$index, + 'clef_alpha' => 'TESTING' . $index, + 'titre_principal' => 'Testing ' . $index]); + + $result = array_map(function($record) + { + return [$record->getId(), '']; + }, + Class_Notice::findAll()); + + Zend_Registry::set('sql', + $this->mock() + ->whenCalled('fetchAll') + ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(HARRY HARRYS ARI) +(POTTER POTTERS POT)' IN BOOLEAN MODE)) and type=1 order by (MATCH(titres) AGAINST(' HARRY POTTER') * 1.5) + (MATCH(auteurs) AGAINST(' HARRY POTTER')) desc", true, false) + ->answers($result) + ->beStrict()); + + $this + ->fixture('Class_Profil', + ['id' => 12, + 'mail_site' => 'admin@bokeh-portal.fr']) + ->beCurrentProfil(); + } + + + public function setUp() { + parent::setUp(); + Storm_Cache::beVolatile(); + + $this->_mail_transport = new MockMailTransport(); + Zend_Mail::setDefaultTransport($this->_mail_transport); + + $this->_phase = $this->_buildPhase('BookmarkedSearches') + ->setMemoryCleaner(function() {}) + ->setPrinter($this->_printer); + + $persistence = Class_Versions_BookmarkedSearch::getPersistence(); + $persistence + ->atPut(8, '2017-03-23_072428', []) + ->setTimeSource(new TimeSourceForTest('2018-02-07 10:50:48')); + + $this->_result = $this->_phase->run(); + + $this->_files_content = $persistence->asArray(); + } + + + public function tearDown() { + Storm_Cache::setDefaultZendCache(null); + parent::tearDown(); + } + + + /** @test */ + public function logShouldNotContainsError() { + $this->assertNotError(); + } + + + /** @test */ + public function withNewArticleShouldNotifyItToUserByMail() { + $mail = $this->_mail_transport->getSentMails()[0]; + $this->assertContains('laurel@server.io', $mail->getRecipients()); + $this->assertContains('Mon POT POTTER', $mail->getBodyText(true)); + $this->assertContains('/cms/articleview', $mail->getBodyText(true)); + $this->assertContains('/id/1=0A', $mail->getBodyText(true)); + } +} + + + + class Bookmarks_SearchDiffNotLoggedTest extends AbstractControllerTestCase { protected $_storm_default_to_volatile = true; -- GitLab