|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2021 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Admin\JsonAdm\Common\Factory; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class BaseTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $client; |
|
15
|
|
|
private $context; |
|
16
|
|
|
private $object; |
|
17
|
|
|
private $view; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
protected function setUp() : void |
|
21
|
|
|
{ |
|
22
|
|
|
$this->context = \TestHelperJadm::getContext(); |
|
23
|
|
|
$this->view = $this->context->getView(); |
|
24
|
|
|
|
|
25
|
|
|
$this->client = new \Aimeos\Admin\JsonAdm\Product\Standard( $this->context, '' ); |
|
26
|
|
|
|
|
27
|
|
|
$this->object = $this->getMockBuilder( \Aimeos\Admin\JsonAdm\Common\Factory\Base::class ) |
|
28
|
|
|
->getMockForAbstractClass(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
public function testInjectClient() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->object->injectClient( 'test', $this->client ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
public function testClientDecorator() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->context->getConfig()->set( 'admin/jsonadm/common/decorators/default', ['Example'] ); |
|
41
|
|
|
|
|
42
|
|
|
$result = \Aimeos\Admin\JsonAdm::create( $this->context, \TestHelperJadm::getAimeos(), 'product' ); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertInstanceOf( '\Aimeos\Admin\JsonAdm\Iface', $result ); |
|
45
|
|
|
$this->assertInstanceOf( '\Aimeos\Admin\JsonAdm\Common\Decorator\Iface', $result ); |
|
46
|
|
|
$this->assertEquals( 'Aimeos\Admin\JsonAdm\Common\Decorator\Example', get_class( $result ) ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
public function testAddClientDecorators() |
|
51
|
|
|
{ |
|
52
|
|
|
$config = $this->context->getConfig(); |
|
53
|
|
|
$config->set( 'admin/jsonadm/common/decorators/default', ['Test'] ); |
|
54
|
|
|
$config->set( 'admin/jsonadm/product/decorators/excludes', ['Test'] ); |
|
55
|
|
|
|
|
56
|
|
|
$params = [$this->client, $this->context, 'product']; |
|
57
|
|
|
$result = $this->access( 'addClientDecorators' )->invokeArgs( $this->object, $params ); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertInstanceOf( '\Aimeos\\Admin\\JsonAdm\\Iface', $result ); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
public function testAddDecorators() |
|
64
|
|
|
{ |
|
65
|
|
|
$prefix = '\Aimeos\\Admin\\JsonAdm\\Common\\Decorator\\'; |
|
66
|
|
|
$params = [$this->client, ['Example'], $prefix, $this->context, '']; |
|
67
|
|
|
|
|
68
|
|
|
$result = $this->access( 'addDecorators' )->invokeArgs( $this->object, $params ); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertInstanceOf( '\Aimeos\\Admin\\JsonAdm\\Iface', $result ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
public function testAddDecoratorsInvalidClass() |
|
75
|
|
|
{ |
|
76
|
|
|
$prefix = '\Aimeos\\Admin\\JsonAdm\\Common\\Decorator\\'; |
|
77
|
|
|
$params = [$this->client, ['Test'], $prefix, $this->context, '']; |
|
78
|
|
|
|
|
79
|
|
|
$this->expectException( \Aimeos\Admin\JsonAdm\Exception::class ); |
|
80
|
|
|
$this->access( 'addDecorators' )->invokeArgs( $this->object, $params ); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
public function testAddDecoratorsInvalidName() |
|
85
|
|
|
{ |
|
86
|
|
|
$prefix = '\Aimeos\\Admin\\JsonAdm\\Common\\Decorator\\'; |
|
87
|
|
|
$params = [$this->client, [''], $prefix, $this->context, '']; |
|
88
|
|
|
|
|
89
|
|
|
$this->expectException( \Aimeos\Admin\JsonAdm\Exception::class ); |
|
90
|
|
|
$this->access( 'addDecorators' )->invokeArgs( $this->object, $params ); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
public function testCreateClientBase() |
|
95
|
|
|
{ |
|
96
|
|
|
$iface = '\Aimeos\\Admin\\JsonAdm\\Iface'; |
|
97
|
|
|
$class = '\Aimeos\\Admin\\JsonAdm\\Product\\Standard'; |
|
98
|
|
|
$params = [$class, $iface, $this->context, '']; |
|
99
|
|
|
|
|
100
|
|
|
$result = $this->access( 'createAdmin' )->invokeArgs( $this->object, $params ); |
|
101
|
|
|
|
|
102
|
|
|
$this->assertInstanceOf( '\Aimeos\\Admin\\JsonAdm\\Iface', $result ); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
public function testCreateClientBaseCache() |
|
107
|
|
|
{ |
|
108
|
|
|
$iface = '\Aimeos\\Admin\\JsonAdm\\Iface'; |
|
109
|
|
|
$params = ['test', $iface, $this->context, '']; |
|
110
|
|
|
|
|
111
|
|
|
$this->object->injectClient( 'test', $this->client ); |
|
112
|
|
|
$result = $this->access( 'createAdmin' )->invokeArgs( $this->object, $params ); |
|
113
|
|
|
|
|
114
|
|
|
$this->assertSame( $this->client, $result ); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
public function testCreateClientBaseInvalidClass() |
|
119
|
|
|
{ |
|
120
|
|
|
$iface = '\Aimeos\\Admin\\JsonAdm\\Iface'; |
|
121
|
|
|
$params = ['invalid', $iface, $this->context, '']; |
|
122
|
|
|
|
|
123
|
|
|
$this->expectException( \Aimeos\Admin\JsonAdm\Exception::class ); |
|
124
|
|
|
$this->access( 'createAdmin' )->invokeArgs( $this->object, $params ); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
public function testCreateClientBaseInvalidIface() |
|
129
|
|
|
{ |
|
130
|
|
|
$iface = '\Aimeos\\Admin\\JsonAdm\\Common\\Decorator\\Iface'; |
|
131
|
|
|
$class = '\Aimeos\\Admin\\JsonAdm\\Product\\Standard'; |
|
132
|
|
|
$params = [$class, $iface, $this->context, '']; |
|
133
|
|
|
|
|
134
|
|
|
$this->expectException( \Aimeos\MW\Common\Exception::class ); |
|
135
|
|
|
$this->access( 'createAdmin' )->invokeArgs( $this->object, $params ); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
protected function access( $name ) |
|
140
|
|
|
{ |
|
141
|
|
|
$class = new \ReflectionClass( \Aimeos\Admin\JsonAdm\Common\Factory\Base::class ); |
|
142
|
|
|
$method = $class->getMethod( $name ); |
|
143
|
|
|
$method->setAccessible( true ); |
|
144
|
|
|
|
|
145
|
|
|
return $method; |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|