1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018-2023 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Supplier; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $context; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() : void |
19
|
|
|
{ |
20
|
|
|
$this->context = \TestHelper::context(); |
21
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Supplier\Standard( $this->context ); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
protected function tearDown() : void |
26
|
|
|
{ |
27
|
|
|
unset( $this->object, $this->context ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
public function testCompare() |
32
|
|
|
{ |
33
|
|
|
$this->assertEquals( 2, count( $this->object->compare( '=~', 'supplier.label', 'Unit' )->search() ) ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
public function testFind() |
38
|
|
|
{ |
39
|
|
|
$item = $this->object->uses( ['text'] )->find( 'unitSupplier001' ); |
40
|
|
|
|
41
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Iface::class, $item ); |
42
|
|
|
$this->assertEquals( 3, count( $item->getRefItems( 'text' ) ) ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testFunction() |
47
|
|
|
{ |
48
|
|
|
$str = $this->object->function( 'supplier:has', ['domain', 'type', 'refid'] ); |
49
|
|
|
$this->assertEquals( 'supplier:has("domain","type","refid")', $str ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function testGet() |
54
|
|
|
{ |
55
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'supplier' )->find( 'unitSupplier001' ); |
56
|
|
|
$item = $this->object->uses( ['text'] )->get( $item->getId() ); |
57
|
|
|
|
58
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Iface::class, $item ); |
59
|
|
|
$this->assertEquals( 3, count( $item->getRefItems( 'text' ) ) ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
public function testHas() |
64
|
|
|
{ |
65
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'text' ); |
66
|
|
|
$filter = $manager->filter()->add( ['text.domain' => 'supplier'] )->slice( 0, 1 ); |
67
|
|
|
$id = $manager->search( $filter )->first()->getId(); |
68
|
|
|
|
69
|
|
|
$this->assertEquals( 1, count( $this->object->has( 'text', 'default', $id )->search() ) ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
public function testParse() |
74
|
|
|
{ |
75
|
|
|
$cond = ['&&' => [['==' => ['supplier.status' => 1]], ['=~' => ['supplier.label' => 'Unit']]]]; |
76
|
|
|
$this->assertEquals( 2, count( $this->object->parse( $cond )->search() ) ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
public function testResolve() |
81
|
|
|
{ |
82
|
|
|
$item = $this->object->resolve( 'unitSupplier001' ); |
83
|
|
|
|
84
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Iface::class, $item ); |
85
|
|
|
$this->assertEquals( 'Unit Supplier 001', $item->getLabel() ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
public function testSearch() |
90
|
|
|
{ |
91
|
|
|
$total = 0; |
92
|
|
|
$items = $this->object->uses( ['text'] )->compare( '=~', 'supplier.code', 'unit' ) |
93
|
|
|
->sort( 'supplier.code' )->search( $total ); |
94
|
|
|
|
95
|
|
|
$this->assertGreaterThanOrEqual( 2, count( $items ) ); |
96
|
|
|
$this->assertGreaterThanOrEqual( 2, $total ); |
97
|
|
|
$this->assertEquals( 3, count( $items->first()->getRefItems( 'text' ) ) ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function testSlice() |
102
|
|
|
{ |
103
|
|
|
$this->assertEquals( 1, count( $this->object->slice( 0, 1 )->search() ) ); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
public function testSort() |
108
|
|
|
{ |
109
|
|
|
$this->assertGreaterThanOrEqual( 2, count( $this->object->sort()->search() ) ); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
public function testSortGeneric() |
114
|
|
|
{ |
115
|
|
|
$this->assertGreaterThanOrEqual( 2, count( $this->object->sort( 'supplier.label' )->search() ) ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testSortMultiple() |
120
|
|
|
{ |
121
|
|
|
$this->assertGreaterThanOrEqual( 2, count( $this->object->sort( 'supplier.label,-supplier.id' )->search() ) ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
public function testUses() |
126
|
|
|
{ |
127
|
|
|
$this->assertSame( $this->object, $this->object->uses( ['text'] ) ); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|