MediaWiki  1.29.1
HTMLFancyCaptchaFieldTest.php
Go to the documentation of this file.
1 <?php
2 
3 require_once __DIR__ . '/../../FancyCaptcha/HTMLFancyCaptchaField.php';
4 
5 class HTMLFancyCaptchaFieldTest extends PHPUnit_Framework_TestCase {
6  public function testGetHTML() {
7  $html = $this->getForm( [ 'imageUrl' => 'https://example.com/' ] )->getHTML( false );
8  $this->assertRegExp( '/"fancycaptcha-image"/', $html );
9  $this->assertRegExp( '#src="https://example.com/"#', $html );
10  $this->assertNotRegExp( '/"mw-createacct-captcha-assisted"/', $html );
11 
12  $html = $this->getForm( [ 'imageUrl' => '', 'showCreateHelp' => true ] )->getHTML( false );
13  $this->assertRegExp( '/"mw-createacct-captcha-assisted"/', $html );
14 
15  $html = $this->getForm( [ 'imageUrl' => '', 'label' => 'FooBarBaz' ] )->getHTML( false );
16  $this->assertRegExp( '/FooBarBaz/', $html );
17  }
18 
19  public function testValue() {
20  $mockClosure = $this->getMockBuilder( 'object' )->setMethods( [ '__invoke' ] )->getMock();
21  $request = new FauxRequest( [ 'wpcaptchaWord' => 'abc' ], true );
22  $form = $this->getForm( [ 'imageUrl' => 'https://example.com/' ], $request );
23  $form->setSubmitCallback( $mockClosure );
24 
25  $mockClosure->expects( $this->once() )->method( '__invoke' )
26  ->with( [ 'captchaWord' => 'abc' ] )->willReturn( true );
27  $form->trySubmit();
28  }
29 
30  protected function getForm( $params = [], WebRequest $request = null ) {
32  $form = new HTMLForm( [ 'captchaWord' => $params ] );
33  if ( $request ) {
35  $context->setRequest( $request );
36  $form->setContext( $context );
37  }
38  $form->setTitle( Title::newFromText( 'Foo' ) );
39  $form->prepareForm();
40  return $form;
41  }
42 }
$context
error also a ContextSource you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2612
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:265
$request
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2612
HTMLFancyCaptchaFieldTest\testValue
testValue()
Definition: HTMLFancyCaptchaFieldTest.php:19
$params
$params
Definition: styleTest.css.php:40
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:30
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:31
$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:1956
ContextSource\setContext
setContext(IContextSource $context)
Set the IContextSource object.
Definition: ContextSource.php:58
RequestContext\getMain
static getMain()
Static methods.
Definition: RequestContext.php:468
HTMLFancyCaptchaFieldTest
Definition: HTMLFancyCaptchaFieldTest.php:5
WebRequest
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
Definition: WebRequest.php:38
HTMLFancyCaptchaFieldTest\testGetHTML
testGetHTML()
Definition: HTMLFancyCaptchaFieldTest.php:6
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:128