public function testMergeFieldInfo() { $msg = wfMessage('foo'); $req1 = $this->getMock(AuthenticationRequest::class); $req1->required = AuthenticationRequest::REQUIRED; $req1->expects($this->any())->method('getFieldInfo')->will($this->returnValue(['string1' => ['type' => 'string', 'label' => $msg, 'help' => $msg], 'string2' => ['type' => 'string', 'label' => $msg, 'help' => $msg], 'optional' => ['type' => 'string', 'label' => $msg, 'help' => $msg, 'optional' => true], 'select' => ['type' => 'select', 'options' => ['foo' => $msg, 'baz' => $msg], 'label' => $msg, 'help' => $msg]])); $req2 = $this->getMock(AuthenticationRequest::class); $req2->required = AuthenticationRequest::REQUIRED; $req2->expects($this->any())->method('getFieldInfo')->will($this->returnValue(['string1' => ['type' => 'string', 'label' => $msg, 'help' => $msg], 'string3' => ['type' => 'string', 'label' => $msg, 'help' => $msg], 'select' => ['type' => 'select', 'options' => ['bar' => $msg, 'baz' => $msg], 'label' => $msg, 'help' => $msg]])); $req3 = $this->getMock(AuthenticationRequest::class); $req3->required = AuthenticationRequest::REQUIRED; $req3->expects($this->any())->method('getFieldInfo')->will($this->returnValue(['string1' => ['type' => 'checkbox', 'label' => $msg, 'help' => $msg]])); $req4 = $this->getMock(AuthenticationRequest::class); $req4->required = AuthenticationRequest::REQUIRED; $req4->expects($this->any())->method('getFieldInfo')->will($this->returnValue([])); // Basic combining $fields = AuthenticationRequest::mergeFieldInfo([$req1]); $expect = $req1->getFieldInfo(); foreach ($expect as $name => &$options) { $options['optional'] = !empty($options['optional']); } unset($options); $this->assertEquals($expect, $fields); $fields = AuthenticationRequest::mergeFieldInfo([$req1, $req4]); $this->assertEquals($expect, $fields); try { AuthenticationRequest::mergeFieldInfo([$req1, $req3]); $this->fail('Expected exception not thrown'); } catch (\UnexpectedValueException $ex) { $this->assertSame('Field type conflict for "string1", "string" vs "checkbox"', $ex->getMessage()); } $fields = AuthenticationRequest::mergeFieldInfo([$req1, $req2]); $expect += $req2->getFieldInfo(); $expect['string2']['optional'] = false; $expect['string3']['optional'] = false; $expect['select']['options']['bar'] = $msg; $this->assertEquals($expect, $fields); // Combining with something not required $req1->required = AuthenticationRequest::PRIMARY_REQUIRED; $fields = AuthenticationRequest::mergeFieldInfo([$req1]); $expect = $req1->getFieldInfo(); foreach ($expect as $name => &$options) { $options['optional'] = true; } unset($options); $this->assertEquals($expect, $fields); $fields = AuthenticationRequest::mergeFieldInfo([$req1, $req2]); $expect += $req2->getFieldInfo(); $expect['string1']['optional'] = false; $expect['string3']['optional'] = false; $expect['select']['optional'] = false; $expect['select']['options']['bar'] = $msg; $this->assertEquals($expect, $fields); }