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\Type; |
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
|
|
|
$manager = \Aimeos\MShop\Customer\Manager\Factory::createManager( \TestHelperMShop::getContext() ); |
22
|
|
|
$this->object = $manager->getSubManager( 'property' )->getSubManager('type'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
protected function tearDown() |
27
|
|
|
{ |
28
|
|
|
unset($this->object); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
public function testCleanup() |
33
|
|
|
{ |
34
|
|
|
$this->object->cleanup( array( -1 ) ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
public function testCreateItem() |
39
|
|
|
{ |
40
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Type\\Iface', $this->object->createItem() ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testGetResourceType() |
45
|
|
|
{ |
46
|
|
|
$result = $this->object->getResourceType(); |
47
|
|
|
|
48
|
|
|
$this->assertContains( 'customer/property/type', $result ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
public function testGetSearchAttributes() |
53
|
|
|
{ |
54
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) { |
55
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute ); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
public function testGetItem() |
61
|
|
|
{ |
62
|
|
|
$search = $this->object->createSearch(); |
63
|
|
|
$conditions = array( |
64
|
|
|
$search->compare( '==', 'customer.property.type.code', 'newsletter' ), |
65
|
|
|
$search->compare( '==', 'customer.property.type.editor', $this->editor ) |
66
|
|
|
); |
67
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
68
|
|
|
|
69
|
|
|
$results = $this->object->searchItems( $search ); |
70
|
|
|
|
71
|
|
|
if( ($expected = reset($results) ) === false ) |
72
|
|
|
{ |
73
|
|
|
throw new \RuntimeException( 'No property type item found.' ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$actual = $this->object->getItem( $expected->getId() ); |
77
|
|
|
|
78
|
|
|
$this->assertEquals( $expected, $actual ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testSaveInvalid() |
83
|
|
|
{ |
84
|
|
|
$this->setExpectedException( '\Aimeos\MShop\Exception' ); |
85
|
|
|
$this->object->saveItem( new \Aimeos\MShop\Locale\Item\Standard() ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
public function testSaveUpdateDeleteItem() |
90
|
|
|
{ |
91
|
|
|
$search = $this->object->createSearch(); |
92
|
|
|
$search->setConditions( $search->compare( '==', 'customer.property.type.editor', $this->editor ) ); |
93
|
|
|
$results = $this->object->searchItems($search); |
94
|
|
|
|
95
|
|
|
if( ( $item = reset($results) ) === false ) { |
96
|
|
|
throw new \RuntimeException( 'No type item found' ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$item->setId(null); |
100
|
|
|
$item->setCode( 'unitTestSave' ); |
101
|
|
|
$resultSaved = $this->object->saveItem( $item ); |
|
|
|
|
102
|
|
|
$itemSaved = $this->object->getItem( $item->getId() ); |
103
|
|
|
|
104
|
|
|
$itemExp = clone $itemSaved; |
105
|
|
|
$itemExp->setCode( 'unitTestSave2' ); |
106
|
|
|
$resultUpd = $this->object->saveItem( $itemExp ); |
|
|
|
|
107
|
|
|
$itemUpd = $this->object->getItem( $itemExp->getId() ); |
108
|
|
|
|
109
|
|
|
$this->object->deleteItem( $itemSaved->getId() ); |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
$this->assertTrue( $item->getId() !== null ); |
113
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
114
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
115
|
|
|
$this->assertEquals( $item->getCode(), $itemSaved->getCode() ); |
116
|
|
|
$this->assertEquals( $item->getDomain(), $itemSaved->getDomain() ); |
117
|
|
|
$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() ); |
118
|
|
|
$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() ); |
119
|
|
|
|
120
|
|
|
$this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
121
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
122
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
123
|
|
|
|
124
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
125
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
126
|
|
|
$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() ); |
127
|
|
|
$this->assertEquals( $itemExp->getDomain(), $itemUpd->getDomain() ); |
128
|
|
|
$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() ); |
129
|
|
|
$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() ); |
130
|
|
|
|
131
|
|
|
$this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
132
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
133
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
134
|
|
|
|
135
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultSaved ); |
136
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultUpd ); |
137
|
|
|
|
138
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
139
|
|
|
$this->object->getItem( $itemSaved->getId() ); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
public function testSearchItems() |
144
|
|
|
{ |
145
|
|
|
$total = 0; |
146
|
|
|
$search = $this->object->createSearch(); |
147
|
|
|
|
148
|
|
|
$expr = []; |
149
|
|
|
$expr[] = $search->compare( '!=', 'customer.property.type.id', null ); |
150
|
|
|
$expr[] = $search->compare( '!=', 'customer.property.type.siteid', null ); |
151
|
|
|
$expr[] = $search->compare( '==', 'customer.property.type.domain', 'customer' ); |
152
|
|
|
$expr[] = $search->compare( '==', 'customer.property.type.code', 'newsletter' ); |
153
|
|
|
$expr[] = $search->compare( '>', 'customer.property.type.label', '' ); |
154
|
|
|
$expr[] = $search->compare( '==', 'customer.property.type.status', 1 ); |
155
|
|
|
$expr[] = $search->compare( '>=', 'customer.property.type.mtime', '1970-01-01 00:00:00' ); |
156
|
|
|
$expr[] = $search->compare( '>=', 'customer.property.type.ctime', '1970-01-01 00:00:00' ); |
157
|
|
|
$expr[] = $search->compare( '==', 'customer.property.type.editor', $this->editor ); |
158
|
|
|
|
159
|
|
|
$search->setConditions( $search->combine('&&', $expr) ); |
160
|
|
|
$results = $this->object->searchItems( $search, [], $total ); |
161
|
|
|
$this->assertEquals( 1, count( $results ) ); |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
$search = $this->object->createSearch(); |
165
|
|
|
$conditions = array( |
166
|
|
|
$search->compare( '=~', 'customer.property.type.code', 'newsletter'), |
167
|
|
|
$search->compare( '==', 'customer.property.type.editor', $this->editor ) |
168
|
|
|
); |
169
|
|
|
$search->setConditions( $search->combine('&&', $conditions ) ); |
170
|
|
|
$search->setSlice(0, 1); |
171
|
|
|
$items = $this->object->searchItems( $search, [], $total); |
172
|
|
|
|
173
|
|
|
$this->assertEquals( 1, count( $items ) ); |
174
|
|
|
$this->assertEquals( 1, $total ); |
175
|
|
|
|
176
|
|
|
foreach($items as $itemId => $item) { |
177
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
|
182
|
|
|
public function testGetSubManager() |
183
|
|
|
{ |
184
|
|
|
$this->setExpectedException('\\Aimeos\\MShop\\Exception'); |
185
|
|
|
$this->object->getSubManager('unknown'); |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.