Completed
Push — master ( 452e16...087a76 )
by Aimeos
02:19
created

StandardTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Aimeos\Controller\Frontend\Service;
4
5
6
/**
7
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
8
 * @copyright Metaways Infosystems GmbH, 2012
9
 * @copyright Aimeos (aimeos.org), 2015-2016
10
 */
11
class StandardTest extends \PHPUnit_Framework_TestCase
12
{
13
	private $object;
14
	private static $basket;
15
16
17
	protected function setUp()
18
	{
19
		$this->object = new \Aimeos\Controller\Frontend\Service\Standard( \TestHelperFrontend::getContext() );
20
	}
21
22
23
	public static function setUpBeforeClass()
24
	{
25
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperFrontend::getContext() );
26
		$orderBaseMgr = $orderManager->getSubManager( 'base' );
27
		self::$basket = $orderBaseMgr->createItem();
28
	}
29
30
31
	protected function tearDown()
32
	{
33
		unset( $this->object );
34
	}
35
36
37
	public function testCheckAttributes()
38
	{
39
		$attributes = $this->object->checkAttributes( $this->getServiceItem()->getId(), [] );
40
		$this->assertEquals( [], $attributes );
41
	}
42
43
44
	public function testGetProviders()
45
	{
46
		$providers = $this->object->getProviders( 'delivery' );
47
		$this->assertGreaterThan( 0, count( $providers ) );
48
49
		foreach( $providers as $provider ) {
50
			$this->assertInstanceOf( '\\Aimeos\\MShop\\Service\\Provider\\Iface', $provider );
51
		}
52
	}
53
54
55
	public function testGetProvider()
56
	{
57
		$provider = $this->object->getProvider( $this->getServiceItem()->getId() );
58
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Service\\Provider\\Iface', $provider );
59
	}
60
61
62
	public function testGetServices()
63
	{
64
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperFrontend::getContext() );
65
		$basket = $orderManager->getSubManager( 'base' )->createItem();
66
67
		$services = $this->object->getServices( 'delivery', $basket );
0 ignored issues
show
Deprecated Code introduced by
The method Aimeos\Controller\Fronte...Standard::getServices() has been deprecated with message: Use getProviders() 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...
68
		$this->assertGreaterThan( 0, count( $services ) );
69
70
		foreach( $services as $service ) {
71
			$this->assertInstanceOf( '\\Aimeos\\MShop\\Service\\Item\\Iface', $service );
72
		}
73
	}
74
75
76
	public function testGetServiceAttributes()
77
	{
78
		$service = $this->getServiceItem();
79
		$attributes = $this->object->getServiceAttributes( 'delivery', $service->getId(), self::$basket );
0 ignored issues
show
Deprecated Code introduced by
The method Aimeos\Controller\Fronte...:getServiceAttributes() has been deprecated with message: Use getProvider() 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...
80
81
		$this->assertEquals( 0, count( $attributes ) );
82
	}
83
84
85
	public function testGetServiceAttributesCache()
86
	{
87
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperFrontend::getContext() );
88
		$basket = $orderManager->getSubManager( 'base' )->createItem();
89
90
		$services = $this->object->getServices( 'delivery', $basket );
0 ignored issues
show
Deprecated Code introduced by
The method Aimeos\Controller\Fronte...Standard::getServices() has been deprecated with message: Use getProviders() 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...
91
92
		if( ( $service = reset( $services ) ) === false ) {
93
			throw new \RuntimeException( 'No service item found' );
94
		}
95
96
		$attributes = $this->object->getServiceAttributes( 'delivery', $service->getId(), self::$basket );
0 ignored issues
show
Deprecated Code introduced by
The method Aimeos\Controller\Fronte...:getServiceAttributes() has been deprecated with message: Use getProvider() 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...
97
98
		$this->assertEquals( 0, count( $attributes ) );
99
	}
100
101
102
	public function testGetServiceAttributesNoItems()
103
	{
104
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
105
		$this->object->getServiceAttributes( 'invalid', -1, self::$basket );
0 ignored issues
show
Deprecated Code introduced by
The method Aimeos\Controller\Fronte...:getServiceAttributes() has been deprecated with message: Use getProvider() 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...
106
	}
107
108
109
	public function testGetServicePrice()
110
	{
111
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperFrontend::getContext() );
112
		$basket = $orderManager->getSubManager( 'base' )->createItem();
113
114
		$service = $this->getServiceItem();
115
		$price = $this->object->getServicePrice( 'delivery', $service->getId(), $basket );
0 ignored issues
show
Deprecated Code introduced by
The method Aimeos\Controller\Fronte...dard::getServicePrice() has been deprecated with message: Use getProvider() 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...
116
117
		$this->assertEquals( '12.95', $price->getValue() );
118
		$this->assertEquals( '1.99', $price->getCosts() );
119
	}
120
121
122
	public function testGetServicePriceCache()
123
	{
124
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperFrontend::getContext() );
125
		$basket = $orderManager->getSubManager( 'base' )->createItem();
126
127
		$services = $this->object->getServices( 'delivery', $basket );
0 ignored issues
show
Deprecated Code introduced by
The method Aimeos\Controller\Fronte...Standard::getServices() has been deprecated with message: Use getProviders() 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...
128
129
		if( ( $service = reset( $services ) ) === false ) {
130
			throw new \RuntimeException( 'No service item found' );
131
		}
132
133
		$price = $this->object->getServicePrice( 'delivery', $service->getId(), $basket );
0 ignored issues
show
Deprecated Code introduced by
The method Aimeos\Controller\Fronte...dard::getServicePrice() has been deprecated with message: Use getProvider() 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...
134
135
		$this->assertEquals( '12.95', $price->getValue() );
136
		$this->assertEquals( '1.99', $price->getCosts() );
137
	}
138
139
140
	public function testGetServicePriceNoItems()
141
	{
142
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperFrontend::getContext() );
143
		$basket = $orderManager->getSubManager( 'base' )->createItem();
144
145
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
146
		$this->object->getServicePrice( 'invalid', -1, $basket );
0 ignored issues
show
Deprecated Code introduced by
The method Aimeos\Controller\Fronte...dard::getServicePrice() has been deprecated with message: Use getProvider() 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 testCheckServiceAttributes()
151
	{
152
		$service = $this->getServiceItem();
153
		$attributes = $this->object->checkServiceAttributes( 'delivery', $service->getId(), array() );
0 ignored issues
show
Deprecated Code introduced by
The method Aimeos\Controller\Fronte...heckServiceAttributes() has been deprecated with message: Use checkAttributes() 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...
154
155
		$this->assertEquals( array(), $attributes );
156
	}
157
158
159
	/**
160
	 * @return \Aimeos\MShop\Service\Item\Iface
161
	 */
162
	protected function getServiceItem()
163
	{
164
		$manager = \Aimeos\MShop\Service\Manager\Factory::createManager( \TestHelperFrontend::getContext() );
165
		return $manager->findItem( 'unitcode', [], 'service', 'delivery' );
166
	}
167
}
168