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