1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018-2024 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Review\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class Example extends Base |
13
|
|
|
{ |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class BaseTest extends \PHPUnit\Framework\TestCase |
18
|
|
|
{ |
19
|
|
|
private $context; |
20
|
|
|
private $object; |
21
|
|
|
private $stub; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
protected function setUp() : void |
25
|
|
|
{ |
26
|
|
|
$this->context = \TestHelper::context(); |
27
|
|
|
|
28
|
|
|
$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Review\Standard::class ) |
29
|
|
|
->disableOriginalConstructor() |
30
|
|
|
->getMock(); |
31
|
|
|
|
32
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Review\Decorator\Example( $this->stub, $this->context ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
protected function tearDown() : void |
37
|
|
|
{ |
38
|
|
|
unset( $this->context, $this->object, $this->stub ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
public function testCall() |
43
|
|
|
{ |
44
|
|
|
$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Review\Standard::class ) |
45
|
|
|
->disableOriginalConstructor() |
46
|
|
|
->onlyMethods( ['__call'] ) |
47
|
|
|
->getMock(); |
48
|
|
|
|
49
|
|
|
$object = new \Aimeos\Controller\Frontend\Review\Decorator\Example( $stub, $this->context ); |
50
|
|
|
|
51
|
|
|
$stub->expects( $this->once() )->method( '__call' )->willReturn( true ); |
52
|
|
|
|
53
|
|
|
$this->assertTrue( $object->invalid() ); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
public function testAggregate() |
58
|
|
|
{ |
59
|
|
|
$this->stub->expects( $this->once() )->method( 'aggregate' ) |
60
|
|
|
->willReturn( map() ); |
61
|
|
|
|
62
|
|
|
$this->assertEquals( [], $this->object->aggregate( 'test' )->toArray() ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
public function testCompare() |
67
|
|
|
{ |
68
|
|
|
$this->assertSame( $this->object, $this->object->compare( '==', 'supplier.status', 1 ) ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
public function testCreate() |
73
|
|
|
{ |
74
|
|
|
$result = $this->object->create( ['review.rating' => 5] ); |
75
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Review\Item\Iface::class, $result ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
public function testDelete() |
80
|
|
|
{ |
81
|
|
|
$this->stub->expects( $this->once() )->method( 'delete' ); |
82
|
|
|
|
83
|
|
|
$this->assertSame( $this->object, $this->object->delete( '-1' ) ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
public function testDomain() |
88
|
|
|
{ |
89
|
|
|
$this->assertSame( $this->object, $this->object->domain( 'product' ) ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
public function testFor() |
94
|
|
|
{ |
95
|
|
|
$this->assertSame( $this->object, $this->object->for( 'product', '-1' ) ); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
public function testGet() |
100
|
|
|
{ |
101
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'review' )->create(); |
102
|
|
|
|
103
|
|
|
$this->stub->expects( $this->once() )->method( 'get' ) |
104
|
|
|
->willReturn( $item ); |
105
|
|
|
|
106
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Review\Item\Iface::class, $this->object->get( -1 ) ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
public function testList() |
111
|
|
|
{ |
112
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'review' )->create(); |
113
|
|
|
|
114
|
|
|
$this->stub->expects( $this->once() )->method( 'list' ) |
115
|
|
|
->willReturn( map( [$item] ) ); |
116
|
|
|
|
117
|
|
|
$this->assertEquals( [$item], $this->object->list()->toArray() ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
public function testParse() |
122
|
|
|
{ |
123
|
|
|
$this->assertSame( $this->object, $this->object->parse( [] ) ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
public function testSave() |
128
|
|
|
{ |
129
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'review' )->create(); |
130
|
|
|
|
131
|
|
|
$this->stub->expects( $this->once() )->method( 'save' ) |
132
|
|
|
->willReturn( $item ); |
133
|
|
|
|
134
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Review\Item\Iface::class, $this->object->save( $item ) ); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
public function testSearch() |
139
|
|
|
{ |
140
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'review' )->create(); |
141
|
|
|
|
142
|
|
|
$this->stub->expects( $this->once() )->method( 'search' ) |
143
|
|
|
->willReturn( map( [$item] ) ); |
144
|
|
|
|
145
|
|
|
$this->assertEquals( [$item], $this->object->search()->toArray() ); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
|
149
|
|
|
public function testSlice() |
150
|
|
|
{ |
151
|
|
|
$this->assertSame( $this->object, $this->object->slice( 0, 100 ) ); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
|
155
|
|
|
public function testSort() |
156
|
|
|
{ |
157
|
|
|
$this->assertSame( $this->object, $this->object->sort( 'interval' ) ); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
|
161
|
|
|
public function testGetController() |
162
|
|
|
{ |
163
|
|
|
$this->assertSame( $this->stub, $this->access( 'getController' )->invokeArgs( $this->object, [] ) ); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
|
167
|
|
|
protected function access( $name ) |
168
|
|
|
{ |
169
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Review\Decorator\Base::class ); |
170
|
|
|
$method = $class->getMethod( $name ); |
171
|
|
|
$method->setAccessible( true ); |
172
|
|
|
|
173
|
|
|
return $method; |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|