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 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 {
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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 {
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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
/** @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 {
Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR',
['valeur' => 'prenom;mode_contact;telephone']);
/** @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 {
Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR',
['valeur' => 'nom;mail;password']);
/** @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"]');
}