Completed
Push — master ( 921503...9109fd )
by Aimeos
02:03
created

StandardTest::testCreateFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2018
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Attribute;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
17
18
	protected function setUp()
19
	{
20
		$this->context = \TestHelperFrontend::getContext();
21
		$this->object = new \Aimeos\Controller\Frontend\Attribute\Standard( $this->context );
22
	}
23
24
25
	protected function tearDown()
26
	{
27
		unset( $this->object, $this->context );
28
	}
29
30
31
	public function testAttribute()
32
	{
33
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
34
35
		$blueId = $manager->findItem( 'blue', [], 'product', 'color' )->getId();
36
		$whiteId = $manager->findItem( 'white', [], 'product', 'color' )->getId();
37
38
		$this->assertEquals( 2, count( $this->object->attribute( [$blueId, $whiteId] )->search() ) );
39
	}
40
41
42
	public function testDomain()
43
	{
44
		$this->assertEquals( 5, count( $this->object->domain( 'media' )->search() ) );
45
	}
46
47
48
	public function testCompare()
49
	{
50
		$this->assertEquals( 5, count( $this->object->compare( '==', 'attribute.type', 'color' )->search() ) );
51
	}
52
53
54
	public function testGet()
55
	{
56
		$iface = \Aimeos\MShop\Attribute\Item\Iface::class;
57
		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->findItem( 'white', [], 'product', 'color' );
58
59
		$this->assertInstanceOf( $iface, $this->object->get( $item->getId() ) );
60
	}
61
62
63
	public function testFind()
64
	{
65
		$iface = \Aimeos\MShop\Attribute\Item\Iface::class;
66
		$this->assertInstanceOf( $iface, $this->object->find( 'white', [], 'color' ) );
67
	}
68
69
70
	public function testParse()
71
	{
72
		$cond = ['&&' => [['>' => ['attribute.status' => 0]], ['==' => ['attribute.type' => 'color']]]];
73
		$this->assertEquals( 5, count( $this->object->parse( $cond )->search() ) );
74
	}
75
76
77
	public function testSearch()
78
	{
79
		$total = 0;
80
		$this->assertGreaterThanOrEqual( 26, count( $this->object->search( [], $total ) ) );
81
		$this->assertGreaterThanOrEqual( 26, $total );
82
	}
83
84
85
	public function testSlice()
86
	{
87
		$this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) );
88
	}
89
90
91
	public function testSort()
92
	{
93
		$this->assertGreaterThanOrEqual( 26, count( $this->object->sort()->search() ) );
94
	}
95
96
97
	public function testSortGeneric()
98
	{
99
		$this->assertGreaterThanOrEqual( 26, count( $this->object->sort( 'attribute.status' )->search() ) );
100
	}
101
102
103
	public function testSortPosition()
104
	{
105
		$result = $this->object->sort( 'position' )->search( [] );
106
		$this->assertEquals( 'white', reset( $result )->getCode() );
107
	}
108
109
110
	public function testSortCodeDesc()
111
	{
112
		$result = $this->object->sort( '-position' )->search( [] );
113
		$this->assertStringStartsWith( 'white', end( $result )->getCode() );
114
	}
115
116
117
	public function testType()
118
	{
119
		$this->assertEquals( 6, count( $this->object->type( 'size' )->search() ) );
120
	}
121
}
122