1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Locale\Manager\Currency; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
$this->object = new \Aimeos\MShop\Locale\Manager\Currency\Standard( \TestHelperMShop::getContext() ); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
protected function tearDown() |
25
|
|
|
{ |
26
|
|
|
$this->object = null; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
public function testCreateItem() |
31
|
|
|
{ |
32
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Locale\\Item\\Currency\\Iface', $this->object->createItem() ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function testSaveUpdateDeleteItem() |
37
|
|
|
{ |
38
|
|
|
// insert case |
39
|
|
|
$item = $this->object->createItem(); |
40
|
|
|
$item->setLabel( 'new name' ); |
41
|
|
|
$item->setStatus( 1 ); |
42
|
|
|
$item->setCode( 'XXX' ); |
43
|
|
|
|
44
|
|
|
$resultSaved = $this->object->saveItem( $item ); |
45
|
|
|
$itemSaved = $this->object->getItem( $item->getId() ); |
46
|
|
|
|
47
|
|
|
// update case |
48
|
|
|
$itemExp = clone $itemSaved; |
49
|
|
|
$itemExp->setLabel( 'new new name' ); |
50
|
|
|
$resultUpd = $this->object->saveItem( $itemExp ); |
51
|
|
|
$itemUpd = $this->object->getItem( $itemExp->getId() ); |
52
|
|
|
|
53
|
|
|
$this->object->deleteItem( $item->getId() ); |
54
|
|
|
|
55
|
|
|
$context = \TestHelperMShop::getContext(); |
56
|
|
|
|
57
|
|
|
$this->assertTrue( $item->getId() !== null ); |
58
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
59
|
|
|
$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() ); |
60
|
|
|
$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() ); |
61
|
|
|
$this->assertEquals( $item->getCode(), $itemSaved->getCode() ); |
62
|
|
|
|
63
|
|
|
$this->assertEquals( $context->getEditor(), $itemSaved->getEditor() ); |
64
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
65
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
66
|
|
|
|
67
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
68
|
|
|
$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() ); |
69
|
|
|
$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() ); |
70
|
|
|
$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() ); |
71
|
|
|
|
72
|
|
|
$this->assertEquals( $context->getEditor(), $itemUpd->getEditor() ); |
73
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
74
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
75
|
|
|
|
76
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultSaved ); |
77
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultUpd ); |
78
|
|
|
|
79
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
80
|
|
|
$this->object->getItem( $item->getId() ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
public function testFindItem() |
85
|
|
|
{ |
86
|
|
|
$item = $this->object->findItem( 'EUR' ); |
87
|
|
|
|
88
|
|
|
$this->assertEquals( 'EUR', $item->getCode() ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
public function testGetItem() |
93
|
|
|
{ |
94
|
|
|
$actual = $this->object->getItem( 'EUR' ); |
95
|
|
|
|
96
|
|
|
$this->assertEquals( 'EUR', $actual->getId() ); |
97
|
|
|
$this->assertEquals( 'Euro', $actual->getLabel() ); |
98
|
|
|
$this->assertEquals( 1, $actual->getStatus() ); |
99
|
|
|
$this->assertEquals( 'EUR', $actual->getCode() ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
public function testSearchItems() |
104
|
|
|
{ |
105
|
|
|
$search = $this->object->createSearch(); |
106
|
|
|
|
107
|
|
|
$expr = []; |
108
|
|
|
$expr[] = $search->compare( '==', 'locale.currency.id', 'EUR' ); |
109
|
|
|
$expr[] = $search->compare( '==', 'locale.currency.label', 'Euro' ); |
110
|
|
|
$expr[] = $search->compare( '==', 'locale.currency.code', 'EUR' ); |
111
|
|
|
$expr[] = $search->compare( '==', 'locale.currency.status', 1 ); |
112
|
|
|
$expr[] = $search->compare( '>=', 'locale.currency.mtime', '1970-01-01 00:00:00' ); |
113
|
|
|
$expr[] = $search->compare( '>=', 'locale.currency.ctime', '1970-01-01 00:00:00' ); |
114
|
|
|
$expr[] = $search->compare( '>=', 'locale.currency.editor', '' ); |
115
|
|
|
|
116
|
|
|
$total = 0; |
117
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
118
|
|
|
$results = $this->object->searchItems( $search, [], $total ); |
119
|
|
|
|
120
|
|
|
$this->assertEquals( 1, count( $results ) ); |
121
|
|
|
$this->assertEquals( 1, $total ); |
122
|
|
|
|
123
|
|
|
// search without base criteria, slice & total |
124
|
|
|
$search = $this->object->createSearch(); |
125
|
|
|
$search->setConditions( $search->compare( '~=', 'locale.currency.label', 'CFA' ) ); |
126
|
|
|
$search->setSlice( 0, 1 ); |
127
|
|
|
$results = $this->object->searchItems( $search, [], $total ); |
128
|
|
|
$this->assertEquals( 1, count( $results ) ); |
129
|
|
|
$this->assertEquals( 2, $total ); |
130
|
|
|
|
131
|
|
|
foreach( $results as $itemId => $item ) { |
132
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
public function testGetResourceType() |
138
|
|
|
{ |
139
|
|
|
$result = $this->object->getResourceType(); |
140
|
|
|
|
141
|
|
|
$this->assertContains( 'locale/currency', $result ); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
public function testGetSearchAttributes() |
146
|
|
|
{ |
147
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) { |
148
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute ); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
public function testGetSubManager() |
154
|
|
|
{ |
155
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
156
|
|
|
$this->object->getSubManager( 'unknown' ); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|