Passed
Push — master ( 776560...15a7cc )
by Aimeos
04:19
created

StandardTest::testSearchItemsUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
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-2018
7
 */
8
9
10
namespace Aimeos\MShop\Index\Manager\Text;
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\Index\Manager\Text\Standard( \TestHelperMShop::getContext() );
21
	}
22
23
24
	protected function tearDown()
25
	{
26
		unset( $this->object );
27
	}
28
29
30
	public function testCleanup()
31
	{
32
		$this->object->cleanup( array( -1 ) );
33
	}
34
35
36
	public function testAggregate()
37
	{
38
		$this->object->aggregate( $this->object->createSearch(), 'index.text.id' );
39
	}
40
41
42
	public function testGetResourceType()
43
	{
44
		$result = $this->object->getResourceType();
45
46
		$this->assertContains( 'index/text', $result );
47
	}
48
49
50
	public function testGetSearchAttributes()
51
	{
52
		foreach( $this->object->getSearchAttributes() as $attribute ) {
53
			$this->assertInstanceOf( \Aimeos\MW\Criteria\Attribute\Iface::class, $attribute );
54
		}
55
	}
56
57
58
	public function testGetSubManager()
59
	{
60
		$this->setExpectedException( \Aimeos\MShop\Exception::class );
61
		$this->object->getSubManager( 'unknown' );
62
	}
63
64
65
	public function testSearchItemsRelevance()
66
	{
67
		$search = $this->object->createSearch();
68
69
		$func = $search->createFunction( 'index.text:relevance', array( 'de', 'Expr' ) );
70
		$search->setConditions( $search->compare( '>', $func, 0 ) );
71
72
		$sortfunc = $search->createFunction( 'sort:index.text:relevance', array( 'de', 'Expr' ) );
73
		$search->setSortations( array( $search->sort( '+', $sortfunc ) ) );
74
75
		$result = $this->object->searchItems( $search, [] );
76
77
		$this->assertEquals( 2, count( $result ) );
78
	}
79
80
81
	public function testSearchItemsName()
82
	{
83
		$search = $this->object->createSearch();
84
85
		$func = $search->createFunction( 'index.text:name', ['de'] );
86
		$search->setConditions( $search->compare( '=~', $func, 'Cafe' ) );
87
88
		$sortfunc = $search->createFunction( 'sort:index.text:name', ['de'] );
89
		$search->setSortations( array( $search->sort( '+', $sortfunc ) ) );
90
91
		$result = $this->object->searchItems( $search, [] );
92
93
		$this->assertEquals( 2, count( $result ) );
94
	}
95
96
97
	public function testSearchItemsUrl()
98
	{
99
		$search = $this->object->createSearch();
100
101
		$func = $search->createFunction( 'index.text:url', ['de'] );
102
		$search->setConditions( $search->compare( '==', $func, 'Cafe_Noire_Cappuccino' ) );
103
104
		$result = $this->object->searchItems( $search, [] );
105
106
		$this->assertEquals( 1, count( $result ) );
107
	}
108
109
110
	public function testSaveDeleteItem()
111
	{
112
		$productManager = \Aimeos\MShop\Product\Manager\Factory::create( \TestHelperMShop::getContext() );
113
		$product = $productManager->findItem( 'CNC', ['text'] );
114
115
		$this->object->deleteItem( $product->getId() );
116
		$this->object->saveItem( $product );
117
118
		$search = $this->object->createSearch();
119
120
		$func = $search->createFunction( 'index.text:name', ['de'] );
121
		$search->setConditions( $search->compare( '==', $func, 'Cafe Noire Expresso' ) );
122
123
		$this->assertEquals( 1, count( $this->object->searchItems( $search ) ) );
124
	}
125
126
127
	public function testSaveDeleteItemNoName()
128
	{
129
		$productManager = \Aimeos\MShop\Product\Manager\Factory::create( \TestHelperMShop::getContext() );
130
		$product = $productManager->findItem( 'IJKL', ['text'] );
131
132
		$this->object->deleteItem( $product->getId() );
133
		$this->object->saveItem( $product );
134
135
		$search = $this->object->createSearch();
136
137
		$func = $search->createFunction( 'index.text:name', ['de'] );
138
		$search->setConditions( $search->compare( '==', $func, 'Unterproduct 3' ) );
139
140
		$this->assertEquals( 1, count( $this->object->searchItems( $search ) ) );
141
	}
142
143
144
	public function testCleanupIndex()
145
	{
146
		$this->object->cleanupIndex( '1970-01-01 00:00:00' );
147
	}
148
149
}
150