wiki.techinc.nl/tests/phpunit/includes/auth/AuthenticationRequestTestCase.php
Brad Jorsch d245bd25ae Add AuthManager
This implements the AuthManager class and its needed interfaces and
subclasses, and integrates them into the backend portion of MediaWiki.
Integration with frontend portions of MediaWiki (e.g. ApiLogin,
Special:Login) is left for a followup.

Bug: T91699
Bug: T71589
Bug: T111299
Co-Authored-By: Gergő Tisza <gtisza@wikimedia.org>
Change-Id: If89d24838e326fe25fe867d02181eebcfbb0e196
2016-05-16 15:11:02 +00:00

96 lines
2.6 KiB
PHP

<?php
namespace MediaWiki\Auth;
/**
* @group AuthManager
*/
abstract class AuthenticationRequestTestCase extends \MediaWikiTestCase {
protected function setUp() {
global $wgDisableAuthManager;
parent::setUp();
if ( $wgDisableAuthManager ) {
$this->markTestSkipped( '$wgDisableAuthManager is set' );
}
}
abstract protected function getInstance( array $args = [] );
/**
* @dataProvider provideGetFieldInfo
*/
public function testGetFieldInfo( array $args ) {
$info = $this->getInstance( $args )->getFieldInfo();
$this->assertType( 'array', $info );
foreach ( $info as $field => $data ) {
$this->assertType( 'array', $data, "Field $field" );
$this->assertArrayHasKey( 'type', $data, "Field $field" );
$this->assertArrayHasKey( 'label', $data, "Field $field" );
$this->assertInstanceOf( 'Message', $data['label'], "Field $field, label" );
if ( $data['type'] !== 'null' ) {
$this->assertArrayHasKey( 'help', $data, "Field $field" );
$this->assertInstanceOf( 'Message', $data['help'], "Field $field, help" );
}
if ( isset( $data['optional'] ) ) {
$this->assertType( 'bool', $data['optional'], "Field $field, optional" );
}
if ( isset( $data['image'] ) ) {
$this->assertType( 'string', $data['image'], "Field $field, image" );
}
switch ( $data['type'] ) {
case 'string':
case 'password':
case 'hidden':
break;
case 'select':
case 'multiselect':
$this->assertArrayHasKey( 'options', $data, "Field $field" );
$this->assertType( 'array', $data['options'], "Field $field, options" );
foreach ( $data['options'] as $val => $msg ) {
$this->assertInstanceOf( 'Message', $msg, "Field $field, option $val" );
}
break;
case 'checkbox':
break;
case 'button':
break;
case 'null':
break;
default:
$this->fail( "Field $field, unknown type " . $data['type'] );
break;
}
}
}
public static function provideGetFieldInfo() {
return [
[ [] ]
];
}
/**
* @dataProvider provideLoadFromSubmission
* @param array $args
* @param array $data
* @param array|bool $expectState
*/
public function testLoadFromSubmission( array $args, array $data, $expectState ) {
$instance = $this->getInstance( $args );
$ret = $instance->loadFromSubmission( $data );
if ( is_array( $expectState ) ) {
$this->assertTrue( $ret );
$expect = call_user_func( [ get_class( $instance ), '__set_state' ], $expectState );
$this->assertEquals( $expect, $instance );
} else {
$this->assertFalse( $ret );
}
}
abstract public function provideLoadFromSubmission();
}