1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Subscription; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $context; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
\Aimeos\MShop\Factory::setCache( true ); |
21
|
|
|
|
22
|
|
|
$this->context = \TestHelperFrontend::getContext(); |
23
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Subscription\Standard( $this->context ); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
protected function tearDown() |
28
|
|
|
{ |
29
|
|
|
unset( $this->object, $this->context ); |
30
|
|
|
|
31
|
|
|
\Aimeos\MShop\Factory::setCache( false ); |
32
|
|
|
\Aimeos\MShop\Factory::clear(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function testCancel() |
37
|
|
|
{ |
38
|
|
|
$this->context->setUserId( $this->getCustomerId() ); |
39
|
|
|
$item = \Aimeos\MShop\Factory::createManager( $this->context, 'subscription' )->createItem(); |
40
|
|
|
|
41
|
|
|
$cntl = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Subscription\Standard' ) |
42
|
|
|
->setConstructorArgs( [$this->context] ) |
43
|
|
|
->setMethods( ['saveItem'] ) |
44
|
|
|
->getMock(); |
45
|
|
|
|
46
|
|
|
$cntl->expects( $this->once() )->method( 'saveItem' ) |
47
|
|
|
->will( $this->returnValue( $item ) ); |
48
|
|
|
|
49
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Subscription\Item\Iface', $cntl->cancel( $this->getSubscriptionId() ) ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function testCreateFilter() |
54
|
|
|
{ |
55
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createFilter() ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
public function testGetIntervals() |
60
|
|
|
{ |
61
|
|
|
$this->assertGreaterThan( 0, count( $this->object->getIntervals() ) ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
public function testGetItem() |
66
|
|
|
{ |
67
|
|
|
$id = $this->getSubscriptionId(); |
68
|
|
|
$this->context->setUserId( $this->getCustomerId() ); |
69
|
|
|
|
70
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Subscription\Item\Iface', $this->object->getItem( $id ) ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
public function testGetItemException() |
75
|
|
|
{ |
76
|
|
|
$this->setExpectedException( '\Aimeos\Controller\Frontend\Subscription\Exception' ); |
77
|
|
|
$this->object->getItem( -1 ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
public function testSaveItem() |
82
|
|
|
{ |
83
|
|
|
$manager = $this->getMockBuilder( '\\Aimeos\\MShop\\Subscription\\Manager\\Standard' ) |
84
|
|
|
->setConstructorArgs( [$this->context] ) |
85
|
|
|
->setMethods( ['saveItem'] ) |
86
|
|
|
->getMock(); |
87
|
|
|
|
88
|
|
|
\Aimeos\MShop\Factory::injectManager( $this->context, 'subscription', $manager ); |
89
|
|
|
|
90
|
|
|
$manager->expects( $this->once() )->method( 'saveItem' ) |
91
|
|
|
->will( $this->returnValue( $manager->createItem() ) ); |
92
|
|
|
|
93
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Subscription\Item\Iface', $this->object->saveItem( $manager->createItem() ) ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
public function testSearchItems() |
98
|
|
|
{ |
99
|
|
|
$this->assertGreaterThan( 1, $this->object->searchItems( $this->object->createFilter() ) ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
protected function getCustomerId() |
103
|
|
|
{ |
104
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' ); |
105
|
|
|
return $manager->findItem( 'UTC001' )->getId(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
protected function getSubscriptionId() |
110
|
|
|
{ |
111
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'subscription' ); |
112
|
|
|
$search = $manager->createSearch()->setSlice( 0, 1 ); |
113
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.customerid', $this->getCustomerId() ) ); |
114
|
|
|
$result = $manager->searchItems( $search ); |
115
|
|
|
|
116
|
|
|
if( ( $item = reset( $result ) ) === false ) { |
117
|
|
|
throw new \RuntimeException( 'No subscription item found' ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return $item->getId(); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|