Completed
Push — master ( 4c5eea...8c1ffe )
by Aimeos
02:39
created

StandardTest::testGetItems()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 17
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 10
nc 2
nop 0
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\Attribute;
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\Attribute\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( 1, count( $filter->getSortations() ) );
35
		$this->assertEquals( 0, $filter->getSliceStart() );
36
		$this->assertEquals( 100, $filter->getSliceSize() );
37
	}
38
39
40
	public function testAddFilterTypes()
41
	{
42
		$filter = $this->object->createFilter();
43
		$filter = $this->object->addFilterTypes( $filter, ['size'] );
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( 'attribute.type.code', $list[0]->getName() );
52
		$this->assertEquals( 1, count( $list[0]->getValue() ) );
53
	}
54
55
56
	public function testGetItem()
57
	{
58
		$context = \TestHelperFrontend::getContext();
59
		$manager = \Aimeos\MShop\Factory::createManager( $context, 'attribute' );
60
		$id = $manager->findItem( 'xs', [], 'product', 'size' )->getId();
61
62
		$result = $this->object->getItem( $id, ['text'] );
63
64
		$this->assertInstanceOf( '\Aimeos\MShop\Attribute\Item\Iface', $result );
65
		$this->assertEquals( 3, count( $result->getRefItems( 'text' ) ) );
66
	}
67
68
69
	public function testGetItems()
70
	{
71
		$context = \TestHelperFrontend::getContext();
72
		$manager = \Aimeos\MShop\Factory::createManager( $context, 'attribute' );
73
		$id = $manager->findItem( 'xs', [], 'product', 'size' )->getId();
74
75
		$result = $this->object->getItems( [$id], ['text'] );
76
77
		$this->assertInternalType( 'array', $result );
78
		$this->assertEquals( 1, count( $result ) );
79
80
		foreach( $result as $attrItem )
81
		{
82
			$this->assertInstanceOf( '\Aimeos\MShop\Attribute\Item\Iface', $attrItem );
83
			$this->assertEquals( 3, count( $attrItem->getRefItems( 'text' ) ) );
84
		}
85
	}
86
87
88
	public function testSearchItems()
89
	{
90
		$filter = $this->object->createFilter();
91
		$filter = $this->object->addFilterTypes( $filter, ['size'] );
92
93
		$total = 0;
94
		$results = $this->object->searchItems( $filter, ['text'], $total );
95
96
		$this->assertEquals( 6, $total );
97
		$this->assertEquals( 6, count( $results ) );
98
	}
99
}
100