<?php /** * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. * * BOKEH 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). * * BOKEH 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 BOKEH; 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 AbonneControllerEditActionWithAbonneSIGBTestCase extends AbstractControllerTestCase { protected $_jerome; public function setUp() { parent::setUp(); $mock_emprunteur = Storm_Test_ObjectWrapper::mock(); $mock_emprunteur->whenCalled('updateFromUserAndSave')->answers(true); $this->_jerome = Class_Users::newInstanceWithId(4, ['login' => 'jm', 'prenom' => 'Jerome', 'is_contact_sms' => true, 'idabon' => '12345', 'id_site' => 1, 'password' => 'secret', 'fiche_sigb' => ['fiche' => $mock_emprunteur]])->beAbonneSIGB(); ZendAfi_Auth::getInstance()->logUser($this->_jerome); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') ->whenCalled('save') ->answers(true); } } class AbonneControllerEditWithContactMailSmsPostTest extends AbonneControllerEditActionWithAbonneSIGBTestCase { public function setUp() { parent::setUp(); Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', ['valeur' => 'prenom;mode_contact;telephone;mail']); $this->postDispatch('/abonne/edit', ['telephone' => '12 34 56 78 90', 'mail' => 'mm@gmail.com', 'mode_contact' => 'is_contact_mail', 'prenom' => 'Marcel', 'nom' => 'Mazout']); } /** @test */ public function telephoneShouldBe1234567890() { $this->assertEquals('12 34 56 78 90', $this->_jerome->getTelephone()); } /** @test */ public function nomShouldStayEmpty() { $this->assertEquals('', $this->_jerome->getNom()); } /** @test */ public function isContactByMailShouldBeTrue() { $this->assertTrue($this->_jerome->getIsContactMail()); } /** @test */ public function userShouldBeSaved() { $this->assertTrue(Class_Users::methodHasBeenCalled('save'), implode(',', $this->_jerome->getErrors())); } /** @test */ public function responseShouldRedirectToFiche() { $this->assertRedirectTo('/abonne/fiche'); } } class AbonneControllerEditWithContactMailPostErrorsTest extends AbonneControllerEditActionWithAbonneSIGBTestCase { /** @test */ public function pageShouldDisplayErrorNoMailProvided() { Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', ['valeur' => 'prenom;mode_contact;telephone;mail']); $this->postDispatch('/abonne/edit', ['telephone' => '12 34 56 78 98', 'mail' => '', 'mode_contact' => 'is_contact_mail', 'prenom' => 'Marcel', 'nom' => 'Mazout']); $this->assertXPathContentContains('//ul[@class="errors"]//li', 'Vous devez fournir une adresse mail valide'); } /** @test */ public function pageShouldDisplayErrorInvalidPhone() { Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', ['valeur' => 'prenom;mode_contact;telephone;mail']); $this->postDispatch('/abonne/edit', ['telephone' => '12 34 56', 'mail' => '', 'mode_contact' => 'is_contact_mail', 'prenom' => 'Marcel', 'nom' => 'Mazout']); $this->assertXPathContentContains('//ul[@class="errors"]//li', "'12 34 56' n'est pas un numéro de téléphone"); } /** @test */ public function pageShouldDisplayErrorNoTelephoneProvided() { Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', ['valeur' => 'prenom;mode_contact;telephone']); $this->postDispatch('/abonne/edit', ['telephone' => '', 'mode_contact' => 'is_contact_sms', 'prenom' => 'Marcel', 'nom' => 'Mazout']); $this->assertXPathContentContains('//ul[@class="errors"]//li', 'Vous devez saisir un numéro de téléphone'); } /** @test */ public function pageShouldDisplayErrorMailInvalidProvided() { Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', ['valeur' => 'prenom;mode_contact;telephone;mail']); $this->postDispatch('/abonne/edit', ['telephone' => '12 34 56', 'mail' => 'glouglou', 'mode_contact' => 'is_contact_mail', 'prenom' => 'Marcel', 'nom' => 'Mazout']); $this->assertXPathContentContains('//ul[@class="errors"]//li', "'glouglou' n'est pas un email valide", $this->_response->getBody()); } } class AbonneControllerEditWithContactMailSmsTest extends AbonneControllerEditActionWithAbonneSIGBTestCase { public function setUp() { parent::setUp(); Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', ['valeur' => 'prenom;mode_contact;telephone']); $this->dispatch('/abonne/edit', true); } /** @test */ public function inputNomShouldNotBePresent() { $this->assertNotXPath('//input[@name="nom"]'); } /** @test */ public function inputPrenomShouldHaveValueJerome() { $this->assertXPath('//input[@name="prenom"][@value="Jerome"]'); } /** @test */ public function radioButtonIsContactSmsShouldBeChecked() { $this->assertXPath('//input[@type="radio"][@name="mode_contact"][@value="is_contact_sms"][@checked="checked"]'); } /** @test */ public function radioButtonIsContactMailShouldNotBeChecked() { $this->assertXPath('//input[@type="radio"][@name="mode_contact"][@value="is_contact_mail"][not(@checked)]'); } /** @test */ public function radioButtonIsContactLetterShouldNotBeChecked() { $this->assertXPath('//input[@type="radio"][@name="mode_contact"][@value="is_contact_letter"][not(@checked)]'); } /** @test */ public function passwordInputShouldNotBePresent() { $this->assertNotXPath('//input[@name="password"]'); } /** @test */ public function confirmPasswordInputShouldNotBePresent() { $this->assertNotXPath('//input[@name="confirm_password"]'); } } class AbonneControllerEditWithContactPasswordMailTest extends AbonneControllerEditActionWithAbonneSIGBTestCase { public function setUp() { parent::setUp(); Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', ['valeur' => 'nom;mail;password']); $this->dispatch('/abonne/edit', true); } /** @test */ public function checkboxIsContactSmsShouldNotBePresent() { $this->assertNotXPath('//input[@type="radio"][@name="mode_contact"]'); } /** @test */ public function passwordInputShouldBePresent() { $this->assertXPath('//input[@name="password"]'); } /** @test */ public function confirmPasswordShouldBeInFieldSetIdentification() { $this->assertXPath('//fieldset[@id="fieldset-identification"]//input[@name="confirm_password"]'); } } ?>