1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018-2025 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Aimeos\Controller\Jobs\Common\Subscription\Process\Processor\Cgroup; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
12
|
|
|
{ |
13
|
|
|
private $context; |
14
|
|
|
private $custStub; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
protected function setUp() : void |
18
|
|
|
{ |
19
|
|
|
\Aimeos\MShop::cache( true ); |
20
|
|
|
|
21
|
|
|
$this->context = \TestHelper::context(); |
22
|
|
|
|
23
|
|
|
$this->custStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Customer\\Manager\\Standard' ) |
24
|
|
|
->setConstructorArgs( [$this->context] ) |
25
|
|
|
->onlyMethods( ['get', 'save'] ) |
26
|
|
|
->getMock(); |
27
|
|
|
|
28
|
|
|
\Aimeos\MShop::inject( '\\Aimeos\\MShop\\Customer\\Manager\\Standard', $this->custStub ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
protected function tearDown() : void |
33
|
|
|
{ |
34
|
|
|
\Aimeos\MShop::cache( false ); |
35
|
|
|
unset( $this->context ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
public function testBegin() |
40
|
|
|
{ |
41
|
|
|
$ordProdStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Product\\Standard' ) |
42
|
|
|
->setConstructorArgs( [$this->context] ) |
43
|
|
|
->onlyMethods( ['get', 'type'] ) |
44
|
|
|
->getMock(); |
45
|
|
|
|
46
|
|
|
$ordProdStub->method( 'type' )->willReturn( ['order', 'product'] ); |
47
|
|
|
|
48
|
|
|
\Aimeos\MShop::inject( '\\Aimeos\\MShop\\Order\\Manager\\Product\\Standard', $ordProdStub ); |
49
|
|
|
|
50
|
|
|
$subscription = $this->getSubscription(); |
51
|
|
|
$ordProdAttrManager = $ordProdStub->getSubManager( 'attribute' ); |
52
|
|
|
$ordProdAttrItem = $ordProdAttrManager->create()->setType( 'hidden' )->setCode( 'group' ); |
53
|
|
|
|
54
|
|
|
$ordProdItem = $ordProdStub->create()->setAttributeItems( [ |
55
|
|
|
( clone $ordProdAttrItem )->setAttributeId( 10 )->setValue( '3' ), |
56
|
|
|
( clone $ordProdAttrItem )->setAttributeId( 11 )->setValue( '4' ), |
57
|
|
|
] ); |
58
|
|
|
|
59
|
|
|
$ordProdStub->expects( $this->once() )->method( 'get' ) |
60
|
|
|
->willReturn( $ordProdItem ); |
61
|
|
|
|
62
|
|
|
$this->custStub->expects( $this->once() )->method( 'get' ) |
63
|
|
|
->willReturn( $this->custStub->create() ); |
64
|
|
|
|
65
|
|
|
$this->custStub->expects( $this->once() )->method( 'save' ) |
66
|
|
|
->with( $this->callback( function( $subject ) { |
67
|
|
|
return $subject->getGroups() === ['3', '4']; |
68
|
|
|
} ) ); |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
$object = new \Aimeos\Controller\Jobs\Common\Subscription\Process\Processor\Cgroup\Standard( $this->context ); |
72
|
|
|
$object->begin( $subscription, $subscription->getOrderItem() ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testBeginCustomGroups() |
77
|
|
|
{ |
78
|
|
|
$this->custStub->expects( $this->once() )->method( 'get' ) |
79
|
|
|
->willReturn( $this->custStub->create()->setGroups( ['1', '2'] ) ); |
80
|
|
|
|
81
|
|
|
$this->custStub->expects( $this->once() )->method( 'save' ) |
82
|
|
|
->with( $this->callback( function( $subject ) { |
83
|
|
|
return $subject->getGroups() === ['1', '2']; |
84
|
|
|
} ) ); |
85
|
|
|
|
86
|
|
|
$subscription = $this->getSubscription(); |
87
|
|
|
|
88
|
|
|
$object = new \Aimeos\Controller\Jobs\Common\Subscription\Process\Processor\Cgroup\Standard( $this->context ); |
89
|
|
|
$object->begin( $subscription, $subscription->getOrderItem() ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
public function testEnd() |
94
|
|
|
{ |
95
|
|
|
$ordProdStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Product\\Standard' ) |
96
|
|
|
->setConstructorArgs( [$this->context] ) |
97
|
|
|
->onlyMethods( ['get', 'type'] ) |
98
|
|
|
->getMock(); |
99
|
|
|
|
100
|
|
|
$ordProdStub->method( 'type' )->willReturn( ['order', 'product'] ); |
101
|
|
|
|
102
|
|
|
\Aimeos\MShop::inject( '\\Aimeos\\MShop\\Order\\Manager\\Product\\Standard', $ordProdStub ); |
103
|
|
|
|
104
|
|
|
$subscription = $this->getSubscription(); |
105
|
|
|
$ordProdAttrManager = $ordProdStub->getSubManager( 'attribute' ); |
106
|
|
|
$ordProdAttrItem = $ordProdAttrManager->create()->setType( 'hidden' )->setCode( 'group' ); |
107
|
|
|
|
108
|
|
|
$ordProdItem = $ordProdStub->create()->setAttributeItems( [ |
109
|
|
|
( clone $ordProdAttrItem )->setAttributeId( 10 )->setValue( '3' ), |
110
|
|
|
( clone $ordProdAttrItem )->setAttributeId( 11 )->setValue( '4' ), |
111
|
|
|
] ); |
112
|
|
|
|
113
|
|
|
$ordProdStub->expects( $this->once() )->method( 'get' ) |
114
|
|
|
->willReturn( $ordProdItem ); |
115
|
|
|
|
116
|
|
|
$this->custStub->expects( $this->once() )->method( 'get' ) |
117
|
|
|
->willReturn( $this->custStub->create() ); |
118
|
|
|
|
119
|
|
|
$this->custStub->expects( $this->once() )->method( 'save' ) |
120
|
|
|
->with( $this->callback( function( $subject ) { |
121
|
|
|
return $subject->getGroups() === []; |
122
|
|
|
} ) ); |
123
|
|
|
|
124
|
|
|
$object = new \Aimeos\Controller\Jobs\Common\Subscription\Process\Processor\Cgroup\Standard( $this->context ); |
125
|
|
|
$object->end( $subscription, $subscription->getOrderItem() ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
public function testEndCustomGroups() |
130
|
|
|
{ |
131
|
|
|
$this->custStub->expects( $this->once() )->method( 'get' ) |
132
|
|
|
->willReturn( $this->custStub->create() ); |
133
|
|
|
|
134
|
|
|
$this->custStub->expects( $this->once() )->method( 'save' ) |
135
|
|
|
->with( $this->callback( function( $subject ) { |
136
|
|
|
return $subject->getGroups() === []; |
137
|
|
|
} ) ); |
138
|
|
|
|
139
|
|
|
$subscription = $this->getSubscription(); |
140
|
|
|
|
141
|
|
|
$object = new \Aimeos\Controller\Jobs\Common\Subscription\Process\Processor\Cgroup\Standard( $this->context ); |
142
|
|
|
$object->end( $subscription, $subscription->getOrderItem() ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
protected function getSubscription() |
147
|
|
|
{ |
148
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'subscription' ); |
149
|
|
|
$search = $manager->filter()->add( ['subscription.dateend' => '2010-01-01'] ); |
150
|
|
|
$domains = ['order', 'order/address', 'order/coupon', 'order/product', 'order/service']; |
151
|
|
|
|
152
|
|
|
return $manager->search( $search, $domains )->first( new \Exception( 'No subscription item found' ) ); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|