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