MediaWiki REL1_31
HTMLFancyCaptchaFieldTest.php
Go to the documentation of this file.
1<?php
2
3require_once __DIR__ . '/../../FancyCaptcha/HTMLFancyCaptchaField.php';
4
8class HTMLFancyCaptchaFieldTest extends PHPUnit\Framework\TestCase {
9 public function testGetHTML() {
10 $html = $this->getForm( [ 'imageUrl' => 'https://example.com/' ] )->getHTML( false );
11 $this->assertRegExp( '/"fancycaptcha-image"/', $html );
12 $this->assertRegExp( '#src="https://example.com/"#', $html );
13 $this->assertNotRegExp( '/"mw-createacct-captcha-assisted"/', $html );
14
15 $html = $this->getForm( [ 'imageUrl' => '', 'showCreateHelp' => true ] )->getHTML( false );
16 $this->assertRegExp( '/"mw-createacct-captcha-assisted"/', $html );
17
18 $html = $this->getForm( [ 'imageUrl' => '', 'label' => 'FooBarBaz' ] )->getHTML( false );
19 $this->assertRegExp( '/FooBarBaz/', $html );
20 }
21
22 public function testValue() {
23 $mockClosure = $this->getMockBuilder( stdClass::class )
24 ->setMethods( [ '__invoke' ] )->getMock();
25 $request = new FauxRequest( [ 'wpcaptchaWord' => 'abc' ], true );
26 $form = $this->getForm( [ 'imageUrl' => 'https://example.com/' ], $request );
27 $form->setSubmitCallback( $mockClosure );
28
29 $mockClosure->expects( $this->once() )->method( '__invoke' )
30 ->with( [ 'captchaWord' => 'abc' ] )->willReturn( true );
31 $form->trySubmit();
32 }
33
34 protected function getForm( $params = [], WebRequest $request = null ) {
35 $params['class'] = HTMLFancyCaptchaField::class;
36 $form = new HTMLForm( [ 'captchaWord' => $params ] );
37 if ( $request ) {
39 $context->setRequest( $request );
40 $form->setContext( $context );
41 }
42 $form->setTitle( Title::newFromText( 'Foo' ) );
43 $form->prepareForm();
44 return $form;
45 }
46}
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:130
static getMain()
Get the RequestContext object associated with the main request.
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:2806
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:2811
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:2013
$params