Completed
Push — master ( 937f3b...5e44e2 )
by Aimeos
16:51 queued 07:27
created

BundleTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 46
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A tearDown() 0 7 1
A testAddProductBundle() 0 10 1
A testAddProductNoBundle() 0 10 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Basket\Decorator;
10
11
12
class BundleTest extends \PHPUnit_Framework_TestCase
13
{
14
	private $object;
15
	private $context;
16
17
18
	protected function setUp()
19
	{
20
		$this->context = \TestHelperFrontend::getContext();
21
		$object = new \Aimeos\Controller\Frontend\Basket\Standard( $this->context );
22
		$this->object = new \Aimeos\Controller\Frontend\Basket\Decorator\Bundle( $object, $this->context );
23
	}
24
25
26
	protected function tearDown()
27
	{
28
		$this->object->clear();
29
		$this->context->getSession()->set( 'aimeos', array() );
30
31
		unset( $this->object );
32
	}
33
34
35
	public function testAddProductBundle()
36
	{
37
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'product' )->findItem( 'U:BUNDLE' );
38
39
		$this->object->addProduct( $item->getId(), 1 );
40
41
		$this->assertEquals( 1, count( $this->object->get()->getProducts() ) );
42
		$this->assertEquals( 'U:BUNDLE', $this->object->get()->getProduct( 0 )->getProductCode() );
43
		$this->assertEquals( 2, count( $this->object->get()->getProduct( 0 )->getProducts() ) );
44
	}
45
46
47
	public function testAddProductNoBundle()
48
	{
49
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'product' )->findItem( 'CNC' );
50
51
		$this->object->addProduct( $item->getId(), 1 );
52
53
		$this->assertEquals( 1, count( $this->object->get()->getProducts() ) );
54
		$this->assertEquals( 'CNC', $this->object->get()->getProduct( 0 )->getProductCode() );
55
		$this->assertEquals( 0, count( $this->object->get()->getProduct( 0 )->getProducts() ) );
56
	}
57
}
58