Completed
Push — master ( 25c6af...9f51fe )
by Aimeos
02:20
created

StandardTest::testBlock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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