Passed
Push — master ( 635cae...14ad00 )
by Aimeos
02:06
created

StandardTest   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 19
eloc 38
dl 0
loc 139
rs 10
c 0
b 0
f 0

19 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testAttribute() 0 8 1
A testDomain() 0 3 1
A tearDown() 0 3 1
A testCompare() 0 3 1
A testParse() 0 4 1
A testSort() 0 3 1
A testGet() 0 7 1
A testSlice() 0 3 1
A testSearch() 0 8 1
A testSortGeneric() 0 3 1
A testHas() 0 3 1
A testProperty() 0 3 1
A testFind() 0 6 1
A testType() 0 3 1
A testSortPosition() 0 4 1
A testSortMultiple() 0 3 1
A testUses() 0 3 1
A testSortCodeDesc() 0 4 1
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
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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 testFind()
55
	{
56
		$item = $this->object->uses( ['text'] )->find( 'white', 'color' );
57
58
		$this->assertInstanceOf( \Aimeos\MShop\Attribute\Item\Iface::class, $item );
59
		$this->assertEquals( 1, count( $item->getRefItems( 'text' ) ) );
60
	}
61
62
63
	public function testGet()
64
	{
65
		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->findItem( 'white', [], 'product', 'color' );
66
		$item = $this->object->uses( ['text'] )->get( $item->getId() );
67
68
		$this->assertInstanceOf( \Aimeos\MShop\Attribute\Item\Iface::class, $item );
69
		$this->assertEquals( 1, count( $item->getRefItems( 'text' ) ) );
70
	}
71
72
73
74
	public function testHas()
75
	{
76
		$this->assertEquals( 2, count( $this->object->has( 'price', 'default' )->search() ) );
77
	}
78
79
80
	public function testParse()
81
	{
82
		$cond = ['&&' => [['>' => ['attribute.status' => 0]], ['==' => ['attribute.type' => 'color']]]];
83
		$this->assertEquals( 5, count( $this->object->parse( $cond )->search() ) );
84
	}
85
86
87
	public function testProperty()
88
	{
89
		$this->assertEquals( 1, count( $this->object->property( 'size', '1024' )->search() ) );
90
	}
91
92
93
	public function testSearch()
94
	{
95
		$total = 0;
96
		$items = $this->object->uses( ['text'] )->sort( 'attribute.code' )->search( $total );
97
98
		$this->assertGreaterThanOrEqual( 26, count( $items ) );
99
		$this->assertGreaterThanOrEqual( 26, $total );
100
		$this->assertEquals( 1, count( current( array_reverse( $items, true ) )->getRefItems( 'text' ) ) );
101
	}
102
103
104
	public function testSlice()
105
	{
106
		$this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) );
107
	}
108
109
110
	public function testSort()
111
	{
112
		$this->assertGreaterThanOrEqual( 26, count( $this->object->sort()->search() ) );
113
	}
114
115
116
	public function testSortGeneric()
117
	{
118
		$this->assertGreaterThanOrEqual( 26, count( $this->object->sort( 'attribute.status' )->search() ) );
119
	}
120
121
122
	public function testSortMultiple()
123
	{
124
		$this->assertGreaterThanOrEqual( 26, count( $this->object->sort( 'attribute.status,-attribute.code' )->search() ) );
125
	}
126
127
128
	public function testSortPosition()
129
	{
130
		$result = $this->object->sort( 'position' )->search();
131
		$this->assertEquals( 'white', reset( $result )->getCode() );
132
	}
133
134
135
	public function testSortCodeDesc()
136
	{
137
		$result = $this->object->sort( '-position' )->search();
138
		$this->assertStringStartsWith( 'white', end( $result )->getCode() );
139
	}
140
141
142
	public function testType()
143
	{
144
		$this->assertEquals( 6, count( $this->object->type( 'size' )->search() ) );
145
	}
146
147
148
	public function testUses()
149
	{
150
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
151
	}
152
}
153