MediaWiki REL1_32
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.
getForm( $params=[], WebRequest $request=null)
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition HTMLForm.php:136
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2880
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2885
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition hooks.txt:2062
$params