Completed
Push — master ( f23e00...1d5010 )
by Aimeos
02:31
created

StandardTest::testAddItemLimit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
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
48
		$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Iface', $this->object->addItem( -1, 'test' ) );
49
	}
50
51
52
	public function testAddItemLimit()
53
	{
54
		$this->context->getConfig()->set( 'controller/frontend/order/limit-seconds', 86400 * 365 );
55
56
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base' );
57
		$result = $manager->searchItems( $manager->createSearch()->setSlice( 0, 1 ) );
58
59
		if( ( $item = reset( $result ) ) === false ) {
60
			throw new \RuntimeException( 'No order item found' );
61
		}
62
63
		$this->setExpectedException( '\Aimeos\Controller\Frontend\Order\Exception' );
64
		$this->object->addItem( $item->getId(), 'test' );
65
	}
66
67
68
	public function testCreateFilter()
69
	{
70
		$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createFilter() );
71
	}
72
73
74
	public function testGetItem()
75
	{
76
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' );
77
		$customerItem = $manager->findItem( 'UTC001' );
78
79
		$this->context->setUserId( $customerItem->getId() );
80
81
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'order' );
82
		$search = $manager->createSearch()->setSlice( 0, 1 );
83
		$search->setConditions( $search->compare( '==', 'order.base.customerid', $customerItem->getId() ) );
84
		$result = $manager->searchItems( $search );
85
86
		if( ( $item = reset( $result ) ) === false ) {
87
			throw new \RuntimeException( 'No order item found' );
88
		}
89
90
		$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Iface', $this->object->getItem( $item->getId() ) );
91
	}
92
93
94
	public function testGetItemException()
95
	{
96
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'order' );
97
		$search = $manager->createSearch()->setSlice( 0, 1 );
98
		$result = $manager->searchItems( $search );
99
100
		if( ( $item = reset( $result ) ) === false ) {
101
			throw new \RuntimeException( 'No order item found' );
102
		}
103
104
		$this->setExpectedException( '\Aimeos\Controller\Frontend\Order\Exception' );
105
		$this->object->getItem( $item->getId() );
106
	}
107
108
109
	public function testSearchItems()
110
	{
111
		$this->assertGreaterThan( 1, $this->object->searchItems( $this->object->createFilter() ) );
112
	}
113
114
115
	public function testStore()
116
	{
117
		$name = 'ControllerFrontendOrderStore';
118
		$this->context->getConfig()->set( 'mshop/order/manager/name', $name );
119
120
121
		$orderManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' )
122
			->setMethods( array( 'saveItem', 'getSubManager' ) )
123
			->setConstructorArgs( array( $this->context ) )
124
			->getMock();
125
126
		$orderBaseManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Base\\Standard' )
127
			->setMethods( array( 'store' ) )
128
			->setConstructorArgs( array( $this->context ) )
129
			->getMock();
130
131
		\Aimeos\MShop\Order\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Order\\Manager\\' . $name, $orderManagerStub );
132
133
134
		$orderBaseItem = $orderBaseManagerStub->createItem();
135
		$orderBaseItem->setId( 1 );
136
137
138
		$orderBaseManagerStub->expects( $this->once() )->method( 'store' );
139
140
		$orderManagerStub->expects( $this->once() )->method( 'getSubManager' )
141
			->will( $this->returnValue( $orderBaseManagerStub ) );
142
143
		$orderManagerStub->expects( $this->once() )->method( 'saveItem' );
144
145
146
		$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...
147
	}
148
149
150
	public function testBlock()
151
	{
152
		$name = 'ControllerFrontendOrderBlock';
153
		$this->context->getConfig()->set( 'controller/common/order/name', $name );
154
155
156
		$orderCntlStub = $this->getMockBuilder( '\\Aimeos\\Controller\\Common\\Order\\Standard' )
157
			->setMethods( array( 'block' ) )
158
			->setConstructorArgs( array( $this->context ) )
159
			->getMock();
160
161
		\Aimeos\Controller\Common\Order\Factory::injectController( '\\Aimeos\\Controller\\Common\\Order\\' . $name, $orderCntlStub );
162
163
		$orderCntlStub->expects( $this->once() )->method( 'block' );
164
165
166
		$this->object->block( \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem() );
167
	}
168
169
170
	public function testUnblock()
171
	{
172
		$name = 'ControllerFrontendOrderUnblock';
173
		$this->context->getConfig()->set( 'controller/common/order/name', $name );
174
175
176
		$orderCntlStub = $this->getMockBuilder( '\\Aimeos\\Controller\\Common\\Order\\Standard' )
177
			->setMethods( array( 'unblock' ) )
178
			->setConstructorArgs( array( $this->context ) )
179
			->getMock();
180
181
		\Aimeos\Controller\Common\Order\Factory::injectController( '\\Aimeos\\Controller\\Common\\Order\\' . $name, $orderCntlStub );
182
183
		$orderCntlStub->expects( $this->once() )->method( 'unblock' );
184
185
186
		$this->object->unblock( \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem() );
187
	}
188
189
190
	public function testUpdate()
191
	{
192
		$name = 'ControllerFrontendOrderUpdate';
193
		$this->context->getConfig()->set( 'controller/common/order/name', $name );
194
195
196
		$orderCntlStub = $this->getMockBuilder( '\\Aimeos\\Controller\\Common\\Order\\Standard' )
197
			->setMethods( array( 'update' ) )
198
			->setConstructorArgs( array( $this->context ) )
199
			->getMock();
200
201
		\Aimeos\Controller\Common\Order\Factory::injectController( '\\Aimeos\\Controller\\Common\\Order\\' . $name, $orderCntlStub );
202
203
		$orderCntlStub->expects( $this->once() )->method( 'update' );
204
205
206
		$this->object->update( \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem() );
207
	}
208
}
209