Completed
Push — master ( 764ed5...7b4a42 )
by Aimeos
02:43
created

StandardTest::testUses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
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-2020
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() : void
20
	{
21
		\Aimeos\MShop::cache( 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() : void
29
	{
30
		\Aimeos\MShop::cache( false );
31
		unset( $this->object, $this->context );
32
	}
33
34
35
	public function testAdd()
36
	{
37
		$this->assertSame( $this->object, $this->object->add( -1, [] ) );
38
	}
39
40
41
	public function testCompare()
42
	{
43
		$this->assertSame( $this->object, $this->object->compare( '==', 'order.type', 'test' ) );
44
	}
45
46
47
	public function testGet()
48
	{
49
		$manager = \Aimeos\MShop::create( $this->context, 'order' );
50
		$items = $manager->searchItems( $manager->createSearch()->setSlice( 0, 1 ) );
51
52
		if( ( $item = $items->first() ) === null ) {
53
			throw new \RuntimeException( 'No order item found' );
54
		}
55
56
		$this->assertEquals( $item, $this->object->get( $item->getId(), false ) );
57
	}
58
59
60
	public function testParse()
61
	{
62
		$this->assertSame( $this->object, $this->object->parse( [] ) );
63
	}
64
65
66
	public function testSave()
67
	{
68
		$manager = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class )
69
			->setConstructorArgs( [$this->context] )
70
			->setMethods( ['saveItem'] )
71
			->getMock();
72
73
		\Aimeos\MShop::inject( 'order', $manager );
74
75
		$item = $manager->createItem();
76
		$object = new \Aimeos\Controller\Frontend\Order\Standard( $this->context );
77
78
		$manager->expects( $this->once() )->method( 'saveItem' )->will( $this->returnArgument( 0 ) );
79
80
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $object->save( $item ) );
81
	}
82
83
84
	public function testSearch()
85
	{
86
		$userId = \Aimeos\MShop::create( $this->context, 'customer' )->findItem( 'UTC001' )->getId();
87
		$this->context->setUserId( $userId );
88
89
		$total = 0;
90
		$object = new \Aimeos\Controller\Frontend\Order\Standard( $this->context );
91
		$items = $object->uses( ['order/base'] )->search( $total );
92
93
		$this->assertGreaterThanOrEqual( 4, $items->count() );
94
		$this->assertGreaterThanOrEqual( 4, $total );
95
96
		foreach( $items as $item ) {
97
			$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $item->getBaseItem() );
98
		}
99
	}
100
101
102
	public function testSlice()
103
	{
104
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
105
	}
106
107
108
	public function testSort()
109
	{
110
		$this->assertSame( $this->object, $this->object->sort( '-order.type,order.id' ) );
111
	}
112
113
114
	public function testStore()
115
	{
116
		$class = \Aimeos\Controller\Common\Order\Standard::class;
117
118
		$manager = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class )
119
			->setConstructorArgs( [$this->context] )
120
			->setMethods( ['saveItem'] )
121
			->getMock();
122
123
		\Aimeos\MShop::inject( 'order', $manager );
124
125
		$stub = $this->getMockBuilder( $class )
126
			->setConstructorArgs( [$this->context] )
127
			->setMethods( ['block'] )
128
			->getMock();
129
130
		$object = new \Aimeos\Controller\Frontend\Order\Standard( $this->context );
131
		$object->add( -1 );
132
133
		$item = $manager->createItem()->setBaseId( -1 );
134
135
		$manager->expects( $this->once() )->method( 'saveItem' )->will( $this->returnValue( $item ) );
136
		$stub->expects( $this->once() )->method( 'block' )->will( $this->returnValue( $item ) );
137
138
		\Aimeos\Controller\Common\Order\Factory::inject( $class, $stub );
139
		$this->assertEquals( $item, $object->store() );
140
		\Aimeos\Controller\Common\Order\Factory::inject( $class, null );
141
	}
142
143
144
	public function testStoreLimit()
145
	{
146
		$this->context->getConfig()->set( 'controller/frontend/order/limit-seconds', 86400 * 365 );
147
148
		$manager = \Aimeos\MShop::create( $this->context, 'order/base' );
149
		$items = $manager->searchItems( $manager->createSearch()->setSlice( 0, 1 ) );
150
151
		if( ( $item = $items->first() ) === false ) {
152
			throw new \RuntimeException( 'No order base item found' );
153
		}
154
155
		$this->expectException( \Aimeos\Controller\Frontend\Order\Exception::class );
156
		$this->object->add( $item->getId() )->store();
157
	}
158
159
160
	public function testUses()
161
	{
162
		$this->assertSame( $this->object, $this->object->uses( ['order/base'] ) );
163
	}
164
}
165