Skip to content
Snippets Groups Projects
Commit 8b452464 authored by Sebastien ANDRE's avatar Sebastien ANDRE
Browse files

Merge branch 'hotline#172828_journal_ajout_des_supressions_dans_la_liste' into 'master'

hotline : #172828 : add journal delete event on articles

See merge request !4771
parents 52eeda22 02974351
Branches
Tags
1 merge request!4771hotline : #172828 : add journal delete event on articles
Pipeline #24313 passed with stage
- correctif #172828 : Journal : Ajout de la suppression des Articles
\ No newline at end of file
<?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);
}
}
......@@ -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))
......
......@@ -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'),
......
<?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');
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment