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