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