1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2024 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Client\Html\Cms\Page\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class RecaptchaTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $context; |
16
|
|
|
private $view; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
$this->context = \TestHelper::context(); |
22
|
|
|
$this->view = $this->context->view(); |
23
|
|
|
|
24
|
|
|
$this->object = new \Aimeos\Client\Html\Cms\Page\Standard( $this->context ); |
25
|
|
|
$this->object = new \Aimeos\Client\Html\Cms\Page\Decorator\Recaptcha( $this->object, $this->context ); |
26
|
|
|
$this->object->setView( $this->view ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
protected function tearDown() : void |
31
|
|
|
{ |
32
|
|
|
\Aimeos\Controller\Frontend::cache( true ); |
33
|
|
|
|
34
|
|
|
unset( $this->object, $this->context, $this->view ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
public function testBody() |
39
|
|
|
{ |
40
|
|
|
$output = $this->object->body(); |
41
|
|
|
$this->assertEquals( '', $output ); |
42
|
|
|
|
43
|
|
|
$this->context->config()->set( 'resource/recaptcha/sitekey', 'abcd' ); |
44
|
|
|
$output = $this->object->body(); |
45
|
|
|
$this->assertStringContainsString( 'abcd', $output ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
public function testInit() |
50
|
|
|
{ |
51
|
|
|
$this->object->init(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function testInitTokenMissing() |
56
|
|
|
{ |
57
|
|
|
$this->context->config()->set( 'resource/recaptcha/secretkey', 'abcd' ); |
58
|
|
|
|
59
|
|
|
$helper = new \Aimeos\Base\View\Helper\Request\Standard( $this->view, $this->view->request()->withMethod( 'POST' ) ); |
60
|
|
|
$this->view->addHelper( 'request', $helper ); |
61
|
|
|
|
62
|
|
|
$this->expectException( \Aimeos\Client\Html\Exception::class ); |
63
|
|
|
$this->object->init(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
public function testInitTokenInvalid() |
68
|
|
|
{ |
69
|
|
|
$this->context->config()->set( 'resource/recaptcha/secretkey', 'abcd' ); |
70
|
|
|
|
71
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, ['g-recaptcha-response' => 'test'] ); |
72
|
|
|
$this->view->addHelper( 'param', $helper ); |
73
|
|
|
|
74
|
|
|
$helper = new \Aimeos\Base\View\Helper\Request\Standard( $this->view, $this->view->request()->withMethod( 'POST' ) ); |
75
|
|
|
$this->view->addHelper( 'request', $helper ); |
76
|
|
|
|
77
|
|
|
$this->expectException( \Aimeos\Client\Html\Exception::class ); |
78
|
|
|
$this->object->init(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|