|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Aimeos\Controller\Common\Subscription\Process\Processor\Cgroup; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
protected function setUp() |
|
14
|
|
|
{ |
|
15
|
|
|
\Aimeos\MShop\Factory::setCache( true ); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
protected function tearDown() |
|
20
|
|
|
{ |
|
21
|
|
|
\Aimeos\MShop\Factory::setCache( false ); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
public function testBegin() |
|
26
|
|
|
{ |
|
27
|
|
|
$context = \TestHelperCntl::getContext(); |
|
28
|
|
|
|
|
29
|
|
|
$context->getConfig()->set( 'controller/common/subscription/process/processor/cgroup/groupids', ['1', '2'] ); |
|
30
|
|
|
|
|
31
|
|
|
$customerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Customer\\Manager\\Standard' ) |
|
32
|
|
|
->setConstructorArgs( [$context] ) |
|
33
|
|
|
->setMethods( ['getItem', 'saveItem'] ) |
|
34
|
|
|
->getMock(); |
|
35
|
|
|
|
|
36
|
|
|
\Aimeos\MShop\Factory::injectManager( $context, 'customer', $customerStub ); |
|
37
|
|
|
|
|
38
|
|
|
$customerItem = $customerStub->createItem(); |
|
39
|
|
|
|
|
40
|
|
|
$customerStub->expects( $this->once() )->method( 'getItem' ) |
|
41
|
|
|
->will( $this->returnValue( $customerItem ) ); |
|
42
|
|
|
|
|
43
|
|
|
$customerStub->expects( $this->once() )->method( 'saveItem' ) |
|
44
|
|
|
->with( $this->callback( |
|
45
|
|
|
function( $subject ){ |
|
46
|
|
|
return $subject->getGroups() === ['1', '2']; |
|
47
|
|
|
} |
|
48
|
|
|
) ); |
|
49
|
|
|
|
|
50
|
|
|
$object = new \Aimeos\Controller\Common\Subscription\Process\Processor\Cgroup\Standard( $context ); |
|
51
|
|
|
$object->begin( $this->getSubscription( $context ) ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
public function testEnd() |
|
56
|
|
|
{ |
|
57
|
|
|
$context = \TestHelperCntl::getContext(); |
|
58
|
|
|
|
|
59
|
|
|
$context->getConfig()->set( 'controller/common/subscription/process/processor/cgroup/groupids', ['1', '2'] ); |
|
60
|
|
|
|
|
61
|
|
|
$customerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Customer\\Manager\\Standard' ) |
|
62
|
|
|
->setConstructorArgs( [$context] ) |
|
63
|
|
|
->setMethods( ['getItem', 'saveItem'] ) |
|
64
|
|
|
->getMock(); |
|
65
|
|
|
|
|
66
|
|
|
\Aimeos\MShop\Factory::injectManager( $context, 'customer', $customerStub ); |
|
67
|
|
|
|
|
68
|
|
|
$customerItem = $customerStub->createItem()->setGroups( ['1', '2'] ); |
|
69
|
|
|
|
|
70
|
|
|
$customerStub->expects( $this->once() )->method( 'getItem' ) |
|
71
|
|
|
->will( $this->returnValue( $customerItem ) ); |
|
72
|
|
|
|
|
73
|
|
|
$customerStub->expects( $this->once() )->method( 'saveItem' ) |
|
74
|
|
|
->with( $this->callback( |
|
75
|
|
|
function( $subject ){ |
|
76
|
|
|
return $subject->getGroups() === []; |
|
77
|
|
|
} |
|
78
|
|
|
) ); |
|
79
|
|
|
|
|
80
|
|
|
$object = new \Aimeos\Controller\Common\Subscription\Process\Processor\Cgroup\Standard( $context ); |
|
81
|
|
|
$object->end( $this->getSubscription( $context ) ); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
protected function getSubscription( $context ) |
|
86
|
|
|
{ |
|
87
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $context, 'subscription' ); |
|
88
|
|
|
|
|
89
|
|
|
$search = $manager->createSearch(); |
|
90
|
|
|
$search->setConditions( $search->compare( '==', 'subscription.dateend', '2010-01-01' ) ); |
|
91
|
|
|
|
|
92
|
|
|
$items = $manager->searchItems( $search ); |
|
93
|
|
|
|
|
94
|
|
|
if( ( $item = reset( $items ) ) !== false ) { |
|
95
|
|
|
return $item; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
throw new \Exception( 'No subscription item found' ); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|