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

Domain controller tests refactoring

parent 31d53f56
Branches
Tags
2 merge requests!258Dev/13872 Orphee Allow Hold Available Items,!4dev#12091 Moulins portail jeunesse
......@@ -20,19 +20,23 @@
*/
class DomainsController extends ZendAfi_Controller_Action {
public function browseAction() {
if (!$catalogue=Class_Catalogue::find($this->_getParam('id')))
if (!$catalog = Class_Catalogue::find($this->_getParam('id'))) {
$this->_redirect();
if (!$catalogue->hasSousDomaines()){
return;
}
if (!$catalog->hasSousDomaines()){
$this->_redirect($this->view->url(array_filter(['controller' => 'recherche',
'action' => 'simple',
'id_catalogue' => $catalogue->getId(),
'parents' => $this->_getParam('parents')]),null,true));
'id_catalogue' => $catalog->getId(),
'parents' => $this->_getParam('parents')]),
null, true));
return;
}
$this->view->current_domain=$catalogue;
$this->view->current_breadcrumb=$this->_getParam('parents');
$this->view->current_domain = $catalog;
$this->view->current_breadcrumb = $this->_getParam('parents');
}
}
?>
\ No newline at end of file
......@@ -21,167 +21,90 @@
require_once 'AbstractControllerTestCase.php';
abstract class DomainsControllerSearchResultFixtures extends AbstractControllerTestCase {
abstract class DomainsControllerBrowseTestCase extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
$this->mock_sql = Storm_Test_ObjectWrapper::mock();
$this->mock_moteur_recherche = Storm_Test_ObjectWrapper::mock();
$this->mock_codif = Storm_Test_ObjectWrapper::mock();
$this->mock_moteur_recherche
->whenCalled('getFacettes')
->answers([ "facettes" => [ "T" =>
[ "titre" => "Type de document",
1 => [
"id" => "D3",
"libelle" => "disques",
"nombre" =>"2",
"url" => "/une/url/Bidon"]
]] ,
"tags" => [
1=>[
"id" => "M1355",
"libelle" => "CD",
"nombre" => 2]],
"url_facette" => "/recherche/simple/facettes/"
]
);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice')
->whenCalled('findAllByRequeteRecherche')
->answers([Class_Notice::newInstanceWithId(8),
Class_Notice::newInstanceWithId(9)]);
$this->mock_codif
->whenCalled('getNomFacette')
->answers('nom de la facette');
$this->mock_codif
->whenCalled('getLibelleFacette')
->answers('facette');
$this->mock_codif
->whenCalled('getNomChamp')
->answers('champ');
Class_CodifThesaurus::beVolatile();
$this->mock_moteur_recherche
->whenCalled('lancerRecherche')
->answers([ "req_liste" => "select" ,
"nombre" => 10,
"req_facettes" => "select",
'facettes' => 'M123-A989'
]);
Class_Codification::setInstance($this->mock_codif);
Class_MoteurRecherche::setInstance($this->mock_moteur_recherche);
$this->mock_sql
->whenCalled('fetchOne')
->with('select libelle from codif_dewey where id_dewey=\'66\'')
->answers( 'Generalites')->beStrict();
$this->mock_sql
->whenCalled('fetchOne')
->with('select libelle from codif_dewey where id_dewey=\'77\'')
->answers('Arts')->beStrict();
Zend_Registry::set('sql', $this->mock_sql);
$this->fixture(
'Class_Catalogue',
['id' => 3, 'libelle' => 'Youth', 'url_img' => 'http://imgs/youth.png',
'sous_domaines' => [
$this->fixture('Class_Catalogue',
['id' => 4, 'libelle' => 'A',
'sous_domaines' => [
$this->fixture('Class_Catalogue',
['id' => 10, 'libelle' => 'Animals'])]]),
$this->fixture('Class_Catalogue',
['id' => 6, 'libelle' => 'C',
'sous_domaines' => [
$this->fixture('Class_Catalogue',
['id' => 15, 'libelle' => 'Car']),
$this->fixture('Class_Catalogue',
['id' => 25, 'libelle' => 'Cinema'])]])]]);
}
}
abstract class DomainsControllerTest extends DomainsControllerSearchResultFixtures{
public function setup() {
parent::setup();
}
}
class DomainsControllerBrowseTest extends DomainsControllerTest {
class DomainsControllerYouthBrowseTest extends DomainsControllerBrowseTestCase {
public function setUp() {
parent::setUp();
Class_CodifThesaurus::beVolatile();
$this->youth_domain = $this->fixture('Class_Catalogue',['id'=>3,
'libelle' => 'Youth',
'url_img' => 'http://imgs/youth.png'
]);
$this->a_letter_domain = $this->fixture('Class_Catalogue',['id'=>4,
'domaine_parent' => $this->youth_domain,
'libelle' => 'A']);
$this->c_letter_domain = $this->fixture('Class_Catalogue',['id'=>6,
'domaine_parent' => $this->youth_domain,
'libelle' => 'C']);
$this->animals_domain = $this->fixture('Class_Catalogue',['id'=>10,
'domaine_parent' => $this->a_letter_domain,
'libelle' => 'Animals']);
$this->car_domain = $this->fixture('Class_Catalogue',['id'=>15,
'domaine_parent' => $this->c_letter_domain,
'libelle' => 'Car']);
$this->cinema_domain = $this->fixture('Class_Catalogue',['id'=>25,
'domaine_parent' => $this->c_letter_domain,
'libelle' => 'Cinema']);
$this->dispatch('/domains/browse/id/3', true);
}
/** @test */
public function browsingYouthDomainShouldDisplayLinkToLetterADomain() {
$this->dispatch('/domains/browse/id/3');
$this->assertXPath('//div[@class="children_domains"]/ul/li/a[@href="/domains/browse/id/4/parents/3"]');
}
/** @test */
public function browsingYouthDomainShouldDisplayLinkToLetterCDomain() {
$this->dispatch('/domains/browse/id/3');
$this->assertXPath('//div[@class="children_domains"]/ul/li/a[@href="/domains/browse/id/6/parents/3"]');
}
}
class DomainsControllerBrowseALetterDomainTest extends DomainsControllerBrowseTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/domains/browse/id/4/parents/3', true);
}
/** @test */
public function browsingADomainShouldDisplayLinkAnimalsDomainAsRechercheSimple() {
$this->dispatch('/domains/browse/id/4/parents/3');
$this->assertXPath('//div[@class="children_domains"]/ul/li/a[@href="/recherche/simple/id_catalogue/10/parents/3%3B4"]');
}
/** @test */
public function browsingADomainShouldDisplayLinkADomain() {
$this->dispatch('/domains/browse/id/4/parents/3');
$this->assertXPath('//div[@class="breadcrumb_domains"]/ul/li/a[@href="/domains/browse/id/4/parents/3"]');
}
/** @test */
public function browsingADomainShouldDisplayLinkToYouthDomain() {
$this->dispatch('/domains/browse/id/4/parents/3');
$this->assertXPath('//div[@class="breadcrumb_domains"]/ul/li/a[@href="/domains/browse/id/3"]/img[@src="http://imgs/youth.png"]');
}
}
class DomainsControllerBrowseCLetterDomainTest extends DomainsControllerBrowseTestCase {
/** @test **/
public function browsingCLetterDomainShouldDisplayLinkToCarAndLinkToCinema() {
$this->dispatch('/domains/browse/id/6/parents/3');
$this->dispatch('/domains/browse/id/6/parents/3', true);
$this->assertXPathCount('//div[@class="children_domains"]/ul/li/a[contains(@href,"/recherche/simple/id")]', 2);
}
}
class DomainsControllerBrowseCarDomainTest extends DomainsControllerBrowseTestCase {
/** @test */
public function browsingCarDomainShouldRedirectToSearchResult() {
$this->dispatch('/domains/browse/id/15/parents/3;6',true);
$this->dispatch('/domains/browse/id/15/parents/3;6', true);
$this->assertRedirectTo('/recherche/simple/id_catalogue/15/parents/3%3B6');
}
}
......
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