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\Subscription; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $context; |
15
|
|
|
private $manager; |
16
|
|
|
private $object; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
\Aimeos\MShop::cache( true ); |
22
|
|
|
|
23
|
|
|
$this->context = \TestHelper::context(); |
24
|
|
|
$this->context->setUser( $this->getCustomer() ); |
25
|
|
|
|
26
|
|
|
$this->manager = $this->getMockBuilder( '\\Aimeos\\MShop\\Subscription\\Manager\\Standard' ) |
27
|
|
|
->setConstructorArgs( [$this->context] ) |
28
|
|
|
->onlyMethods( ['save'] ) |
29
|
|
|
->getMock(); |
30
|
|
|
|
31
|
|
|
\Aimeos\MShop::inject( '\\Aimeos\\MShop\\Subscription\\Manager\\Standard', $this->manager ); |
32
|
|
|
|
33
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Subscription\Standard( $this->context ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
protected function tearDown() : void |
38
|
|
|
{ |
39
|
|
|
\Aimeos\MShop::cache( false ); |
40
|
|
|
unset( $this->object, $this->manager, $this->context ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testCancel() |
45
|
|
|
{ |
46
|
|
|
$expected = \Aimeos\MShop\Subscription\Item\Iface::class; |
47
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'subscription' )->create(); |
48
|
|
|
|
49
|
|
|
$this->manager->expects( $this->once() )->method( 'save' ) |
50
|
|
|
->will( $this->returnValue( $item ) ); |
51
|
|
|
|
52
|
|
|
$this->assertInstanceOf( $expected, $this->object->cancel( $this->getSubscription() ) ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
public function testCompare() |
57
|
|
|
{ |
58
|
|
|
$this->assertEquals( 2, count( $this->object->compare( '>=', 'subscription.datenext', '2000-01-01' )->search() ) ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function testGet() |
63
|
|
|
{ |
64
|
|
|
$expected = \Aimeos\MShop\Subscription\Item\Iface::class; |
65
|
|
|
$this->assertInstanceOf( $expected, $this->object->get( $this->getSubscription() ) ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
public function testGetException() |
70
|
|
|
{ |
71
|
|
|
$this->expectException( \Aimeos\Controller\Frontend\Subscription\Exception::class ); |
72
|
|
|
$this->object->get( -1 ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testGetIntervals() |
77
|
|
|
{ |
78
|
|
|
$this->assertGreaterThan( 0, count( $this->object->getIntervals() ) ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testParse() |
83
|
|
|
{ |
84
|
|
|
$cond = ['&&' => [['==' => ['subscription.datenext' => '2000-01-01']], ['==' => ['subscription.status' => 1]]]]; |
85
|
|
|
$this->assertEquals( 1, count( $this->object->parse( $cond )->search() ) ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
public function testSave() |
90
|
|
|
{ |
91
|
|
|
$item = $this->manager->create(); |
92
|
|
|
$expected = \Aimeos\MShop\Subscription\Item\Iface::class; |
93
|
|
|
|
94
|
|
|
$this->manager->expects( $this->once() )->method( 'save' ) |
95
|
|
|
->will( $this->returnValue( $item ) ); |
96
|
|
|
|
97
|
|
|
$this->assertInstanceOf( $expected, $this->object->save( $item ) ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function testSearch() |
102
|
|
|
{ |
103
|
|
|
$total = 0; |
104
|
|
|
$items = $this->object->uses( ['order'] )->search( $total ); |
105
|
|
|
|
106
|
|
|
$this->assertGreaterThanOrEqual( 2, count( $items ) ); |
107
|
|
|
$this->assertGreaterThanOrEqual( 2, $total ); |
108
|
|
|
|
109
|
|
|
foreach( $items as $item ) { |
110
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $item->getOrderItem() ); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
public function testSlice() |
116
|
|
|
{ |
117
|
|
|
$this->assertEquals( 1, count( $this->object->slice( 0, 1 )->search() ) ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
public function testSort() |
122
|
|
|
{ |
123
|
|
|
$this->assertEquals( 2, count( $this->object->sort()->search() ) ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
public function testSortInterval() |
128
|
|
|
{ |
129
|
|
|
$this->assertEquals( 2, count( $this->object->sort( 'interval' )->search() ) ); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
public function testSortGeneric() |
134
|
|
|
{ |
135
|
|
|
$this->assertEquals( 2, count( $this->object->sort( 'subscription.dateend' )->search() ) ); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
public function testSortMultiple() |
140
|
|
|
{ |
141
|
|
|
$this->assertEquals( 2, count( $this->object->sort( 'subscription.dateend,-subscription.id' )->search() ) ); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
public function testUses() |
146
|
|
|
{ |
147
|
|
|
$this->assertSame( $this->object, $this->object->uses( ['order'] ) ); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
protected function getCustomer() |
152
|
|
|
{ |
153
|
|
|
return \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]' ); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
protected function getSubscription() |
158
|
|
|
{ |
159
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'subscription' ); |
160
|
|
|
$search = $manager->filter()->slice( 0, 1 ); |
161
|
|
|
|
162
|
|
|
return $manager->search( $search )->first( new \RuntimeException( 'No subscription item found' ) ); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|