|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016-2020 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\MW\View\Helper\Request; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class SlimTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $object; |
|
15
|
|
|
private $mock; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
protected function setUp() : void |
|
19
|
|
|
{ |
|
20
|
|
|
if( !interface_exists( '\Psr\Http\Message\ServerRequestInterface' ) ) { |
|
21
|
|
|
$this->markTestSkipped( '\Psr\Http\Message\ServerRequestInterface is not available' ); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
if( !class_exists( '\Slim\Route' ) ) { |
|
25
|
|
|
$this->markTestSkipped( '\Slim\Route is not available' ); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
$view = new \Aimeos\MW\View\Standard(); |
|
29
|
|
|
$route = new \Slim\Route( array( 'GET' ), '/shop', null ); |
|
30
|
|
|
$route->setName( 'route' ); |
|
31
|
|
|
|
|
32
|
|
|
$this->mock = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock(); |
|
33
|
|
|
|
|
34
|
|
|
$this->mock->expects( $this->once() )->method( 'getAttribute' ) |
|
35
|
|
|
->will( $this->returnValue( $route ) ); |
|
36
|
|
|
|
|
37
|
|
|
$this->mock->expects( $this->once() )->method( 'getServerParams' ) |
|
38
|
|
|
->will( $this->returnValue( array( 'REMOTE_ADDR' => '127.0.0.1' ) ) ); |
|
39
|
|
|
|
|
40
|
|
|
$this->object = new \Aimeos\MW\View\Helper\Request\Slim( $view, $this->mock ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
protected function tearDown() : void |
|
45
|
|
|
{ |
|
46
|
|
|
unset( $this->object, $this->mock ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
public function testTransform() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->assertInstanceOf( \Aimeos\MW\View\Helper\Request\Slim::class, $this->object->transform() ); |
|
53
|
|
|
$this->assertInstanceOf( \Psr\Http\Message\ServerRequestInterface::class, $this->object->transform() ); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
public function testGetClientAddress() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->assertEquals( '127.0.0.1', $this->object->getClientAddress() ); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
public function testGetTarget() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->assertEquals( 'route', $this->object->getTarget() ); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|