|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2022 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Index\Manager\Text; |
|
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\MShop\Index\Manager\Text\Standard( $this->context ); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
protected function tearDown() : void |
|
27
|
|
|
{ |
|
28
|
|
|
unset( $this->object ); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
public function testClear() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Index\Manager\Iface::class, $this->object->clear( array( -1 ) ) ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
public function testCleanup() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Index\Manager\Iface::class, $this->object->cleanup( '1970-01-01 00:00:00' ) ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
public function testGetResourceType() |
|
45
|
|
|
{ |
|
46
|
|
|
$result = $this->object->getResourceType(); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertContains( 'index/text', $result ); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
public function testGetSearchAttributes() |
|
53
|
|
|
{ |
|
54
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) { |
|
55
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Criteria\Attribute\Iface::class, $attribute ); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
public function testGetSubManager() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
|
63
|
|
|
$this->object->getSubManager( 'unknown' ); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
public function testIterate() |
|
68
|
|
|
{ |
|
69
|
|
|
$filter = $this->object->filter( true ); |
|
70
|
|
|
$filter->add( $filter->make( 'index.text:name', ['de'] ), '=~', 'Cafe' ); |
|
71
|
|
|
|
|
72
|
|
|
$iterator = $this->object->iterator( $filter ); |
|
73
|
|
|
$products = $this->object->iterate( $iterator, [], 10 ); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertEquals( 2, count( $products ) ); |
|
76
|
|
|
|
|
77
|
|
|
foreach( $products as $itemId => $item ) { |
|
78
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
public function testRemove() |
|
84
|
|
|
{ |
|
85
|
|
|
$this->assertEquals( $this->object, $this->object->remove( [-1] ) ); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
public function testSearchItemsRelevance() |
|
90
|
|
|
{ |
|
91
|
|
|
$config = $this->context->config(); |
|
92
|
|
|
$dbadapter = $config->get( 'resource/db-product/adapter', $config->get( 'resource/db/adapter' ) ); |
|
93
|
|
|
|
|
94
|
|
|
if( $dbadapter === 'sqlsrv' ) { |
|
95
|
|
|
$this->markTestSkipped( 'Not supported by SQL Server' ); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$search = $this->object->filter(); |
|
99
|
|
|
$search->setConditions( $search->compare( '>', $search->make( 'index.text:relevance', ['de', 't-disc'] ), 0 ) ); |
|
100
|
|
|
$search->setSortations( [$search->sort( '-', $search->make( 'sort:index.text:relevance', ['de', 't-disc'] ) )] ); |
|
101
|
|
|
|
|
102
|
|
|
$result = $this->object->search( $search, [] ); |
|
103
|
|
|
|
|
104
|
|
|
$this->assertEquals( 2, count( $result ) ); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
public function testSearchItemsRelevanceCase() |
|
109
|
|
|
{ |
|
110
|
|
|
$config = $this->context->config(); |
|
111
|
|
|
$dbadapter = $config->get( 'resource/db-product/adapter', $config->get( 'resource/db/adapter' ) ); |
|
112
|
|
|
|
|
113
|
|
|
if( $dbadapter === 'sqlsrv' ) { |
|
114
|
|
|
$this->markTestSkipped( 'Not supported by SQL Server' ); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$search = $this->object->filter(); |
|
118
|
|
|
$search->setConditions( $search->compare( '>', $search->make( 'index.text:relevance', ['de', 'T-DISC'] ), 0 ) ); |
|
119
|
|
|
$search->setSortations( [$search->sort( '-', $search->make( 'sort:index.text:relevance', ['de', 'T-DISC'] ) )] ); |
|
120
|
|
|
|
|
121
|
|
|
$result = $this->object->search( $search, [] ); |
|
122
|
|
|
|
|
123
|
|
|
$this->assertEquals( 2, count( $result ) ); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
public function testSearchItemsNoLanguage() |
|
128
|
|
|
{ |
|
129
|
|
|
$config = $this->context->config(); |
|
130
|
|
|
$dbadapter = $config->get( 'resource/db-product/adapter', $config->get( 'resource/db/adapter' ) ); |
|
131
|
|
|
|
|
132
|
|
|
if( $dbadapter === 'sqlsrv' ) { |
|
133
|
|
|
$this->markTestSkipped( 'Not supported by SQL Server' ); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
$search = $this->object->filter(); |
|
137
|
|
|
$search->setConditions( $search->compare( '>', $search->make( 'index.text:relevance', ['de', 'language'] ), 0 ) ); |
|
138
|
|
|
$search->setSortations( [$search->sort( '-', $search->make( 'sort:index.text:relevance', ['de', 'language'] ) )] ); |
|
139
|
|
|
|
|
140
|
|
|
$result = $this->object->search( $search, [] ); |
|
141
|
|
|
|
|
142
|
|
|
$this->assertEquals( 3, count( $result ) ); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
public function testSearchItemsName() |
|
147
|
|
|
{ |
|
148
|
|
|
$search = $this->object->filter(); |
|
149
|
|
|
|
|
150
|
|
|
$func = $search->make( 'index.text:name', ['de'] ); |
|
151
|
|
|
$search->setConditions( $search->compare( '=~', $func, 'Cafe' ) ); |
|
152
|
|
|
|
|
153
|
|
|
$sortfunc = $search->make( 'sort:index.text:name', ['de'] ); |
|
154
|
|
|
$search->setSortations( array( $search->sort( '+', $sortfunc ) ) ); |
|
155
|
|
|
|
|
156
|
|
|
$result = $this->object->search( $search, [] ); |
|
157
|
|
|
|
|
158
|
|
|
$this->assertEquals( 2, count( $result ) ); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
public function testSearchItemsUrl() |
|
163
|
|
|
{ |
|
164
|
|
|
$search = $this->object->filter(); |
|
165
|
|
|
$search->setConditions( $search->compare( '==', 'index.text:url()', 'cafe-noire-cappuccino' ) ); |
|
166
|
|
|
$result = $this->object->search( $search, [] ); |
|
167
|
|
|
|
|
168
|
|
|
$this->assertEquals( 1, count( $result ) ); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
public function testSaveDeleteItem() |
|
173
|
|
|
{ |
|
174
|
|
|
$product = \Aimeos\MShop::create( $this->context, 'product' )->find( 'CNC', ['text'] ); |
|
175
|
|
|
|
|
176
|
|
|
$this->object->delete( $product->getId() ); |
|
177
|
|
|
$this->object->save( $product ); |
|
178
|
|
|
|
|
179
|
|
|
$search = $this->object->filter(); |
|
180
|
|
|
|
|
181
|
|
|
$func = $search->make( 'index.text:name', ['de'] ); |
|
182
|
|
|
$search->setConditions( $search->compare( '==', $func, 'Cafe Noire Expresso' ) ); |
|
183
|
|
|
|
|
184
|
|
|
$this->assertEquals( 1, count( $this->object->search( $search )->toArray() ) ); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
|
|
188
|
|
|
public function testSaveDeleteItemNoName() |
|
189
|
|
|
{ |
|
190
|
|
|
$product = \Aimeos\MShop::create( $this->context, 'product' )->find( 'IJKL', ['text'] ); |
|
191
|
|
|
|
|
192
|
|
|
$this->object->delete( $product->getId() ); |
|
193
|
|
|
$this->object->save( $product ); |
|
194
|
|
|
|
|
195
|
|
|
$search = $this->object->filter(); |
|
196
|
|
|
|
|
197
|
|
|
$func = $search->make( 'index.text:name', ['de'] ); |
|
198
|
|
|
$search->setConditions( $search->compare( '==', $func, 'Unterproduct 3' ) ); |
|
199
|
|
|
|
|
200
|
|
|
$this->assertEquals( 1, count( $this->object->search( $search )->toArray() ) ); |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
|