Passed
Push — master ( 91b6db...c8efcd )
by Aimeos
27:02 queued 24:35
created

StandardTest::testSlice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
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-2021
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() : void
20
	{
21
		$this->context = \TestHelperFrontend::context();
22
		$this->object = new \Aimeos\Controller\Frontend\Catalog\Standard( $this->context );
23
	}
24
25
26
	protected function tearDown() : void
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( ['text'] )->find( 'cafe' );
42
43
		$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $item );
44
		$this->assertEquals( 1, count( $item->getRefItems( 'text' ) ) );
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' )->find( 'cafe' );
58
		$item = $this->object->uses( ['text'] )->get( $item->getId() );
59
60
		$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $item );
61
		$this->assertEquals( 1, count( $item->getRefItems( 'text' ) ) );
62
	}
63
64
65
	public function testGetPath()
66
	{
67
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->find( 'cafe', [] );
68
		$items = $this->object->uses( ['text'] )->getPath( $item->getId() );
69
70
		$this->assertEquals( 3, count( $items ) );
71
		$this->assertEquals( 1, count( $items->last()->getRefItems( 'text' ) ) );
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( ['text'] )->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( 5, count( $tree->toList()->last()->getRefItems( 'text' ) ) );
89
	}
90
91
92
	public function testHas()
93
	{
94
		$manager = \Aimeos\MShop::create( $this->context, 'text' );
95
		$filter = $manager->filter()->add( ['text.domain' => 'catalog'] )->slice( 0, 1 );
96
		$id = $manager->search( $filter )->first()->getId();
97
98
		$this->assertEquals( 1, count( $this->object->has( 'text', 'unittype1', $id )->search() ) );
99
	}
100
101
102
	public function testParse()
103
	{
104
		$cond = ['>' => ['catalog.status' => 0]];
105
		$this->assertEquals( 8, count( $this->object->parse( $cond )->getTree()->toList() ) );
106
	}
107
108
109
	public function testRoot()
110
	{
111
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
112
113
		$root = $manager->find( 'categories' );
114
		$item = $manager->find( 'cafe' );
115
116
		$this->assertEquals( 2, count( $this->object->root( $root->getId() )->getPath( $item->getId() ) ) );
117
	}
118
119
120
	public function testSearch()
121
	{
122
		$total = 0;
123
		$items = $this->object->uses( ['text'] )->compare( '==', 'catalog.code', 'cafe' )->search( $total );
124
125
		$this->assertCount( 1, $items );
126
		$this->assertEquals( 1, count( $items->first()->getRefItems( 'text' ) ) );
127
	}
128
129
130
	public function testSlice()
131
	{
132
		$this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) );
133
	}
134
135
136
	public function testSort()
137
	{
138
		$this->assertGreaterThanOrEqual( 8, count( $this->object->sort( 'catalog.label' )->search() ) );
139
	}
140
141
142
	public function testUses()
143
	{
144
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
145
	}
146
147
148
	public function testVisible()
149
	{
150
		$this->context->config()->set( 'controller/frontend/catalog/levels-always', null );
151
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
152
153
		$root = $manager->find( 'root' );
154
		$item = $manager->find( 'cafe' );
155
		$catIds = $manager->getPath( $item->getId() )->keys()->toArray();
156
157
		$result = $this->object->root( $root->getId() )->visible( $catIds )->getTree();
158
159
		$this->assertEquals( 6, count( $result->toList() ) );
160
	}
161
}
162