<?php
/**
 * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
 *
 * AFI-OPAC 2.0 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).
 *
 * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
 */
require_once 'AbstractControllerTestCase.php';

abstract class AbonneFlorenceIsLoggedControllerTestCase extends AbstractControllerTestCase {
	protected function _initProfilHook($profil) {
		$profil
			->setBrowser('opac')
			->setCfgAccueil('a:2:{s:7:"modules";a:0:{}s:7:"options";a:0:{}}');
	}


	public function setUp() {
		parent::setUp();
		Class_Users::beVolatile();
		Class_AvisNotice::beVolatile();
		Class_Notice::beVolatile();
		$this->florence = Class_Users::newInstanceWithId(123456)
			->setPseudo('FloFlo')
			->setRoleLevel(3)
			->setRole('abonne_sigb')
			->setLogin('florence')
			->setPassword('caramel')
			->setIdSite(1)
			->setIdabon('00123')
			->setFicheSIGB(['type_com' => 0]);
		$this->florence->save();
		
		ZendAfi_Auth::getInstance()->logUser($this->florence);
		
	}
}



abstract class AbonneControllerAvisTestCase extends AbonneFlorenceIsLoggedControllerTestCase {
	public function setUp() {
		parent::setUp();
	
		$this->potter = Class_Notice::newInstanceWithId(53,
																												['clef_oeuvre' =>'POTTER']);
		$this->potter->save();
	}
}




class AbonneControllerAvisNoticeWithoutAvisTest extends AbonneControllerAvisTestCase {
	public $xpath, $json;
	public function setUp() {
		parent::setUp();
		$this->xpath = new Storm_Test_XPath();
		$this->dispatch('/opac/abonne/avis/id_notice/53');
		$this->json = json_decode($this->_response->getbody());
	}


	/** @test */
	public function actionControllerShouldBeAbonneAvis() {
		$this->assertController('abonne');
		$this->assertAction('avis');
	}


	/** @test */
	public function inputAvisSignatureShouldContainFloFlo() {
		$this->xpath->assertXPath($this->json->content,"//input[@name='avisSignature'][@value='FloFlo']",$this->_response->getBody());
	}


	/** @test */
	public function formActionShouldBeAvisId53() {
		$this->xpath->assertXPath($this->json->content,"//form[@action='/abonne/avis/id_notice/53']");
	}
}




class AbonneControllerAvisInvalidNoticeAvisSaveTest extends  AbonneControllerAvisTestCase {
	public $xpath,$json;
	public function setUp() {
		parent::setUp();

		$this->avis_min_saisie = new Class_AdminVar();
		$this->avis_min_saisie
			->setId('AVIS_MIN_SAISIE')
			->setValeur(10);

		$this->avis_max_saisie = new Class_AdminVar();
		$this->avis_max_saisie
			->setId('AVIS_MAX_SAISIE')
			->setValeur(1200);

		Class_AdminVar::getLoader()
			->cacheInstance($this->avis_min_saisie)
			->cacheInstance($this->avis_max_saisie);
	}


	public function testAvisTooShort() {
		$data = array('avisEntete' => 'Sorcellerie',
									'avisTexte' => 'On adore',
									'avisNote' => 5,
									'avisSignature' => 'FloCouv');
		$this->xpath = new Storm_Test_XPath();
		$this->getRequest()
			->setMethod('POST')
			->setPost($data);
		$this->dispatch('/opac/abonne/avis/id_notice/53');
		$this->json = json_decode($this->_response->getbody());
		$this->assertController('abonne');
		$this->assertAction('avis');
		$this->xpath->assertXPathContentContains($this->json->content,'//p[@class="error"]','une longueur comprise entre 10 et 1200',$this->_response->getBody());
	}

	public function testEmptyEntete() {
		$data = array('avisEntete' => '',
									'avisTexte' => 'On adore la magie',
									'avisNote' => 5,
									'avisSignature' => '');
		$this->xpath = new Storm_Test_XPath();
		$this->getRequest()
			->setMethod('POST')
			->setPost($data);
		$this->dispatch('/opac/abonne/avis/id_notice/53');
		$this->json = json_decode($this->_response->getbody());
		$this->assertController('abonne');
		$this->assertAction('avis');
		$this->xpath->assertXPathContentContains($this->json->content,'//p[@class="error"]','Vous devez saisir un titre',$this->_response->getBody());
	}
}



class AbonneControllerAvisNoticeAvisSaveTest extends  AbonneControllerAvisTestCase {
	public function testSaveNewAvis() {
		$expected_avis = Class_AvisNotice::newInstance();
		$expected_avis
			->setEntete('Sorcellerie')
			->setAvis('On adore la magie')
			->setNote(5)
			->setClefOeuvre('POTTER')
			->setUser($this->florence)
			->setAbonOuBib(1)
			->setStatut(0);
		$expected_avis->save();
		$this->postAndAssertAvisIsSaved($expected_avis);
	}
	

	public function postAndAssertAvisIsSaved($expected_avis) {
		$data = ['avisEntete' => 'Sorcellerie',
									'avisTexte' => 'On adore la magie',
									'avisNote' => 5,
									'avisSignature' => 'FloCouv'];

		$this->getRequest()
			->setMethod('POST')
			->setPost($data);
		$this->dispatch('/opac/abonne/avis/id_notice/53');

		$this->assertEquals('FloCouv', $this->florence->getPseudo());
	}


	public function testSaveExistingAvis() {

		$expected_avis = Class_AvisNotice::newInstanceWithId(12);
		$expected_avis
			->setEntete('Sorcellerie')
			->setAvis('On adore la magie')
			->setNote(5)
			->setClefOeuvre('POTTER')
			->setUser($this->florence)
			->setAbonOuBib(1)
			->setStatut(0);

		$this->postAndAssertAvisIsSaved($expected_avis);
	}
}


class AbonneControllerAvisNoticeWithAvisTest extends AbonneControllerAvisTestCase {
	protected $_xpath,$_json;
	public function setUp() {
		parent::setUp();

		$avis = Class_AvisNotice::newInstanceWithId(12, ['Avis' => 'Excellent livre',
																										 'Entete' => 'Le sorcier super mimi',
																										 'note' => 4,
																										 'clef_oeuvre' => 'POTTER',
																										 'user' => $this->florence]);
		$avis->save();
		$this->dispatch('/opac/abonne/avis/id_notice/53');
		$this->_xpath = new Storm_Test_XPath();
		$this->_json = json_decode($this->_response->getBody());
	}

	public function testAvisFormRendered() {
		$this->assertController('abonne');
		$this->assertAction('avis');
	}


	public function testAvisIsFilled() {
		$this->_xpath->assertXPathContentContains($this->_json->content,'//form//textarea[@name="avisTexte"]','Excellent livre',$this->_response->getBody());
	}

	public function testSignatureIsFloFlo() {
		$this->_xpath->assertXPath($this->_json->content,"//input[@name='avisSignature'][@value='FloFlo']");
	}

	public function testEntete() {
		$this->_xpath->assertXPath($this->_json->content,"//input[@name='avisEntete'][@value='Le sorcier super mimi']");
	}

	public function testNote() {
		$this->_xpath->assertXPath($this->_json->content,"//select[@name='avisNote']/option[@value='4'][@selected='1']");
	}

	public function testFormActionIsAvis() {
		$this->_xpath->assertXPath($this->_json->content,"//form[@action='/abonne/avis/id_notice/53/id/12']");
	}
}


