MediaWiki  1.33.0
HTMLFancyCaptchaFieldTest.php
Go to the documentation of this file.
1 <?php
2 
6 class 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 ) {
34  $form = new HTMLForm( [ 'captchaWord' => $params ] );
35  if ( $request ) {
37  $context->setRequest( $request );
38  $form->setContext( $context );
39  }
40  $form->setTitle( Title::newFromText( 'Foo' ) );
41  $form->prepareForm();
42  return $form;
43  }
44 }
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:306
HTMLFancyCaptchaFieldTest\testValue
testValue()
Definition: HTMLFancyCaptchaFieldTest.php:20
$context
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:2636
$params
$params
Definition: styleTest.css.php:44
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
HTMLFancyCaptchaFieldTest\getForm
getForm( $params=[], WebRequest $request=null)
Definition: HTMLFancyCaptchaFieldTest.php:32
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:30
$html
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:1985
$request
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:2636
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:430
HTMLFancyCaptchaFieldTest
HTMLFancyCaptchaField.
Definition: HTMLFancyCaptchaFieldTest.php:6
WebRequest
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
Definition: WebRequest.php:41
HTMLFancyCaptchaFieldTest\testGetHTML
testGetHTML()
Definition: HTMLFancyCaptchaFieldTest.php:7
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:133