<?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 AbonneControllerEditActionWithAbonneSIGBTestCase extends AbstractControllerTestCase { protected $_jerome; public function setUp() { parent::setUp(); $this->_jerome = Class_Users::newInstanceWithId(4, ['login' => 'jm', 'prenom' => 'Jerome', 'is_contact_sms' => true, 'idabon' => '12345', 'id_site' => 1, 'password' => 'secret'])->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;is_contact_mail;is_contact_sms;telephone']); $this->postDispatch('/abonne/edit', ['telephone' => '12 34 56', 'is_contact_mail' => true, 'prenom' => 'Marcel', 'nom' => 'Mazout']); } /** @test */ public function telephoneShouldBe123456() { $this->assertEquals('12 34 56', $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 AbonneControllerEditWithContactMailSmsTest extends AbonneControllerEditActionWithAbonneSIGBTestCase { public function setUp() { parent::setUp(); Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', ['valeur' => 'prenom;is_contact_mail;is_contact_sms;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 checkboxIsContactSmsShouldBeChecked() { $this->assertXPath('//input[@type="checkbox"][@name="is_contact_sms"][@checked="checked"]'); } /** @test */ public function checkboxIsContactMailShouldNotBeChecked() { $this->assertXPath('//input[@type="checkbox"][@name="is_contact_mail"][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="checkbox"][@name="is_contact_sms"]'); } /** @test */ public function passwordInputShouldBePresent() { $this->assertXPath('//input[@name="password"]'); } /** @test */ public function confirmPasswordShouldBeInFieldSetIdentification() { $this->assertXPath('//fieldset[@id="fieldset-identification"]//input[@name="confirm_password"]'); } } ?>