|
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\Product\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\Product\Standard' ) |
|
24
|
|
|
->disableOriginalConstructor() |
|
25
|
|
|
->getMock(); |
|
26
|
|
|
|
|
27
|
|
|
$this->object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Product\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 testAddFilterAttribute() |
|
40
|
|
|
{ |
|
41
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
|
42
|
|
|
|
|
43
|
|
|
$this->stub->expects( $this->once() )->method( 'addFilterAttribute' ) |
|
44
|
|
|
->will( $this->returnArgument( 0 ) ); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->addFilterAttribute( $search, [], [], [] ) ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
public function testAddFilterCategory() |
|
51
|
|
|
{ |
|
52
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
|
53
|
|
|
|
|
54
|
|
|
$this->stub->expects( $this->once() )->method( 'addFilterCategory' ) |
|
55
|
|
|
->will( $this->returnArgument( 0 ) ); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->addFilterCategory( $search, -1 ) ); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
public function testAddFilterText() |
|
62
|
|
|
{ |
|
63
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
|
64
|
|
|
|
|
65
|
|
|
$this->stub->expects( $this->once() )->method( 'addFilterText' ) |
|
66
|
|
|
->will( $this->returnArgument( 0 ) ); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->addFilterText( $search, 'test' ) ); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
public function testAggregate() |
|
73
|
|
|
{ |
|
74
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
|
75
|
|
|
|
|
76
|
|
|
$this->stub->expects( $this->once() )->method( 'aggregate' ) |
|
77
|
|
|
->will( $this->returnValue( [] ) ); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertEquals( [], $this->object->aggregate( $search, 'test' ) ); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
public function testCreateFilter() |
|
84
|
|
|
{ |
|
85
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
|
86
|
|
|
|
|
87
|
|
|
$this->stub->expects( $this->once() )->method( 'createFilter' ) |
|
88
|
|
|
->will( $this->returnValue( $search ) ); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createFilter() ); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
public function testGetItem() |
|
95
|
|
|
{ |
|
96
|
|
|
$prodItem = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createItem(); |
|
97
|
|
|
|
|
98
|
|
|
$this->stub->expects( $this->once() )->method( 'getItem' ) |
|
99
|
|
|
->will( $this->returnValue( $prodItem ) ); |
|
100
|
|
|
|
|
101
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $this->object->getItem( -1 ) ); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
public function testGetItems() |
|
106
|
|
|
{ |
|
107
|
|
|
$this->stub->expects( $this->once() )->method( 'getItems' ) |
|
108
|
|
|
->will( $this->returnValue( [] ) ); |
|
109
|
|
|
|
|
110
|
|
|
$this->assertEquals( [], $this->object->getItems( [-1] ) ); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
public function testSearchItems() |
|
115
|
|
|
{ |
|
116
|
|
|
$search = \Aimeos\MShop\Factory::createManager( $this->context, 'index' )->createSearch(); |
|
117
|
|
|
|
|
118
|
|
|
$this->stub->expects( $this->once() )->method( 'searchItems' ) |
|
119
|
|
|
->will( $this->returnValue( [] ) ); |
|
120
|
|
|
|
|
121
|
|
|
$this->assertEquals( [], $this->object->searchItems( $search ) ); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
public function testGetContext() |
|
126
|
|
|
{ |
|
127
|
|
|
$result = $this->access( 'getContext' )->invokeArgs( $this->object, [] ); |
|
128
|
|
|
|
|
129
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Context\Item\Iface', $result ); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
protected function access( $name ) |
|
134
|
|
|
{ |
|
135
|
|
|
$class = new \ReflectionClass( '\Aimeos\Controller\Frontend\Product\Decorator\Base' ); |
|
136
|
|
|
$method = $class->getMethod( $name ); |
|
137
|
|
|
$method->setAccessible( true ); |
|
138
|
|
|
|
|
139
|
|
|
return $method; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|