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

sql mocking on suggests tests

parent d49d89f9
Branches
Tags
5 merge requests!529Hotline 6.56,!512Master,!484Master,!476Sandbox #16325 inspector gadget,!470Sandbox #16325 inspector gadget
......@@ -16,10 +16,46 @@
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class AjaxControllerSuggestTest extends AbstractControllerTestCase {
protected $_sql_mock;
public function setUp() {
parent::setUp();
$this->_sql_mock = $this
->mock()
->whenCalled('fetchAll')
->with("select id_auteur,libelle from codif_auteur where formes like'1%' order by FORMES limit 100", false)
->answers([['id_auteur' => 12999, 'libelle' => 'André Gosciny']])
->whenCalled('fetchAll')
->with("select id_auteur,libelle from codif_auteur where formes like'L%' order by FORMES limit 100", false)
->answers([['id_auteur' => 12999, 'libelle' => 'André Gosciny']])
->whenCalled('fetchAll')
->with("select id_matiere,libelle from codif_matiere where code_alpha like 'L%' order by code_alpha limit 100", true)
->answers([[999, 'Testing test']])
->whenCalled('fetchAll')
->with("select id_interet,libelle from codif_interet where code_alpha like 'L%' order by code_alpha limit 100", true)
->answers([[777, 'Cinéma']])
->whenCalled('fetchAll')
->with("select id_dewey,libelle from codif_dewey where id_dewey like'%' order by id_dewey limit 100", false)
->answers([['id_dewey' => '888', 'libelle' => 'Actualités']])
->whenCalled('fetchAll')
->with("select id_pcdm4,libelle from codif_pcdm4 where id_pcdm4 like'%' order by id_pcdm4 limit 100", false)
->answers([['id_pcdm4' => '566', 'libelle' => 'Bande dessiné']])
->beStrict();
Zend_Registry::set('sql', $this->_sql_mock);
}
/** @test */
public function forAuthorsAsAdminPortailBodyShouldContainsTagListe() {
$this->dispatch('/admin/ajax/listesuggestion/type_autorite/auteur/mode/1/valeur/1/id_champ/suggest', true);
......@@ -36,26 +72,24 @@ class AjaxControllerSuggestTest extends AbstractControllerTestCase {
public function getTypeAutorites() {
return [
['auteur'],
['matiere'],
['interet'],
['dewey'],
['pcdm4'],
return [['auteur'],
['matiere'],
['interet'],
['dewey'],
['pcdm4'],
// ['thesaurus'],
// ['tag'],
];
];
}
/**
* @test
/**
* @test
* @dataProvider getTypeAutorites
*/
public function forAutoritysAsAdminPortailBodyShouldContainsTagListe($type_autorite) {
$this->dispatch('/admin/ajax/listesuggestion/type_autorite/'.$type_autorite.'/mode/1/valeur/l/id_champ/suggest',
$this->dispatch('/admin/ajax/listesuggestion/type_autorite/'.$type_autorite.'/mode/1/valeur/l/id_champ/suggest',
true);
$this->assertXPath('//div[@class="tag_liste"]',
$this->_response->getBody());
$this->assertXPath('//div[@class="tag_liste"]', $this->_response->getBody());
}
}
......@@ -63,7 +97,7 @@ class AjaxControllerSuggestTest extends AbstractControllerTestCase {
class AjaxControllerSuggestThesaurusPirateTest extends AbstractControllerTestCase {
class AjaxControllerSuggestThesaurusPirateTest extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
$this->mock_sql = $this->mock();
......@@ -78,7 +112,7 @@ class AjaxControllerSuggestThesaurusPirateTest extends AbstractControllerTestCas
public function datas() {
return [
[Class_CodifThesaurus::MODE_HIERARCHY_CONTAINS,
[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"],
......@@ -90,8 +124,8 @@ class AjaxControllerSuggestThesaurusPirateTest extends AbstractControllerTestCas
}
/**
* @test
/**
* @test
* @dataProvider datas
*/
public function withModeShouldRunExpectedQueryAndSuggestPirate($mode, $query) {
......@@ -107,8 +141,8 @@ class AjaxControllerSuggestThesaurusPirateTest extends AbstractControllerTestCas
protected function assertPirateIsSuggested() {
$this->assertXPathContentContains('//div[@class="tag_liste"][@clef="1"]',
'1 : pirate',
$this->assertXPathContentContains('//div[@class="tag_liste"][@clef="1"]',
'1 : pirate',
$this->_response->getBody());
}
......
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