diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/extensions/ConfirmEdit/tests/HTMLFancyCaptchaFieldTest.php |
first commit
Diffstat (limited to 'www/wiki/extensions/ConfirmEdit/tests/HTMLFancyCaptchaFieldTest.php')
-rw-r--r-- | www/wiki/extensions/ConfirmEdit/tests/HTMLFancyCaptchaFieldTest.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/www/wiki/extensions/ConfirmEdit/tests/HTMLFancyCaptchaFieldTest.php b/www/wiki/extensions/ConfirmEdit/tests/HTMLFancyCaptchaFieldTest.php new file mode 100644 index 00000000..016302bc --- /dev/null +++ b/www/wiki/extensions/ConfirmEdit/tests/HTMLFancyCaptchaFieldTest.php @@ -0,0 +1,42 @@ +<?php + +require_once __DIR__ . '/../FancyCaptcha/HTMLFancyCaptchaField.php'; + +class HTMLFancyCaptchaFieldTest extends PHPUnit_Framework_TestCase { + public function testGetHTML() { + $html = $this->getForm( [ 'imageUrl' => 'https://example.com/' ] )->getHTML( false ); + $this->assertRegExp( '/"fancycaptcha-image"/', $html ); + $this->assertRegExp( '#src="https://example.com/"#', $html ); + $this->assertNotRegExp( '/"mw-createacct-captcha-assisted"/', $html ); + + $html = $this->getForm( [ 'imageUrl' => '', 'showCreateHelp' => true ] )->getHTML( false ); + $this->assertRegExp( '/"mw-createacct-captcha-assisted"/', $html ); + + $html = $this->getForm( [ 'imageUrl' => '', 'label' => 'FooBarBaz' ] )->getHTML( false ); + $this->assertRegExp( '/FooBarBaz/', $html ); + } + + public function testValue() { + $mockClosure = $this->getMockBuilder( 'object' )->setMethods( [ '__invoke' ] )->getMock(); + $request = new FauxRequest( [ 'wpcaptchaWord' => 'abc' ], true ); + $form = $this->getForm( [ 'imageUrl' => 'https://example.com/' ], $request ); + $form->setSubmitCallback( $mockClosure ); + + $mockClosure->expects( $this->once() )->method( '__invoke' ) + ->with( [ 'captchaWord' => 'abc' ] )->willReturn( true ); + $form->trySubmit(); + } + + protected function getForm( $params = [], WebRequest $request = null ) { + $params['class'] = HTMLFancyCaptchaField::class; + $form = new HTMLForm( [ 'captchaWord' => $params ] ); + if ( $request ) { + $context = new DerivativeContext( RequestContext::getMain() ); + $context->setRequest( $request ); + $form->setContext( $context ); + } + $form->setTitle( Title::newFromText( 'Foo' ) ); + $form->prepareForm(); + return $form; + } +} |