1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2023 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class ContextTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
protected function setUp() : void |
18
|
|
|
{ |
19
|
|
|
$this->object = new \Aimeos\MShop\Context(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
public function testGetConfig() |
24
|
|
|
{ |
25
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
26
|
|
|
$this->object->config(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
public function testGetDatabaseManager() |
31
|
|
|
{ |
32
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
33
|
|
|
$this->object->db(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
public function testGetDateTime() |
38
|
|
|
{ |
39
|
|
|
$this->assertMatchesRegularExpression( '/^[0-9]{4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]$/', $this->object->datetime() ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
public function testGetFilesystem() |
44
|
|
|
{ |
45
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
46
|
|
|
$this->object->fs( 'fs' ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
public function testGetLocale() |
51
|
|
|
{ |
52
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
53
|
|
|
$this->object->locale(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
public function testGetI18n() |
58
|
|
|
{ |
59
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
60
|
|
|
$this->object->i18n(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
public function testGetLogger() |
65
|
|
|
{ |
66
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
67
|
|
|
$this->object->logger(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
public function testGetMail() |
72
|
|
|
{ |
73
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
74
|
|
|
$this->object->mail(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testGetQueue() |
79
|
|
|
{ |
80
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
81
|
|
|
$this->object->queue( 'email', 'test' ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
public function testGetPassword() |
86
|
|
|
{ |
87
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
88
|
|
|
$this->object->password(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
public function testGetProcess() |
93
|
|
|
{ |
94
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
95
|
|
|
$this->object->process(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
public function testGetSession() |
100
|
|
|
{ |
101
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
102
|
|
|
$this->object->session(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
public function testGetView() |
107
|
|
|
{ |
108
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
109
|
|
|
$this->object->view(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
public function testGetToken() |
114
|
|
|
{ |
115
|
|
|
$this->assertNull( $this->object->token() ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testSetConfig() |
120
|
|
|
{ |
121
|
|
|
$config = new \Aimeos\Base\Config\PHPArray(); |
122
|
|
|
$return = $this->object->setConfig( $config ); |
123
|
|
|
|
124
|
|
|
$this->assertSame( $config, $this->object->config() ); |
125
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
public function testSetDatabaseManager() |
130
|
|
|
{ |
131
|
|
|
$config = \TestHelper::context()->config()->get( 'resource' ); |
132
|
|
|
$return = $this->object->setDatabaseManager( new \Aimeos\Base\DB\Manager\Standard( $config ) ); |
133
|
|
|
|
134
|
|
|
$this->assertInstanceOf( \Aimeos\Base\DB\Connection\Iface::class, $this->object->db() ); |
135
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
public function testSetDateTime() |
140
|
|
|
{ |
141
|
|
|
$return = $this->object->setDateTime( '2000-01-01 00:00:00' ); |
142
|
|
|
|
143
|
|
|
$this->assertEquals( '2000-01-01 00:00:00', $this->object->datetime() ); |
144
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
|
148
|
|
|
public function testSetFilesystemManager() |
149
|
|
|
{ |
150
|
|
|
$config = \TestHelper::context()->config()->get( 'resource' ); |
151
|
|
|
$return = $this->object->setFilesystemManager( new \Aimeos\Base\Filesystem\Manager\Standard( $config ) ); |
152
|
|
|
|
153
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Filesystem\Iface::class, $this->object->fs( 'fs-admin' ) ); |
154
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
public function testSetI18n() |
159
|
|
|
{ |
160
|
|
|
$context = \TestHelper::context(); |
161
|
|
|
|
162
|
|
|
$locale = \Aimeos\MShop::create( \TestHelper::context(), 'locale' )->create(); |
163
|
|
|
$this->object->setLocale( $locale->setLanguageId( 'en' ) ); |
164
|
|
|
|
165
|
|
|
$return = $this->object->setI18n( ['en' => $context->i18n()] ); |
166
|
|
|
|
167
|
|
|
$this->assertSame( $context->i18n(), $this->object->i18n() ); |
168
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
public function testTranslate() |
173
|
|
|
{ |
174
|
|
|
$context = \TestHelper::context(); |
175
|
|
|
|
176
|
|
|
$this->assertEquals( 'mr', $context->translate( 'mshop/code', 'mr' ) ); |
177
|
|
|
$this->assertEquals( 'two apples', $context->translate( 'mshop', 'one apple', 'two apples', 2 ) ); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
public function testSetLocale() |
182
|
|
|
{ |
183
|
|
|
$locale = \Aimeos\MShop::create( \TestHelper::context(), 'locale' )->create(); |
184
|
|
|
$return = $this->object->setLocale( $locale ); |
185
|
|
|
|
186
|
|
|
$this->assertSame( $locale, $this->object->locale() ); |
187
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
|
191
|
|
|
public function testSetLogger() |
192
|
|
|
{ |
193
|
|
|
$logger = new \Aimeos\Base\Logger\Errorlog(); |
194
|
|
|
$return = $this->object->setLogger( $logger ); |
195
|
|
|
|
196
|
|
|
$this->assertSame( $logger, $this->object->logger() ); |
197
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
public function testSetMail() |
202
|
|
|
{ |
203
|
|
|
$mail = new \Aimeos\Base\Mail\None(); |
204
|
|
|
$return = $this->object->setMail( $mail ); |
205
|
|
|
|
206
|
|
|
$this->assertSame( $mail, $this->object->mail() ); |
207
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
|
211
|
|
|
public function testSetMessageQueueManager() |
212
|
|
|
{ |
213
|
|
|
$config = \TestHelper::context()->config()->get( 'resource' ); |
214
|
|
|
$mq = new \Aimeos\Base\MQueue\Manager\Standard( $config ); |
215
|
|
|
$return = $this->object->setMessageQueueManager( $mq ); |
216
|
|
|
|
217
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
218
|
|
|
|
219
|
|
|
$this->object->queue( 'mq-test', 'test' ); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
|
223
|
|
|
public function testSetNonce() |
224
|
|
|
{ |
225
|
|
|
$return = $this->object->setNonce( 'abcdef' ); |
226
|
|
|
|
227
|
|
|
$this->assertEquals( 'abcdef', $this->object->nonce() ); |
228
|
|
|
$this->assertNull( $this->object->setNonce( null )->nonce() ); |
229
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
|
233
|
|
|
public function testSetPassword() |
234
|
|
|
{ |
235
|
|
|
$password = new \Aimeos\Base\Password\Standard(); |
236
|
|
|
$return = $this->object->setPassword( $password ); |
237
|
|
|
|
238
|
|
|
$this->assertSame( $password, $this->object->password() ); |
239
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
|
243
|
|
|
public function testSetProcess() |
244
|
|
|
{ |
245
|
|
|
$process = new \Aimeos\Base\Process\Pcntl(); |
246
|
|
|
$return = $this->object->setProcess( $process ); |
247
|
|
|
|
248
|
|
|
$this->assertSame( $process, $this->object->process() ); |
249
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
|
253
|
|
|
public function testSetSession() |
254
|
|
|
{ |
255
|
|
|
$session = new \Aimeos\Base\Session\None(); |
256
|
|
|
$return = $this->object->setSession( $session ); |
257
|
|
|
|
258
|
|
|
$this->assertSame( $session, $this->object->session() ); |
259
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
|
263
|
|
|
public function testSetToken() |
264
|
|
|
{ |
265
|
|
|
$return = $this->object->setToken( 'token-123' ); |
266
|
|
|
|
267
|
|
|
$this->assertEquals( 'token-123', $this->object->token() ); |
268
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
|
272
|
|
|
public function testSetView() |
273
|
|
|
{ |
274
|
|
|
$view = new \Aimeos\Base\View\Standard(); |
275
|
|
|
$return = $this->object->setView( $view ); |
276
|
|
|
|
277
|
|
|
$this->assertInstanceOf( \Aimeos\Base\View\Iface::class, $this->object->view() ); |
278
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
|
282
|
|
|
public function testGetSetEditor() |
283
|
|
|
{ |
284
|
|
|
$this->assertEquals( '', $this->object->editor() ); |
285
|
|
|
|
286
|
|
|
$return = $this->object->setEditor( 'testuser' ); |
287
|
|
|
|
288
|
|
|
$this->assertEquals( 'testuser', $this->object->editor() ); |
289
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
|
293
|
|
|
public function testGetSetUser() |
294
|
|
|
{ |
295
|
|
|
$mock = $this->getMockBuilder( \Aimeos\MShop\Customer\Item\Iface::class )->getMock(); |
296
|
|
|
$fcn = function() use ( $mock ) { |
297
|
|
|
return $mock; |
298
|
|
|
}; |
299
|
|
|
|
300
|
|
|
$this->assertEquals( null, $this->object->user() ); |
301
|
|
|
|
302
|
|
|
$return = $this->object->setUser( $fcn ); |
303
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
304
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Iface::class, $this->object->user() ); |
305
|
|
|
|
306
|
|
|
$return = $this->object->setUser( $fcn() ); |
307
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
308
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Iface::class, $this->object->user() ); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
|
312
|
|
|
public function testGetSetGroups() |
313
|
|
|
{ |
314
|
|
|
$fcn = function() { |
315
|
|
|
return [123 => 'admin']; |
316
|
|
|
}; |
317
|
|
|
|
318
|
|
|
$this->assertEquals( [], $this->object->groups() ); |
319
|
|
|
|
320
|
|
|
$return = $this->object->setGroups( $fcn ); |
321
|
|
|
$this->assertEquals( [123 => 'admin'], $this->object->groups() ); |
322
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
323
|
|
|
|
324
|
|
|
$return = $this->object->setGroups( $fcn() ); |
325
|
|
|
$this->assertEquals( [123 => 'admin'], $this->object->groups() ); |
326
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return ); |
327
|
|
|
} |
328
|
|
|
} |
329
|
|
|
|