Passed
Push — master ( 7ff05c...452a4e )
by Aimeos
04:44
created

StandardTest::testSaveDeleteItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 14
rs 10
c 0
b 0
f 0
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-2021
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 = \TestHelperMShop::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\MW\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 testRemove()
68
	{
69
		$this->assertEquals( $this->object, $this->object->remove( [-1] ) );
70
	}
71
72
73
	public function testSearchItemsRelevance()
74
	{
75
		$config = $this->context->getConfig();
76
		$dbadapter = $config->get( 'resource/db-product/adapter', $config->get( 'resource/db/adapter' ) );
77
78
		if( $dbadapter === 'sqlsrv' ) {
79
			$this->markTestSkipped( 'Not supported by SQL Server' );
80
		}
81
82
		$search = $this->object->filter();
83
		$search->setConditions( $search->compare( '>', $search->make( 'index.text:relevance', ['de', 't-disc'] ), 0 ) );
84
		$search->setSortations( [$search->sort( '-', $search->make( 'sort:index.text:relevance', ['de', 't-disc'] ) )] );
85
86
		$result = $this->object->search( $search, [] );
87
88
		$this->assertEquals( 1, count( $result ) );
89
	}
90
91
92
	public function testSearchItemsRelevanceCase()
93
	{
94
		$config = $this->context->getConfig();
95
		$dbadapter = $config->get( 'resource/db-product/adapter', $config->get( 'resource/db/adapter' ) );
96
97
		if( $dbadapter === 'sqlsrv' ) {
98
			$this->markTestSkipped( 'Not supported by SQL Server' );
99
		}
100
101
		$search = $this->object->filter();
102
		$search->setConditions( $search->compare( '>', $search->make( 'index.text:relevance', ['de', 'T-DISC'] ), 0 ) );
103
		$search->setSortations( [$search->sort( '-', $search->make( 'sort:index.text:relevance', ['de', 'T-DISC'] ) )] );
104
105
		$result = $this->object->search( $search, [] );
106
107
		$this->assertEquals( 1, count( $result ) );
108
	}
109
110
111
	public function testSearchItemsNoLanguage()
112
	{
113
		$config = $this->context->getConfig();
114
		$dbadapter = $config->get( 'resource/db-product/adapter', $config->get( 'resource/db/adapter' ) );
115
116
		if( $dbadapter === 'sqlsrv' ) {
117
			$this->markTestSkipped( 'Not supported by SQL Server' );
118
		}
119
120
		$search = $this->object->filter();
121
		$search->setConditions( $search->compare( '>', $search->make( 'index.text:relevance', ['de', 'language'] ), 0 ) );
122
		$search->setSortations( [$search->sort( '-', $search->make( 'sort:index.text:relevance', ['de', 'language'] ) )] );
123
124
		$result = $this->object->search( $search, [] );
125
126
		$this->assertEquals( 2, count( $result ) );
127
	}
128
129
130
	public function testSearchItemsName()
131
	{
132
		$search = $this->object->filter();
133
134
		$func = $search->make( 'index.text:name', ['de'] );
135
		$search->setConditions( $search->compare( '=~', $func, 'Cafe' ) );
136
137
		$sortfunc = $search->make( 'sort:index.text:name', ['de'] );
138
		$search->setSortations( array( $search->sort( '+', $sortfunc ) ) );
139
140
		$result = $this->object->search( $search, [] );
141
142
		$this->assertEquals( 2, count( $result ) );
143
	}
144
145
146
	public function testSearchItemsUrl()
147
	{
148
		$search = $this->object->filter();
149
		$search->setConditions( $search->compare( '==', 'index.text:url()', 'Cafe-Noire-Cappuccino' ) );
150
		$result = $this->object->search( $search, [] );
151
152
		$this->assertEquals( 1, count( $result ) );
153
	}
154
155
156
	public function testSaveDeleteItem()
157
	{
158
		$productManager = \Aimeos\MShop\Product\Manager\Factory::create( $this->context );
159
		$product = $productManager->find( 'CNC', ['text'] );
160
161
		$this->object->delete( $product->getId() );
162
		$this->object->save( $product );
163
164
		$search = $this->object->filter();
165
166
		$func = $search->make( 'index.text:name', ['de'] );
167
		$search->setConditions( $search->compare( '==', $func, 'Cafe Noire Expresso' ) );
168
169
		$this->assertEquals( 1, count( $this->object->search( $search )->toArray() ) );
170
	}
171
172
173
	public function testSaveDeleteItemNoName()
174
	{
175
		$productManager = \Aimeos\MShop\Product\Manager\Factory::create( $this->context );
176
		$product = $productManager->find( 'IJKL', ['text'] );
177
178
		$this->object->delete( $product->getId() );
179
		$this->object->save( $product );
180
181
		$search = $this->object->filter();
182
183
		$func = $search->make( 'index.text:name', ['de'] );
184
		$search->setConditions( $search->compare( '==', $func, 'Unterproduct 3' ) );
185
186
		$this->assertEquals( 1, count( $this->object->search( $search )->toArray() ) );
187
	}
188
}
189