1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Customer\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\Customer\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->object->cleanup( array( -1 ) ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
public function testCreateItem() |
38
|
|
|
{ |
39
|
|
|
$item = $this->object->createItem(); |
40
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Property\\Iface', $item ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testSaveInvalid() |
45
|
|
|
{ |
46
|
|
|
$this->setExpectedException( '\Aimeos\MShop\Exception' ); |
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( '==', 'customer.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->getTypeId(), $itemSaved->getTypeId() ); |
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->getTypeId(), $itemUpd->getTypeId() ); |
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', $resultSaved ); |
101
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultUpd ); |
102
|
|
|
|
103
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
104
|
|
|
$this->object->getItem( $itemSaved->getId() ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
public function testGetItem() |
109
|
|
|
{ |
110
|
|
|
$search = $this->object->createSearch(); |
111
|
|
|
$conditions = array( |
112
|
|
|
$search->compare( '~=', 'customer.property.value', '1'), |
113
|
|
|
$search->compare( '==', 'customer.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 customer property item found for value "%1$s".', '1' ) ); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$actual = $this->object->getItem( $expected->getId() ); |
123
|
|
|
$this->assertNotEquals( '', $actual->getTypeName() ); |
124
|
|
|
$this->assertEquals( $expected, $actual ); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
public function testGetResourceType() |
129
|
|
|
{ |
130
|
|
|
$result = $this->object->getResourceType(); |
131
|
|
|
|
132
|
|
|
$this->assertContains( 'customer/property', $result ); |
133
|
|
|
$this->assertContains( 'customer/property/type', $result ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
public function testGetSearchAttributes() |
138
|
|
|
{ |
139
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) { |
140
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute ); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
public function testSearchItems() |
146
|
|
|
{ |
147
|
|
|
$total = 0; |
148
|
|
|
$search = $this->object->createSearch(); |
149
|
|
|
|
150
|
|
|
$expr = []; |
151
|
|
|
$expr[] = $search->compare( '!=', 'customer.property.id', null ); |
152
|
|
|
$expr[] = $search->compare( '!=', 'customer.property.parentid', null ); |
153
|
|
|
$expr[] = $search->compare( '!=', 'customer.property.siteid', null ); |
154
|
|
|
$expr[] = $search->compare( '!=', 'customer.property.typeid', null ); |
155
|
|
|
$expr[] = $search->compare( '==', 'customer.property.languageid', null ); |
156
|
|
|
$expr[] = $search->compare( '==', 'customer.property.value', '1' ); |
157
|
|
|
$expr[] = $search->compare( '==', 'customer.property.editor', $this->editor ); |
158
|
|
|
|
159
|
|
|
$expr[] = $search->compare( '!=', 'customer.property.type.id', null ); |
160
|
|
|
$expr[] = $search->compare( '!=', 'customer.property.type.siteid', null ); |
161
|
|
|
$expr[] = $search->compare( '==', 'customer.property.type.domain', 'customer' ); |
162
|
|
|
$expr[] = $search->compare( '==', 'customer.property.type.code', 'newsletter' ); |
163
|
|
|
$expr[] = $search->compare( '>', 'customer.property.type.label', '' ); |
164
|
|
|
$expr[] = $search->compare( '==', 'customer.property.type.status', 1 ); |
165
|
|
|
$expr[] = $search->compare( '>=', 'customer.property.type.mtime', '1970-01-01 00:00:00' ); |
166
|
|
|
$expr[] = $search->compare( '>=', 'customer.property.type.ctime', '1970-01-01 00:00:00' ); |
167
|
|
|
$expr[] = $search->compare( '==', 'customer.property.type.editor', $this->editor ); |
168
|
|
|
|
169
|
|
|
$search->setConditions( $search->combine('&&', $expr) ); |
170
|
|
|
$results = $this->object->searchItems( $search, [], $total ); |
171
|
|
|
$this->assertEquals( 1, count( $results ) ); |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
$search = $this->object->createSearch(); |
175
|
|
|
$conditions = array( |
176
|
|
|
$search->compare( '=~', 'customer.property.type.code', 'newsletter' ), |
177
|
|
|
$search->compare( '==', 'customer.property.editor', $this->editor ) |
178
|
|
|
); |
179
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
180
|
|
|
$search->setSlice(0, 1); |
181
|
|
|
$items = $this->object->searchItems( $search, [], $total ); |
182
|
|
|
|
183
|
|
|
$this->assertEquals( 1, count( $items ) ); |
184
|
|
|
$this->assertEquals( 1, $total ); |
185
|
|
|
|
186
|
|
|
foreach($items as $itemId => $item) { |
187
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
public function testGetSubManager() |
193
|
|
|
{ |
194
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager('type') ); |
195
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager('type', 'Standard') ); |
196
|
|
|
|
197
|
|
|
$this->setExpectedException('\\Aimeos\\MShop\\Exception'); |
198
|
|
|
$this->object->getSubManager('unknown'); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
|
202
|
|
|
public function testGetSubManagerInvalidName() |
203
|
|
|
{ |
204
|
|
|
$this->setExpectedException('\\Aimeos\\MShop\\Exception'); |
205
|
|
|
$this->object->getSubManager('type', 'unknown'); |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|