abstract class AvisControllersFixturesTestCase extends AbonneFlorenceIsLoggedControllerTestCase {
	public function setUp() {
		parent::setUp();

		$this->modo_avis = new Class_AdminVar();
		$this->modo_avis
			->setId('MODO_AVIS')
			->setValeur(0);

		$this->modo_avis_biblio = new Class_AdminVar();
		$this->modo_avis_biblio
			->setId('MODO_AVIS_BIBLIO')
			->setValeur(0);

		$this->readspeaker = new Class_AdminVar();
		$this->readspeaker
			->setId('ID_READ_SPEAKER')
			->setValeur('54QCJRHZ31IPBV7GW3DKBPUYYP579A14');


		Class_AdminVar::getLoader()
			->cacheInstance($this->modo_avis)
			->cacheInstance($this->modo_avis_biblio)
			->cacheInstance($this->readspeaker);


		$this->millenium = Class_Notice::newInstanceWithId(816, ['titre_principal' => 'Millenium',
																														 'clef_alpha' => 'MILLENIUM',
																														 'auteur_principal' => 'Stieg Larsson',
																														 'url_vignette' => '',
																														 'url_image' => ''
																												 ]
			);

		$this->millenium->save();
		$this->millenium_with_vignette = Class_Notice::newInstanceWithId(817, ['titre_principal' => 'Millenium',
																														 'clef_alpha' => 'MILLENIUM',
																														 'auteur_principal' => 'Stieg Larsson',
																														 'url_vignette' => 'http://amazon.com/vignette_millenium.png'
																												 ]
			);
		$this->millenium_with_vignette->save();


		$this->avis_millenium =  Class_AvisNotice::newInstanceWithId(13, [
																																	 'entete' => "J'adore",
																																	 'avis' => "Suspense intense",
																																	 'note' => 5,
																																	 'date_avis' => '2011-03-18 13:00:00',
																																	 'user' => $this->florence,
																																	 'statut' => 0,
																																	 'abon_ou_bib'=>1 ,
																																	 'notices' => [$this->millenium,
																																								 $this->millenium_with_vignette] ]);
		
		$this->avis_millenium->save();
		$this->potter = Class_Notice::newInstance();
		$this->potter
			->setTitrePrincipal('Potter et la chambre des secrets')
			->setAuteurPrincipal('')
			->setUrlVignette('http://amazon.com/vignette_potter.png');
		$this->potter->save();
		$this->avis_potter = Class_AvisNotice::newInstanceWithId(25, 
																														 ['entete' => 'Prenant',
																															'avis' => "Mais un peu trop naïf",
																															'note'=>4,
																															'date_avis' => '2010-10-12 10:00:00',
																															'user'=>$this->florence,
																															'statut' => 1,
																															'abon_out_bib' => 1,
																															'notices' => [$this->potter]]);
		
		$this->avis_potter->save();

		$this->avis_lost = Class_AvisNotice::newInstanceWithId(67,
																													 ['entete' =>"C'est perdu",
																														'avis' =>"Plus de notice, ni d'utilisateur",
																														'note' => 4,
																																'date_avis' => '2008-10-12 10:00:00',
																															'user'=>null,
																															'statut' => 1,
																															'abon_out_bib' => 1,
																														'notices' => []]);
		$this->avis_lost->save();


		$this->florence->setAvis([$this->avis_millenium, $this->avis_potter]);
		$this->florence->save();
		$dupont = Class_Users::newInstanceWithId(56, ['nom'=>'Dupont']);

		$avis_millenium_dupont = Class_AvisNotice::newInstanceWithId(156)
			->setEntete("Cool")
			->setAvis("effrayant")
			->setNote(5)
			->setDateAvis('2011-03-18 13:00:00')
			->setAuteur($dupont)
			->setUser($dupont)
			->setStatut(0)
			->setAbonOuBib(1)
			->setNotices([$this->millenium]);
		$dupont->setAvis([$avis_millenium_dupont]);
		$dupont->save();
		$avis_millenium_dupont->save();
	}
}


class AbonneControllerAvisBlogControllerViewUnknownAuteurTest extends AvisControllersFixturesTestCase {
	public function setUp() {
		parent::setUp();
		$this->dispatch('/opac/blog/viewauteur/id/999999999');
	}


	public function testPageIsRendered() {
		$this->assertController('blog');
		$this->assertAction('viewauteur');
	}


	public function testDisplayAuteurIntrouvable() {
		$this->assertXPathContentContains('//h1', 'Auteur introuvable');
	}
}




class AbonneControllerAvisViewFicheWithAvisTest extends AvisControllersFixturesTestCase {
	public function setUp() {
		parent::setUp();
		$this->dispatch('/opac/abonne/fiche', true);
	}

	/** @test */
	public function pageShouldDisplayVousAvezRedigeDeuxAvis() {
		$this->assertXPathContentContains('//a', 
																			'Vous avez rédigé 2 avis',
																			$this->_response->getBody());
	}


	/** @test */
	public function linkAvisShouldGoToAbonneViewAvis() {
		$this->assertXPath('//a[contains(@href, "/abonne/viewavis/id/123456")]');
	}
}




class AbonneControllerAvisBlogControllerViewAuteurActionTest extends AvisControllersFixturesTestCase {
	public function setUp() {
		parent::setUp();
		$this->dispatch('/opac/blog/viewauteur/id/123456');
	}

