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

StandardTest::testClear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018-2022
6
 */
7
8
9
namespace Aimeos\MShop\Index\Manager\Supplier;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
17
18
	protected function setUp() : void
19
	{
20
		$this->context = \TestHelper::context();
21
		$this->object = new \Aimeos\MShop\Index\Manager\Supplier\Standard( \TestHelper::context() );
22
	}
23
24
25
	protected function tearDown() : void
26
	{
27
		unset( $this->object, $this->context );
28
	}
29
30
31
	public function testClear()
32
	{
33
		$this->assertInstanceOf( \Aimeos\MShop\Index\Manager\Iface::class, $this->object->clear( array( -1 ) ) );
34
	}
35
36
37
	public function testAggregate()
38
	{
39
		$item = \Aimeos\MShop::create( $this->context, 'supplier' )->find( 'unitSupplier001' );
40
41
		$search = $this->object->filter( true );
42
		$result = $this->object->aggregate( $search, 'index.supplier.id' )->toArray();
43
44
		$this->assertEquals( 1, count( $result ) );
45
		$this->assertArrayHasKey( $item->getId(), $result );
46
		$this->assertEquals( 2, $result[$item->getId()] );
47
	}
48
49
50
	public function testCleanup()
51
	{
52
		$this->assertInstanceOf( \Aimeos\MShop\Index\Manager\Iface::class, $this->object->cleanup( '1970-01-01 00:00:00' ) );
53
	}
54
55
56
	public function testGetResourceType()
57
	{
58
		$result = $this->object->getResourceType();
59
60
		$this->assertContains( 'index/supplier', $result );
61
	}
62
63
64
	public function testGetSearchAttributes()
65
	{
66
		foreach( $this->object->getSearchAttributes() as $attribute ) {
67
			$this->assertInstanceOf( \Aimeos\Base\Criteria\Attribute\Iface::class, $attribute );
68
		}
69
	}
70
71
72
	public function testIterate()
73
	{
74
		$id = \Aimeos\MShop::create( $this->context, 'supplier' )->find( 'unitSupplier001' )->getId();
75
76
		$filter = $this->object->filter( true );
77
		$filter->add( $filter->make( 'index.supplier:position', ['default', $id] ), '>=', 0 );
78
79
		$iterator = $this->object->iterator( $filter );
80
		$products = $this->object->iterate( $iterator, [], 10 );
81
82
		$this->assertEquals( 2, count( $products ) );
83
84
		foreach( $products as $itemId => $item ) {
85
			$this->assertEquals( $itemId, $item->getId() );
86
		}
87
	}
88
89
90
	public function testRemove()
91
	{
92
		$this->assertEquals( $this->object, $this->object->remove( [-1] ) );
93
	}
94
95
96
	public function testSaveDeleteItem()
97
	{
98
		$supplierManager = \Aimeos\MShop::create( $this->context, 'supplier' );
99
		$supItem = $supplierManager->find( 'unitSupplier001' );
100
101
		$productManager = \Aimeos\MShop::create( $this->context, 'product' );
102
		$product = $productManager->find( 'CNC' )->setId( null )->setCode( 'ModifiedCNC' )
103
			->addListItem( 'supplier', $productManager->createListItem(), $supItem );
104
105
		$product = $productManager->save( $product );
106
107
		$this->object->save( $product );
108
109
110
		$search = $this->object->filter();
111
		$search->setConditions( $search->compare( '==', 'index.supplier.id', $supItem->getId() ) );
112
		$result = $this->object->search( $search );
113
114
115
		$this->object->delete( $product->getId() );
116
		$productManager->delete( $product->getId() );
117
118
119
		$search = $this->object->filter();
120
		$search->setConditions( $search->compare( '==', 'index.supplier.id', $supItem->getId() ) );
121
		$result2 = $this->object->search( $search );
122
123
124
		$this->assertTrue( $result->has( $product->getId() ) );
125
		$this->assertFalse( $result2->has( $product->getId() ) );
126
	}
127
128
129
	public function testGetSubManager()
130
	{
131
		$this->expectException( \Aimeos\MShop\Exception::class );
132
		$this->object->getSubManager( 'unknown' );
133
	}
134
135
136
	public function testSearchItemsId()
137
	{
138
		$id = \Aimeos\MShop::create( $this->context, 'supplier' )->find( 'unitSupplier001' )->getId();
139
140
		$search = $this->object->filter();
141
		$search->setConditions( $search->compare( '==', 'index.supplier.id', $id ) );
142
		$result = $this->object->search( $search, [] );
143
144
		$this->assertEquals( 2, count( $result ) );
145
	}
146
147
148
	public function testSearchItemsIdNull()
149
	{
150
		$search = $this->object->filter();
151
		$search->setConditions( $search->compare( '!=', 'index.supplier.id', null ) );
152
		$result = $this->object->search( $search, [] );
153
154
		$this->assertEquals( 2, count( $result ) );
155
	}
156
157
158
	public function testSearchItemsPosition()
159
	{
160
		$id = \Aimeos\MShop::create( $this->context, 'supplier' )->find( 'unitSupplier001' )->getId();
161
162
		$search = $this->object->filter();
163
		$search->setConditions( $search->compare( '>=', $search->make( 'index.supplier:position', ['default', $id] ), 0 ) );
164
		$search->setSortations( [$search->sort( '+', $search->make( 'sort:index.supplier:position', ['default', $id] ) )] );
165
166
		$result = $this->object->search( $search, [] );
167
168
		$this->assertEquals( 2, count( $result ) );
169
	}
170
171
172
	public function testSearchItemsPositionList()
173
	{
174
		$id = \Aimeos\MShop::create( $this->context, 'supplier' )->find( 'unitSupplier001' )->getId();
175
176
		$search = $this->object->filter();
177
		$search->setConditions( $search->compare( '>=', $search->make( 'index.supplier:position', ['default', [$id]] ), 0 ) );
178
		$search->setSortations( [$search->sort( '+', $search->make( 'sort:index.supplier:position', ['default', [$id]] ) )] );
179
180
		$result = $this->object->search( $search, [] );
181
182
		$this->assertEquals( 2, count( $result ) );
183
	}
184
185
186
	public function testSearchItemsRadiusInside()
187
	{
188
		$search = $this->object->filter()->order( 'index.supplier.id' );
189
		$search->add( $search->make( 'index.supplier:radius', [52.5, 10, 115] ), '!=', null );
190
191
		$this->assertEquals( 2, $this->object->search( $search, [] )->count() );
192
	}
193
194
195
	public function testSearchItemsRadiusOutside()
196
	{
197
		$search = $this->object->filter()->order( 'index.supplier.id' );
198
		$search->add( $search->make( 'index.supplier:radius', [52.5, 10, 110] ), '!=', null );
199
200
		$this->assertEquals( 0, $this->object->search( $search, [] )->count() );
201
	}
202
}
203