3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2013 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
28 * @package GaletteTests
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2013 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
34 * @link http://galette.tuxfamily.org
38 namespace Galette\Core\test\units
;
43 * Preferences tests class
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2013 The Galette Team
50 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
51 * @link http://galette.tuxfamily.org
54 class Preferences
extends atoum
56 private $_preferences = null;
62 * @param string $testMethod Calling method
66 public function beforeTestMethod($testMethod)
68 $this->_zdb
= new \Galette\Core\
Db();
69 $this->_preferences
= new \Galette\Core\
Preferences(
75 * Test preferences initialization
79 public function testInstallInit()
81 $result = $this->_preferences
->installInit(
84 password_hash('da_secret', PASSWORD_BCRYPT
)
86 $this->boolean($result)->isTrue();
88 //new object with values loaded from database to compare
89 $prefs = new \Galette\Core\
Preferences($this->_zdb
);
91 foreach ( $prefs->getDefaults() as $key=>$expected ) {
92 $value = $prefs->$key;
95 case 'pref_admin_login':
96 $this->variable($value)->isIdenticalTo('da_admin');
98 case 'pref_admin_pass':
99 $pw_checked = password_verify('da_secret', $value);
100 $this->boolean($pw_checked)->isTrue();
103 $this->variable($value)->isIdenticalTo('en_US');
105 case 'pref_card_year':
106 $this->variable($value)->isIdenticalTo(date('Y'));
109 $this->variable($value)->isEqualTo($expected);
114 //tru to set and get a non existent value
115 $prefs->doesnotexists
= 'that *does* not exists.';
116 $false_result = $prefs->doesnotexists
;
117 $this->boolean($false_result)->isFalse();
120 $slogan = 'One Galette to rule them all';
121 $prefs->pref_slogan
= $slogan;
122 $check = $prefs->pref_slogan
;
123 $this->string($check)->isIdenticalTo($slogan);
126 $new_pass = 'anoth3er_s3cr3t';
127 $prefs->pref_admin_pass
= $new_pass;
128 $pass = $prefs->pref_admin_pass
;
129 $pw_checked = password_verify($new_pass, $pass);
130 $this->boolean($pw_checked)->isTrue();
132 $this->_preferences
->pref_nom
= 'Galette';
133 $this->_preferences
->pref_ville
= 'Avignon';
134 $this->_preferences
->pref_cp
= '84000';
135 $this->_preferences
->pref_adresse
= 'Palais des Papes';
136 $this->_preferences
->pref_adresse2
= 'Au milieu';
137 $this->_preferences
->pref_pays
= 'France';
139 $expected = "Galette\n\nPalais des Papes\nAu milieu\n84000 Avignon - France";
140 $address = $this->_preferences
->getPostalAdress();
142 $this->variable($address)->isIdenticalTo($expected);
150 public function testPrefsStorage()
152 $slogan = $this->_preferences
->pref_slogan
;
153 $this->variable($slogan)->isEqualTo('');
155 $slogan = 'One Galette to rule them all';
156 $this->_preferences
->pref_slogan
= $slogan;
157 $result = $this->_preferences
->store();
159 $this->boolean($result)->isTrue();
161 $prefs = new \Galette\Core\
Preferences($this->_zdb
);
162 $check_slogan = $prefs->pref_slogan
;
163 $this->variable($check_slogan)->isEqualTo($slogan);
171 public function testFieldsNames()
173 $this->_preferences
->load();
174 $fields_names = $this->_preferences
->getFieldsNames();
175 $expected = array_keys($this->_preferences
->getDefaults());
180 $this->array($fields_names)->isIdenticalTo($expected);
184 * Test preferences updating when some are missing
188 public function testUpdate()
195 $del = $this->_zdb
->db
->delete(
196 PREFIX_DB
. \Galette\Core\Preferences
::TABLE
,
197 \Galette\Core\Preferences
::PK
. ' IN ("' . implode('", "', $remove) . '")'
200 $this->_preferences
->load();
201 $fb = $this->_preferences
->pref_facebook
;
202 $viadeo = $this->_preferences
->pref_viadeo
;
204 $this->boolean($fb)->isFalse();
205 $this->boolean($viadeo)->isFalse();
207 $prefs = new \Galette\Core\
Preferences($this->_zdb
);
208 $fb = $prefs->pref_facebook
;
209 $viadeo = $prefs->pref_viadeo
;
211 $this->variable($fb)->isIdenticalTo('');
212 $this->variable($viadeo)->isIdenticalTo('');