|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2025 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Admin\JQAdm\Product\Physical; |
|
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 = \TestHelper::view(); |
|
22
|
|
|
$this->context = \TestHelper::context(); |
|
23
|
|
|
|
|
24
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Product\Physical\Standard( $this->context ); |
|
25
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context ); |
|
26
|
|
|
$this->object->setAimeos( \TestHelper::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 testCreate() |
|
38
|
|
|
{ |
|
39
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
|
40
|
|
|
|
|
41
|
|
|
$this->view->item = $manager->create(); |
|
42
|
|
|
$result = $this->object->create(); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertStringContainsString( 'item-physical', $result ); |
|
45
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
public function testCopy() |
|
50
|
|
|
{ |
|
51
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
|
52
|
|
|
|
|
53
|
|
|
$this->view->item = $manager->find( 'CNC', ['product/property'] ); |
|
54
|
|
|
$result = $this->object->copy(); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
|
57
|
|
|
$this->assertStringContainsString( 'value="20.0"', $result ); |
|
58
|
|
|
$this->assertStringContainsString( 'value="15.0"', $result ); |
|
59
|
|
|
$this->assertStringContainsString( 'value="10.0"', $result ); |
|
60
|
|
|
$this->assertStringContainsString( 'value="1.25"', $result ); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
public function testGet() |
|
65
|
|
|
{ |
|
66
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
|
67
|
|
|
|
|
68
|
|
|
$this->view->item = $manager->find( 'CNC', ['product/property'] ); |
|
69
|
|
|
$result = $this->object->get(); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
|
72
|
|
|
$this->assertStringContainsString( 'value="20.0"', $result ); |
|
73
|
|
|
$this->assertStringContainsString( 'value="15.0"', $result ); |
|
74
|
|
|
$this->assertStringContainsString( 'value="10.0"', $result ); |
|
75
|
|
|
$this->assertStringContainsString( 'value="1.25"', $result ); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
public function testSave() |
|
80
|
|
|
{ |
|
81
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
|
82
|
|
|
$this->view->item = $manager->create(); |
|
83
|
|
|
|
|
84
|
|
|
$param = array( |
|
85
|
|
|
'site' => 'unittest', |
|
86
|
|
|
'physical' => array( |
|
87
|
|
|
'package-length' => '10.00', |
|
88
|
|
|
'package-weight' => '5.25', |
|
89
|
|
|
), |
|
90
|
|
|
); |
|
91
|
|
|
|
|
92
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
|
93
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
94
|
|
|
|
|
95
|
|
|
$result = $this->object->save(); |
|
96
|
|
|
|
|
97
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
|
98
|
|
|
$this->assertEmpty( $result ); |
|
99
|
|
|
$this->assertEquals( 2, count( $this->view->item->getPropertyItems() ) ); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
public function testSaveException() |
|
104
|
|
|
{ |
|
105
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Product\Physical\Standard::class ) |
|
106
|
|
|
->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) ) |
|
107
|
|
|
->onlyMethods( array( 'fromArray' ) ) |
|
108
|
|
|
->getMock(); |
|
109
|
|
|
|
|
110
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
|
111
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
|
112
|
|
|
|
|
113
|
|
|
$this->view = \TestHelper::view(); |
|
114
|
|
|
$this->view->item = \Aimeos\MShop::create( $this->context, 'product' )->create(); |
|
115
|
|
|
|
|
116
|
|
|
$object->setView( $this->view ); |
|
117
|
|
|
|
|
118
|
|
|
$this->expectException( \RuntimeException::class ); |
|
119
|
|
|
$object->save(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
public function testSaveMShopException() |
|
124
|
|
|
{ |
|
125
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Product\Physical\Standard::class ) |
|
126
|
|
|
->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) ) |
|
127
|
|
|
->onlyMethods( array( 'fromArray' ) ) |
|
128
|
|
|
->getMock(); |
|
129
|
|
|
|
|
130
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
|
131
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
|
132
|
|
|
|
|
133
|
|
|
$this->view = \TestHelper::view(); |
|
134
|
|
|
$this->view->item = \Aimeos\MShop::create( $this->context, 'product' )->create(); |
|
135
|
|
|
|
|
136
|
|
|
$object->setView( $this->view ); |
|
137
|
|
|
|
|
138
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
|
139
|
|
|
$object->save(); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
public function testGetSubClient() |
|
144
|
|
|
{ |
|
145
|
|
|
$this->expectException( \LogicException::class ); |
|
146
|
|
|
$this->object->getSubClient( 'unknown' ); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|