1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\Controller\Frontend\Service; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
private $context; |
17
|
|
|
private static $basket; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
\Aimeos\MShop\Factory::setCache( true ); |
23
|
|
|
|
24
|
|
|
$this->context = \TestHelperFrontend::getContext(); |
25
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Service\Standard( $this->context ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
public static function setUpBeforeClass() |
30
|
|
|
{ |
31
|
|
|
$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperFrontend::getContext() ); |
32
|
|
|
$orderBaseMgr = $orderManager->getSubManager( 'base' ); |
33
|
|
|
self::$basket = $orderBaseMgr->createItem(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
protected function tearDown() |
38
|
|
|
{ |
39
|
|
|
unset( $this->object, $this->context ); |
40
|
|
|
|
41
|
|
|
\Aimeos\MShop\Factory::setCache( false ); |
42
|
|
|
\Aimeos\MShop\Factory::clear(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testCheckAttributes() |
47
|
|
|
{ |
48
|
|
|
$attributes = $this->object->checkAttributes( $this->getServiceItem()->getId(), [] ); |
49
|
|
|
$this->assertEquals( [], $attributes ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function testGetProviders() |
54
|
|
|
{ |
55
|
|
|
$providers = $this->object->getProviders( 'delivery' ); |
56
|
|
|
$this->assertGreaterThan( 0, count( $providers ) ); |
57
|
|
|
|
58
|
|
|
foreach( $providers as $provider ) { |
59
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Service\\Provider\\Iface', $provider ); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
public function testGetProvider() |
65
|
|
|
{ |
66
|
|
|
$provider = $this->object->getProvider( $this->getServiceItem()->getId() ); |
67
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Service\\Provider\\Iface', $provider ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
public function testProcess() |
72
|
|
|
{ |
73
|
|
|
$form = new \Aimeos\MShop\Common\Item\Helper\Form\Standard(); |
74
|
|
|
$item = \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem(); |
75
|
|
|
$serviceId = \Aimeos\MShop\Factory::createManager( $this->context, 'service' )->findItem( 'unitcode' )->getId(); |
76
|
|
|
|
77
|
|
|
$provider = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Provider\\Delivery\\Standard' ) |
78
|
|
|
->disableOriginalConstructor() |
79
|
|
|
->setMethods( ['process'] ) |
80
|
|
|
->getMock(); |
81
|
|
|
|
82
|
|
|
$manager = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Manager\\Standard' ) |
83
|
|
|
->setConstructorArgs( [$this->context] ) |
84
|
|
|
->setMethods( ['getProvider'] ) |
85
|
|
|
->getMock(); |
86
|
|
|
|
87
|
|
|
\Aimeos\MShop\Factory::injectManager( $this->context, 'service', $manager ); |
88
|
|
|
|
89
|
|
|
$provider->expects( $this->once() )->method( 'process' )->will( $this->returnValue( $form ) ); |
90
|
|
|
$manager->expects( $this->once() )->method( 'getProvider' )->will( $this->returnValue( $provider ) ); |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
$result = $this->object->process( $item, $serviceId, [], [] ); |
94
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Helper\Form\Iface', $result ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
public function testUpdatePush() |
99
|
|
|
{ |
100
|
|
|
$request = $this->getMockBuilder( '\Psr\Http\Message\ServerRequestInterface' )->getMock(); |
101
|
|
|
$response = $this->getMockBuilder( '\Psr\Http\Message\ResponseInterface' )->getMock(); |
102
|
|
|
|
103
|
|
|
$response->expects( $this->once() )->method( 'withStatus' )->will( $this->returnValue( $response ) ); |
104
|
|
|
|
105
|
|
|
$this->assertInstanceOf( '\Psr\Http\Message\ResponseInterface', $this->object->updatePush( $request, $response, 'unitcode' ) ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
public function testUpdateSync() |
110
|
|
|
{ |
111
|
|
|
$item = \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem(); |
112
|
|
|
|
113
|
|
|
$stream = $this->getMockBuilder( 'Psr\Http\Message\StreamInterface' )->getMock(); |
114
|
|
|
$request = $this->getMockBuilder( '\Psr\Http\Message\ServerRequestInterface' )->getMock(); |
115
|
|
|
$response = $this->getMockBuilder( '\Aimeos\MW\View\Helper\Response\Iface' ) |
116
|
|
|
->getMock(); |
117
|
|
|
|
118
|
|
|
$provider = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Provider\\Delivery\\Standard' ) |
119
|
|
|
->setMethods( ['updateSync', 'query', 'isImplemented'] ) |
120
|
|
|
->disableOriginalConstructor() |
121
|
|
|
->getMock(); |
122
|
|
|
|
123
|
|
|
$manager = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Manager\\Standard' ) |
124
|
|
|
->setConstructorArgs( array( $this->context ) ) |
125
|
|
|
->setMethods( ['getProvider'] ) |
126
|
|
|
->getMock(); |
127
|
|
|
|
128
|
|
|
\Aimeos\MShop\Factory::injectManager( $this->context, 'service', $manager ); |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
$request->expects( $this->once() )->method( 'getQueryParams' )->will( $this->returnValue( ['code' => 'unitcode'] ) ); |
132
|
|
|
$response->expects( $this->once() )->method( 'createStreamFromString' )->will( $this->returnValue( $stream ) ); |
133
|
|
|
$manager->expects( $this->once() )->method( 'getProvider' )->will( $this->returnValue( $provider ) ); |
134
|
|
|
$provider->expects( $this->once() )->method( 'updateSync' )->will( $this->returnValue( $item ) ); |
135
|
|
|
$provider->expects( $this->once() )->method( 'isImplemented' )->will( $this->returnValue( true ) ); |
136
|
|
|
$provider->expects( $this->once() )->method( 'query' ); |
137
|
|
|
|
138
|
|
|
$this->object->updateSync( $request, $response, [], 'paypalexpress', -1 ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return \Aimeos\MShop\Service\Item\Iface |
144
|
|
|
*/ |
145
|
|
|
protected function getServiceItem() |
146
|
|
|
{ |
147
|
|
|
$manager = \Aimeos\MShop\Service\Manager\Factory::createManager( \TestHelperFrontend::getContext() ); |
148
|
|
|
return $manager->findItem( 'unitcode' ); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|