Passed
Pull Request — master (#297)
by Aimeos
10:30
created

StandardTest::testSearchItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 1
nc 1
nop 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-2022
7
 */
8
9
10
namespace Aimeos\MShop\Index\Manager\Price;
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\Price\Standard( $this->context );
23
	}
24
25
26
	protected function tearDown() : void
27
	{
28
		unset( $this->object, $this->context );
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 testGetResourceType()
39
	{
40
		$result = $this->object->getResourceType();
41
42
		$this->assertContains( 'index/price', $result );
43
	}
44
45
46
	public function testGetSearchAttributes()
47
	{
48
		foreach( $this->object->getSearchAttributes() as $attribute ) {
49
			$this->assertInstanceOf( \Aimeos\Base\Criteria\Attribute\Iface::class, $attribute );
50
		}
51
	}
52
53
54
	public function testSaveDeleteItem()
55
	{
56
		$productManager = \Aimeos\MShop::create( $this->context, 'product' );
57
		$product = $productManager->find( 'CNC', ['price'] );
58
59
		$this->object->delete( $product->getId() );
60
		$this->object->save( $product );
61
62
		$search = $this->object->filter();
63
64
		$func = $search->make( 'index.price:value', ['EUR'] );
65
		$search->setConditions( $search->compare( '==', $func, '18.00' ) );
66
67
		$this->assertEquals( 3, count( $this->object->search( $search )->toArray() ) );
68
	}
69
70
71
	public function testGetSubManager()
72
	{
73
		$this->expectException( \Aimeos\MShop\Exception::class );
74
		$this->object->getSubManager( 'unknown' );
75
	}
76
77
78
	public function testIterate()
79
	{
80
		$filter = $this->object->filter();
81
		$filter->add( $filter->make( 'index.price:value', ['EUR'] ), '>=', '18.00' );
82
83
		$iterator = $this->object->iterator( $filter );
84
		$products1 = $this->object->iterate( $iterator, [], 10 );
85
		$products2 = $this->object->iterate( $iterator, [], 10 );
86
87
		$this->assertEquals( 10, count( $products1 ) );
88
		$this->assertEquals( 1, count( $products2 ) );
89
90
		foreach( $products1 as $itemId => $item ) {
91
			$this->assertEquals( $itemId, $item->getId() );
92
		}
93
	}
94
95
96
	public function testRemove()
97
	{
98
		$this->assertEquals( $this->object, $this->object->remove( [-1] ) );
99
	}
100
101
102
	public function testSearchItems()
103
	{
104
		$search = $this->object->filter();
105
106
		$func = $search->make( 'index.price:value', ['EUR'] );
107
		$search->setConditions( $search->compare( '>=', $func, '18.00' ) );
108
109
		$sortfunc = $search->make( 'sort:index.price:value', ['EUR'] );
110
		$search->setSortations( array( $search->sort( '+', $sortfunc ) ) );
111
112
		$result = $this->object->search( $search, [] );
113
114
		$this->assertEquals( 11, count( $result ) );
115
	}
116
117
118
	public function testCleanup()
119
	{
120
		$this->assertInstanceOf( \Aimeos\MShop\Index\Manager\Iface::class, $this->object->cleanup( '1970-01-01 00:00:00' ) );
121
	}
122
123
}
124