1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016-2018 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Customer\Manager; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class EzpublishTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $address; |
15
|
|
|
private $context; |
16
|
|
|
private $object; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
if( !interface_exists( 'eZ\Publish\API\Repository\UserService' ) ) { |
22
|
|
|
$this->markTestSkipped( 'Install ezsystems/ezpublish-api first' ); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
$this->context = \TestHelper::getContext(); |
26
|
|
|
|
27
|
|
|
$this->object = new \Aimeos\MShop\Customer\Manager\Ezpublish( $this->context ); |
28
|
|
|
$this->address = new \Aimeos\MShop\Common\Item\Address\Standard( 'common.address.' ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
protected function tearDown() : void |
33
|
|
|
{ |
34
|
|
|
unset( $this->object, $this->context, $this->address ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
public function testClear() |
39
|
|
|
{ |
40
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( array( -1 ) ) ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testCreateItem() |
45
|
|
|
{ |
46
|
|
|
$this->assertInstanceOf( 'Aimeos\MShop\Customer\Item\Iface', $this->object->createItem() ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
public function testDeleteItems() |
51
|
|
|
{ |
52
|
|
|
$mock = $this->getMockBuilder( 'eZ\Publish\API\Repository\UserService' )->getMock(); |
53
|
|
|
$user = $this->getMockBuilder( 'eZ\Publish\API\Repository\Values\User\User' )->getMock(); |
54
|
|
|
|
55
|
|
|
$mock->expects( $this->once() )->method( 'loadUser' )->will( $this->returnValue( $user ) ); |
56
|
|
|
$mock->expects( $this->once() )->method( 'deleteUser' ); |
57
|
|
|
|
58
|
|
|
$this->context->setEzUserService( $mock ); |
59
|
|
|
$this->object->deleteItems( array( -1 ) ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
public function testGetSearchAttributes() |
64
|
|
|
{ |
65
|
|
|
$attributes = $this->object->getSearchAttributes(); |
66
|
|
|
$this->assertGreaterThan( 0, count( $attributes ) ); |
67
|
|
|
|
68
|
|
|
foreach( $attributes as $attribute ) { |
69
|
|
|
$this->assertInstanceOf( \Aimeos\MW\Criteria\Attribute\Iface::class, $attribute ); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
public function testGetSubManager() |
75
|
|
|
{ |
76
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'address' ) ); |
77
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'address', 'Standard' ) ); |
78
|
|
|
|
79
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
80
|
|
|
$this->object->getSubManager( 'unknown' ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
public function testGetSubManagerInvalidName() |
85
|
|
|
{ |
86
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
87
|
|
|
$this->object->getSubManager( 'address', 'unknown' ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
public function testSaveItemInsert() |
92
|
|
|
{ |
93
|
|
|
$service = $this->getMockBuilder( 'eZ\Publish\API\Repository\UserService' )->getMock(); |
94
|
|
|
$struct = $this->getMockBuilder( 'eZ\Publish\API\Repository\Values\User\UserCreateStruct' )->getMock(); |
95
|
|
|
$user = $this->getMockBuilder( \eZ\Publish\API\Repository\Values\User\User::class ) |
|
|
|
|
96
|
|
|
->setMethods( array( 'getUserId', 'getVersionInfo', 'getFieldValue', 'getFields', 'getFieldsByLanguage' ) ) |
97
|
|
|
->getMock(); |
98
|
|
|
|
99
|
|
|
$dbm = $this->getMockBuilder( 'Aimeos\MW\DB\Manager\Iface' )->getMock(); |
100
|
|
|
$conn = $this->getMockBuilder( 'Aimeos\MW\DB\Connection\Iface' )->getMock(); |
101
|
|
|
$stmt = $this->getMockBuilder( 'Aimeos\MW\DB\Statement\Iface' )->getMock(); |
102
|
|
|
$result = $this->getMockBuilder( 'Aimeos\MW\DB\Result\Iface' )->getMock(); |
103
|
|
|
|
104
|
|
|
$service->expects( $this->once() )->method( 'newUserCreateStruct' )->will( $this->returnValue( $struct ) ); |
105
|
|
|
$service->expects( $this->once() )->method( 'createUser' )->will( $this->returnValue( $user ) ); |
106
|
|
|
$user->expects( $this->once() )->method( 'getUserId' )->will( $this->returnValue( 1 ) ); |
107
|
|
|
$dbm->expects( $this->once() )->method( 'acquire' )->will( $this->returnValue( $conn ) ); |
108
|
|
|
$conn->expects( $this->once() )->method( 'create' )->will( $this->returnValue( $stmt ) ); |
109
|
|
|
$stmt->expects( $this->once() )->method( 'execute' )->will( $this->returnValue( $result ) ); |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
$this->context->setDatabaseManager( $dbm ); |
113
|
|
|
$this->context->setEzUserService( $service ); |
114
|
|
|
|
115
|
|
|
$this->object->saveItem( new \Aimeos\MShop\Customer\Item\Standard( $this->address ) ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testSaveItemUpdate() |
120
|
|
|
{ |
121
|
|
|
$service = $this->getMockBuilder( 'eZ\Publish\API\Repository\UserService' )->getMock(); |
122
|
|
|
$user = $this->getMockBuilder( 'eZ\Publish\API\Repository\Values\User\User' )->getMock(); |
123
|
|
|
$struct = $this->getMockBuilder( 'eZ\Publish\API\Repository\Values\User\UserUpdateStruct' )->getMock(); |
124
|
|
|
$dbm = $this->getMockBuilder( 'Aimeos\MW\DB\Manager\Iface' )->getMock(); |
125
|
|
|
$conn = $this->getMockBuilder( 'Aimeos\MW\DB\Connection\Iface' )->getMock(); |
126
|
|
|
$stmt = $this->getMockBuilder( 'Aimeos\MW\DB\Statement\Iface' )->getMock(); |
127
|
|
|
$result = $this->getMockBuilder( 'Aimeos\MW\DB\Result\Iface' )->getMock(); |
128
|
|
|
|
129
|
|
|
$service->expects( $this->once() )->method( 'updateUser' ); |
130
|
|
|
$service->expects( $this->once() )->method( 'loadUser' )->will( $this->returnValue( $user ) ); |
131
|
|
|
$service->expects( $this->once() )->method( 'newUserUpdateStruct' )->will( $this->returnValue( $struct ) ); |
132
|
|
|
$dbm->expects( $this->once() )->method( 'acquire' )->will( $this->returnValue( $conn ) ); |
133
|
|
|
$conn->expects( $this->once() )->method( 'create' )->will( $this->returnValue( $stmt ) ); |
134
|
|
|
$stmt->expects( $this->once() )->method( 'execute' )->will( $this->returnValue( $result ) ); |
135
|
|
|
$result->expects( $this->once() )->method( 'finish' ); |
136
|
|
|
$dbm->expects( $this->once() )->method( 'release' ); |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
$item = new \Aimeos\MShop\Customer\Item\Standard( $this->address, array( 'customer.id' => 1 ) ); |
140
|
|
|
$item->setCode( 'test' ); |
141
|
|
|
|
142
|
|
|
$this->context->setDatabaseManager( $dbm ); |
143
|
|
|
$this->context->setEzUserService( $service ); |
144
|
|
|
$this->object->saveItem( $item ); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
|
148
|
|
|
public function testSaveItemNotModified() |
149
|
|
|
{ |
150
|
|
|
$item = new \Aimeos\MShop\Customer\Item\Standard( $this->address, array( 'customer.id' => 1 ) ); |
151
|
|
|
$this->object->saveItem( $item ); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
|
155
|
|
|
public function testSaveItemInvalidContext() |
156
|
|
|
{ |
157
|
|
|
$context = new \Aimeos\MShop\Context\Item\Standard(); |
158
|
|
|
$context->setConfig( $this->context->getConfig() ); |
159
|
|
|
$context->setLocale( $this->context->getLocale() ); |
160
|
|
|
|
161
|
|
|
$object = new \Aimeos\MShop\Customer\Manager\Ezpublish( $context ); |
162
|
|
|
|
163
|
|
|
$this->expectException( \Aimeos\MShop\Customer\Exception::class ); |
164
|
|
|
$object->saveItem( new \Aimeos\MShop\Customer\Item\Standard( $this->address ) ); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
public function testSearchItems() |
169
|
|
|
{ |
170
|
|
|
$mock = $this->getMockBuilder( \Aimeos\MShop\Customer\Manager\Ezpublish::class ) |
171
|
|
|
->setConstructorArgs( array( $this->context ) ) |
172
|
|
|
->setMethods( array( 'searchItemsBase' ) ) |
173
|
|
|
->getMock(); |
174
|
|
|
|
175
|
|
|
$result1 = $this->getMockBuilder( \Aimeos\MW\DB\Result\Iface::class )->getMock(); |
176
|
|
|
|
177
|
|
|
$mock->expects( $this->once() )->method( 'searchItemsBase' )->will( $this->returnValue( $result1 ) ); |
178
|
|
|
$result1->expects( $this->exactly( 2 ) )->method( 'fetch' ) |
179
|
|
|
->will( $this->onConsecutiveCalls( array( 'customer.id' => -1 ), null ) ); |
180
|
|
|
|
181
|
|
|
|
182
|
|
|
$dbm = $this->getMockBuilder( 'Aimeos\MW\DB\Manager\Iface' )->getMock(); |
183
|
|
|
$conn = $this->getMockBuilder( 'Aimeos\MW\DB\Connection\Iface' )->getMock(); |
184
|
|
|
$stmt = $this->getMockBuilder( 'Aimeos\MW\DB\Statement\Iface' )->getMock(); |
185
|
|
|
$result2 = $this->getMockBuilder( \Aimeos\MW\DB\Result\Iface::class )->getMock(); |
186
|
|
|
|
187
|
|
|
$dbm->expects( $this->any() )->method( 'acquire' )->will( $this->returnValue( $conn ) ); |
188
|
|
|
$conn->expects( $this->once() )->method( 'create' )->will( $this->returnValue( $stmt ) ); |
189
|
|
|
$stmt->expects( $this->once() )->method( 'execute' )->will( $this->returnValue( $result2 ) ); |
190
|
|
|
$result2->expects( $this->exactly( 2 ) )->method( 'fetch' ) |
191
|
|
|
->will( $this->onConsecutiveCalls( array( 'contentobject_id' => -1, 'role_id' => -2 ), null ) ); |
192
|
|
|
|
193
|
|
|
$dbm->expects( $this->any() )->method( 'release' ); |
194
|
|
|
|
195
|
|
|
|
196
|
|
|
$this->context->setDatabaseManager( $dbm ); |
197
|
|
|
$list = $mock->searchItems( $mock->createSearch() ); |
198
|
|
|
|
199
|
|
|
$this->assertEquals( 1, count( $list ) ); |
200
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Iface::class, $list[-1] ); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
public function testSearchItemsException() |
205
|
|
|
{ |
206
|
|
|
$object = $this->getMockBuilder( \Aimeos\MShop\Customer\Manager\Ezpublish::class ) |
207
|
|
|
->setConstructorArgs( array( $this->context ) ) |
208
|
|
|
->setMethods( array( 'searchItemsBase' ) ) |
209
|
|
|
->getMock(); |
210
|
|
|
|
211
|
|
|
$object->expects( $this->once() )->method( 'searchItemsBase' ) |
212
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
213
|
|
|
|
214
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
215
|
|
|
$object->searchItems( $object->createSearch() ); |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths