1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2019 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Price\Manager\Property; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $editor = ''; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
$this->editor = \TestHelperMShop::getContext()->getEditor(); |
21
|
|
|
$this->object = new \Aimeos\MShop\Price\Manager\Property\Standard( \TestHelperMShop::getContext() ); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
protected function tearDown() |
26
|
|
|
{ |
27
|
|
|
unset( $this->object ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
public function testCleanup() |
32
|
|
|
{ |
33
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->cleanup( [-1] ) ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
public function testCreateItem() |
38
|
|
|
{ |
39
|
|
|
$item = $this->object->createItem(); |
40
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $item ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testSaveInvalid() |
45
|
|
|
{ |
46
|
|
|
$this->setExpectedException( \Aimeos\MW\Common\Exception::class ); |
47
|
|
|
$this->object->saveItem( new \Aimeos\MShop\Locale\Item\Standard() ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
public function testSaveUpdateDeleteItem() |
52
|
|
|
{ |
53
|
|
|
$search = $this->object->createSearch(); |
54
|
|
|
$search->setConditions( $search->compare( '==', 'price.property.editor', $this->editor ) ); |
55
|
|
|
$results = $this->object->searchItems( $search ); |
56
|
|
|
|
57
|
|
|
if( ( $item = reset($results) ) === false ) { |
58
|
|
|
throw new \RuntimeException( 'No property item found' ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$item->setId(null); |
62
|
|
|
$item->setLanguageId( 'en' ); |
63
|
|
|
$resultSaved = $this->object->saveItem( $item ); |
64
|
|
|
$itemSaved = $this->object->getItem( $item->getId() ); |
65
|
|
|
|
66
|
|
|
$itemExp = clone $itemSaved; |
67
|
|
|
$itemExp->setValue( 'unittest' ); |
68
|
|
|
$resultUpd = $this->object->saveItem( $itemExp ); |
69
|
|
|
$itemUpd = $this->object->getItem( $itemExp->getId() ); |
70
|
|
|
|
71
|
|
|
$this->object->deleteItem( $itemSaved->getId() ); |
72
|
|
|
|
73
|
|
|
$context = \TestHelperMShop::getContext(); |
74
|
|
|
|
75
|
|
|
$this->assertTrue( $item->getId() !== null ); |
76
|
|
|
$this->assertTrue( $itemSaved->getType() !== null ); |
77
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
78
|
|
|
$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); |
79
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
80
|
|
|
$this->assertEquals( $item->getType(), $itemSaved->getType() ); |
81
|
|
|
$this->assertEquals( $item->getLanguageId(), $itemSaved->getLanguageId() ); |
82
|
|
|
$this->assertEquals( $item->getValue(), $itemSaved->getValue() ); |
83
|
|
|
|
84
|
|
|
$this->assertEquals( $context->getEditor(), $itemSaved->getEditor() ); |
85
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
86
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
87
|
|
|
|
88
|
|
|
$this->assertTrue( $itemUpd->getType() !== null ); |
89
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
90
|
|
|
$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); |
91
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
92
|
|
|
$this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
93
|
|
|
$this->assertEquals( $itemExp->getLanguageId(), $itemUpd->getLanguageId() ); |
94
|
|
|
$this->assertEquals( $itemExp->getValue(), $itemUpd->getValue() ); |
95
|
|
|
|
96
|
|
|
$this->assertEquals( $context->getEditor(), $itemUpd->getEditor() ); |
97
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
98
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
99
|
|
|
|
100
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
101
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
102
|
|
|
|
103
|
|
|
$this->setExpectedException( \Aimeos\MShop\Exception::class ); |
104
|
|
|
$this->object->getItem( $itemSaved->getId() ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
public function testGetItem() |
109
|
|
|
{ |
110
|
|
|
$search = $this->object->createSearch()->setSlice( 0, 1 ); |
111
|
|
|
$conditions = array( |
112
|
|
|
$search->compare( '~=', 'price.property.value', '5.0'), |
113
|
|
|
$search->compare( '==', 'price.property.editor', $this->editor ) |
114
|
|
|
); |
115
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
116
|
|
|
$results = $this->object->searchItems( $search ); |
117
|
|
|
|
118
|
|
|
if( ($expected = reset($results)) === false ) { |
119
|
|
|
throw new \RuntimeException( sprintf( 'No price property item found for value "%1$s".', '1024' ) ); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$actual = $this->object->getItem( $expected->getId() ); |
123
|
|
|
$this->assertEquals( $expected, $actual ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
public function testGetResourceType() |
128
|
|
|
{ |
129
|
|
|
$result = $this->object->getResourceType(); |
130
|
|
|
|
131
|
|
|
$this->assertContains( 'price/property', $result ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
public function testGetSearchAttributes() |
136
|
|
|
{ |
137
|
|
|
foreach( $this->object->getSearchAttributes() as $price ) { |
138
|
|
|
$this->assertInstanceOf( \Aimeos\MW\Criteria\Attribute\Iface::class, $price ); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
public function testSearchItems() |
144
|
|
|
{ |
145
|
|
|
$total = 0; |
146
|
|
|
$search = $this->object->createSearch(); |
147
|
|
|
|
148
|
|
|
$expr = []; |
149
|
|
|
$expr[] = $search->compare( '!=', 'price.property.id', null ); |
150
|
|
|
$expr[] = $search->compare( '!=', 'price.property.parentid', null ); |
151
|
|
|
$expr[] = $search->compare( '!=', 'price.property.siteid', null ); |
152
|
|
|
$expr[] = $search->compare( '==', 'price.property.type', 'taxrate-local' ); |
153
|
|
|
$expr[] = $search->compare( '==', 'price.property.languageid', null ); |
154
|
|
|
$expr[] = $search->compare( '==', 'price.property.value', '5.0' ); |
155
|
|
|
$expr[] = $search->compare( '==', 'price.property.editor', $this->editor ); |
156
|
|
|
|
157
|
|
|
$search->setConditions( $search->combine('&&', $expr) ); |
158
|
|
|
$results = $this->object->searchItems( $search, [], $total ); |
159
|
|
|
$this->assertEquals( 4, count( $results ) ); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
public function testGetSubManager() |
164
|
|
|
{ |
165
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager('type') ); |
166
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager('type', 'Standard') ); |
167
|
|
|
|
168
|
|
|
$this->setExpectedException( \Aimeos\MShop\Exception::class ); |
169
|
|
|
$this->object->getSubManager('unknown'); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
public function testGetSubManagerInvalidName() |
174
|
|
|
{ |
175
|
|
|
$this->setExpectedException( \Aimeos\MShop\Exception::class ); |
176
|
|
|
$this->object->getSubManager('type', 'unknown'); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|