Passed
Push — master ( 57ed15...c8b0fe )
by Aimeos
24:08 queued 14:12
created

StandardTest::testGetQueue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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