Completed
Push — master ( b59167...a8e478 )
by Aimeos
02:35
created

StandardTest::testUpdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2014
6
 * @copyright Aimeos (aimeos.org), 2015-2017
7
 */
8
9
10
namespace Aimeos\Controller\Frontend\Order;
11
12
13
class StandardTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $object;
16
	private $context;
17
18
19
	protected function setUp()
20
	{
21
		\Aimeos\MShop\Factory::setCache( true );
22
23
		$this->context = \TestHelperFrontend::getContext();
24
		$this->object = new \Aimeos\Controller\Frontend\Order\Standard( $this->context );
25
	}
26
27
28
	protected function tearDown()
29
	{
30
		unset( $this->object, $this->context );
31
32
		\Aimeos\MShop\Factory::setCache( false );
33
		\Aimeos\MShop\Factory::clear();
34
	}
35
36
37
	public function testAddItem()
38
	{
39
		$manager = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' )
40
			->setConstructorArgs( [$this->context] )
41
			->setMethods( ['saveItem'] )
42
			->getMock();
43
44
		\Aimeos\MShop\Factory::injectManager( $this->context, 'order', $manager );
45
46
		$manager->expects( $this->once() )->method( 'saveItem' )
47
			->will( $this->returnValue( $manager->createItem() ) );
48
49
		$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Iface', $this->object->addItem( -1, 'test' ) );
50
	}
51
52
53
	public function testAddItemLimit()
54
	{
55
		$this->context->getConfig()->set( 'controller/frontend/order/limit-seconds', 86400 * 365 );
56
57
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base' );
58
		$result = $manager->searchItems( $manager->createSearch()->setSlice( 0, 1 ) );
59
60
		if( ( $item = reset( $result ) ) === false ) {
61
			throw new \RuntimeException( 'No order item found' );
62
		}
63
64
		$this->setExpectedException( '\Aimeos\Controller\Frontend\Order\Exception' );
65
		$this->object->addItem( $item->getId(), 'test' );
66
	}
67
68
69
	public function testCreateFilter()
70
	{
71
		$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createFilter() );
72
	}
73
74
75
	public function testGetItem()
76
	{
77
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' );
78
		$customerItem = $manager->findItem( 'UTC001' );
79
80
		$this->context->setEditor( 'core:unittest' );
81
82
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'order' );
83
		$search = $manager->createSearch()->setSlice( 0, 1 );
84
		$search->setConditions( $search->compare( '==', 'order.base.customerid', $customerItem->getId() ) );
85
		$result = $manager->searchItems( $search );
86
87
		if( ( $item = reset( $result ) ) === false ) {
88
			throw new \RuntimeException( 'No order item found' );
89
		}
90
91
		$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Iface', $this->object->getItem( $item->getId() ) );
92
	}
93
94
95
	public function testGetItemException()
96
	{
97
		$this->setExpectedException( '\Aimeos\Controller\Frontend\Order\Exception' );
98
		$this->object->getItem( -1 );
99
	}
100
101
102
	public function testSaveItem()
103
	{
104
		$manager = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' )
105
			->setConstructorArgs( [$this->context] )
106
			->setMethods( ['saveItem'] )
107
			->getMock();
108
109
		\Aimeos\MShop\Factory::injectManager( $this->context, 'order', $manager );
110
111
		$manager->expects( $this->once() )->method( 'saveItem' )
112
			->will( $this->returnValue( $manager->createItem() ) );
113
114
		$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Iface', $this->object->saveItem( $manager->createItem() ) );
115
	}
116
117
118
	public function testSearchItems()
119
	{
120
		$this->assertGreaterThan( 1, $this->object->searchItems( $this->object->createFilter() ) );
121
	}
122
123
124
	public function testStore()
125
	{
126
		$name = 'ControllerFrontendOrderStore';
127
		$this->context->getConfig()->set( 'mshop/order/manager/name', $name );
128
129
130
		$orderManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' )
131
			->setMethods( array( 'saveItem', 'getSubManager' ) )
132
			->setConstructorArgs( array( $this->context ) )
133
			->getMock();
134
135
		$orderBaseManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Base\\Standard' )
136
			->setMethods( array( 'store' ) )
137
			->setConstructorArgs( array( $this->context ) )
138
			->getMock();
139
140
		\Aimeos\MShop\Order\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Order\\Manager\\' . $name, $orderManagerStub );
141
142
143
		$orderBaseItem = $orderBaseManagerStub->createItem();
144
		$orderBaseItem->setId( 1 );
145
146
147
		$orderBaseManagerStub->expects( $this->once() )->method( 'store' );
148
149
		$orderManagerStub->expects( $this->once() )->method( 'getSubManager' )
150
			->will( $this->returnValue( $orderBaseManagerStub ) );
151
152
		$orderManagerStub->expects( $this->once() )->method( 'saveItem' );
153
154
155
		$this->object->store( $orderBaseItem );
0 ignored issues
show
Deprecated Code introduced by
The method Aimeos\Controller\Frontend\Order\Standard::store() has been deprecated with message: 2017.04 Use store() from basket controller instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
156
	}
157
158
159
	public function testBlock()
160
	{
161
		$name = 'ControllerFrontendOrderBlock';
162
		$this->context->getConfig()->set( 'controller/common/order/name', $name );
163
164
165
		$orderCntlStub = $this->getMockBuilder( '\\Aimeos\\Controller\\Common\\Order\\Standard' )
166
			->setMethods( array( 'block' ) )
167
			->setConstructorArgs( array( $this->context ) )
168
			->getMock();
169
170
		\Aimeos\Controller\Common\Order\Factory::injectController( '\\Aimeos\\Controller\\Common\\Order\\' . $name, $orderCntlStub );
171
172
		$orderCntlStub->expects( $this->once() )->method( 'block' );
173
174
175
		$this->object->block( \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem() );
176
	}
177
178
179
	public function testUnblock()
180
	{
181
		$name = 'ControllerFrontendOrderUnblock';
182
		$this->context->getConfig()->set( 'controller/common/order/name', $name );
183
184
185
		$orderCntlStub = $this->getMockBuilder( '\\Aimeos\\Controller\\Common\\Order\\Standard' )
186
			->setMethods( array( 'unblock' ) )
187
			->setConstructorArgs( array( $this->context ) )
188
			->getMock();
189
190
		\Aimeos\Controller\Common\Order\Factory::injectController( '\\Aimeos\\Controller\\Common\\Order\\' . $name, $orderCntlStub );
191
192
		$orderCntlStub->expects( $this->once() )->method( 'unblock' );
193
194
195
		$this->object->unblock( \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem() );
196
	}
197
198
199
	public function testUpdate()
200
	{
201
		$name = 'ControllerFrontendOrderUpdate';
202
		$this->context->getConfig()->set( 'controller/common/order/name', $name );
203
204
205
		$orderCntlStub = $this->getMockBuilder( '\\Aimeos\\Controller\\Common\\Order\\Standard' )
206
			->setMethods( array( 'update' ) )
207
			->setConstructorArgs( array( $this->context ) )
208
			->getMock();
209
210
		\Aimeos\Controller\Common\Order\Factory::injectController( '\\Aimeos\\Controller\\Common\\Order\\' . $name, $orderCntlStub );
211
212
		$orderCntlStub->expects( $this->once() )->method( 'update' );
213
214
215
		$this->object->update( \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem() );
216
	}
217
}
218