Completed
Push — master ( 94eb6c...a336e2 )
by Aimeos
02:13
created

StandardTest::testFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2012
6
 * @copyright Aimeos (aimeos.org), 2015-2018
7
 */
8
9
10
namespace Aimeos\Controller\Frontend\Catalog;
11
12
13
class StandardTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $context;
16
	private $object;
17
18
19
	protected function setUp()
20
	{
21
		$this->context = \TestHelperFrontend::getContext();
22
		$this->object = new \Aimeos\Controller\Frontend\Catalog\Standard( $this->context );
23
	}
24
25
26
	protected function tearDown()
27
	{
28
		unset( $this->object, $this->context );
29
	}
30
31
32
	public function testCompare()
33
	{
34
		$list = $this->object->compare( '==', 'catalog.code', 'categories' )->getTree()->toList();
35
		$this->assertEquals( 1, count( $list ) );
36
	}
37
38
39
	public function testFind()
40
	{
41
		$item = $this->object->uses( ['product'] )->find( 'cafe' );
42
43
		$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $item );
44
		$this->assertEquals( 2, count( $item->getRefItems( 'product' ) ) );
45
	}
46
47
48
	public function testFunction()
49
	{
50
		$str = $this->object->function( 'catalog:has', ['domain', 'type', 'refid'] );
51
		$this->assertEquals( 'catalog:has("domain","type","refid")', $str );
52
	}
53
54
55
	public function testGet()
56
	{
57
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->findItem( 'cafe' );
58
		$item = $this->object->uses( ['product'] )->get( $item->getId() );
59
60
		$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $item );
61
		$this->assertEquals( 2, count( $item->getRefItems( 'product' ) ) );
62
	}
63
64
65
	public function testGetPath()
66
	{
67
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->findItem( 'cafe', [] );
68
		$items = $this->object->uses( ['product'] )->getPath( $item->getId() );
69
70
		$this->assertEquals( 3, count( $items ) );
71
		$this->assertEquals( 2, count( current( array_reverse( $items, true ) )->getRefItems( 'product' ) ) );
72
73
		foreach( $items as $item ) {
74
			$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $item );
75
		}
76
	}
77
78
79
	public function testGetTree()
80
	{
81
		$tree = $this->object->uses( ['product'] )->getTree();
82
83
		foreach( $tree->toList() as $item ) {
84
			$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $item );
85
		}
86
87
		$this->assertEquals( 2, count( $tree->getChildren() ) );
88
		$this->assertEquals( 4, count( current( array_reverse( $tree->toList(), true ) )->getRefItems( 'product' ) ) );
89
	}
90
91
92
	public function testParse()
93
	{
94
		$cond = ['>' => ['catalog.status' => 0]];
95
		$this->assertEquals( 8, count( $this->object->parse( $cond )->getTree()->toList() ) );
96
	}
97
98
99
	public function testRoot()
100
	{
101
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
102
103
		$root = $manager->findItem( 'categories' );
104
		$item = $manager->findItem( 'cafe' );
105
106
		$this->assertEquals( 2, count( $this->object->root( $root->getId() )->getPath( $item->getId() ) ) );
107
	}
108
109
110
	public function testSearch()
111
	{
112
		$total = 0;
113
		$items = $this->object->uses( ['product'] )->compare( '==', 'catalog.code', 'cafe' )->search( $total );
114
115
		$this->assertCount( 1, $items );
116
		$this->assertEquals( 2, count( current( $items )->getRefItems( 'product' ) ) );
0 ignored issues
show
Bug introduced by
It seems like $items can also be of type Countable and Traversable; however, parameter $array of current() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

116
		$this->assertEquals( 2, count( current( /** @scrutinizer ignore-type */ $items )->getRefItems( 'product' ) ) );
Loading history...
117
	}
118
119
120
	public function testUses()
121
	{
122
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
123
	}
124
125
126
	public function testVisible()
127
	{
128
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
129
130
		$root = $manager->findItem( 'root' );
131
		$item = $manager->findItem( 'cafe' );
132
		$catIds = array_keys( $manager->getPath( $item->getId() ) );
133
134
		$result = $this->object->root( $root->getId() )->visible( $catIds )->getTree();
135
136
		$this->assertEquals( 6, count( $result->toList() ) );
137
	}
138
}
139