1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2018 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Locale\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\Locale\Standard::class ) |
24
|
|
|
->disableOriginalConstructor() |
25
|
|
|
->getMock(); |
26
|
|
|
|
27
|
|
|
$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Locale\Decorator\Base::class ) |
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::class )->getMock(); |
42
|
|
|
|
43
|
|
|
$this->setExpectedException( \Aimeos\MW\Common\Exception::class ); |
44
|
|
|
|
45
|
|
|
$this->getMockBuilder( \Aimeos\Controller\Frontend\Locale\Decorator\Base::class ) |
46
|
|
|
->setConstructorArgs( [$stub, $this->context] ) |
47
|
|
|
->getMockForAbstractClass(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
public function testCall() |
52
|
|
|
{ |
53
|
|
|
$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Locale\Standard::class ) |
54
|
|
|
->disableOriginalConstructor() |
55
|
|
|
->setMethods( ['invalid'] ) |
56
|
|
|
->getMock(); |
57
|
|
|
|
58
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Locale\Decorator\Base::class ) |
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 testCompare() |
69
|
|
|
{ |
70
|
|
|
$expected = \Aimeos\Controller\Frontend\Locale\Iface::class; |
71
|
|
|
|
72
|
|
|
$this->stub->expects( $this->once() )->method( 'compare' ) |
73
|
|
|
->will( $this->returnValue( $this->stub ) ); |
74
|
|
|
|
75
|
|
|
$this->assertInstanceOf( $expected, $this->object->compare( '==', 'locale.status', 1 ) ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
public function testGet() |
80
|
|
|
{ |
81
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'locale' )->createItem(); |
82
|
|
|
|
83
|
|
|
$this->stub->expects( $this->once() )->method( 'get' ) |
84
|
|
|
->will( $this->returnValue( $item ) ); |
85
|
|
|
|
86
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Iface::class, $this->object->get( -1 ) ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
public function testParse() |
91
|
|
|
{ |
92
|
|
|
$expected = \Aimeos\Controller\Frontend\Locale\Iface::class; |
93
|
|
|
|
94
|
|
|
$this->stub->expects( $this->once() )->method( 'parse' ) |
95
|
|
|
->will( $this->returnValue( $this->stub ) ); |
96
|
|
|
|
97
|
|
|
$this->assertInstanceOf( $expected, $this->object->parse( [] ) ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function testSearch() |
102
|
|
|
{ |
103
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'locale' )->createItem(); |
104
|
|
|
|
105
|
|
|
$this->stub->expects( $this->once() )->method( 'search' ) |
106
|
|
|
->will( $this->returnValue( [$item] ) ); |
107
|
|
|
|
108
|
|
|
$this->assertEquals( [$item], $this->object->search() ); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
public function testSlice() |
113
|
|
|
{ |
114
|
|
|
$expected = \Aimeos\Controller\Frontend\Locale\Iface::class; |
115
|
|
|
|
116
|
|
|
$this->stub->expects( $this->once() )->method( 'slice' ) |
117
|
|
|
->will( $this->returnValue( $this->stub ) ); |
118
|
|
|
|
119
|
|
|
$this->assertInstanceOf( $expected, $this->object->slice( 0, 100 ) ); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
public function testSort() |
124
|
|
|
{ |
125
|
|
|
$expected = \Aimeos\Controller\Frontend\Locale\Iface::class; |
126
|
|
|
|
127
|
|
|
$this->stub->expects( $this->once() )->method( 'sort' ) |
128
|
|
|
->will( $this->returnValue( $this->stub ) ); |
129
|
|
|
|
130
|
|
|
$this->assertInstanceOf( $expected, $this->object->sort( 'position' ) ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
public function testGetController() |
135
|
|
|
{ |
136
|
|
|
$result = $this->access( 'getController' )->invokeArgs( $this->object, [] ); |
137
|
|
|
|
138
|
|
|
$this->assertSame( $this->stub, $result ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
protected function access( $name ) |
143
|
|
|
{ |
144
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Locale\Decorator\Base::class ); |
145
|
|
|
$method = $class->getMethod( $name ); |
146
|
|
|
$method->setAccessible( true ); |
147
|
|
|
|
148
|
|
|
return $method; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|