MediaWiki REL1_34
HTMLFancyCaptchaFieldTest.php
Go to the documentation of this file.
1<?php
2
6class HTMLFancyCaptchaFieldTest extends PHPUnit\Framework\TestCase {
7 public function testGetHTML() {
8 $html = $this->getForm( [ 'imageUrl' => 'https://example.com/' ] )->getHTML( false );
9 $this->assertRegExp( '/"fancycaptcha-image"/', $html );
10 $this->assertRegExp( '#src="https://example.com/"#', $html );
11 $this->assertNotRegExp( '/"mw-createacct-captcha-assisted"/', $html );
12
13 $html = $this->getForm( [ 'imageUrl' => '', 'showCreateHelp' => true ] )->getHTML( false );
14 $this->assertRegExp( '/"mw-createacct-captcha-assisted"/', $html );
15
16 $html = $this->getForm( [ 'imageUrl' => '', 'label' => 'FooBarBaz' ] )->getHTML( false );
17 $this->assertRegExp( '/FooBarBaz/', $html );
18 }
19
20 public function testValue() {
21 $mockClosure = $this->getMockBuilder( stdClass::class )
22 ->setMethods( [ '__invoke' ] )->getMock();
23 $request = new FauxRequest( [ 'wpcaptchaWord' => 'abc' ], true );
24 $form = $this->getForm( [ 'imageUrl' => 'https://example.com/' ], $request );
25 $form->setSubmitCallback( $mockClosure );
26
27 $mockClosure->expects( $this->once() )->method( '__invoke' )
28 ->with( [ 'captchaWord' => 'abc' ] )->willReturn( true );
29 $form->trySubmit();
30 }
31
32 protected function getForm( $params = [], WebRequest $request = null ) {
33 $params['class'] = HTMLFancyCaptchaField::class;
34 $form = new HTMLForm( [ 'captchaWord' => $params ] );
35 if ( $request ) {
36 $context = new DerivativeContext( RequestContext::getMain() );
37 $context->setRequest( $request );
38 $form->setContext( $context );
39 }
40 $form->setTitle( Title::newFromText( 'Foo' ) );
41 $form->prepareForm();
42 return $form;
43 }
44}
An IContextSource implementation which will inherit context from another source but allow individual ...
WebRequest clone which takes values from a provided array.
@covers HTMLFancyCaptchaField
getForm( $params=[], WebRequest $request=null)
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:131
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
$context
Definition load.php:45