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