1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2021-2025 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Cms\Manager\Lists; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $context; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() : void |
19
|
|
|
{ |
20
|
|
|
$this->context = \TestHelper::context(); |
21
|
|
|
$this->object = new \Aimeos\MShop\Cms\Manager\Lists\Standard( $this->context ); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
protected function tearDown() : void |
26
|
|
|
{ |
27
|
|
|
unset( $this->object, $this->context ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
public function testClear() |
32
|
|
|
{ |
33
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( [-1] ) ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
public function testCreateItem() |
38
|
|
|
{ |
39
|
|
|
$item = $this->object->create(); |
40
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Lists\Iface::class, $item ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testGetItem() |
45
|
|
|
{ |
46
|
|
|
$search = $this->object->filter()->slice( 0, 1 ); |
47
|
|
|
$item = $this->object->search( $search )->first( new \RuntimeException( 'No item found' ) ); |
48
|
|
|
|
49
|
|
|
$this->assertEquals( $item, $this->object->get( $item->getId() ) ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function testSaveUpdateDeleteItem() |
54
|
|
|
{ |
55
|
|
|
$search = $this->object->filter(); |
56
|
|
|
$item = $this->object->search( $search )->first( new \RuntimeException( 'No item found' ) ); |
57
|
|
|
|
58
|
|
|
$item->setId( null ); |
59
|
|
|
$item->setDomain( 'unittest' ); |
60
|
|
|
$resultSaved = $this->object->save( $item ); |
61
|
|
|
$itemSaved = $this->object->get( $item->getId() ); |
62
|
|
|
|
63
|
|
|
$itemExp = clone $itemSaved; |
64
|
|
|
$itemExp->setDomain( 'unittest1' ); |
65
|
|
|
$resultUpd = $this->object->save( $itemExp ); |
66
|
|
|
$itemUpd = $this->object->get( $itemExp->getId() ); |
67
|
|
|
|
68
|
|
|
$this->object->delete( $itemSaved->getId() ); |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
$this->assertTrue( $item->getId() !== null ); |
72
|
|
|
$this->assertTrue( $itemSaved->getType() !== null ); |
73
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
74
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
75
|
|
|
$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); |
76
|
|
|
$this->assertEquals( $item->getType(), $itemSaved->getType() ); |
77
|
|
|
$this->assertEquals( $item->getRefId(), $itemSaved->getRefId() ); |
78
|
|
|
$this->assertEquals( $item->getDomain(), $itemSaved->getDomain() ); |
79
|
|
|
$this->assertEquals( $item->getDateStart(), $itemSaved->getDateStart() ); |
80
|
|
|
$this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() ); |
81
|
|
|
$this->assertEquals( $item->getPosition(), $itemSaved->getPosition() ); |
82
|
|
|
|
83
|
|
|
$this->assertEquals( $this->context->editor(), $itemSaved->editor() ); |
84
|
|
|
$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
85
|
|
|
$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
86
|
|
|
|
87
|
|
|
$this->assertTrue( $itemUpd->getType() !== null ); |
88
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
89
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
90
|
|
|
$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); |
91
|
|
|
$this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
92
|
|
|
$this->assertEquals( $itemExp->getRefId(), $itemUpd->getRefId() ); |
93
|
|
|
$this->assertEquals( $itemExp->getDomain(), $itemUpd->getDomain() ); |
94
|
|
|
$this->assertEquals( $itemExp->getDateStart(), $itemUpd->getDateStart() ); |
95
|
|
|
$this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() ); |
96
|
|
|
$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() ); |
97
|
|
|
|
98
|
|
|
$this->assertEquals( $this->context->editor(), $itemUpd->editor() ); |
99
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
100
|
|
|
$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
101
|
|
|
|
102
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
103
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
104
|
|
|
|
105
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
106
|
|
|
$this->object->get( $itemSaved->getId() ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
public function testSearchItems() |
111
|
|
|
{ |
112
|
|
|
$total = 0; |
113
|
|
|
$search = $this->object->filter(); |
114
|
|
|
|
115
|
|
|
$expr = []; |
116
|
|
|
$expr[] = $search->compare( '!=', 'cms.lists.id', null ); |
117
|
|
|
$expr[] = $search->compare( '!=', 'cms.lists.siteid', null ); |
118
|
|
|
$expr[] = $search->compare( '!=', 'cms.lists.parentid', null ); |
119
|
|
|
$expr[] = $search->compare( '==', 'cms.lists.domain', 'text' ); |
120
|
|
|
$expr[] = $search->compare( '==', 'cms.lists.type', 'default' ); |
121
|
|
|
$expr[] = $search->compare( '>', 'cms.lists.refid', 0 ); |
122
|
|
|
$expr[] = $search->compare( '==', 'cms.lists.datestart', null ); |
123
|
|
|
$expr[] = $search->compare( '==', 'cms.lists.dateend', null ); |
124
|
|
|
$expr[] = $search->compare( '!=', 'cms.lists.config', null ); |
125
|
|
|
$expr[] = $search->compare( '==', 'cms.lists.position', 0 ); |
126
|
|
|
$expr[] = $search->compare( '==', 'cms.lists.status', 1 ); |
127
|
|
|
$expr[] = $search->compare( '!=', 'cms.lists.editor', '' ); |
128
|
|
|
|
129
|
|
|
$search->setConditions( $search->and( $expr ) ); |
130
|
|
|
$results = $this->object->search( $search, [], $total )->toArray(); |
131
|
|
|
$this->assertEquals( 2, count( $results ) ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
public function testSearchItemsAll() |
136
|
|
|
{ |
137
|
|
|
$search = $this->object->filter(); |
138
|
|
|
$this->assertEquals( 9, count( $this->object->search( $search )->toArray() ) ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
public function testSearchItemsBase() |
143
|
|
|
{ |
144
|
|
|
$total = 0; |
145
|
|
|
$search = $this->object->filter( true )->slice( 0, 1 ); |
146
|
|
|
$results = $this->object->search( $search, [], $total )->toArray(); |
147
|
|
|
|
148
|
|
|
$this->assertEquals( 1, count( $results ) ); |
149
|
|
|
$this->assertEquals( 9, $total ); |
150
|
|
|
|
151
|
|
|
foreach( $results as $itemId => $item ) { |
152
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
public function testGetSubManager() |
158
|
|
|
{ |
159
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'type' ) ); |
160
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'type', 'Standard' ) ); |
161
|
|
|
|
162
|
|
|
$this->expectException( \LogicException::class ); |
163
|
|
|
$this->object->getSubManager( 'unknown' ); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|