|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2020 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Admin\JQAdm\Supplier\Product; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $context; |
|
15
|
|
|
private $object; |
|
16
|
|
|
private $view; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
protected function setUp() : void |
|
20
|
|
|
{ |
|
21
|
|
|
$this->view = \TestHelperJqadm::getView(); |
|
22
|
|
|
$this->context = \TestHelperJqadm::getContext(); |
|
23
|
|
|
|
|
24
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Supplier\Product\Standard( $this->context ); |
|
25
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context ); |
|
26
|
|
|
$this->object->setAimeos( \TestHelperJqadm::getAimeos() ); |
|
27
|
|
|
$this->object->setView( $this->view ); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
protected function tearDown() : void |
|
32
|
|
|
{ |
|
33
|
|
|
unset( $this->object, $this->view, $this->context ); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
public function testCopy() |
|
38
|
|
|
{ |
|
39
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'supplier' ); |
|
40
|
|
|
$this->view->item = $manager->findItem( 'unitCode001' ); |
|
41
|
|
|
|
|
42
|
|
|
$result = $this->object->copy(); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertStringContainsString( 'item-product', $result ); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
public function testCreate() |
|
49
|
|
|
{ |
|
50
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'supplier' ); |
|
51
|
|
|
$this->view->item = $manager->findItem( 'unitCode001' ); |
|
52
|
|
|
|
|
53
|
|
|
$result = $this->object->create(); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertStringContainsString( 'item-product', $result ); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
public function testGet() |
|
60
|
|
|
{ |
|
61
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'supplier' ); |
|
62
|
|
|
$this->view->item = $manager->findItem( 'unitCode001' ); |
|
63
|
|
|
|
|
64
|
|
|
$result = $this->object->get(); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertStringContainsString( 'item-product', $result ); |
|
67
|
|
|
$this->assertStringContainsString( 'default', $result ); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
public function testSave() |
|
72
|
|
|
{ |
|
73
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'supplier' ); |
|
74
|
|
|
|
|
75
|
|
|
$item = $manager->findItem( 'unitCode001' ); |
|
76
|
|
|
$item->setCode( 'jqadm-test-save' ); |
|
77
|
|
|
$item->setId( null ); |
|
78
|
|
|
|
|
79
|
|
|
$item = $manager->saveItem( $item ); |
|
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
$param = array( |
|
83
|
|
|
'site' => 'unittest', |
|
84
|
|
|
'product' => array( |
|
85
|
|
|
'supplier.lists.id' => [0 => ''], |
|
86
|
|
|
'supplier.lists.status' => [0 => 1], |
|
87
|
|
|
'supplier.lists.refid' => [0 => 'test'], |
|
88
|
|
|
'supplier.lists.type' => [0 => 'default'], |
|
89
|
|
|
'supplier.lists.datestart' => [0 => '2000-01-01 00:00:00'], |
|
90
|
|
|
'supplier.lists.dateend' => [0 => '2100-01-01 00:00:00'], |
|
91
|
|
|
'config' => [0 => ['key' => [0 => 'test'], 'val' => [0 => 'value']]], |
|
92
|
|
|
), |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
|
96
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
97
|
|
|
$this->view->item = $item; |
|
98
|
|
|
|
|
99
|
|
|
$result = $this->object->save(); |
|
100
|
|
|
|
|
101
|
|
|
$item = $manager->getItem( $item->getId(), ['product'] ); |
|
102
|
|
|
$manager->deleteItem( $item->getId() ); |
|
103
|
|
|
|
|
104
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
|
105
|
|
|
$this->assertEmpty( $result ); |
|
106
|
|
|
$this->assertEquals( 1, count( $item->getListItems() ) ); |
|
107
|
|
|
|
|
108
|
|
|
foreach( $item->getListItems( 'product' ) as $listItem ) |
|
109
|
|
|
{ |
|
110
|
|
|
$this->assertEquals( $item->getId(), $listItem->getParentId() ); |
|
111
|
|
|
$this->assertEquals( 'default', $listItem->getType() ); |
|
112
|
|
|
$this->assertEquals( 'product', $listItem->getDomain() ); |
|
113
|
|
|
$this->assertEquals( '2000-01-01 00:00:00', $listItem->getDateStart() ); |
|
114
|
|
|
$this->assertEquals( '2100-01-01 00:00:00', $listItem->getDateEnd() ); |
|
115
|
|
|
$this->assertEquals( ['test' => 'value'], $listItem->getConfig() ); |
|
116
|
|
|
$this->assertEquals( 'test', $listItem->getRefId() ); |
|
117
|
|
|
$this->assertEquals( 1, $listItem->getStatus() ); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
public function testSaveException() |
|
123
|
|
|
{ |
|
124
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Supplier\Product\Standard::class ) |
|
125
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
|
126
|
|
|
->setMethods( array( 'fromArray' ) ) |
|
127
|
|
|
->getMock(); |
|
128
|
|
|
|
|
129
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
|
130
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
|
131
|
|
|
|
|
132
|
|
|
$object->setView( $this->getViewNoRender() ); |
|
133
|
|
|
|
|
134
|
|
|
$this->expectException( \RuntimeException::class ); |
|
135
|
|
|
$object->save(); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
public function testGetSubClient() |
|
140
|
|
|
{ |
|
141
|
|
|
$this->expectException( \Aimeos\Admin\JQAdm\Exception::class ); |
|
142
|
|
|
$this->object->getSubClient( 'unknown' ); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
protected function getViewNoRender() |
|
147
|
|
|
{ |
|
148
|
|
|
$view = $this->getMockBuilder( \Aimeos\MW\View\Standard::class ) |
|
149
|
|
|
->setConstructorArgs( array( [] ) ) |
|
150
|
|
|
->setMethods( array( 'render', 'config' ) ) |
|
151
|
|
|
->getMock(); |
|
152
|
|
|
|
|
153
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'supplier' ); |
|
154
|
|
|
$view->item = $manager->findItem( 'unitCode001' ); |
|
|
|
|
|
|
155
|
|
|
|
|
156
|
|
|
return $view; |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.