]>
git.agnieray.net Git - galette.git/blob - tests/Galette/Core/tests/units/PasswordImage.php
2baacff4389d2cc51ee89016c93574cd66d8c0c6
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2013-2014 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-2014 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 * PasswordImage tests class
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2013-2014 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 PasswordImage
extends atoum
61 * @param string $testMethod Method name
65 public function beforeTestMethod($testMethod)
67 $this->pass
= new \Galette\Core\
PasswordImage(false);
71 * Test new PasswordImage generation
75 public function testGenerateNewPassword()
78 $res = $pass->generateNewPassword();
79 $this->boolean($res)->isTrue();
80 $new_pass = $pass->getNewPassword();
81 $this->string($new_pass)
82 ->hasLength($pass::DEFAULT_SIZE
);
83 $hash = $pass->getHash();
84 $this->string($hash)->hasLength(60);
86 $this->string($pass->getImageName())
87 ->isIdenticalTo('pw_' . md5($hash) . '.png');
91 * Test new PasswordImage image generation
95 public function testNewImage()
97 $pass = new \mock\Galette\Core\
PasswordImage(false);
98 $password = 'azerty12';
99 $this->calling($pass)->makeRandomPassword
= $password;
103 $pw_checked = password_verify('azerty12', $pass->getHash());
104 $this->boolean($pw_checked)->isTrue();
106 $this->string($pass->getImageName())
107 ->isIdenticalTo('pw_' . md5($pass->getHash()) . '.png');
110 GALETTE_TEMPIMAGES_PATH
. '/' . $pass->getImageName()
112 $this->boolean($exists)->isTrue();
120 public function testGetImage()
122 $this->assert('Image generated without exif')
123 ->given($pass = new \Galette\Core\
PasswordImage(false))
124 ->if($this->function->function_exists
= false)
126 ->string($pass->newImage())
128 ->string($pass->getImage())
129 ->hasLengthGreaterThan(200)
130 ->startWith('data:image/png;base64,');
132 if (function_exists('exif_imagetype')) {
133 $this->assert('Image generated without exif')
134 ->given($pass = new \Galette\Core\
PasswordImage(false))
135 ->if($this->function->function_exists
= true)
137 ->string($pass->newImage())
139 ->string($pass->getImage())
140 ->hasLengthGreaterThan(200)
141 ->startWith('data:image/png;base64,');
150 public function testCleanExpired()
152 $files = scandir(GALETTE_TEMPIMAGES_PATH
);
154 if (count($files) == 2) {
162 foreach ($files as $f) {
163 if ($f != '.' && $f != '..') {
164 touch(GALETTE_TEMPIMAGES_PATH
. '/' . $f, time() - 3600);
168 $dirfiles = scandir(GALETTE_TEMPIMAGES_PATH
);
169 $this->integer(count($dirfiles))->isGreaterThan(2);
171 //default constructor call clean
172 $pass = new \Galette\Core\
PasswordImage();
173 $dirfiles = scandir(GALETTE_TEMPIMAGES_PATH
);
174 $this->integer(count($dirfiles))->isEqualTo(2);