1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Customer\Manager\Property; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class LaravelTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $editor = ''; |
16
|
|
|
|
17
|
|
|
|
18
|
|
View Code Duplication |
protected function setUp() |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
$context = \TestHelper::getContext(); |
21
|
|
|
$this->editor = $context->getEditor(); |
22
|
|
|
|
23
|
|
|
$manager = \Aimeos\MShop\Customer\Manager\Factory::createManager( $context, 'Laravel' ); |
24
|
|
|
$this->object = $manager->getSubManager( 'property', 'Laravel' ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
protected function tearDown() |
29
|
|
|
{ |
30
|
|
|
unset( $this->object ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
public function testCleanup() |
35
|
|
|
{ |
36
|
|
|
$this->object->cleanup( array( -1 ) ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
public function testCreateItem() |
41
|
|
|
{ |
42
|
|
|
$item = $this->object->createItem(); |
43
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Property\\Iface', $item ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
public function testSaveInvalid() |
48
|
|
|
{ |
49
|
|
|
$this->setExpectedException( \Aimeos\MW\Common\Exception::class ); |
50
|
|
|
$this->object->saveItem( new \Aimeos\MShop\Locale\Item\Standard() ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testSaveUpdateDeleteItem() |
55
|
|
|
{ |
56
|
|
|
$search = $this->object->createSearch(); |
57
|
|
|
$search->setConditions( $search->compare( '==', 'customer.property.editor', $this->editor ) ); |
58
|
|
|
$results = $this->object->searchItems( $search ); |
59
|
|
|
|
60
|
|
|
if( ( $item = reset($results) ) === false ) { |
61
|
|
|
throw new \RuntimeException( 'No property item found' ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$item->setId(null); |
65
|
|
|
$item->setLanguageId( 'en' ); |
66
|
|
|
$resultSaved = $this->object->saveItem( $item ); |
67
|
|
|
$itemSaved = $this->object->getItem( $item->getId() ); |
68
|
|
|
|
69
|
|
|
$itemExp = clone $itemSaved; |
70
|
|
|
$itemExp->setValue( 'unittest' ); |
71
|
|
|
$resultUpd = $this->object->saveItem( $itemExp ); |
72
|
|
|
$itemUpd = $this->object->getItem( $itemExp->getId() ); |
73
|
|
|
|
74
|
|
|
$this->object->deleteItem( $itemSaved->getId() ); |
75
|
|
|
|
76
|
|
|
$context = \TestHelper::getContext(); |
77
|
|
|
|
78
|
|
|
$this->assertTrue( $item->getId() !== null ); |
79
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
80
|
|
|
$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); |
81
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
82
|
|
|
$this->assertEquals( $item->getType(), $itemSaved->getType() ); |
83
|
|
|
$this->assertEquals( $item->getLanguageId(), $itemSaved->getLanguageId() ); |
84
|
|
|
$this->assertEquals( $item->getValue(), $itemSaved->getValue() ); |
85
|
|
|
|
86
|
|
|
$this->assertEquals( $context->getEditor(), $itemSaved->getEditor() ); |
87
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
88
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
89
|
|
|
|
90
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
91
|
|
|
$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); |
92
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
93
|
|
|
$this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
94
|
|
|
$this->assertEquals( $itemExp->getLanguageId(), $itemUpd->getLanguageId() ); |
95
|
|
|
$this->assertEquals( $itemExp->getValue(), $itemUpd->getValue() ); |
96
|
|
|
|
97
|
|
|
$this->assertEquals( $context->getEditor(), $itemUpd->getEditor() ); |
98
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
99
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
100
|
|
|
|
101
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
102
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
103
|
|
|
|
104
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
105
|
|
|
$this->object->getItem( $itemSaved->getId() ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
View Code Duplication |
public function testGetItem() |
|
|
|
|
110
|
|
|
{ |
111
|
|
|
$search = $this->object->createSearch(); |
112
|
|
|
$conditions = array( |
113
|
|
|
$search->compare( '~=', 'customer.property.value', '1'), |
114
|
|
|
$search->compare( '==', 'customer.property.editor', $this->editor ) |
115
|
|
|
); |
116
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
117
|
|
|
$results = $this->object->searchItems( $search ); |
118
|
|
|
|
119
|
|
|
if( ($expected = reset($results)) === false ) { |
120
|
|
|
throw new \RuntimeException( sprintf( 'No customer property item found for value "%1$s".', '1' ) ); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
$actual = $this->object->getItem( $expected->getId() ); |
124
|
|
|
$this->assertEquals( $expected, $actual ); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
public function testGetResourceType() |
129
|
|
|
{ |
130
|
|
|
$result = $this->object->getResourceType(); |
131
|
|
|
|
132
|
|
|
$this->assertContains( 'customer/property', $result ); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
public function testGetSearchAttributes() |
137
|
|
|
{ |
138
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) { |
139
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute ); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
public function testSearchItems() |
145
|
|
|
{ |
146
|
|
|
$total = 0; |
|
|
|
|
147
|
|
|
$search = $this->object->createSearch(); |
148
|
|
|
|
149
|
|
|
$expr = []; |
150
|
|
|
$expr[] = $search->compare( '!=', 'customer.property.id', null ); |
151
|
|
|
$expr[] = $search->compare( '!=', 'customer.property.parentid', null ); |
152
|
|
|
$expr[] = $search->compare( '!=', 'customer.property.siteid', null ); |
153
|
|
|
$expr[] = $search->compare( '==', 'customer.property.type', 'newsletter' ); |
154
|
|
|
$expr[] = $search->compare( '==', 'customer.property.languageid', null ); |
155
|
|
|
$expr[] = $search->compare( '==', 'customer.property.value', '1' ); |
156
|
|
|
$expr[] = $search->compare( '==', 'customer.property.editor', $this->editor ); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
|
160
|
|
View Code Duplication |
public function testGetSubManager() |
|
|
|
|
161
|
|
|
{ |
162
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager('type') ); |
163
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager('type', 'Standard') ); |
164
|
|
|
|
165
|
|
|
$this->setExpectedException('\\Aimeos\\MShop\\Exception'); |
166
|
|
|
$this->object->getSubManager('unknown'); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
public function testGetSubManagerInvalidName() |
171
|
|
|
{ |
172
|
|
|
$this->setExpectedException('\\Aimeos\\MShop\\Exception'); |
173
|
|
|
$this->object->getSubManager('type', 'unknown'); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.