Newer
Older
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* 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).
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once 'AbstractControllerTestCase.php';
abstract class AbstractAbonneControllerNewslettersTestCase extends AbstractControllerTestCase {

efalcy
committed
protected $_storm_default_to_volatile=true;
public function setUp() {
parent::setUp();
Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR',
['valeur' => 'pseudo;nom;prenom;mail;password']);

efalcy
committed
$this->marcus = $this->fixture('Class_Users',['id'=> 10,
'prenom' => 'Marcus',
'nom' => 'Miller',
'login' => 'mmiller' ,
'mail' => 'marcus@gmail.com',
'pseudo' => 'mimi',
'password' => 'mysecret',
'date_debut' => null,
'role' => 'abonne_sigb',
'role_level' => 3,
'id_site' => 999,
'idabon' => '00123',
'fiche_SIGB' => ['type_comm' => 0,
'nom_aff' => 'Marcus']
]);
ZendAfi_Auth::getInstance()->logUser($this->marcus);
}
}
abstract class AbonneControllerWithTwoNewslettersTestCase extends AbstractAbonneControllerNewslettersTestCase {
$this->concerts = $this->fixture('Class_Newsletter',
['id' => 12,
'titre' =>'Concerts',
'contenu' => 'Festival jazz']);
$this->visites = $this->fixture('Class_Newsletter',
['id' => 14,
'titre' =>'Visites',
'contenu' => 'du patrimoine']);
$this->marcus->setNewsletters([$this->concerts])->save();
}
class AbonneControllerNewslettersFicheActionWithNoExistingNewslettersTest extends AbstractAbonneControllerNewslettersTestCase {

efalcy
committed
$this->marcus->setNewsletters([]);
public function testInfoAbonnementNewsletterConcerts () {
$this->assertNotQueryContentContains('div.abonneFiche',
"Vous n'êtes abonné à aucune lettre d'information");
}
public function testLinkToEditInformationsInfoAbonnements() {
$this->assertNotXPathContentContains("//div[@class='abonneFiche']//a[@href='/abonne/edit']",
'Modifier mes abonnements');
public function testEditFormDoNotShowSubscriptions() {
$this->dispatch('/opac/abonne/edit');
$this->assertAction('edit');
$this->assertNotXPath("//form//input[@type='checkbox'][@name='subscriptions[]']");
$this->assertNotXPath("//form//label[@for='subscriptions']");
}
class AbonneControllerNewslettersFicheActionWithOneSubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase {
public function setUp() {
parent::setUp();
$this->fixture('Class_AdminVar', ['id' => 'INTERDIRE_MODIF_FICHE_ABONNE',
'valeur' => '0']);
$this->dispatch('/opac/abonne', true);
}
public function testForwardedToFiche() {
$this->assertController('abonne');
$this->assertAction('fiche');
}
public function testLinkToEditInformationsInTitle() {
$this->assertXPathContentContains("//div[@class='abonneTitre']//a[@href='/abonne/edit']",
'Modifier ma fiche',
$this->_response->getBody());
public function testInfoAbonnementNewsletterConcerts () {
$this->assertQueryContentContains('div.abonneFiche',
"Vous êtes abonné à la lettre d'information: Concerts");
}
public function testIconeNewsletterDisplayed () {
$this->assertXPath('//div[contains(@class, "abonneFiche")]//a[contains(@href, "/abonne/edit")]//img[contains(@src, "abonnes/newsletter.png")]');
}
public function testLinkToEditInformationsInfoAbonnements() {
$this->assertXPathContentContains("//div[contains(@class, 'abonneFiche')]//a[@href='/abonne/edit']",
'Modifier mes abonnements');
class AbonneControllerNewslettersFicheActionWithTwoSubscriptionsTest extends AbonneControllerWithTwoNewslettersTestCase {
$this->dispatch('/opac/abonne/fiche');
$this->assertController('abonne');
$this->assertAction('fiche');
}
public function testInfoAbonnementNewsletterConcertsEtVisites () {
$this->assertQueryContentContains('div.abonneFiche',
"Vous êtes abonné aux lettres d'information: Concerts, Visites");
}
class AbonneControllerNewslettersFicheActionWithNoSubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase {
public function setUp() {
parent::setUp();
$this->marcus->setNewsletters(array());
$this->dispatch('/opac/abonne/fiche');
$this->assertController('abonne');
$this->assertAction('fiche');
}
public function testInfoAbonnementNewsletterConcerts () {
$this->assertQueryContentContains('div.abonneFiche',
"Vous n'êtes abonné à aucune lettre d'information");
}
class AbonneControllerNewslettersEditActionTest extends AbonneControllerWithTwoNewslettersTestCase {
$this->aide_fiche_abonne = new Class_AdminVar();
$this->aide_fiche_abonne
->setId('AIDE_FICHE_ABONNE')
->setValeur("Saisissez\nvos données");
Class_AdminVar::getLoader()
->cacheInstance($this->aide_fiche_abonne);

efalcy
committed
$this->fixture('Class_Newsletter',
['id' => 5,
'titre' => 'hidden newsletter',
'draft' => true]);
public function testNewsletterActionFound() {
$this->assertController('abonne');
$this->assertAction('edit');
}
public function testAideIsDisplayed() {
$this->assertContains("<div class='help'>Saisissez<br />\nvos données</div>", $this->_response->getBody());
}
public function testUserForm() {
$this->assertXPath("//form[@id='user'][@method='post'][@action='/abonne/edit/id/10']");
}
public function testConcertsInCheckbox() {
$this->assertXPathContentContains("//form//input[@type='checkbox'][@name='subscriptions[]'][@value=12]/..",
'Concerts');
}
public function testConcertsIsChecked() {
$this->assertXPath("//form//input[@type='checkbox'][@name='subscriptions[]'][@value=12][@checked]");
}
public function testVisitesInCheckbox() {
$this->assertXPathContentContains("//form//input[@type='checkbox'][@name='subscriptions[]'][@value=14]/..",
'Visites');
}
public function testVisitesIsNotChecked() {
$this->assertNotXPath("//form//input[@type='checkbox'][@name='subscriptions[]'][@value=14][@checked]");
}
public function testEmailField() {
$this->assertXPath("//form//input[@id='mail'][@value='marcus@gmail.com']");
}
public function testNomField() {
$this->assertXPath("//form//input[@id='nom'][@value='Miller']");
}
public function testPrenomField() {
$this->assertXPath("//form//input[@id='prenom'][@value='Marcus']");
}
public function testPseudoField() {
$this->assertXPath("//form//input[@id='pseudo'][@value='mimi']");
}
public function testSubmitButton() {
$this->assertXPath("//table//div[contains(@onclick, 'form.submit()')]");
}
public function testBackButton() {
$this->assertXPath("//table//div[contains(@onclick, 'window.location.replace')]");
}

efalcy
committed
/** @test */
public function hiddenNewsletterShouldNotBedisplayed() {
$this->assertNotXPathContentContains("//form//input[@type='checkbox'][@name='subscriptions[]']/..",
'hidden newsletter',$this->_response->getBody());
}
class AbonneControllerNewslettersSaveActionTest extends AbonneControllerWithTwoNewslettersTestCase {

efalcy
committed
$data = ['nom' => 'MILLER',
'prenom' => 'MARCUS',
'mail' => 'marcus@free.fr',
'pseudo' => 'M2',
'subscriptions' => [14],
'password' => 'amstramgram',
'confirm_password' => 'amstramgram'];
$this->getRequest()
->setMethod('POST')
->setPost($data);
$this->dispatch('/opac/abonne/edit', true);
}
/** @test */
public function marcusShouldHaveBeenSaved() {

efalcy
committed
$this->assertEquals($this->marcus, Class_Users::findFirstBy(['pseudo' => 'M2']));
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
}
public function testNomSetToMILLER() {
$this->assertEquals('MILLER', $this->marcus->getNom());
}
public function testPrenomSetToMARCUS() {
$this->assertEquals('MARCUS', $this->marcus->getPrenom());
}
public function testMailSetToMarcusAtFreeDotFr() {
$this->assertEquals('marcus@free.fr', $this->marcus->getMail());
}
public function testPseudoSetToM2() {
$this->assertEquals('M2', $this->marcus->getPseudo());
}
public function testPasswordSetToAmstramgram() {
$this->assertEquals('amstramgram', $this->marcus->getPassword());
}
public function testNewslettersContainsVisites() {
$this->assertEquals(array($this->visites), $this->marcus->getNewsletters());
}
public function testRedirectedToFiche() {
$this->assertRedirectTo('/abonne/fiche', $this->_response->getBody());
}
class AbonneControllerNewslettersSaveWithEmptyDataTest extends AbonneControllerWithTwoNewslettersTestCase {
/** @test */
public function marcusShouldHaveBeenSaved() {

efalcy
committed
$this->assertEquals($this->marcus, Class_Users::findFirstBy(['idabon' => '00123']));
public function testNoNewsletters() {
$this->assertEquals(array(), $this->marcus->getNewsletters());
}
public function testPasswordNotChanged() {
$this->assertEquals('mysecret', $this->marcus->getPassword());
}
class AbonneControllerNewslettersOpsysCommunicationTest extends AbonneControllerWithTwoNewslettersTestCase {
$this->opsys_service = $this->getMock('MockOpsysService', array('saveEmprunteur'));
$this->emprunteur = new Class_WebService_SIGB_Emprunteur('00123', 'Marcus');
$this->emprunteur->setService($this->opsys_service);
$this->marcus->setFicheSIGB(array('type_comm' => Class_IntBib::COM_OPSYS,
'fiche' => $this->emprunteur,
'nom_aff' => 'Marcus'));
protected function _postData() {
$this->getRequest()
->setMethod('POST')
->setPost(array('nom' => 'Duchamp',
'prenom' => 'Michel',
'mail' => 'mduchamp@orange.fr',
'password' => 'carambar',
'confirm_password' => 'carambar'));
$this->dispatch('/opac/abonne/edit');
}
public function testWithNoSIGBErrorRedirectToFiche() {
$this->opsys_service
->expects($this->once())
->method('saveEmprunteur')
->with($this->emprunteur)
->will($this->returnValue($this->opsys_service));
public function testWithSIGBErrorDisplayErrorMessage() {
$this->opsys_service
->expects($this->once())
->method('saveEmprunteur')
->with($this->emprunteur)
->will($this->throwException(new Exception('(1023) Le SIGB ne réponds pas')));
$this->assertQueryContentContains("ul.errors li",
'(1023) Le SIGB ne réponds pas');
}
class AbonneControllerNewslettersSubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase {
public function setUp() {
parent::setUp();
$_SERVER['HTTP_REFERER'] = '/opac/index';
$this->dispatch('/opac/abonne/subscribe-newsletter/id/14',true);
/** @test **/
public function subscribeActionShouldCallSubscribenewsletterAction() {
$this->assertAction('subscribe-newsletter');
}
/** @test **/
public function subscribeActionShouldRedirectToCurrentPage() {
$this->assertRedirectTo('/opac/index');
}
/** @test **/
public function subscribeActionShouldAddNewsletterToUser() {
$this->assertContains( $this->visites,$this->marcus->getNewsletters());
}
}
class AbonneControllerNewslettersUnsubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase {
public function setUp() {
parent::setUp();
$_SERVER['REQUEST_URI'] = '/';
$this->dispatch('/opac/abonne/unsubscribe-newsletter/id/14',true);
/** @test **/
public function unsubscribeActionShouldCallSubscribenewsletterAction() {
$this->assertAction('unsubscribe-newsletter');
}
/** @test **/
public function unsubscribeActionShouldAddNewsletterToUser() {
$this->assertNotContains( $this->visites,$this->marcus->getNewsletters());
}
class AbonneControllerNewslettersValidationsTest extends AbonneControllerWithTwoNewslettersTestCase {
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
protected function _postData($data) {
$this->getRequest()
->setMethod('POST')
->setPost($data);
$this->dispatch('/opac/abonne/edit', true);
$this->assertAction('edit');
}
public function testWrongMail() {
$this->_postData(array('mail' => 'marc'));
$this->assertQueryContentContains("form ul.errors li",
"'marc' n'est pas un email valide");
}
public function testOnlyPasswordFilled() {
$this->_postData(array('password' => 'picetpic'));
$this->assertQueryContentContains('form ul.errors li',
'Vous devez confirmer le mot de passe');
}
public function testOnlyConfirmPasswordFilled() {
$this->_postData(array('confirm_password' => 'ratatam'));
$this->assertQueryContentContains('form ul.errors li',
'Vous devez saisir un mot de passe');
}
public function testPasswordAndConfirmationDoesNotMatch() {
$this->_postData(array('password' => 'picetpic',
'confirm_password' => 'ratatam'));
$this->assertQueryContentContains('form ul.errors li',
'Les mots de passe ne correspondent pas');
}
public function testPasswordTooShort() {
$this->_postData(array('password' => 'pic',
'confirm_password' => 'pic'));
$this->assertQueryContentContains('form ul.errors li',
"'***' contient moins de 4 caractères");
}
public function testPasswordTooLong() {
$this->_postData(array('password' => '26 caracteres *************',
'confirm_password' => '26 caracteres **************'));
$this->assertQueryContentContains('form ul.errors li',
"'***************************' contient plus de 24 caractères");
}
/** @test */
public function withEmptyPasswordMarcusShouldBeSaved() {
$this->_postData(array('password' => ''));

efalcy
committed
$this->assertEquals($this->marcus->getPassword(), Class_Users::findFirstBy(['idabon' => '00123'])->getPassword());
class AbonneControllerNewslettersSubscriptionTwiceTest extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
$_SERVER['HTTP_REFERER'] = '/opac/index';
$newsletter = $this->fixture('Class_Newsletter',
['id' => 5,
'titre' => 'Daily News']);
$user = $this->fixture('Class_Users',
['id' => 156,
'login' => 'tomato',
'password' => 'pwd']);
$this->fixture('Class_NewsletterSubscription',
['id' => 1,
'user' => $user,
'newsletter' => $newsletter]);
$this->dispatch('/opac/abonne/subscribe-newsletter/id/5',true);
}
/** @test **/
public function dailyNewsSubscribersShouldContainsTomatoOnlyOne() {
$this->assertEquals(1 , Class_NewsletterSubscription::countBy(['user_id' => 156]));
}

efalcy
committed