Skip to content
Snippets Groups Projects
Commit 1c6e02f8 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

hotline MT #120102 : Improve testing new template checks

parent 3ad8c38a
Branches
Tags
2 merge requests!3718Hotline,!3712hotline MT #120102 : Improve testing new template checks
Pipeline #11543 failed with stage
in 1 hour, 31 minutes, and 31 seconds
- ticket #120102 : Magasin de thèmes : Vérification du profil de test avant l'essai d'un thème
\ No newline at end of file
......@@ -45,19 +45,50 @@ class Admin_TemplateController extends ZendAfi_Controller_Action {
}
public function tryAction() {
if(!$template = (new Class_Template_Loader)->find($this->_getParam('template'))) {
$this->_helper->notify($this->_('Une erreur c\'est produite. Vous ne pouvez pas tester le thème'));
public function checkBeforeTryAction(){
if (!$params = $this->_checkTryParams())
return $this->_redirectToIndex();
}
if(!$profile = Class_Profil::find($this->_getParam('on'))) {
$this->_helper->notify($this->_('Une erreur c\'est produite. Vous ne pouvez pas tester le thème'));
$this->view->template = $params->getTemplate();
$this->view->titre = $this->_('Veuillez choisir le profil qui sera utilisé pour tester le thème %s',
$this->view->template->getTitle());
$control_key = $this->view->template->getControlKey($params->getProfile());
if ($this->view->profile = Class_Profil::findFirstBy(['commentaire' => $control_key]))
return;
$this->_forward('try');
}
protected function _checkTryParams(){
if(($profile = Class_Profil::find($this->_getParam('on')))
&& ($template = (new Class_Template_Loader)->find($this->_getParam('template'))))
return new Class_Entity([ 'Profile' => $profile, 'Template' => $template] );
$this->_helper->notify($this->_('Une erreur s\'est produite. Vous ne pouvez pas tester le thème'));
return null;
}
public function tryOnNewProfileAction(){
if (!$params = $this->_checkTryParams())
return $this->_redirectToIndex();
}
if(!$id_profile = $template->tryOn($profile)) {
$this->_helper->notify($this->_('Une erreur c\'est produite. Vous ne pouvez pas tester le thème'));
$params->getTemplate()->removeControlKeys($params->getProfile());
$this->_forward('try');
}
public function tryAction() {
if (!$params = $this->_checkTryParams())
return $this->_redirectToIndex();
if(!$id_profile = $params->getTemplate()->tryOn($params->getProfile())) {
$this->_helper->notify($this->_('Une erreur s\'est produite. Vous ne pouvez pas tester le thème'));
return $this->_redirectToIndex();
}
......
<?php
$html = [
$this->tagAnchor($this->template->getTryOnNewProfileUrl(),
$this->_('Nouveau profil'),
['class'=> 'admin-button']),
$this->tagAnchor($this->template->getTryUrl(),
$this->_('Continuer avec %d : %s',
$this->profile->getId(),
$this->profile->getLibelle()),
['class'=> 'admin-button'])
];
echo implode($html);
......@@ -101,6 +101,16 @@ class Class_Template {
}
public function getCheckBeforeTryUrl() {
return Class_Url::relative(sprintf('/admin/template/check-before-try/template/%s/on/1', $this->getId()));
}
public function getTryOnNewProfileUrl() {
return Class_Url::relative(sprintf('/admin/template/try-on-new-profile/template/%s/on/1', $this->getId()));
}
public function getApplyUrl() {
return Class_Url::relative(sprintf('/admin/template/apply/template/%s', $this->getId()));
}
......@@ -129,6 +139,16 @@ class Class_Template {
}
public function removeControlKeys($profile){
$this->getControlKey($profile);
foreach (Class_Profil::findAllBy(['commentaire' => $this->_control_key ])
as $test_profile)
$test_profile->resetTemplateTestKey()
->save();
return $this;
}
public function tryOn($profile) {
if(!$profile)
return null;
......
......@@ -23,10 +23,10 @@
class ZendAfi_Controller_Plugin_Manager_Template extends ZendAfi_Controller_Plugin_Manager_Manager {
public function getActions($model) {
return [
['url' => $model->getTryUrl(),
['url' => $model->getCheckBeforeTryUrl(),
'icon' => 'view',
'label' => $this->_('Essayer le thème %s', $model->getTitle()),
'anchorOptions' => ['target' => '_blank']],
'anchorOptions' => ['data-popup' => true]],
['url' => $model->getEditUrl(),
'icon' => 'edit',
......
<?php
/**
* Copyright (c) 2012-2017, 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 TemplatesAdminIndexDispatchTest
extends Admin_AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
Class_AdminVar::set('TEMPLATING', 1);
$this->dispatch('/admin/template/index', true);
}
/** @test */
public function shouldDisplayAailableTemplates() {
$this->assertXPathContentContains('//table//th', 'Modèle');
}
/** @test */
public function editIntonationUrlShouldBeDisplay() {
$this->assertXPath('//table//a[contains(@href,"/admin/template/edit/template/INTONATION")]');
}
/** @test */
public function checkBeforeTryIntonationUrlShouldBeDisplay() {
$this->assertXPath('//table//a[contains(@href,"/admin/template/check-before-try/template/INTONATION/on/1")][@data-popup="1"]');
}
/** @test */
public function resetIntonationShouldBePresent() {
$this->assertXPath('//table//a[contains(@href,"/admin/template/reset/template/INTONATION")]');
}
/** @test */
public function updateIntonationShouldBePresent() {
$this->assertXPath('//table//a[contains(@href,"/admin/template/update/template/INTONATION")]');
}
/** @test */
public function applyIntonationShouldBePresent() {
$this->assertXPath('//table//a[contains(@href,"/admin/template/apply/template/INTONATION")]');
}
}
......@@ -35,53 +35,6 @@ abstract class TemplatesEnabledTestCase extends Admin_AbstractControllerTestCase
class TemplatesControllerIndexDispatchTest extends TemplatesEnabledTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$this->dispatch('/admin/template/index', true);
}
/** @test */
public function shouldDisplayAailableTemplates() {
$this->assertXPathContentContains('//table//th', 'Modèle');
}
/** @test */
public function editIntonationUrlShouldBeDisplay() {
$this->assertXPath('//table//a[contains(@href,"/admin/template/edit/template/INTONATION")]');
}
/** @test */
public function tryIntonationUrlShouldBeDisplay() {
$this->assertXPath('//table//a[contains(@href,"/admin/template/try/template/INTONATION/on/1")]');
}
/** @test */
public function resetIntonationShouldBePresent() {
$this->assertXPath('//table//a[contains(@href,"/admin/template/reset/template/INTONATION")]');
}
/** @test */
public function updateIntonationShouldBePresent() {
$this->assertXPath('//table//a[contains(@href,"/admin/template/update/template/INTONATION")]');
}
/** @test */
public function applyIntonationShouldBePresent() {
$this->assertXPath('//table//a[contains(@href,"/admin/template/apply/template/INTONATION")]');
}
}
class TemplatesControllerApplyIntonationTest extends TemplatesEnabledTestCase {
protected $_storm_default_to_volatile = true;
......
<?php
/**
* Copyright (c) 2012-2017, 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 TemplatesTryCheckBeforeTryIntonationTest
extends Admin_AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
Class_AdminVar::set('TEMPLATING', 1);
$this->fixture('Class_Profil',
['id' => 57,
'libelle' => 'Mon profil de test',
'commentaire' => 'eb0da18cfce1c2efaaa1d1ec97c86b10',
'template' => 'INTONATION'
]);
$this->dispatch('admin/template/check-before-try/template/INTONATION/on/1');
}
/** @test */
public function linkToTryIntonationShouldBePresent() {
$this->assertXPathContentContains('//a[contains(@href, "admin/template/try/template/INTONATION/on/1")]',
'Continuer avec 57 : Mon profil de test');
}
/** @test */
public function linkToTryOnNewProfileShouldBePresent() {
$this->assertXPathContentContains('//a[contains(@href, "admin/template/try-on-new-profile/template/INTONATION/on/1")]',
'Nouveau profil');
}
}
class TemplatesTryOnNewProfileIntonationTest
extends Admin_AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
Class_AdminVar::set('TEMPLATING', 1);
$this->fixture('Class_Profil',
['id' => 57,
'libelle' => 'Mon profil de test',
'commentaire' => 'eb0da18cfce1c2efaaa1d1ec97c86b10',
'template' => 'INTONATION'
]);
$this->fixture('Class_Profil',
['id' => 47,
'libelle' => 'Un autre profil de test',
'commentaire' => 'eb0da18cfce1c2efaaa1d1ec97c86b10',
'template' => 'INTONATION'
]);
$this->dispatch('admin/template/try-on-new-profile/template/INTONATION/on/1');
}
/** @test */
public function shouldRedirectToOpacIndexWithProfile58() {
$this->assertRedirectTo('/opac/index/index/id_profil/58');
}
/** @test */
public function profile57CommentShouldBeEmpty() {
$this->assertEmpty(Class_Profil::find(57)->getCommentaire());
}
/** @test */
public function profile47CommentShouldBeEmpty() {
$this->assertEmpty(Class_Profil::find(47)->getCommentaire());
}
/** @test */
public function newProfile58CommentShouldBeEb0da() {
$this->assertEquals('eb0da18cfce1c2efaaa1d1ec97c86b10',
Class_Profil::find(58)->getCommentaire());
}
}
class TemplatesTryActionsErrorsTest
extends Admin_AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
Class_AdminVar::set('TEMPLATING', 1);
}
/** @test */
public function checkBeforeTryWithWrongTemplateShouldNotifyErreurSestProduite() {
$this->dispatch('admin/template/check-before-try/template/RANDOM/on/1');
$this->assertRedirectTo('/admin/template/index');
$this->assertFlashMessengerContentContains('Une erreur s\'est produite. Vous ne pouvez pas tester le thème');
}
/** @test */
public function checkBeforeTryWithWrongProfileShouldNotifyErreurSestProduite() {
$this->dispatch('admin/template/check-before-try/template/INTONATION/on/51');
$this->assertRedirectTo('/admin/template/index');
$this->assertFlashMessengerContentContains('Une erreur s\'est produite. Vous ne pouvez pas tester le thème');
}
/** @test */
public function tryOnNewProfileWithWrongTemplateShouldNotifyErreurSestProduite() {
$this->dispatch('admin/template/try-on-new-profile/template/RANDOM/on/1');
$this->assertRedirectTo('/admin/template/index');
$this->assertFlashMessengerContentContains('Une erreur s\'est produite. Vous ne pouvez pas tester le thème');
}
/** @test */
public function tryOnNewProfileWithWrongProfileShouldNotifyErreurSestProduite() {
$this->dispatch('admin/template/try-on-new-profile/template/INTONATION/on/51');
$this->assertRedirectTo('/admin/template/index');
$this->assertFlashMessengerContentContains('Une erreur s\'est produite. Vous ne pouvez pas tester le thème');
}
/** @test */
public function tryWithWrongTemplateShouldNotifyErreurSestProduite() {
$this->dispatch('admin/template/try/template/RANDOM/on/1');
$this->assertRedirectTo('/admin/template/index');
$this->assertFlashMessengerContentContains('Une erreur s\'est produite. Vous ne pouvez pas tester le thème');
}
/** @test */
public function tryWithWrongProfileShouldNotifyErreurSestProduite() {
$this->dispatch('admin/template/try/template/INTONATION/on/51');
$this->assertRedirectTo('/admin/template/index');
$this->assertFlashMessengerContentContains('Une erreur s\'est produite. Vous ne pouvez pas tester le thème');
}
}
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