Passed
Push — master ( 5a84de...2d6aa3 )
by Aimeos
05:36
created

ContextTest::testGetLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2022
6
 */
7
8
9
namespace Aimeos\Base;
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->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() );
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 testSetConfig()
114
	{
115
		$config = new \Aimeos\Base\Config\PHPArray();
116
		$return = $this->object->setConfig( $config );
117
118
		$this->assertSame( $config, $this->object->config() );
119
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
120
	}
121
122
123
	public function testSetDatabaseManager()
124
	{
125
		$config = new \Aimeos\Base\Config\PHPArray();
126
		$dbm = new \Aimeos\Base\DB\Manager\PDO( $config );
127
		$return = $this->object->setDatabaseManager( $dbm );
128
129
		$this->assertSame( $dbm, $this->object->db() );
130
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::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\ContextIface::class, $return );
140
	}
141
142
143
	public function testSetFilesystemManager()
144
	{
145
		$config = \TestHelper::context()->config()->get( 'resource' );
146
		$return = $this->object->setFilesystemManager( new \Aimeos\Base\Filesystem\Manager\Standard( $config ) );
147
148
		$this->assertInstanceOf( \Aimeos\Base\Filesystem\Iface::class, $this->object->fs( 'fs-admin' ) );
149
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
150
	}
151
152
153
	public function testSetI18n()
154
	{
155
		$context = \TestHelper::context();
156
157
		$locale = \Aimeos\MShop\Locale\Manager\Factory::create( \TestHelper::context() )->create();
158
		$this->object->setLocale( $locale->setLanguageId( 'en' ) );
159
160
		$return = $this->object->setI18n( ['en' => $context->i18n()] );
161
162
		$this->assertSame( $context->i18n(), $this->object->i18n() );
163
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
164
	}
165
166
167
	public function testTranslate()
168
	{
169
		$context = \TestHelper::context();
170
171
		$this->assertEquals( 'mr', $context->translate( 'mshop/code', 'mr' ) );
172
		$this->assertEquals( 'two apples', $context->translate( 'mshop', 'one apple', 'two apples', 2 ) );
173
	}
174
175
176
	public function testSetLocale()
177
	{
178
		$locale = \Aimeos\MShop\Locale\Manager\Factory::create( \TestHelper::context() )->create();
179
		$return = $this->object->setLocale( $locale );
180
181
		$this->assertSame( $locale, $this->object->locale() );
182
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
183
	}
184
185
186
	public function testSetLogger()
187
	{
188
		$logger = new \Aimeos\Base\Logger\Errorlog();
189
		$return = $this->object->setLogger( $logger );
190
191
		$this->assertSame( $logger, $this->object->logger() );
192
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
193
	}
194
195
196
	public function testSetMail()
197
	{
198
		$mail = new \Aimeos\Base\Mail\None();
199
		$return = $this->object->setMail( $mail );
200
201
		$this->assertSame( $mail, $this->object->mail() );
202
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
203
	}
204
205
206
	public function testSetMessageQueueManager()
207
	{
208
		$config = \TestHelper::context()->config();
209
		$mq = new \Aimeos\Base\MQueue\Manager\Standard( $config );
210
		$return = $this->object->setMessageQueueManager( $mq );
211
212
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
213
214
		$this->object->queue( 'mq-test', 'test' );
215
	}
216
217
218
	public function testSetNonce()
219
	{
220
		$return = $this->object->setNonce( 'abcdef' );
221
222
		$this->assertEquals( 'abcdef', $this->object->nonce() );
223
		$this->assertNull( $this->object->setNonce( null )->nonce() );
224
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
225
	}
226
227
228
	public function testSetPassword()
229
	{
230
		$password = new \Aimeos\Base\Password\Standard();
231
		$return = $this->object->setPassword( $password );
232
233
		$this->assertSame( $password, $this->object->password() );
234
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
235
	}
236
237
238
	public function testSetProcess()
239
	{
240
		$process = new \Aimeos\Base\Process\Pcntl();
241
		$return = $this->object->setProcess( $process );
242
243
		$this->assertSame( $process, $this->object->process() );
244
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
245
	}
246
247
248
	public function testSetSession()
249
	{
250
		$session = new \Aimeos\Base\Session\None();
251
		$return = $this->object->setSession( $session );
252
253
		$this->assertSame( $session, $this->object->session() );
254
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
255
	}
256
257
258
	public function testSetView()
259
	{
260
		$view = new \Aimeos\Base\View\Standard();
261
		$return = $this->object->setView( $view );
262
263
		$this->assertInstanceOf( \Aimeos\Base\View\Iface::class, $this->object->view() );
264
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
265
	}
266
267
268
	public function testGetSetEditor()
269
	{
270
		$this->assertEquals( '', $this->object->editor() );
271
272
		$return = $this->object->setEditor( 'testuser' );
273
274
		$this->assertEquals( 'testuser', $this->object->editor() );
275
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
276
	}
277
278
279
	public function testGetSetUserId()
280
	{
281
		$this->assertEquals( null, $this->object->user() );
282
283
		$return = $this->object->setUserId( 123 );
284
		$this->assertEquals( '123', $this->object->user() );
285
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
286
287
		$return = $this->object->setUserId( function() { return 456; } );
288
		$this->assertEquals( '456', $this->object->user() );
289
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
290
	}
291
292
293
	public function testGetSetGroupIds()
294
	{
295
		$this->assertEquals( [], $this->object->groups() );
296
297
		$return = $this->object->setGroupIds( array( 123 ) );
298
		$this->assertEquals( array( '123' ), $this->object->groups() );
299
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
300
301
		$return = $this->object->setGroupIds( function() { return array( 456 ); } );
302
		$this->assertEquals( array( '456' ), $this->object->groups() );
303
		$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $return );
304
	}
305
}
306