	public function testPageIsRendered() {
		$this->assertController('blog');
		$this->assertAction('viewauteur');
	}

	public function testMilleniumIsHere() {
		$this->assertXPathContentContains("//div[@class='critique'][1]//h2", 'Millenium (Stieg Larsson)');
	}


	/** @test */
	public function milleniumShouldLinkToNoticeMilleniumWithRetourAbonneViewAvis() {
		$this->assertXPath('//a[contains(@href, "/recherche/viewnotice/id/817/clef/MILLENIUM/retour_abonne/viewavis")]',$this->_response->getBody());
	}

	public function testPotterIsHere() {
		$this->assertXPathContentContains("//div[@class='critique'][2]//h2", 'Potter et la chambre des secrets');
	}

	public function testDeleteMilleniumButtonPresent() {
		$this->assertXPath('//a[contains(@href, "/blog/delavisnotice/id/13")]');
	}

	public function testDeletePotterButtonPresent() {
		$this->assertXPath('//a[contains(@href, "/blog/delavisnotice/id/25")]');
	}

	/** @test */
	function rssLinkShouldBePresent() {
		$this->assertXPath("//div[@class='rss']/a[@href='/rss/user/id/123456']");
	}
}




class AbonneControllerAvisViewAvisActionTest extends AvisControllersFixturesTestCase {
	public function setUp() {
		parent::setUp();
		$this->dispatch('/opac/abonne/viewavis/id/123456');
	}


	public function testDeleteMilleniumButtonPresent() {
		$this->assertXPath("//a[contains(@href, '/abonne/delavisnotice/id/13')]");
	}
}




class AbonneControllerAvisBlogControllerViewOtherAuteurAsAdminActionTest extends AvisControllersFixturesTestCase {
	public function setUp() {
		parent::setUp();
		$this->florence->beAdminPortail();
		$this->dispatch('/opac/blog/viewauteur/id/56');
	}


	public function testDeleteMilleniumButtonPresent() {
		$this->assertXPath("//a[contains(@href, '/blog/delavisnotice/id/156')]",$this->_response->getBody());
	}
}



class AbonneControllerAvisRssControllerViewAvisUserTest extends AvisControllersFixturesTestCase {
	public function setUp() {
		parent::setUp();
		$this->dispatch('/opac/rss/user/id/123456');
	}


	/** @test */
	function channelTitleShouldBeAvisDeFloFlo() {
		$this->assertXpathContentContains('//channel/title', 'Avis de FloFlo');
	}


	/** @test */
	function linkShouldBeLocalhostAfiOpac3BlogRssUser123456() {
		$this->assertXPathContentContains('//channel/link', 
																			'http://localhost' . BASE_URL . '/blog/viewauteur/id/123456', 
																			$this->_response->getBody());
	}


	/** @test */
	function channelItemCountShouldBeTwo() {
		$this->assertXpathCount('//channel/item', 2);
	}


	/** @test */
	function firstItemTitleShouldBeJAdore() {
		$this->assertXPathContentContains('//channel/item/title', "J'adore");
	}


	/** @test */
	function firstItemLinkShouldBeBlogViewAvisId13() {
		$this->assertXPathContentContains('//channel/item/link', 
																			"http://localhost" . BASE_URL . "/opac/blog/viewavis/id/13",$this->_response->getBody());
	}


	/** @test */
	function firstItemPubUpdateShouldBeTue12Oct() {
		$this->assertXPathContentContains('//channel/item/pubDate', "Tue, 12 Oct 2010");
	}


	/** @test */
	function firstItemNoteCritiqueShouldBeImgStars4Gif() {
		$this->assertTrue(false !== strpos($this->_response->getBody(),
																			 'src="http://localhost' . BASE_URL . '/public/admin/images/stars/stars-4.gif"'));
	}
}




class RssControllerViewAvisInexistingUserTest extends AvisControllersFixturesTestCase {
	public function setUp() {
		parent::setUp();
		$this->dispatch('/opac/rss/user/id/-1', true);
	}


	/** @test */
	function linkShouldBeLocalhostAfiOpac3BlogRssUserMinusOne() {
		$this->assertXPathContentContains('//channel/link', 
																			'http://localhost' . BASE_URL . '/blog/viewauteur/id/-1');
	}
}




class AbonneControllerAvisDeleteAvisTest extends AvisControllersFixturesTestCase {
	public function setUp() {
		parent::setUp();
		$this->dispatch('/abonne/delavisnotice/id/25', true);
	}


