Completed
Push — master ( f97bb5...a4e8a9 )
by Aimeos
02:10
created

StandardTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 4 1
A testCreateFilter() 0 9 1
A testAddFilterCodes() 0 14 3
A testAddFilterTypes() 0 14 3
A testGetItem() 0 10 1
A testSearchItems() 0 11 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\Stock;
10
11
12
class StandardTest extends \PHPUnit_Framework_TestCase
13
{
14
	private $object;
15
16
17
	protected function setUp()
18
	{
19
		$this->object = new \Aimeos\Controller\Frontend\Stock\Standard( \TestHelperFrontend::getContext() );
20
	}
21
22
23
	protected function tearDown()
24
	{
25
		unset( $this->object );
26
	}
27
28
29
	public function testCreateFilter()
30
	{
31
		$filter = $this->object->createFilter();
32
33
		$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter );
34
		$this->assertEquals( array(), $filter->getSortations() );
35
		$this->assertEquals( 0, $filter->getSliceStart() );
36
		$this->assertEquals( 100, $filter->getSliceSize() );
37
	}
38
39
40
	public function testAddFilterCodes()
41
	{
42
		$filter = $this->object->createFilter();
43
		$filter = $this->object->addFilterCodes( $filter, ['CNC', 'CNE'] );
44
45
		$list = $filter->getConditions()->getExpressions();
46
47
		if( !isset( $list[0] ) || !( $list[0] instanceof \Aimeos\MW\Criteria\Expression\Compare\Iface ) ) {
48
			throw new \RuntimeException( 'Wrong expression' );
49
		}
50
51
		$this->assertEquals( 'stock.productcode', $list[0]->getName() );
52
		$this->assertEquals( 2, count( $list[0]->getValue() ) );
53
	}
54
55
56
	public function testAddFilterTypes()
57
	{
58
		$filter = $this->object->createFilter();
59
		$filter = $this->object->addFilterTypes( $filter, ['default'] );
60
61
		$list = $filter->getConditions()->getExpressions();
62
63
		if( !isset( $list[0] ) || !( $list[0] instanceof \Aimeos\MW\Criteria\Expression\Compare\Iface ) ) {
64
			throw new \RuntimeException( 'Wrong expression' );
65
		}
66
67
		$this->assertEquals( 'stock.type.code', $list[0]->getName() );
68
		$this->assertEquals( 1, count( $list[0]->getValue() ) );
69
	}
70
71
72
	public function testGetItem()
73
	{
74
		$context = \TestHelperFrontend::getContext();
75
		$manager = \Aimeos\MShop\Factory::createManager( $context, 'stock' );
76
		$id = $manager->findItem( 'CNC', [], 'product', 'default' )->getId();
77
78
		$result = $this->object->getItem( $id );
79
80
		$this->assertInstanceOf( '\Aimeos\MShop\Stock\Item\Iface', $result );
81
	}
82
83
84
	public function testSearchItems()
85
	{
86
		$filter = $this->object->createFilter();
87
		$filter = $this->object->addFilterCodes( $filter, ['CNC', 'CNE'] );
88
89
		$total = 0;
90
		$results = $this->object->searchItems( $filter, $total );
91
92
		$this->assertEquals( 2, $total );
93
		$this->assertEquals( 2, count( $results ) );
94
	}
95
}
96