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

fix for RT, controller and tests refactorings

parent 4d194918
Branches
Tags
5 merge requests!258Dev/13872 Orphee Allow Hold Available Items,!63Rf13038,!56Rf13038 Front,!47Hotline 6.40,!45Hotline#12905 Catalogue Dynamique
......@@ -18,57 +18,30 @@
* along with AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
//////////////////////////////////////////////////////////////////////////////////////////
// OPAC3 - Appels Ajax
//
//////////////////////////////////////////////////////////////////////////////////////////
class Admin_AjaxController extends Zend_Controller_Action
{
//------------------------------------------------------------------------------------------------------
// Initialisation des parametres et du layout
//------------------------------------------------------------------------------------------------------
function init()
{
// Désactiver le view renderer
$viewRenderer = $this->getHelper('ViewRenderer');
$viewRenderer->setNoRender();
class Admin_AjaxController extends Zend_Controller_Action {
public function preDispatch() {
$this->getHelper('ViewRenderer')->setNoRender();
}
//------------------------------------------------------------------------------------------------------
// Initialisation des parametres et du layout
//------------------------------------------------------------------------------------------------------
function listesuggestionAction() {
// Parametres
$autorite=$this->_getParam('type_autorite');
$id_champ=$this->_getParam('id_champ');
$mode_recherche=$this->_getParam('mode');
$recherche=$this->_getParam('valeur');
$limite_resultat=100;
// Lancer la recherche en fonction du type d'autorite
$theme='';
switch($autorite)
{
case "auteur" : $cls=new Class_Auteur(); break;
case "matiere" : $cls=new Class_Matiere(); break;
case "interet" : $cls=new Class_CentreInteret(); break;
case "dewey" : $cls=new Class_Dewey(); break;
case "pcdm4" : $cls=new Class_Pcdm4(); break;
case "thesaurus" : $cls=new Class_CodifThesaurus();
$theme=$id_champ; break;
case "tag" : $cls=new Class_TagNotice(); break;
default: print("mauvais code rubrique"); exit;
}
if ($theme) {
$liste=$cls->getListeSuggestion($recherche,$mode_recherche,$limite_resultat,$theme);
public function listesuggestionAction() {
$autorite = $this->_getParam('type_autorite');
$id_champ = $this->_getParam('id_champ');
$mode_recherche = $this->_getParam('mode');
$recherche = $this->_getParam('valeur');
$limite_resultat = 100;
if (!$authority = $this->getAuthorityFor($autorite)) {
print('mauvais code rubrique');
return;
}
else
$liste=$cls->getListeSuggestion($recherche,$mode_recherche,$limite_resultat);
// Renvoi de la liste
if(!$liste) {
echo '';
$params = [$recherche, $mode_recherche, $limite_resultat];
if ('thesaurus' == $autorite)
$params[] = $id_champ;
if (!$liste = call_user_func_array([$authority, 'getListeSuggestion'], $params)) {
echo '';
return;
}
......@@ -76,5 +49,20 @@ class Admin_AjaxController extends Zend_Controller_Action
echo '<div class="tag_liste" clef="'.$item[0].'" onclick="selectSuggest(\''.$id_champ.'\',this)">'.$item[1].'</div>';
}
}
}
\ No newline at end of file
protected function getAuthorityFor($code) {
$authorities = ['auteur' => new Class_Auteur(),
'matiere' => new Class_Matiere(),
'interet' => new Class_CentreInteret(),
'dewey' => new Class_Dewey(),
'pcdm4' => new Class_Pcdm4(),
'thesaurus' => new Class_CodifThesaurus(),
'tag' => new Class_TagNotice()];
if (isset($authorities[$code]))
return $authorities[$code];
}
}
?>
\ No newline at end of file
......@@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class AjaxControllerAuteurTest extends AbstractControllerTestCase {
class AjaxControllerSuggestAuteurTest extends AbstractControllerTestCase {
/** @test */
public function asAdminPortailBodyShouldContainsTagListe() {
$this->dispatch('/admin/ajax/listesuggestion/type_autorite/auteur/mode/1/valeur/1/id_champ/suggest', true);
......@@ -38,8 +38,7 @@ class AjaxControllerAuteurTest extends AbstractControllerTestCase {
class AjaxControllerThesaurusTest extends AbstractControllerTestCase {
class AjaxControllerSuggestThesaurusPirateTest extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
$this->mock_sql = $this->mock();
......@@ -51,83 +50,57 @@ class AjaxControllerThesaurusTest extends AbstractControllerTestCase {
}
/** @test */
public function getListeSuggestionForModeHierarchyContains() {
$this->mock_sql
->whenCalled('fetchAll')
->with("select distinct(id),id_thesaurus,id_origine from codif_thesaurus where id_thesaurus regexp (select group_concat(concat(id_thesaurus,'.*') separator '|') from codif_thesaurus where id_thesaurus like 'PUBL%' and id_origine is not null and libelle like '%pirate%') order by id_thesaurus",
false)
->answers([
['id_thesaurus' => 1,
'id_origine' => 1,
'id' => 1]
])
->beStrict();
public function datas() {
return [
[Class_CodifThesaurus::MODE_HIERARCHY_CONTAINS,
"select distinct(id),id_thesaurus,id_origine from codif_thesaurus where id_thesaurus regexp (select group_concat(concat(id_thesaurus,'.*') separator '|') from codif_thesaurus where id_thesaurus like 'PUBL%' and id_origine is not null and libelle like '%pirate%') order by id_thesaurus"],
[Class_CodifThesaurus::MODE_LABEL_STARTS_WITH,
"select id,id_thesaurus,libelle,id_origine from codif_thesaurus where id_thesaurus like 'PUBL%' and libelle like'pirate%' order by id_thesaurus limit 100"],
[Class_CodifThesaurus::MODE_LABEL_CONTAINS,
"select id,libelle,id_origine from codif_thesaurus where id_thesaurus like 'PUBL%' and libelle like'%pirate%' order by id_thesaurus limit 100"],
[Class_CodifThesaurus::MODE_INDEX_STARTS_WITH,
"select id,id_thesaurus,libelle,id_origine from codif_thesaurus where id_thesaurus like 'PUBL%' and id_origine like 'pirate%' order by id_thesaurus limit 100"]
];
}
$this->dispatch('/admin/ajax/listesuggestion/type_autorite/thesaurus/mode/1/valeur/pirate/id_champ/PUBL', true);
$this->assertXPathContentContains('//div[@class="tag_liste"][@clef="1"]', '1 : pirate', $this->_response->getBody());
/**
* @test
* @dataProvider datas
*/
public function withModeShouldRunExpectedQueryAndSuggestPirate($mode, $query) {
$this->expectListQueryReturningPirate($query);
$this->dispatchWithMode($mode);
$this->assertPirateIsSuggested();
}
/** @test */
public function getListeSuggestionForModeLabelStartsWith() {
$this->mock_sql
->whenCalled('fetchAll')
->with("select id,id_thesaurus,libelle,id_origine from codif_thesaurus where id_thesaurus like 'PUBL%' and libelle like'pirate%' order by id_thesaurus limit 100",
false)
->answers([
['id_thesaurus' => 1,
'id_origine' => 1,
'id' => 1]
])
->beStrict();
protected function dispatchWithMode($mode) {
$this->dispatch('/admin/ajax/listesuggestion/type_autorite/thesaurus/mode/' . $mode . '/valeur/pirate/id_champ/PUBL', true);
}
$this->dispatch('/admin/ajax/listesuggestion/type_autorite/thesaurus/mode/2/valeur/pirate/id_champ/PUBL', true);
$this->assertXPathContentContains('//div[@class="tag_liste"][@clef="1"]', '1 : pirate', $this->_response->getBody());
protected function assertPirateIsSuggested() {
$this->assertXPathContentContains('//div[@class="tag_liste"][@clef="1"]',
'1 : pirate',
$this->_response->getBody());
}
/** @test */
public function getListeSuggestionForModeLabelContains() {
$this->mock_sql
->whenCalled('fetchAll')
->with("select id,libelle,id_origine from codif_thesaurus where id_thesaurus like 'PUBL%' and libelle like'%pirate%' order by id_thesaurus limit 100",
false)
->answers([
['id_thesaurus' => 1,
'id_origine' => 1,
'id' => 1]
])
->beStrict();
$this->dispatch('/admin/ajax/listesuggestion/type_autorite/thesaurus/mode/3/valeur/pirate/id_champ/PUBL', true);
$this->assertXPathContentContains('//div[@class="tag_liste"][@clef="1"]', '1 : pirate', $this->_response->getBody());
protected function expectListQueryReturningPirate($query) {
$this->expectListQueryReturning($query,
[['id_thesaurus' => 1,
'id_origine' => 1,
'id' => 1],]);
}
/** @test */
public function getListeSuggestionForModeIndexStartsWith() {
protected function expectListQueryReturning($query, $result) {
$this->mock_sql
->whenCalled('fetchAll')
->with("select id,id_thesaurus,libelle,id_origine from codif_thesaurus where id_thesaurus like 'PUBL%' and id_origine like 'pirate%' order by id_thesaurus limit 100",
false)
->answers([
['id_thesaurus' => 1,
'id_origine' => 1,
'id' => 1]
])
->whenCalled('fetchAll')->with($query, false)->answers($result)
->beStrict();
$this->dispatch('/admin/ajax/listesuggestion/type_autorite/thesaurus/mode/4/valeur/pirate/id_champ/PUBL', true);
$this->assertXPathContentContains('//div[@class="tag_liste"][@clef="1"]', '1 : pirate', $this->_response->getBody());
}
}
?>
\ No newline at end of file
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