Debian Codegraph @

tests/phpunit/unit/includes/password/PasswordTest.php

raw symbols SCIP
1 <?php
2 /**
3 * Testing framework for the Password infrastructure
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 use MediaWiki\Password\MWOldPassword;
24 use MediaWiki\Password\Password;
25 use MediaWiki\Password\PasswordError;
26 use MediaWiki\Password\PasswordFactory;
27
28 /**
29 * @covers \MediaWiki\Password\Password
30 */
31 class PasswordTest extends MediaWikiUnitTestCase {
32 public function testNoTypeThrows() {
33 $factory = new PasswordFactory();
34 $this->expectException( Exception::class );
35 $this->expectExceptionMessage( 'Password configuration must contain a type name' );
36 $this->getMockBuilder( Password::class )
37 ->setConstructorArgs( [ $factory, [] ] )
38 ->getMock();
39 }
40
41 public function testGetType() {
42 $factory = new PasswordFactory();
43 $password = new MWOldPassword( $factory, [ 'type' => 'this is a test' ] );
44 $this->assertSame( 'this is a test', $password->getType() );
45 }
46
47 public function testToStringThrows() {
48 $factory = new PasswordFactory();
49 $password = new MWOldPassword( $factory, [ 'type' => 'B' ], str_repeat( 'X', 300 ) );
50 $this->expectException( PasswordError::class );
51 $this->expectExceptionMessage( 'Password hash is too big' );
52 $password->toString();
53 }
54
55 public function testToString() {
56 $factory = new PasswordFactory();
57 $password = $this->getMockBuilder( Password::class )
58 ->setConstructorArgs( [ $factory, [ 'type' => 'X' ], ':X:foo' ] )
59 ->getMockForAbstractClass();
60 $this->assertSame( ':X:foo', $password->toString() );
61 }
62 }