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 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
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 Aimeos (aimeos.org), 2018
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Supplier;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $context;
16
17
18
	protected function setUp()
19
	{
20
		$this->context = \TestHelperFrontend::getContext();
21
		$this->object = new \Aimeos\Controller\Frontend\Supplier\Standard( $this->context );
22
	}
23
24
25
	protected function tearDown()
26
	{
27
		unset( $this->object, $this->context );
28
	}
29
30
31
	public function testCompare()
32
	{
33
		$this->assertEquals( 2, count( $this->object->compare( '=~', 'supplier.label', 'unit' )->search() ) );
34
	}
35
36
37
	public function testFind()
38
	{
39
		$item = $this->object->uses( ['product'] )->find( 'unitCode001' );
40
41
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Iface::class, $item );
42
		$this->assertEquals( 2, count( $item->getRefItems( 'product' ) ) );
43
	}
44
45
46
	public function testFunction()
47
	{
48
		$str = $this->object->function( 'supplier:has', ['domain', 'type', 'refid'] );
49
		$this->assertEquals( 'supplier:has("domain","type","refid")', $str );
50
	}
51
52
53
	public function testGet()
54
	{
55
		$item = \Aimeos\MShop::create( $this->context, 'supplier' )->findItem( 'unitCode001' );
56
		$item = $this->object->uses( ['product'] )->get( $item->getId() );
57
58
		$this->assertInstanceOf( \Aimeos\MShop\Supplier\Item\Iface::class, $item );
59
		$this->assertEquals( 2, count( $item->getRefItems( 'product' ) ) );
60
	}
61
62
63
	public function testHas()
64
	{
65
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
66
		$prodId = $manager->findItem( 'CNE' )->getId();
67
68
		$this->assertEquals( 1, count( $this->object->has( 'product', 'default', $prodId )->search() ) );
69
	}
70
71
72
	public function testParse()
73
	{
74
		$cond = ['&&' => [['==' => ['supplier.status' => 1]], ['=~' => ['supplier.label' => 'unit']]]];
75
		$this->assertEquals( 2, count( $this->object->parse( $cond )->search() ) );
76
	}
77
78
79
	public function testSearch()
80
	{
81
		$total = 0;
82
		$items = $this->object->uses( ['product'] )->compare( '=~', 'supplier.code', 'unit' )
83
			->sort( 'supplier.code' )->search( $total );
84
85
		$this->assertGreaterThanOrEqual( 2, count( $items ) );
86
		$this->assertGreaterThanOrEqual( 2, $total );
87
		$this->assertEquals( 2, count( current( $items )->getRefItems( 'product' ) ) );
88
	}
89
90
91
	public function testSlice()
92
	{
93
		$this->assertEquals( 1, count( $this->object->slice( 0, 1 )->search() ) );
94
	}
95
96
97
	public function testSort()
98
	{
99
		$this->assertGreaterThanOrEqual( 2, count( $this->object->sort()->search() ) );
100
	}
101
102
103
	public function testSortGeneric()
104
	{
105
		$this->assertGreaterThanOrEqual( 2, count( $this->object->sort( 'supplier.label' )->search() ) );
106
	}
107
108
109
	public function testSortMultiple()
110
	{
111
		$this->assertGreaterThanOrEqual( 2, count( $this->object->sort( 'supplier.label,-supplier.id' )->search() ) );
112
	}
113
114
115
	public function testUses()
116
	{
117
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
118
	}
119
}
120