|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2023 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Order\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() : void |
|
20
|
|
|
{ |
|
21
|
|
|
$this->context = \TestHelper::context(); |
|
22
|
|
|
|
|
23
|
|
|
$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Order\Standard::class ) |
|
24
|
|
|
->disableOriginalConstructor() |
|
25
|
|
|
->getMock(); |
|
26
|
|
|
|
|
27
|
|
|
$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Order\Decorator\Base::class ) |
|
28
|
|
|
->setConstructorArgs( [$this->stub, $this->context] ) |
|
29
|
|
|
->getMockForAbstractClass(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
protected function tearDown() : void |
|
34
|
|
|
{ |
|
35
|
|
|
unset( $this->context, $this->object, $this->stub ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
public function testCall() |
|
40
|
|
|
{ |
|
41
|
|
|
$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Order\Standard::class ) |
|
42
|
|
|
->disableOriginalConstructor() |
|
43
|
|
|
->onlyMethods( ['__call'] ) |
|
44
|
|
|
->getMock(); |
|
45
|
|
|
|
|
46
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Order\Decorator\Base::class ) |
|
47
|
|
|
->setConstructorArgs( [$stub, $this->context] ) |
|
48
|
|
|
->getMockForAbstractClass(); |
|
49
|
|
|
|
|
50
|
|
|
$stub->expects( $this->once() )->method( '__call' )->will( $this->returnValue( true ) ); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertTrue( $object->invalid() ); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
public function testCompare() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->assertSame( $this->object, $this->object->compare( '==', 'order.type', 'test' ) ); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
public function testGet() |
|
63
|
|
|
{ |
|
64
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
|
65
|
|
|
$expected = \Aimeos\MShop\Order\Item\Iface::class; |
|
66
|
|
|
|
|
67
|
|
|
$this->stub->expects( $this->once() )->method( 'get' )->will( $this->returnValue( $item ) ); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertInstanceOf( $expected, $this->object->get( -1, false ) ); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
public function testParse() |
|
74
|
|
|
{ |
|
75
|
|
|
$this->assertSame( $this->object, $this->object->parse( [] ) ); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
public function testSave() |
|
80
|
|
|
{ |
|
81
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
|
82
|
|
|
$expected = \Aimeos\MShop\Order\Item\Iface::class; |
|
83
|
|
|
|
|
84
|
|
|
$this->stub->expects( $this->once() )->method( 'save' )->will( $this->returnArgument( 0 ) ); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertInstanceOf( $expected, $this->object->save( $item ) ); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
public function testSearch() |
|
91
|
|
|
{ |
|
92
|
|
|
$total = 0; |
|
93
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
|
94
|
|
|
|
|
95
|
|
|
$this->stub->expects( $this->once() )->method( 'search' ) |
|
96
|
|
|
->will( $this->returnValue( map( [$item] ) ) ); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertEquals( [$item], $this->object->search( $total )->toArray() ); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
public function testSlice() |
|
103
|
|
|
{ |
|
104
|
|
|
$this->assertSame( $this->object, $this->object->slice( 0, 100 ) ); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
public function testSort() |
|
109
|
|
|
{ |
|
110
|
|
|
$this->assertSame( $this->object, $this->object->sort( 'order.id' ) ); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
public function testUpdate() |
|
115
|
|
|
{ |
|
116
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
|
117
|
|
|
$this->assertSame( $this->object, $this->object->update( $item ) ); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
public function testUses() |
|
122
|
|
|
{ |
|
123
|
|
|
$this->assertSame( $this->object, $this->object->uses( ['order'] ) ); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
public function testGetController() |
|
128
|
|
|
{ |
|
129
|
|
|
$result = $this->access( 'getController' )->invokeArgs( $this->object, [] ); |
|
130
|
|
|
|
|
131
|
|
|
$this->assertSame( $this->stub, $result ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
protected function access( $name ) |
|
136
|
|
|
{ |
|
137
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Order\Decorator\Base::class ); |
|
138
|
|
|
$method = $class->getMethod( $name ); |
|
139
|
|
|
$method->setAccessible( true ); |
|
140
|
|
|
|
|
141
|
|
|
return $method; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|