1 | <?php |
||
13 | class StandardTest extends \PHPUnit\Framework\TestCase |
||
14 | { |
||
15 | private $object; |
||
16 | private $editor = ''; |
||
17 | |||
18 | |||
19 | protected function setUp() |
||
20 | { |
||
21 | $this->editor = \TestHelperMShop::getContext()->getEditor(); |
||
22 | $this->object = \Aimeos\MShop\Attribute\Manager\Factory::createManager( \TestHelperMShop::getContext() ); |
||
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 testGetResourceType() |
||
39 | { |
||
40 | $result = $this->object->getResourceType(); |
||
41 | |||
42 | $this->assertContains( 'attribute', $result ); |
||
43 | $this->assertContains( 'attribute/type', $result ); |
||
44 | $this->assertContains( 'attribute/lists', $result ); |
||
45 | $this->assertContains( 'attribute/lists/type', $result ); |
||
46 | } |
||
47 | |||
48 | |||
49 | public function testGetSearchAttributes() |
||
50 | { |
||
51 | foreach( $this->object->getSearchAttributes() as $obj ) { |
||
52 | $this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $obj ); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | |||
57 | public function testCreateItem() |
||
58 | { |
||
59 | $this->assertInstanceOf( '\\Aimeos\\MShop\\Attribute\\Item\\Iface', $this->object->createItem() ); |
||
60 | } |
||
61 | |||
62 | |||
63 | public function testGetSubManager() |
||
64 | { |
||
65 | $this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'lists' ) ); |
||
66 | $this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'lists', 'Standard' ) ); |
||
67 | |||
68 | $this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'type' ) ); |
||
69 | $this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'type', 'Standard' ) ); |
||
70 | |||
71 | $this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
||
72 | $this->object->getSubManager( 'unknown' ); |
||
73 | } |
||
74 | |||
75 | |||
76 | public function testGetSubManagerInvalidName() |
||
77 | { |
||
78 | $this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
||
79 | $this->object->getSubManager( 'lists', 'unknown' ); |
||
80 | } |
||
81 | |||
82 | |||
83 | public function testFindItem() |
||
84 | { |
||
85 | $item = $this->object->findItem( 'm', array( 'text' ), 'product', 'size' ); |
||
86 | |||
87 | $this->assertEquals( 'm', $item->getCode() ); |
||
88 | $this->assertEquals( 'size', $item->getType() ); |
||
89 | $this->assertEquals( 'product', $item->getDomain() ); |
||
90 | $this->assertEquals( 1, count( $item->getListItems( 'text', null, null, false ) ) ); |
||
91 | $this->assertEquals( 1, count( $item->getRefItems( 'text', null, null, false ) ) ); |
||
92 | } |
||
93 | |||
94 | |||
95 | public function testFindItemInvalid() |
||
96 | { |
||
97 | $this->setExpectedException( '\Aimeos\MShop\Exception' ); |
||
98 | $this->object->findItem( 'invalid' ); |
||
99 | } |
||
100 | |||
101 | |||
102 | public function testFindItemMissing() |
||
103 | { |
||
104 | $this->setExpectedException( '\Aimeos\MShop\Exception' ); |
||
105 | $this->object->findItem( 'm', [], 'product' ); |
||
106 | } |
||
107 | |||
108 | |||
109 | public function testGetItem() |
||
110 | { |
||
111 | $itemA = $this->object->findItem( 'black', [], 'product', 'color' ); |
||
112 | $itemB = $this->object->getItem( $itemA->getId(), ['attribute/property'] ); |
||
113 | |||
114 | $this->assertEquals( $itemA->getId(), $itemB->getId() ); |
||
115 | $this->assertEquals( 1, count( $itemB->getPropertyItems() ) ); |
||
116 | $this->assertEquals( 1, count( $itemB->getListItems( null, null, null, false ) ) ); |
||
117 | $this->assertNotEquals( '', $itemB->getTypeName() ); |
||
118 | } |
||
119 | |||
120 | |||
121 | public function testGetItemLists() |
||
122 | { |
||
123 | $itemA = $this->object->findItem( 'xxl', [], 'product', 'size' ); |
||
124 | $itemB = $this->object->getItem( $itemA->getId(), ['text'] ); |
||
125 | |||
126 | $this->assertEquals( $itemA->getId(), $itemB->getId() ); |
||
127 | $this->assertEquals( 1, count( $itemB->getListItems( 'text', null, null, false ) ) ); |
||
128 | $this->assertEquals( 1, count( $itemB->getRefItems( 'text', null, null, false ) ) ); |
||
129 | } |
||
130 | |||
131 | |||
132 | public function testSaveInvalid() |
||
133 | { |
||
134 | $this->setExpectedException( '\Aimeos\MShop\Attribute\Exception' ); |
||
135 | $this->object->saveItem( new \Aimeos\MShop\Locale\Item\Standard() ); |
||
136 | } |
||
137 | |||
138 | |||
139 | public function testSaveUpdateDeleteItem() |
||
140 | { |
||
141 | $typeItem = $this->object->getSubManager( 'type' )->findItem( 'size', [], 'product' ); |
||
142 | |||
143 | $item = $this->object->createItem(); |
||
144 | $item->setId( null ); |
||
145 | $item->setDomain( 'tmpDomainx' ); |
||
146 | $item->setCode( '106x' ); |
||
147 | $item->setLabel( '106x' ); |
||
148 | $item->setTypeId( $typeItem->getId() ); |
||
149 | $item->setPosition( 0 ); |
||
150 | $item->setStatus( 7 ); |
||
151 | $resultSaved = $this->object->saveItem( $item ); |
||
|
|||
152 | $itemSaved = $this->object->getItem( $item->getId() ); |
||
153 | |||
154 | $itemExp = clone $itemSaved; |
||
155 | $itemExp->setDomain( 'tmpDomain' ); |
||
156 | $itemExp->setCode( '106' ); |
||
157 | $itemExp->setLabel( '106' ); |
||
158 | $resultUpd = $this->object->saveItem( $itemExp ); |
||
159 | $itemUpd = $this->object->getItem( $itemExp->getId() ); |
||
160 | |||
161 | $this->object->deleteItem( $item->getId() ); |
||
162 | |||
163 | $context = \TestHelperMShop::getContext(); |
||
164 | |||
165 | $this->assertTrue( $item->getId() !== null ); |
||
166 | $this->assertTrue( $itemSaved->getType() !== null ); |
||
167 | $this->assertEquals( $item->getId(), $itemSaved->getId() ); |
||
168 | $this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
||
169 | $this->assertEquals( $item->getDomain(), $itemSaved->getDomain() ); |
||
170 | $this->assertEquals( $item->getCode(), $itemSaved->getCode() ); |
||
171 | $this->assertEquals( $item->getLabel(), $itemSaved->getLabel() ); |
||
172 | $this->assertEquals( $item->getTypeId(), $itemSaved->getTypeId() ); |
||
173 | $this->assertEquals( $item->getPosition(), $itemSaved->getPosition() ); |
||
174 | $this->assertEquals( $item->getStatus(), $itemSaved->getStatus() ); |
||
175 | |||
176 | $this->assertEquals( $context->getEditor(), $itemSaved->getEditor() ); |
||
177 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
||
178 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
||
179 | |||
180 | $this->assertTrue( $itemUpd->getType() !== null ); |
||
181 | $this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
||
182 | $this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
||
183 | $this->assertEquals( $itemExp->getDomain(), $itemUpd->getDomain() ); |
||
184 | $this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() ); |
||
185 | $this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() ); |
||
186 | $this->assertEquals( $itemExp->getTypeId(), $itemUpd->getTypeId() ); |
||
187 | $this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() ); |
||
188 | $this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() ); |
||
189 | |||
190 | $this->assertEquals( $context->getEditor(), $itemUpd->getEditor() ); |
||
191 | $this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
||
192 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
||
193 | |||
194 | $this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultSaved ); |
||
195 | $this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultUpd ); |
||
196 | |||
197 | $this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
||
198 | $this->object->getItem( $item->getId() ); |
||
199 | } |
||
200 | |||
201 | |||
202 | public function testGetSavePropertyItems() |
||
203 | { |
||
204 | $item = $this->object->findItem( 'black', [], 'product', 'color' ); |
||
205 | |||
206 | $item->setId( null )->setCode( 'xyz' ); |
||
207 | $this->object->saveItem( $item ); |
||
208 | |||
209 | $item2 = $this->object->findItem( 'xyz', [], 'product', 'color' ); |
||
210 | |||
211 | $this->object->deleteItem( $item->getId() ); |
||
212 | |||
213 | $this->assertEquals( 1, count( $item->getPropertyItems() ) ); |
||
214 | $this->assertEquals( 1, count( $item2->getPropertyItems() ) ); |
||
215 | } |
||
216 | |||
217 | |||
218 | public function testCreateSearch() |
||
223 | |||
224 | |||
225 | public function testSearchItems() |
||
226 | { |
||
227 | $search = $this->object->createSearch(); |
||
228 | |||
229 | $expr = []; |
||
230 | $expr[] = $search->compare( '!=', 'attribute.id', null ); |
||
231 | $expr[] = $search->compare( '!=', 'attribute.siteid', null ); |
||
232 | $expr[] = $search->compare( '!=', 'attribute.typeid', null ); |
||
233 | $expr[] = $search->compare( '==', 'attribute.position', 5 ); |
||
234 | $expr[] = $search->compare( '==', 'attribute.code', 'black' ); |
||
235 | $expr[] = $search->compare( '==', 'attribute.label', 'black' ); |
||
236 | $expr[] = $search->compare( '==', 'attribute.domain', 'product' ); |
||
237 | $expr[] = $search->compare( '==', 'attribute.status', 0 ); |
||
238 | $expr[] = $search->compare( '>=', 'attribute.mtime', '1970-01-01 00:00:00' ); |
||
239 | $expr[] = $search->compare( '>=', 'attribute.ctime', '1970-01-01 00:00:00' ); |
||
302 | |||
303 | |||
304 | public function testSearchBase() |
||
327 | |||
328 | |||
329 | public function testSearchTotal() |
||
345 | } |
||
346 |
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.