Completed
Push — master ( 167152...107be5 )
by Aimeos
05:29
created

StandardTest::testStore()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 33
rs 8.8571
cc 1
eloc 19
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 testBlock()
125
	{
126
		$name = 'ControllerFrontendOrderBlock';
127
		$this->context->getConfig()->set( 'controller/common/order/name', $name );
128
129
130
		$orderCntlStub = $this->getMockBuilder( '\\Aimeos\\Controller\\Common\\Order\\Standard' )
131
			->setMethods( array( 'block' ) )
132
			->setConstructorArgs( array( $this->context ) )
133
			->getMock();
134
135
		\Aimeos\Controller\Common\Order\Factory::injectController( '\\Aimeos\\Controller\\Common\\Order\\' . $name, $orderCntlStub );
136
137
		$orderCntlStub->expects( $this->once() )->method( 'block' );
138
139
140
		$this->object->block( \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem() );
141
	}
142
143
144
	public function testUnblock()
145
	{
146
		$name = 'ControllerFrontendOrderUnblock';
147
		$this->context->getConfig()->set( 'controller/common/order/name', $name );
148
149
150
		$orderCntlStub = $this->getMockBuilder( '\\Aimeos\\Controller\\Common\\Order\\Standard' )
151
			->setMethods( array( 'unblock' ) )
152
			->setConstructorArgs( array( $this->context ) )
153
			->getMock();
154
155
		\Aimeos\Controller\Common\Order\Factory::injectController( '\\Aimeos\\Controller\\Common\\Order\\' . $name, $orderCntlStub );
156
157
		$orderCntlStub->expects( $this->once() )->method( 'unblock' );
158
159
160
		$this->object->unblock( \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem() );
161
	}
162
163
164
	public function testUpdate()
165
	{
166
		$name = 'ControllerFrontendOrderUpdate';
167
		$this->context->getConfig()->set( 'controller/common/order/name', $name );
168
169
170
		$orderCntlStub = $this->getMockBuilder( '\\Aimeos\\Controller\\Common\\Order\\Standard' )
171
			->setMethods( array( 'update' ) )
172
			->setConstructorArgs( array( $this->context ) )
173
			->getMock();
174
175
		\Aimeos\Controller\Common\Order\Factory::injectController( '\\Aimeos\\Controller\\Common\\Order\\' . $name, $orderCntlStub );
176
177
		$orderCntlStub->expects( $this->once() )->method( 'update' );
178
179
180
		$this->object->update( \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem() );
181
	}
182
}
183