|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2020 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Stock; |
|
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 = \TestHelperFrontend::getContext(); |
|
21
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Stock\Standard( $this->context ); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
protected function tearDown() : void |
|
26
|
|
|
{ |
|
27
|
|
|
unset( $this->object, $this->context ); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
public function testProduct() |
|
32
|
|
|
{ |
|
33
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'product' )->find( 'CNC' ); |
|
34
|
|
|
$this->assertEquals( 1, count( $this->object->product( $item->getId() )->search() ) ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
public function testCompare() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->assertEquals( 7, count( $this->object->compare( '==', 'stock.stocklevel', null )->search() ) ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
public function testGet() |
|
45
|
|
|
{ |
|
46
|
|
|
$iface = \Aimeos\MShop\Stock\Item\Iface::class; |
|
47
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'stock' ); |
|
48
|
|
|
$item = $manager->search( $manager->filter()->slice( 0, 1) )->first(); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertInstanceOf( $iface, $this->object->get( $item->getId() ) ); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
public function testParse() |
|
55
|
|
|
{ |
|
56
|
|
|
$cond = ['||' => [['==' => ['stock.dateback' => null]], ['>=' => ['stock.dateback' => '2010-01-01 00:00:00']]]]; |
|
57
|
|
|
$this->assertEquals( 19, count( $this->object->parse( $cond )->search() ) ); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
public function testSearch() |
|
62
|
|
|
{ |
|
63
|
|
|
$total = 0; |
|
64
|
|
|
$this->assertGreaterThanOrEqual( 15, count( $this->object->search( $total ) ) ); |
|
65
|
|
|
$this->assertGreaterThanOrEqual( 15, $total ); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
public function testSlice() |
|
70
|
|
|
{ |
|
71
|
|
|
$this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) ); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
public function testSort() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->assertGreaterThanOrEqual( 15, count( $this->object->sort()->search() ) ); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
public function testSortGeneric() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->assertGreaterThanOrEqual( 15, count( $this->object->sort( 'stock.dateback' )->search() ) ); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
public function testSortMultiple() |
|
88
|
|
|
{ |
|
89
|
|
|
$this->assertGreaterThanOrEqual( 15, count( $this->object->sort( 'stock.type,-stock.dateback' )->search() ) ); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
public function testSortStock() |
|
94
|
|
|
{ |
|
95
|
|
|
$result = $this->object->sort( 'stock' )->search(); |
|
96
|
|
|
$this->assertStringStartsWith( 100, $result->first()->getStocklevel() ); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
public function testSortStockDesc() |
|
101
|
|
|
{ |
|
102
|
|
|
$result = $this->object->sort( '-stock' )->search(); |
|
103
|
|
|
$this->assertStringStartsWith( 100, $result->last()->getStocklevel() ); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
public function testType() |
|
108
|
|
|
{ |
|
109
|
|
|
$this->assertEquals( 8, count( $this->object->type( 'default' )->search() ) ); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|