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