1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2021-2025 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Aimeos\MShop\Cms\Manager; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
12
|
|
|
{ |
13
|
|
|
private $context; |
14
|
|
|
private $object; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
protected function setUp() : void |
18
|
|
|
{ |
19
|
|
|
$this->context = \TestHelper::context(); |
20
|
|
|
$this->object = new \Aimeos\MShop\Cms\Manager\Standard( $this->context ); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
protected function tearDown() : void |
25
|
|
|
{ |
26
|
|
|
unset( $this->object, $this->context ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
public function testClear() |
31
|
|
|
{ |
32
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( [-1] ) ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function testDeleteItems() |
37
|
|
|
{ |
38
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->delete( [-1] ) ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
public function testCreateItem() |
43
|
|
|
{ |
44
|
|
|
$cmsItem = $this->object->create(); |
45
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Cms\Item\Iface::class, $cmsItem ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
public function testCreateItemType() |
50
|
|
|
{ |
51
|
|
|
$item = $this->object->create( ['cms.url' => '/test'] ); |
52
|
|
|
$this->assertEquals( '/test', $item->getUrl() ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
public function testGetSearchAttributes() |
57
|
|
|
{ |
58
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) { |
59
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Criteria\Attribute\Iface::class, $attribute ); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
public function testSearchItems() |
65
|
|
|
{ |
66
|
|
|
$item = $this->object->find( '/contact', ['text'] ); |
67
|
|
|
$listItem = $item->getListItems( 'text', 'default' )->first( new \RuntimeException( 'No list item found' ) ); |
68
|
|
|
|
69
|
|
|
$total = 0; |
70
|
|
|
$search = $this->object->filter(); |
71
|
|
|
|
72
|
|
|
$expr = []; |
73
|
|
|
$expr[] = $search->compare( '!=', 'cms.id', null ); |
74
|
|
|
$expr[] = $search->compare( '!=', 'cms.siteid', null ); |
75
|
|
|
$expr[] = $search->compare( '==', 'cms.url', '/contact' ); |
76
|
|
|
$expr[] = $search->compare( '==', 'cms.label', 'Contact' ); |
77
|
|
|
$expr[] = $search->compare( '==', 'cms.status', 1 ); |
78
|
|
|
$expr[] = $search->compare( '>=', 'cms.mtime', '1970-01-01 00:00:00' ); |
79
|
|
|
$expr[] = $search->compare( '>=', 'cms.ctime', '1970-01-01 00:00:00' ); |
80
|
|
|
$expr[] = $search->compare( '!=', 'cms.editor', '' ); |
81
|
|
|
|
82
|
|
|
$param = ['text', 'default', $listItem->getRefId()]; |
83
|
|
|
$expr[] = $search->compare( '!=', $search->make( 'cms:has', $param ), null ); |
84
|
|
|
|
85
|
|
|
$param = ['text', 'default']; |
86
|
|
|
$expr[] = $search->compare( '!=', $search->make( 'cms:has', $param ), null ); |
87
|
|
|
|
88
|
|
|
$param = ['text']; |
89
|
|
|
$expr[] = $search->compare( '!=', $search->make( 'cms:has', $param ), null ); |
90
|
|
|
|
91
|
|
|
$search->setConditions( $search->and( $expr ) ); |
92
|
|
|
$result = $this->object->search( $search, [], $total )->toArray(); |
93
|
|
|
$this->assertEquals( 1, count( $result ) ); |
94
|
|
|
$this->assertEquals( 1, $total ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
public function testSearchItemsAll() |
99
|
|
|
{ |
100
|
|
|
$search = $this->object->filter(); |
101
|
|
|
$this->assertEquals( 3, count( $this->object->search( $search )->toArray() ) ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
public function testSearchItemsBase() |
106
|
|
|
{ |
107
|
|
|
$total = 0; |
108
|
|
|
$search = $this->object->filter( true )->slice( 0, 1 ); |
109
|
|
|
$results = $this->object->search( $search, [], $total )->toArray(); |
110
|
|
|
|
111
|
|
|
$this->assertEquals( 1, count( $results ) ); |
112
|
|
|
$this->assertEquals( 2, $total ); |
113
|
|
|
|
114
|
|
|
foreach( $results as $itemId => $item ) { |
115
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
public function testGetItem() |
121
|
|
|
{ |
122
|
|
|
$item = $this->object->find( '/contact' ); |
123
|
|
|
|
124
|
|
|
$actual = $this->object->get( $item->getId() ); |
125
|
|
|
$this->assertEquals( $item, $actual ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
public function testSaveUpdateDeleteItem() |
130
|
|
|
{ |
131
|
|
|
$item = $this->object->find( '/contact' ); |
132
|
|
|
|
133
|
|
|
$item->setId( null ); |
134
|
|
|
$item->setUrl( '/contact-test' ); |
135
|
|
|
$item->setLabel( 'Contact test' ); |
136
|
|
|
$resultSaved = $this->object->save( $item ); |
137
|
|
|
$itemSaved = $this->object->get( $item->getId() ); |
138
|
|
|
|
139
|
|
|
$itemExp = clone $itemSaved; |
140
|
|
|
$itemExp->setLabel( 'Contact test 2' ); |
141
|
|
|
$resultUpd = $this->object->save( $itemExp ); |
142
|
|
|
$itemUpd = $this->object->get( $itemExp->getId() ); |
143
|
|
|
|
144
|
|
|
$this->object->delete( $itemSaved->getId() ); |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
$this->assertTrue( $item->getId() !== null ); |
148
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
149
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
150
|
|
|
$this->assertEquals( $item->getUrl(), $itemSaved->getUrl() ); |
151
|
|
|
$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() ); |
152
|
|
|
$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() ); |
153
|
|
|
|
154
|
|
|
$this->assertEquals( $this->context->editor(), $itemSaved->editor() ); |
155
|
|
|
$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
156
|
|
|
$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
157
|
|
|
|
158
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
159
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
160
|
|
|
$this->assertEquals( $itemExp->getUrl(), $itemUpd->getUrl() ); |
161
|
|
|
$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() ); |
162
|
|
|
$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() ); |
163
|
|
|
|
164
|
|
|
$this->assertEquals( $this->context->editor(), $itemUpd->editor() ); |
165
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
166
|
|
|
$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
167
|
|
|
|
168
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
169
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
170
|
|
|
|
171
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
172
|
|
|
$this->object->get( $itemSaved->getId() ); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
public function testGetSubManager() |
177
|
|
|
{ |
178
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'lists' ) ); |
179
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'lists', 'Standard' ) ); |
180
|
|
|
|
181
|
|
|
$this->expectException( \LogicException::class ); |
182
|
|
|
$this->object->getSubManager( 'unknown' ); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
public function testGetSubManagerInvalidName() |
187
|
|
|
{ |
188
|
|
|
$this->expectException( \LogicException::class ); |
189
|
|
|
$this->object->getSubManager( 'lists', 'unknown' ); |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|