Completed
Push — master ( 10606c...22be93 )
by Aimeos
02:49
created

StandardTest::testGetItemException()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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