1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Catalog\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class BaseTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $context; |
15
|
|
|
private $object; |
16
|
|
|
private $stub; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() |
20
|
|
|
{ |
21
|
|
|
$this->context = \TestHelperFrontend::getContext(); |
22
|
|
|
|
23
|
|
|
$this->stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Catalog\Standard' ) |
24
|
|
|
->disableOriginalConstructor() |
25
|
|
|
->getMock(); |
26
|
|
|
|
27
|
|
|
$this->object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Catalog\Decorator\Base' ) |
28
|
|
|
->setConstructorArgs( [$this->stub, $this->context] ) |
29
|
|
|
->getMockForAbstractClass(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
protected function tearDown() |
34
|
|
|
{ |
35
|
|
|
unset( $this->context, $this->object, $this->stub ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
public function testConstructException() |
40
|
|
|
{ |
41
|
|
|
$stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Iface' )->getMock(); |
42
|
|
|
|
43
|
|
|
$this->setExpectedException( '\Aimeos\Controller\Frontend\Exception' ); |
44
|
|
|
|
45
|
|
|
$this->getMockBuilder( '\Aimeos\Controller\Frontend\Catalog\Decorator\Base' ) |
46
|
|
|
->setConstructorArgs( [$stub, $this->context] ) |
47
|
|
|
->getMockForAbstractClass(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
public function testCall() |
52
|
|
|
{ |
53
|
|
|
$stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Catalog\Standard' ) |
54
|
|
|
->disableOriginalConstructor() |
55
|
|
|
->setMethods( ['invalid'] ) |
56
|
|
|
->getMock(); |
57
|
|
|
|
58
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Catalog\Decorator\Base' ) |
59
|
|
|
->setConstructorArgs( [$stub, $this->context] ) |
60
|
|
|
->getMockForAbstractClass(); |
61
|
|
|
|
62
|
|
|
$stub->expects( $this->once() )->method( 'invalid' )->will( $this->returnValue( true ) ); |
63
|
|
|
|
64
|
|
|
$this->assertTrue( $object->invalid() ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testCreateFilter() |
69
|
|
|
{ |
70
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' )->createSearch(); |
71
|
|
|
|
72
|
|
|
$this->stub->expects( $this->once() )->method( 'createFilter' ) |
73
|
|
|
->will( $this->returnValue( $search ) ); |
74
|
|
|
|
75
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createFilter() ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
public function testGetPath() |
80
|
|
|
{ |
81
|
|
|
$this->stub->expects( $this->once() )->method( 'getPath' ) |
82
|
|
|
->will( $this->returnValue( [] ) ); |
83
|
|
|
|
84
|
|
|
$this->assertEquals( [], $this->object->getPath( -1 ) ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
public function testGetTree() |
89
|
|
|
{ |
90
|
|
|
$catItem = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' )->createItem(); |
91
|
|
|
|
92
|
|
|
$this->stub->expects( $this->once() )->method( 'getTree' ) |
93
|
|
|
->will( $this->returnValue( $catItem ) ); |
94
|
|
|
|
95
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Catalog\Item\Iface', $this->object->getTree() ); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
public function testGetController() |
100
|
|
|
{ |
101
|
|
|
$result = $this->access( 'getController' )->invokeArgs( $this->object, [] ); |
102
|
|
|
|
103
|
|
|
$this->assertSame( $this->stub, $result ); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
protected function access( $name ) |
108
|
|
|
{ |
109
|
|
|
$class = new \ReflectionClass( '\Aimeos\Controller\Frontend\Catalog\Decorator\Base' ); |
110
|
|
|
$method = $class->getMethod( $name ); |
111
|
|
|
$method->setAccessible( true ); |
112
|
|
|
|
113
|
|
|
return $method; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|