Merge "Add Database::unionConditionPermutations()"
[lhc/web/wiklou.git] / tests / phpunit / includes / password / PasswordTestCase.php
index 7820d53..80b9838 100644 (file)
@@ -49,10 +49,13 @@ abstract class PasswordTestCase extends MediaWikiTestCase {
         * An array of tests in the form of (bool, string, string), where the first
         * element is whether the second parameter (a password hash) and the third
         * parameter (a password) should match.
-        *
         * @return array
+        * @throws MWException
+        * @abstract
         */
-       abstract public function providePasswordTests();
+       public static function providePasswordTests() {
+               throw new MWException( "Not implemented" );
+       }
 
        /**
         * @dataProvider providePasswordTests
@@ -75,8 +78,7 @@ abstract class PasswordTestCase extends MediaWikiTestCase {
 
        /**
         * @dataProvider providePasswordTests
-        * @covers InvalidPassword::equals
-        * @covers InvalidPassword::toString
+        * @covers InvalidPassword
         */
        public function testInvalidUnequalNormal( $shouldMatch, $hash, $password ) {
                $invalid = $this->passwordFactory->newFromCiphertext( null );
@@ -85,4 +87,26 @@ abstract class PasswordTestCase extends MediaWikiTestCase {
                $this->assertFalse( $invalid->equals( $normal ) );
                $this->assertFalse( $normal->equals( $invalid ) );
        }
+
+       protected function getValidTypes() {
+               return array_keys( $this->getTypeConfigs() );
+       }
+
+       public function provideTypes( $type ) {
+               $params = [];
+               foreach ( $this->getValidTypes() as $type ) {
+                       $params[] = [ $type ];
+               }
+               return $params;
+       }
+
+       /**
+        * @dataProvider provideTypes
+        */
+       public function testCrypt( $type ) {
+               $fromType = $this->passwordFactory->newFromType( $type );
+               $fromType->crypt( 'password' );
+               $fromPlaintext = $this->passwordFactory->newFromPlaintext( 'password', $fromType );
+               $this->assertTrue( $fromType->equals( $fromPlaintext ) );
+       }
 }