diff --git a/VERSIONS_HOTLINE/172828 b/VERSIONS_HOTLINE/172828 new file mode 100644 index 0000000000000000000000000000000000000000..52356fde88ddbe61575c4d1cee5fef642697c856 --- /dev/null +++ b/VERSIONS_HOTLINE/172828 @@ -0,0 +1 @@ + - correctif #172828 : Journal : Ajout de la suppression des Articles \ No newline at end of file diff --git a/library/Class/Journal/ArticleDeleteType.php b/library/Class/Journal/ArticleDeleteType.php new file mode 100644 index 0000000000000000000000000000000000000000..6972757d4ebe1a5642cf8304e28eab03c494eb43 --- /dev/null +++ b/library/Class/Journal/ArticleDeleteType.php @@ -0,0 +1,60 @@ +<?php +/** + * Copyright (c) 2012-2023, 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_Journal_ArticleDeleteType extends Class_Journal_ArticleType { + + const MY_TYPE = 'ARTICLE_DELETE'; + + public static function canHandleEvent(Storm_Event_Abstract $event) : bool { + return (parent::APPLY_ON === get_class($event->getModel())) + && $event->isDeleteEvent(); + } + + + public function renderLabelOn(Zend_View_Interface $view) : string { + return $this->_('%s a supprimé l\'article %s', + $this->renderDetailValueOn(static::CURRENT_USER_ID, $view), + $this->renderDetailValueOn(static::MODEL_ID, $view)); + } + + + public function save($model) { + if ( ! parent::save($model)) + return false; + + $this->_journal + ->addDetail(static::NEW_VALUE, json_encode($model->getRawAttributes())); + + return true; + } + + + public function renderModelLinkOn($id, Zend_View_Interface $view) : string { + $detail = $this->_journal->getDetail(static::NEW_VALUE); + $article = Class_Article::newInstance(json_decode($detail->getValue(), + true)); + + return $article + ? $article->getTitre() + : $this->_('inconnu id: %d', $id); + } +} diff --git a/library/Class/Journal/ArticleType.php b/library/Class/Journal/ArticleType.php index e46db57b6fb9e1e0bd5e11a8585d69582abaf204..2468312c43180e1d77058ba568ec5e57ef522b15 100644 --- a/library/Class/Journal/ArticleType.php +++ b/library/Class/Journal/ArticleType.php @@ -21,10 +21,16 @@ class Class_Journal_ArticleType extends Class_Journal_Type { + const MY_TYPE = 'ARTICLE_SAVE', APPLY_ON = Class_Article::class; + public static function canHandleEvent(Storm_Event_Abstract $event) : bool { + return parent::canHandleEvent($event) + && ! $event->isDeleteEvent(); + } + public function save($model) { if (!parent::save($model)) diff --git a/library/Class/Journal/TypeMapping.php b/library/Class/Journal/TypeMapping.php index 4806a626109cef8fa3f25226fc573ff9d4c4092c..6ef3fe691587ad4f9298ba52dc61c3bf0fc43a8a 100644 --- a/library/Class/Journal/TypeMapping.php +++ b/library/Class/Journal/TypeMapping.php @@ -34,7 +34,8 @@ class Class_Journal_TypeMapping { Class_Journal_CatalogueDeleteType::class => $this->_('Domaines : suppression'), Class_Journal_ProfileType::class => $this->_('Profils : mise à jour'), Class_Journal_ProfileDeleteType::class => $this->_('Profils : suppression'), - Class_Journal_ArticleType::class => $this->_('Articles'), + Class_Journal_ArticleType::class => $this->_('Articles : mise à jour'), + Class_Journal_ArticleDeleteType::class => $this->_('Articles : suppression'), Class_Journal_RequestType::class => $this->_('Requêtes'), Class_Journal_SoapCallType::class => $this->_('Erreurs SOAP'), Class_Journal_CasRequestType::class => $this->_('Requêtes CAS'), diff --git a/tests/scenarios/Journal/JournalArticlesTest.php b/tests/scenarios/Journal/JournalArticlesTest.php new file mode 100644 index 0000000000000000000000000000000000000000..a98aab7b7443f186ca959b52697c031789d0412e --- /dev/null +++ b/tests/scenarios/Journal/JournalArticlesTest.php @@ -0,0 +1,148 @@ +<?php +/** + * Copyright (c) 2012-2023, 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 + */ + +require_once(__DIR__ . '/JournalTest.php'); + +abstract class JournalArticlesTestCase extends JournalTestCase { + + public function setUp() { + parent::setUp(); + + $this->fixture(Class_Article::class, + ['id' => 1, + 'titre' => 'title 1', + 'contenu' => 'content 1']); + $this->fixture(Class_Article::class, + ['id' => 2, + 'titre' => 'title 2', + 'contenu' => 'content 2']); + + Class_AdminVar::set('JOURNAL_ENABLE_STORM', 1); + (new Bokeh_Engine)->setupStormObservers(); + Class_Journal::deleteBy([]); + Class_Journal::setTimeSource(new TimeSourceForTest('2022-12-25 12:12:12')); + } + + + public function tearDown() { + Class_Journal::setTimeSource(null); + parent::tearDown(); + } +} + + + + +class JournalArticlesEditTest extends JournalArticlesTestCase { + + public function setUp() { + parent::setUp(); + + $this->postDispatch('/admin/cms/edit/id/1', ['titre' => 'title 1 updated']); + } + + + /** @test */ + public function journalShouldBeCreated() { + $this->assertNotNull(Class_Journal::findFirstBy(['type' => 'ARTICLE_SAVE'])); + } +} + + + + +class JournalArticlesDeleteTest extends JournalArticlesTestCase { + + public function setUp() { + parent::setUp(); + + $this->dispatch('/admin/cms/force-delete/id/2'); + } + + + /** @test */ + public function journalShouldBeCreated() { + $this->assertNotNull(Class_Journal::findFirstBy(['type' => 'ARTICLE_DELETE'])); + } +} + + + + +class JournalArticlesViewTest extends JournalArticlesTestCase { + + public function setUp() { + parent::setUp(); + + Class_Article::find(1)->setTitre('title 1 updated')->save(); + Class_Article::find(2)->delete(); + + $this->dispatch('/admin/journal'); + } + + + /** @test */ + public function pageShouldContainsTableForArticleSaveOnLine_1() { + $this->assertXPathContentContains('//tr[1]/td', 'ARTICLE_SAVE'); + } + + + /** @test */ + public function pageShouldContainsTableUserAutoTest666OnLine_1() { + $this->assertXPath('//tr[1]/td/a[contains(@href, "/admin/users/edit/id/666")][@title="Modifier l\' utilisateur Zoro"]'); + } + + + /** @test */ + public function pageShouldContainsTableActionEditArticleOnLine_1() { + $this->assertXPath('//tr[1]/td/a[contains(@href, "/admin/cms/edit/id/1")][@title="Modifier l\'article title 1 updated"]'); + } + + + /** @test */ + public function pageShouldContainsTableEditDateOnLine_1() { + $this->assertXPath('//tr[1]/td', '2022-12-25 12:12:12'); + } + + + /** @test */ + public function pageShouldContainsTableForArticleDeleteOnLine_2() { + $this->assertXPathContentContains('//tr[2]/td', 'ARTICLE_DELETE'); + } + + + /** @test */ + public function pageShouldContainsTableUserAutoTest666OnLine_2() { + $this->assertXPath('//tr[2]/td/a[contains(@href, "/admin/users/edit/id/666")][@title="Modifier l\' utilisateur Zoro"]'); + } + + + /** @test */ + public function pageShouldContainsTableSupprimeArticleOnLine_2() { + $this->assertXPathContentContains('//tr[2]/td', 'a supprimé l\'article title 2'); + } + + + /** @test */ + public function pageShouldContainsTableEditDateOnLine_2() { + $this->assertXPath('//tr[2]/td', '2022-12-25 12:12:12'); + } +}