1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018-2025 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Customer\Manager\Property; |
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( 'property', '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
|
|
|
$item = $this->object->create(); |
43
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Property\\Iface', $item ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
public function testSaveUpdateDeleteItem() |
48
|
|
|
{ |
49
|
|
|
$search = $this->object->filter(); |
50
|
|
|
$search->setConditions( $search->compare( '==', 'customer.property.editor', $this->editor ) ); |
51
|
|
|
|
52
|
|
|
if( ( $item = $this->object->search( $search )->first() ) === null ) { |
53
|
|
|
throw new \RuntimeException( 'No property item found' ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$item->setId( null ); |
57
|
|
|
$item->setLanguageId( 'en' ); |
58
|
|
|
$resultSaved = $this->object->save( $item ); |
59
|
|
|
$itemSaved = $this->object->get( $item->getId() ); |
60
|
|
|
|
61
|
|
|
$itemExp = clone $itemSaved; |
62
|
|
|
$itemExp->setValue( 'unittest' ); |
63
|
|
|
$resultUpd = $this->object->save( $itemExp ); |
64
|
|
|
$itemUpd = $this->object->get( $itemExp->getId() ); |
65
|
|
|
|
66
|
|
|
$this->object->delete( $itemSaved->getId() ); |
67
|
|
|
|
68
|
|
|
$context = \TestHelper::context(); |
69
|
|
|
|
70
|
|
|
$this->assertTrue( $item->getId() !== null ); |
71
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
72
|
|
|
$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); |
73
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
74
|
|
|
$this->assertEquals( $item->getType(), $itemSaved->getType() ); |
75
|
|
|
$this->assertEquals( $item->getLanguageId(), $itemSaved->getLanguageId() ); |
76
|
|
|
$this->assertEquals( $item->getValue(), $itemSaved->getValue() ); |
77
|
|
|
|
78
|
|
|
$this->assertEquals( $context->editor(), $itemSaved->editor() ); |
79
|
|
|
$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
80
|
|
|
$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
81
|
|
|
|
82
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
83
|
|
|
$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); |
84
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
85
|
|
|
$this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
86
|
|
|
$this->assertEquals( $itemExp->getLanguageId(), $itemUpd->getLanguageId() ); |
87
|
|
|
$this->assertEquals( $itemExp->getValue(), $itemUpd->getValue() ); |
88
|
|
|
|
89
|
|
|
$this->assertEquals( $context->editor(), $itemUpd->editor() ); |
90
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
91
|
|
|
$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
92
|
|
|
|
93
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
94
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
95
|
|
|
|
96
|
|
|
$this->expectException( '\\Aimeos\\MShop\\Exception' ); |
97
|
|
|
$this->object->get( $itemSaved->getId() ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function testGetItem() |
102
|
|
|
{ |
103
|
|
|
$search = $this->object->filter(); |
104
|
|
|
$conditions = array( |
105
|
|
|
$search->compare( '~=', 'customer.property.value', '1' ), |
106
|
|
|
$search->compare( '==', 'customer.property.editor', $this->editor ) |
107
|
|
|
); |
108
|
|
|
$search->setConditions( $search->and( $conditions ) ); |
109
|
|
|
|
110
|
|
|
if( ( $expected = $this->object->search( $search )->first() ) === null ) { |
111
|
|
|
throw new \RuntimeException( sprintf( 'No customer property item found for value "%1$s".', '1' ) ); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$actual = $this->object->get( $expected->getId() ); |
115
|
|
|
$this->assertEquals( $expected, $actual ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testGetSearchAttributes() |
120
|
|
|
{ |
121
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) { |
122
|
|
|
$this->assertInstanceOf( '\\Aimeos\\Base\\Criteria\\Attribute\\Iface', $attribute ); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
public function testSearchItems() |
128
|
|
|
{ |
129
|
|
|
$total = 0; |
130
|
|
|
$search = $this->object->filter(); |
131
|
|
|
|
132
|
|
|
$expr = []; |
133
|
|
|
$expr[] = $search->compare( '!=', 'customer.property.id', null ); |
134
|
|
|
$expr[] = $search->compare( '!=', 'customer.property.parentid', null ); |
135
|
|
|
$expr[] = $search->compare( '!=', 'customer.property.siteid', null ); |
136
|
|
|
$expr[] = $search->compare( '==', 'customer.property.type', 'newsletter' ); |
137
|
|
|
$expr[] = $search->compare( '==', 'customer.property.languageid', null ); |
138
|
|
|
$expr[] = $search->compare( '==', 'customer.property.value', '1' ); |
139
|
|
|
$expr[] = $search->compare( '==', 'customer.property.editor', $this->editor ); |
140
|
|
|
|
141
|
|
|
$search->setConditions( $search->and( $expr ) ); |
142
|
|
|
$results = $this->object->search( $search, [], $total ); |
143
|
|
|
$this->assertEquals( 1, count( $results ) ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
public function testGetSubManager() |
148
|
|
|
{ |
149
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'type' ) ); |
150
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'type', 'Standard' ) ); |
151
|
|
|
|
152
|
|
|
$this->expectException( \LogicException::class ); |
153
|
|
|
$this->object->getSubManager( 'unknown' ); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
public function testGetSubManagerInvalidName() |
158
|
|
|
{ |
159
|
|
|
$this->expectException( \LogicException::class ); |
160
|
|
|
$this->object->getSubManager( 'type', 'unknown' ); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|