13 $this->assertSame( get_class( $mock ), $mock->getUniqueId() );
15 $this->
assertType(
'array', $mock->getMetadata() );
17 $ret = $mock->describeCredentials();
18 $this->assertInternalType(
'array',
$ret );
19 $this->assertArrayHasKey(
'provider',
$ret );
21 $this->assertArrayHasKey(
'account',
$ret );
27 ->setMethods( [
'loadFromSubmission' ] );
29 $data = [
'foo',
'bar' ];
31 $req1 = $mb->getMockForAbstractClass();
32 $req1->expects( $this->once() )->method(
'loadFromSubmission' )
33 ->with( $this->identicalTo( $data ) )
34 ->will( $this->returnValue(
false ) );
36 $req2 = $mb->getMockForAbstractClass();
37 $req2->expects( $this->once() )->method(
'loadFromSubmission' )
38 ->with( $this->identicalTo( $data ) )
39 ->will( $this->returnValue(
true ) );
48 $mb = $this->getMockBuilder(
53 $this->getMockForAbstractClass(
56 $mb->getMockForAbstractClass(),
57 $mb->getMockForAbstractClass(),
58 $this->getMockForAbstractClass(
60 'AuthenticationRequestTest_PasswordAuthenticationRequest'
65 $reqs,
'AuthenticationRequestTest_AuthenticationRequest0'
68 $reqs,
'AuthenticationRequestTest_AuthenticationRequest1'
71 $reqs,
'AuthenticationRequestTest_AuthenticationRequest2'
77 $reqs,
'ClassThatDoesNotExist'
81 $reqs,
'AuthenticationRequestTest_AuthenticationRequest0',
true
84 $reqs,
'AuthenticationRequestTest_AuthenticationRequest1',
true
87 $reqs,
'AuthenticationRequestTest_AuthenticationRequest2',
true
93 $reqs,
'ClassThatDoesNotExist',
true
100 for ( $i = 0; $i < 3; $i++ ) {
101 $req = $mb->getMockForAbstractClass();
102 $req->expects( $this->
any() )->method(
'getFieldInfo' )->will( $this->returnValue( [
110 $req = $mb->getMockForAbstractClass();
111 $req->expects( $this->
any() )->method(
'getFieldInfo' )->will( $this->returnValue( [] ) );
112 $req->username =
'baz';
117 $reqs[1]->username =
'foo';
120 $reqs[0]->username =
'foo';
121 $reqs[2]->username =
'foo';
124 $reqs[1]->username =
'bar';
127 $this->fail(
'Expected exception not thrown' );
128 }
catch ( \UnexpectedValueException $ex ) {
130 'Conflicting username fields: "bar" from ' .
131 get_class( $reqs[1] ) .
'::$username vs. "foo" from ' .
132 get_class( $reqs[0] ) .
'::$username',
143 $req1->expects( $this->
any() )->method(
'getFieldInfo' )->will( $this->returnValue( [
162 'options' => [
'foo' => $msg,
'baz' => $msg ],
170 $req2->expects( $this->
any() )->method(
'getFieldInfo' )->will( $this->returnValue( [
184 'options' => [
'bar' => $msg,
'baz' => $msg ],
192 $req3->expects( $this->
any() )->method(
'getFieldInfo' )->will( $this->returnValue( [
194 'type' =>
'checkbox',
202 $req4->expects( $this->
any() )->method(
'getFieldInfo' )->will( $this->returnValue( [] ) );
207 $expect = $req1->getFieldInfo();
213 $this->assertEquals( $expect, $fields );
216 $this->assertEquals( $expect, $fields );
220 $this->fail(
'Expected exception not thrown' );
221 }
catch ( \UnexpectedValueException $ex ) {
223 'Field type conflict for "string1", "string" vs "checkbox"',
229 $expect += $req2->getFieldInfo();
230 $expect[
'string1'][
'sensitive'] =
true;
231 $expect[
'string2'][
'optional'] =
false;
232 $expect[
'string3'][
'optional'] =
false;
233 $expect[
'string3'][
'sensitive'] =
false;
234 $expect[
'select'][
'options'][
'bar'] = $msg;
235 $this->assertEquals( $expect, $fields );
242 $expect += $req2->getFieldInfo();
243 $expect[
'string1'][
'optional'] =
false;
244 $expect[
'string1'][
'sensitive'] =
true;
245 $expect[
'string3'][
'optional'] =
false;
246 $expect[
'select'][
'optional'] =
false;
247 $expect[
'select'][
'options'][
'bar'] = $msg;
248 $this->assertEquals( $expect, $fields );
253 $expect = $req1->getFieldInfo() + $req2->getFieldInfo();
257 $expect[
'string1'][
'optional'] =
false;
258 $expect[
'string1'][
'sensitive'] =
true;
259 $expect[
'string2'][
'optional'] =
true;
260 $expect[
'string3'][
'optional'] =
true;
261 $expect[
'select'][
'optional'] =
false;
262 $expect[
'select'][
'options'][
'bar'] = $msg;
263 $this->assertEquals( $expect, $fields );
274 $mock->expects( $this->
any() )->method(
'getFieldInfo' )
275 ->will( $this->returnValue( $fieldInfo ) );
277 $ret = $mock->loadFromSubmission( $data );
278 if ( is_array( $expectState ) ) {
279 $this->assertTrue(
$ret );
280 $expect = call_user_func( [ get_class( $mock ),
'__set_state' ], $expectState );
281 $this->assertEquals( $expect, $mock );
283 $this->assertFalse(
$ret );
291 $data = [
'foo' =>
'bar' ],
301 $data = [
'field' =>
'string!' ],
304 'Simple field, not supplied' => [
313 'Simple field, empty' => [
322 'Simple field, optional, not supplied' => [
332 'Simple field, optional, empty' => [
339 $data = [
'field' =>
'' ],
343 'Checkbox, checked' => [
346 'type' =>
'checkbox',
352 'Checkbox, unchecked' => [
355 'type' =>
'checkbox',
361 'Checkbox, optional, unchecked' => [
364 'type' =>
'checkbox',
381 'Button, unused' => [
390 'Button, optional, unused' => [
400 'Button, image-style' => [
406 [
'push_x' => 0,
'push_y' => 0 ],
420 $data = [
'choose' =>
'foo' ],
423 'Select, invalid choice' => [
433 $data = [
'choose' =>
'baz' ],
436 'Multiselect (2)' => [
439 'type' =>
'multiselect',
446 $data = [
'choose' => [
'foo',
'bar' ] ],
449 'Multiselect (1)' => [
452 'type' =>
'multiselect',
459 $data = [
'choose' => [
'bar' ] ],
462 'Multiselect, string for some reason' => [
465 'type' =>
'multiselect',
472 [
'choose' =>
'foo' ],
473 [
'choose' => [
'foo' ] ]
475 'Multiselect, invalid choice' => [
478 'type' =>
'multiselect',
485 [
'choose' => [
'foo',
'baz' ] ],
488 'Multiselect, empty' => [
491 'type' =>
'multiselect',
501 'Multiselect, optional, nothing submitted' => [
504 'type' =>
'multiselect',