	public function testRedirectToAbonneAvisPage() {
		$this->assertRedirectTo('/abonne/viewavis/id/123456');
	}
}



class AbonneControllerAvisBlogControllerDeleteAvisTest extends AvisControllersFixturesTestCase {
	public function setUp() {
		parent::setUp();
		$this->dispatch('/blog/delavisnotice/id/25');
	}

	public function testRedirectToViewAuteurPage() {
		$this->assertRedirectTo('/blog/viewauteur/id/123456');
	}
}




class AbonneControllerAvisBlogControllerLastCritiquesTest extends AvisControllersFixturesTestCase {
	public function setUp() {
		parent::setUp();
		$this->dispatch('/opac/blog/lastcritique/nb/10');
	}

	public function testPageIsRendered() {
		$this->assertController('blog');
		$this->assertAction('lastcritique');
	}


	public function testMilleniumIsHere() {
		$this->assertXPathContentContains("//div[@class='critique'][1]//h2", 'Millenium (Stieg Larsson)');
	}


	public function testPotterIsBeforeMillenium() {
		$this->assertXPathContentContains("//div[@class='critique'][2]//h2", 'Potter et la chambre des secrets',$this->_response->getBody());
	}


	public function testAvisLostShouldDisplayOeuvreNonTrouvee() {
		$this->assertXPathContentContains("//div[@class='critique'][3]//h2", 'Oeuvre non trouvée');
	}
}



abstract class ModuleSelectionCritiquesTestCase extends AvisControllersFixturesTestCase {
	public function setUp() {
		parent::setUp();

		$preferences = array('modules' => array(3 => array('division' => 2,
																											 'type_module' => 'CRITIQUES',
																											 'preferences' => array('titre' => 'Coups de coeur'))));
		$profil = Class_Profil::getLoader()
			->find(2)
			->setCfgAccueil($preferences);

		$this->_generateLoaderFor('Class_AvisNotice', array('getAvisFromPreferences'))
			->expects($this->once())
			->method('getAvisFromPreferences')
			->will($this->returnValue([$this->avis_millenium, 
																 $this->avis_potter, 
																 $this->avis_lost]));
	}
}




class AbonneControllerAvisBlogControllerViewCritiquesTest extends ModuleSelectionCritiquesTestCase {
	public function setUp() {
		parent::setUp();
		$this->dispatch('/opac/blog/viewcritiques/id_profil/2/id_module/3');
	}

	public function testMilleniumIsHere() {
		$this->assertQueryContentContains('h2', 'Millenium');
	}

	public function testPotterIsHere() {
		$this->assertQueryContentContains('h2', 'Potter');
	}

	/** @test */
	public function titleShouldBeCoupsDeCoeur() {
		$this->assertXPathContentContains('//h1', 'Coups de coeur');
	}
}




class AbonneControllerAvisBlogControllerViewCritiquesWithoutModuleTest extends ModuleSelectionCritiquesTestCase {
	/** @test */
	public function titleShouldBeDernieresCritiques() {
		$this->dispatch('/opac/blog/viewcritiques');
		$this->assertXPathContentContains('//h1', 'Dernières critiques');
	}
}




class AbonneControllerAvisRssControllerLastCritiquesTest extends ModuleSelectionCritiquesTestCase {
	public function setUp() {
		parent::setUp();

		$this->dispatch('/opac/rss/critiques/id_profil/2/id_module/3', true);
		$this->body = $this->getResponse()->getBody();

	}

	public function testMilleniumIsHere() {
		$this->assertNotEquals(false, strpos($this->body, 'Millenium'));
	}

	public function testPotterIsHere() {
		$this->assertNotEquals(false, strpos($this->body, 'Potter'));
	}
}




class AbonneControllerAvisBlogControllerViewReadAvisTest extends  AbonneFlorenceIsLoggedControllerTestCase {
	public function setUp() {
		parent::setUp();

		$millenium = Class_Notice::newInstanceWithId(23,
																								 ['titre_principal' => 'Millenium (Stieg Larsson)',
																									'url_vignette' => 'http://amazon.com/vignette.png',
																									'clef_alpha' => 'MILLENIUM']);

		$avis_millenium = Class_AvisNotice::newInstanceWithId(18)
			->setEntete("J'adore")
			->setAvis("Suspense intense")
			->setNote(5)
			->setDateAvis('2010-03-18 13:00:00')
			->setUser($this->florence)
			->setAbonOuBib(1)
			->setStatut(0)
			->setNotices([$millenium]);
	}


