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