Newer
Older
<?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();
$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']);
$this->postDispatch('/abonne/edit',
['telephone' => '12 34 56',
'mail' => 'mm@gmail.com',
'mode_contact' => 'is_contact_mail',
'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;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"]');
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)]');
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
}
/** @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"]');
}
}
?>