|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2023 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
namespace Aimeos\Controller\Frontend\Catalog; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
private $context; |
|
16
|
|
|
private $object; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
protected function setUp() : void |
|
20
|
|
|
{ |
|
21
|
|
|
$this->context = \TestHelper::context(); |
|
22
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Catalog\Standard( $this->context ); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
protected function tearDown() : void |
|
27
|
|
|
{ |
|
28
|
|
|
unset( $this->object, $this->context ); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
public function testCompare() |
|
33
|
|
|
{ |
|
34
|
|
|
$list = $this->object->compare( '==', 'catalog.code', 'categories' )->getTree()->toList(); |
|
35
|
|
|
$this->assertEquals( 1, count( $list ) ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
public function testFind() |
|
40
|
|
|
{ |
|
41
|
|
|
$item = $this->object->uses( ['text'] )->find( 'cafe' ); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $item ); |
|
44
|
|
|
$this->assertEquals( 1, count( $item->getRefItems( 'text' ) ) ); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
public function testFunction() |
|
49
|
|
|
{ |
|
50
|
|
|
$str = $this->object->function( 'catalog:has', ['domain', 'type', 'refid'] ); |
|
51
|
|
|
$this->assertEquals( 'catalog:has("domain","type","refid")', $str ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
public function testGet() |
|
56
|
|
|
{ |
|
57
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'catalog' )->find( 'cafe' ); |
|
58
|
|
|
$item = $this->object->uses( ['text'] )->get( $item->getId() ); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $item ); |
|
61
|
|
|
$this->assertEquals( 1, count( $item->getRefItems( 'text' ) ) ); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
public function testGetPath() |
|
66
|
|
|
{ |
|
67
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'catalog' )->find( 'cafe', [] ); |
|
68
|
|
|
$items = $this->object->uses( ['text'] )->getPath( $item->getId() ); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertEquals( 3, count( $items ) ); |
|
71
|
|
|
$this->assertEquals( 1, count( $items->last()->getRefItems( 'text' ) ) ); |
|
72
|
|
|
|
|
73
|
|
|
foreach( $items as $item ) { |
|
74
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $item ); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
public function testGetTree() |
|
80
|
|
|
{ |
|
81
|
|
|
$tree = $this->object->uses( ['text'] )->getTree(); |
|
82
|
|
|
|
|
83
|
|
|
foreach( $tree->toList() as $item ) { |
|
84
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $item ); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$this->assertEquals( 2, count( $tree->getChildren() ) ); |
|
88
|
|
|
$this->assertEquals( 5, count( $tree->toList()->last()->getRefItems( 'text' ) ) ); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
public function testHas() |
|
93
|
|
|
{ |
|
94
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'text' ); |
|
95
|
|
|
$filter = $manager->filter()->add( ['text.domain' => 'catalog'] )->slice( 0, 1 ); |
|
96
|
|
|
$id = $manager->search( $filter )->first()->getId(); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertEquals( 1, count( $this->object->has( 'text', 'unittype1', $id )->search() ) ); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
public function testParse() |
|
103
|
|
|
{ |
|
104
|
|
|
$cond = ['>' => ['catalog.status' => 0]]; |
|
105
|
|
|
$this->assertEquals( 8, count( $this->object->parse( $cond )->getTree()->toList() ) ); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
public function testResolve() |
|
110
|
|
|
{ |
|
111
|
|
|
$item = $this->object->resolve( 'tee' ); |
|
112
|
|
|
|
|
113
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $item ); |
|
114
|
|
|
$this->assertEquals( 'Tee', $item->getLabel() ); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
public function testRoot() |
|
119
|
|
|
{ |
|
120
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'catalog' ); |
|
121
|
|
|
|
|
122
|
|
|
$root = $manager->find( 'categories' ); |
|
123
|
|
|
$item = $manager->find( 'cafe' ); |
|
124
|
|
|
|
|
125
|
|
|
$this->assertEquals( 2, count( $this->object->root( $root->getId() )->getPath( $item->getId() ) ) ); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
public function testSearch() |
|
130
|
|
|
{ |
|
131
|
|
|
$total = 0; |
|
132
|
|
|
$items = $this->object->uses( ['text'] )->compare( '==', 'catalog.code', 'cafe' )->search( $total ); |
|
133
|
|
|
|
|
134
|
|
|
$this->assertCount( 1, $items ); |
|
135
|
|
|
$this->assertEquals( 1, count( $items->first()->getRefItems( 'text' ) ) ); |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
public function testSlice() |
|
140
|
|
|
{ |
|
141
|
|
|
$this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) ); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
public function testSort() |
|
146
|
|
|
{ |
|
147
|
|
|
$this->assertGreaterThanOrEqual( 8, count( $this->object->sort( 'catalog.label' )->search() ) ); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
public function testUses() |
|
152
|
|
|
{ |
|
153
|
|
|
$this->assertSame( $this->object, $this->object->uses( ['text'] ) ); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
public function testVisible() |
|
158
|
|
|
{ |
|
159
|
|
|
$this->context->config()->set( 'controller/frontend/catalog/levels-always', null ); |
|
160
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'catalog' ); |
|
161
|
|
|
|
|
162
|
|
|
$root = $manager->find( 'root' ); |
|
163
|
|
|
$item = $manager->find( 'cafe' ); |
|
164
|
|
|
$catIds = $manager->getPath( $item->getId() )->keys()->toArray(); |
|
165
|
|
|
|
|
166
|
|
|
$result = $this->object->root( $root->getId() )->visible( $catIds )->getTree(); |
|
167
|
|
|
|
|
168
|
|
|
$this->assertEquals( 6, count( $result->toList() ) ); |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|