Skip to content
Snippets Groups Projects
Commit 7cd41d10 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

dev #48349 : apply a version

parent 0a1334ef
Branches
Tags
2 merge requests!2334Master,!2104Dev#48349 ux versionning
Pipeline #963 passed with stage
in 18 minutes and 26 seconds
......@@ -52,4 +52,15 @@ class Class_Version extends Class_Entity {
public function callGetterByAttributeName($attribute) {
return $this->get($attribute);
}
public function injectIn($request) {
method_exists($request, 'setMethod')
? $request->setMethod('POST')
: $_SERVER['REQUEST_METHOD'] = 'POST';
$request->setPost($this->getData());
return $this;
}
}
......@@ -109,6 +109,23 @@ class ZendAfi_Controller_Plugin_Versionning_Article
}
public function versionApplyAction() {
if (!$article = Class_Article::find((int)$this->_getParam('id'))) {
$this->_redirectToIndex();
return;
}
if (!$version = $this->_versionsFor($article)->find($this->_getParam('key'))) {
$this->_helper->notify($this->_view->_('Version introuvable'));
$this->_redirectToEdit($article);
return;
}
$version->injectIn($this->_request);
$this->_forward('edit', 'cms', 'admin', ['id' => $article->getId()]);
}
public function versionDeleteAction() {
if (!$article = Class_Article::find((int)$this->_getParam('id'))) {
$this->_redirectToIndex();
......
......@@ -47,7 +47,8 @@ class ZendAfi_View_Helper_Admin_RenderVersionForm
protected function _buttonsFor($form, $buttons) {
return $this
->_renderDefaultButtons($form,
[$this->_prevButton(),
[$this->_applyButton(),
$this->_prevButton(),
$this->_nextButton(),
$this->_deleteButton(),
$this->_listButton($form),
......@@ -100,6 +101,21 @@ class ZendAfi_View_Helper_Admin_RenderVersionForm
}
protected function _applyButton() {
$url = $this->view->url(['key' => $this->_version->getId(),
'action' => 'version-apply']);
$delete = (new Class_Entity())
->setText($this->_('Revenir à cette version'))
->setUrl($url)
->setAttribs(['onclick' => "if (confirm('" . htmlspecialchars($this->_('Êtes-vous sur de vouloir revenir à cette version ?')) . "')) { window.location.href='" . $url ."'}; return false;"])
->setImage($this->view->tagImg(Class_Admin_Skin::current()
->renderIconUrlOn('buttons', 'validate')));
return $this->view->Button($delete);
}
protected function _deleteButton() {
$url = $this->view->url(['key' => $this->_version->getId(),
'action' => 'version-delete']);
......@@ -109,8 +125,7 @@ class ZendAfi_View_Helper_Admin_RenderVersionForm
->setUrl($url)
->setAttribs(['onclick' => "if (confirm('" . htmlspecialchars($this->_('Êtes-vous sur de vouloir supprimer cette version de l\\\'historique ?')) . "')) { window.location.href='" . $url ."'}; return false;"])
->setImage($this->view->tagImg(Class_Admin_Skin::current()
->renderIconUrlOn('buttons',
'remove')));
->renderIconUrlOn('buttons', 'remove')));
return $this->view->Button($delete);
}
......
......@@ -234,10 +234,66 @@ class VersionningArticleVersionTest extends VersionningAdminTestCase {
$this->assertXPathContentContains('//button[contains(@data-url, "/version-delete/id/27/key/2017-03-20_112408_33")]',
'Supprimer');
}
/** @test */
public function applyButtonShouldBePresent() {
$this->assertXPathContentContains('//button[contains(@data-url, "/version-apply/id/27/key/2017-03-20_112408_33")]',
'Revenir à cette version');
}
}
class VersionningArticleVersionApplyTest extends VersionningAdminTestCase {
protected
$_file_name,
$_file_content;
public function setUp() {
parent::setUp();
$this->_file_system->whenCalled('is_readable')->answers(true)
->whenCalled('scandir')
->answers(['.', '..',
'2017-03-18_000000_666.json'])
->whenCalled('file_get_contents')
->answers(json_encode(['titre' => 'A different title',
'debut' => '2016-12-23',
'fin' => '',
'events_debut' => '23/03/2017 16:00',
'events_fin' => '']))
->whenCalled('file_exists')->answers(true)
->whenCalled('file_put_contents')
->willDo(function($path, $content)
{
$this->_file_name = $path;
$this->_file_content = $content;
})
;
$this->dispatch('/admin/cms/version-apply/id/27/key/2017-03-18_000000_666', true);
Class_Article::clearCache();
}
/** @test */
public function articleTitleShouldBecomeADifferentTitle() {
$this->assertEquals('A different title', Class_Article::find(27)->getTitre());
}
/** @test */
public function newVersionShouldBeSaved() {
$this->assertContains('/temp/versions/article/27/2017-03-20_112408_666.json',
$this->_file_name);
}
}
class VersionningArticleVersionDeleteTest extends VersionningAdminTestCase {
protected $_file_deleted;
......
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