Passed
Push — master ( 1c1daf...484f92 )
by Aimeos
04:34
created

PgSQLTest::testSearchItemsRelevance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 17
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2018-2018
6
 */
7
8
9
namespace Aimeos\MShop\Index\Manager\Text;
10
11
12
class PgSQLTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
16
17
	protected function setUp()
18
	{
19
		$context = clone \TestHelperMShop::getContext();
20
		$config = $context->getConfig();
21
22
		$dbadapter = $config->get( 'resource/db-index/adapter', $config->get( 'resource/db/adapter' ) );
23
24
		if( $dbadapter !== 'pgsql' ) {
25
			$this->markTestSkipped( 'PostgreSQL specific test' );
26
		}
27
28
		$this->object = new \Aimeos\MShop\Index\Manager\Text\PgSQL( \TestHelperMShop::getContext() );
29
	}
30
31
32
	protected function tearDown()
33
	{
34
		unset( $this->object );
35
	}
36
37
38
	public function testGetSearchAttributes()
39
	{
40
		$list = $this->object->getSearchAttributes();
41
42
		foreach( $list as $attribute ) {
43
			$this->assertInstanceOf( \Aimeos\MW\Criteria\Attribute\Iface::class, $attribute );
44
		}
45
	}
46
47
48
	public function testSearchItemsRelevance()
49
	{
50
		$search = $this->object->createSearch();
51
52
		$search->setConditions( $search->combine( '&&', [
53
			$search->compare( '>', $search->createFunction( 'index.text:relevance', ['de', 'T-DISC'] ), 0 ),
54
			$search->compare( '>', $search->createFunction( 'index.text:relevance', ['de', 't-disc'] ), 0 ),
55
		] ) );
56
57
		$search->setSortations( [
58
			$search->sort( '+', $search->createFunction( 'sort:index.text:relevance', ['de', 'T-DISC'] ) ),
59
			$search->sort( '+', $search->createFunction( 'sort:index.text:relevance', ['de', 't-disc'] ) ),
60
		] );
61
62
		$result = $this->object->searchItems( $search, [] );
63
64
		$this->assertEquals( 1, count( $result ) );
65
	}
66
}
67