	/** @test */
	public function blogViewAvisShouldRenderTitleLarsson() {
		$this->dispatch('/opac/blog/viewavis/id/18');

		$this->assertController('blog');
		$this->assertAction('viewavis');

		$this->assertQueryContentContains('div.critique h2', 'Millenium (Stieg Larsson)');
	}



	/** @test */
	public function blogViewAvisWithClefInUrlShouldCleanItInNoticeLink() {
		$this->dispatch('/opac/blog/viewavis/id/18/clef/ZORK');
		$this->assertXPath('//a[contains(@href, "recherche/viewnotice/id/23/clef/MILLENIUM")]', 
											 $this->_response->getBody());
	}


	/** @test */
	public function readSpeakerReadAvisShouldRender() {
		$this->dispatch('/opac/blog/readavis/id/18');

		$this->assertController('blog');
		$this->assertAction('readavis');

		$this->assertQueryContentContains('p', 'Millenium (Stieg Larsson)');
		$this->assertQueryContentContains('p', '18 mars 2010');
	}
}



class AbonneControllerEditAvisNoticeNotFoundActionTest extends AbstractControllerTestCase {
	public function setUp() {
		parent::setUp();
		Class_AvisNotice::beVolatile();
		$this->dispatch('/opac/abonne/editavisnotice/id/54', true);
	}


	/** @test */
	public function responseShouldReloadPage() {
		$this->assertTrue(false !== strpos(json_decode($this->_response->getBody())->title, 'Sauvegarde en cours'));
	}
}


class AbonneControllerEditAvisNoticeNotAdminLoggedActionTest extends AbstractControllerTestCase {
	protected function _loginHook($account) {
		$account->ROLE_LEVEL = ZendAfi_Acl_AdminControllerRoles::INVITE;
		$account->ROLE = 'invite';
	}

	public function setUp() {
		parent::setUp();
		$avis = $this->fixture('Class_AvisNotice', ['id' => 54,
																								'entete' => 'Bonjour !',
																								'avis' => 'Ceci est le contenu de l\'avis']);
		$this->dispatch('/opac/abonne/editavisnotice/id/54', true);
	}


	/** @test */
	public function responseShouldReloadPage() {
		$this->assertTrue(false !== strpos(json_decode($this->_response->getBody())->title, 'Sauvegarde en cours'), 
											$this->_response->getBody());
	}
}




class AbonneControllerEditAvisNoticeAdminLoggedActionTest extends AbstractControllerTestCase {
	public function setUp() {
		parent::setUp();
		$avis = $this->fixture('Class_AvisNotice', ['id' => 54,
																								'entete' => 'Bonjour !',
																								'avis' => 'Ceci est le contenu de l\'avis']);

		$this->dispatch('/opac/abonne/editavisnotice/id/54', true);
		$this->json = json_decode($this->_response->getBody());
	}


	/** @test */
	public function titleShouldBeBonjour() {
		$this->assertEquals('Modifier l\'avis "Bonjour !"', $this->json->title);
	}


	/** @test */
	public function formShouldBePresent() {
		$this->assertTrue(false !== strpos($this->json->content, '<form '));
	}
}



class AbonneControllerEditAvisNoticeAdminLoggedPostActionTest extends AbstractControllerTestCase {
	public function setUp() {
		parent::setUp();
		$this->fixture('Class_AvisNotice', ['id' => 54,
																				'entete' => 'Bonjour !',
																				'avis' => 'Ceci est le contenu de l\'avis']);

		$this->postDispatch('/opac/abonne/editavisnotice/id/54', 
												['entete' => 'bye',
												 'avis' => 'ceci n\'est pas le contenu'],
												true);

		$this->avis = Class_AvisNotice::find(54);
	}


	/** @test */
	public function enteteShouldBeBye() {
		$this->assertEquals('bye', $this->avis->getEntete());
	}


	/** @test */
	public function avisShouldBeCeciNEstPasLeContenu() {
		$this->assertEquals('ceci n\'est pas le contenu', $this->avis->getAvis());
	}
}

?>