|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Admin\JQAdm\Product\Price; |
|
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() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->view = \TestHelperJqadm::getView(); |
|
22
|
|
|
$this->context = \TestHelperJqadm::getContext(); |
|
23
|
|
|
$templatePaths = \TestHelperJqadm::getTemplatePaths(); |
|
24
|
|
|
|
|
25
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Product\Price\Standard( $this->context, $templatePaths ); |
|
26
|
|
|
$this->object->setView( $this->view ); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
protected function tearDown() |
|
31
|
|
|
{ |
|
32
|
|
|
unset( $this->object ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
public function testCreate() |
|
37
|
|
|
{ |
|
38
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' ); |
|
39
|
|
|
|
|
40
|
|
|
$this->view->item = $manager->createItem(); |
|
41
|
|
|
$result = $this->object->create(); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertContains( 'Prices', $result ); |
|
44
|
|
|
$this->assertNull( $this->view->get( 'errors' ) ); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
public function testCopy() |
|
49
|
|
|
{ |
|
50
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' ); |
|
51
|
|
|
|
|
52
|
|
|
$this->view->item = $manager->findItem( 'CNC', array( 'price' ) ); |
|
53
|
|
|
$result = $this->object->copy(); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertNull( $this->view->get( 'errors' ) ); |
|
56
|
|
|
$this->assertContains( 'value="for 1 product"', $result ); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
public function testDelete() |
|
61
|
|
|
{ |
|
62
|
|
|
$result = $this->object->delete(); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertNull( $this->view->get( 'errors' ) ); |
|
65
|
|
|
$this->assertNull( $result ); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
public function testGet() |
|
70
|
|
|
{ |
|
71
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' ); |
|
72
|
|
|
|
|
73
|
|
|
$this->view->item = $manager->findItem( 'CNC', array( 'price' ) ); |
|
74
|
|
|
$result = $this->object->get(); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertNull( $this->view->get( 'errors' ) ); |
|
77
|
|
|
$this->assertContains( 'value="for 1 product"', $result ); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
public function testSave() |
|
82
|
|
|
{ |
|
83
|
|
|
$typeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'price/type' ); |
|
84
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' ); |
|
85
|
|
|
|
|
86
|
|
|
$item = $manager->findItem( 'CNC' ); |
|
87
|
|
|
$item->setCode( 'jqadm-test-price' ); |
|
88
|
|
|
$item->setId( null ); |
|
89
|
|
|
|
|
90
|
|
|
$manager->saveItem( $item ); |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
$param = array( |
|
94
|
|
|
'price' => array( |
|
95
|
|
|
'product.lists.id' => array( '' ), |
|
96
|
|
|
'price.typeid' => array( $typeManager->findItem( 'default', array(), 'product' )->getId() ), |
|
97
|
|
|
'price.currencyid' => array( 'EUR' ), |
|
98
|
|
|
'price.label' => array( 'test' ), |
|
99
|
|
|
'price.quantity' => array( '2' ), |
|
100
|
|
|
'price.value' => array( '10.00' ), |
|
101
|
|
|
'price.costs' => array( '1.00' ), |
|
102
|
|
|
'price.rebate' => array( '5.00' ), |
|
103
|
|
|
'price.taxrate' => array( '20.00' ), |
|
104
|
|
|
), |
|
105
|
|
|
); |
|
106
|
|
|
|
|
107
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
|
108
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
109
|
|
|
$this->view->item = $item; |
|
110
|
|
|
|
|
111
|
|
|
$result = $this->object->save(); |
|
112
|
|
|
|
|
113
|
|
|
$item = $manager->getItem( $item->getId(), array( 'price' ) ); |
|
114
|
|
|
$manager->deleteItem( $item->getId() ); |
|
115
|
|
|
|
|
116
|
|
|
$this->assertNull( $this->view->get( 'errors' ) ); |
|
117
|
|
|
$this->assertNull( $result ); |
|
118
|
|
|
$this->assertEquals( 1, count( $item->getListItems() ) ); |
|
119
|
|
|
|
|
120
|
|
|
foreach( $item->getListItems( 'price' ) as $listItem ) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->assertEquals( 'price', $listItem->getDomain() ); |
|
123
|
|
|
$this->assertEquals( 'default', $listItem->getType() ); |
|
124
|
|
|
|
|
125
|
|
|
$refItem = $listItem->getRefItem(); |
|
126
|
|
|
$this->assertEquals( 'default', $refItem->getType() ); |
|
127
|
|
|
$this->assertEquals( 'EUR', $refItem->getCurrencyId() ); |
|
128
|
|
|
$this->assertEquals( 'test', $refItem->getLabel() ); |
|
129
|
|
|
$this->assertEquals( '2', $refItem->getQuantity() ); |
|
130
|
|
|
$this->assertEquals( '10.00', $refItem->getValue() ); |
|
131
|
|
|
$this->assertEquals( '1.00', $refItem->getCosts() ); |
|
132
|
|
|
$this->assertEquals( '5.00', $refItem->getRebate() ); |
|
133
|
|
|
$this->assertEquals( '20.00', $refItem->getTaxRate() ); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
|
|
138
|
|
|
public function testSaveException() |
|
139
|
|
|
{ |
|
140
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Price\Standard' ) |
|
141
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
|
142
|
|
|
->setMethods( array( 'updateItems' ) ) |
|
143
|
|
|
->getMock(); |
|
144
|
|
|
|
|
145
|
|
|
$object->expects( $this->once() )->method( 'updateItems' ) |
|
146
|
|
|
->will( $this->throwException( new \Exception() ) ); |
|
147
|
|
|
|
|
148
|
|
|
$object->setView( \TestHelperJqadm::getView() ); |
|
149
|
|
|
|
|
150
|
|
|
$this->setExpectedException( '\Aimeos\Admin\JQAdm\Exception' ); |
|
|
|
|
|
|
151
|
|
|
$object->save(); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
public function testSaveMShopException() |
|
156
|
|
|
{ |
|
157
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Price\Standard' ) |
|
158
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
|
159
|
|
|
->setMethods( array( 'updateItems' ) ) |
|
160
|
|
|
->getMock(); |
|
161
|
|
|
|
|
162
|
|
|
$object->expects( $this->once() )->method( 'updateItems' ) |
|
163
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
|
164
|
|
|
|
|
165
|
|
|
$object->setView( \TestHelperJqadm::getView() ); |
|
166
|
|
|
|
|
167
|
|
|
$this->setExpectedException( '\Aimeos\Admin\JQAdm\Exception' ); |
|
|
|
|
|
|
168
|
|
|
$object->save(); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
public function testSearch() |
|
173
|
|
|
{ |
|
174
|
|
|
$this->assertNull( $this->object->search() ); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
|
|
178
|
|
|
public function testGetSubClient() |
|
179
|
|
|
{ |
|
180
|
|
|
$this->setExpectedException( '\Aimeos\Admin\JQAdm\Exception' ); |
|
|
|
|
|
|
181
|
|
|
$this->object->getSubClient( 'invalid' ); |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.