summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/auth/ButtonAuthenticationRequestTest.php
blob: 3bc077cb764a6d970a8ec8ffab16d7b0cf427c2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

namespace MediaWiki\Auth;

/**
 * @group AuthManager
 * @covers MediaWiki\Auth\ButtonAuthenticationRequest
 */
class ButtonAuthenticationRequestTest extends AuthenticationRequestTestCase {

	protected function getInstance( array $args = [] ) {
		$data = array_intersect_key( $args, [ 'name' => 1, 'label' => 1, 'help' => 1 ] );
		return ButtonAuthenticationRequest::__set_state( $data );
	}

	public static function provideGetFieldInfo() {
		return [
			[ [ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz' ] ]
		];
	}

	public function provideLoadFromSubmission() {
		return [
			'Empty request' => [
				[ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz' ],
				[],
				false
			],
			'Button present' => [
				[ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz' ],
				[ 'foo' => 'Foobar' ],
				[ 'name' => 'foo', 'label' => 'bar', 'help' => 'baz', 'foo' => true ]
			],
		];
	}

	public function testGetUniqueId() {
		$req = new ButtonAuthenticationRequest( 'foo', wfMessage( 'bar' ), wfMessage( 'baz' ) );
		$this->assertSame(
			'MediaWiki\\Auth\\ButtonAuthenticationRequest:foo', $req->getUniqueId()
		);
	}

	public function testGetRequestByName() {
		$reqs = [];
		$reqs['testOne'] = new ButtonAuthenticationRequest(
			'foo', wfMessage( 'msg' ), wfMessage( 'help' )
		);
		$reqs[] = new ButtonAuthenticationRequest( 'bar', wfMessage( 'msg1' ), wfMessage( 'help1' ) );
		$reqs[] = new ButtonAuthenticationRequest( 'bar', wfMessage( 'msg2' ), wfMessage( 'help2' ) );
		$reqs['testSub'] = $this->getMockBuilder( ButtonAuthenticationRequest::class )
			->setConstructorArgs( [ 'subclass', wfMessage( 'msg3' ), wfMessage( 'help3' ) ] )
			->getMock();

		$this->assertNull( ButtonAuthenticationRequest::getRequestByName( $reqs, 'missing' ) );
		$this->assertSame(
			$reqs['testOne'], ButtonAuthenticationRequest::getRequestByName( $reqs, 'foo' )
		);
		$this->assertNull( ButtonAuthenticationRequest::getRequestByName( $reqs, 'bar' ) );
		$this->assertSame(
			$reqs['testSub'], ButtonAuthenticationRequest::getRequestByName( $reqs, 'subclass' )
		);
	}
}