Passed
Push — master ( 0fdd6c...2a5595 )
by Aimeos
06:40
created

TraitsClass::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 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\MShop\Common\Item\PropertyRef;
10
11
12
class TraitsClass
13
{
14
	use \Aimeos\MShop\Common\Item\PropertyRef\Traits;
15
16
	public function getId()
17
	{
18
		return 'id';
19
	}
20
}
21
22
23
class TraitsTest extends \PHPUnit\Framework\TestCase
24
{
25
	private $object;
26
	private $propItem;
27
	private $propItem2;
28
29
30
	protected function setUp()
31
	{
32
		$this->propItem = new \Aimeos\MShop\Common\Item\Property\Standard( 'c.', ['languageid' => 'de', 'c.type' => 'test', 'c.value' => 'value']);
33
		$this->propItem2 = new \Aimeos\MShop\Common\Item\Property\Standard( 'c.', ['languageid' => 'de', 'c.languageid' => 'en', 'c.type' => 'test2']);
34
35
		$this->object = new TraitsClass();
36
		$this->object->addPropertyItem( $this->propItem );
37
		$this->object->addPropertyItem( $this->propItem2 );
38
	}
39
40
41
	protected function tearDown()
42
	{
43
		unset( $this->object, $this->propItem, $this->propItem2 );
44
	}
45
46
47
	public function testGetProperties()
48
	{
49
		$this->assertEquals( ['value'], array_values( $this->object->getProperties( 'test' ) ) );
50
	}
51
52
53
	public function testGetPropertyItem()
54
	{
55
		$this->assertEquals( $this->propItem, $this->object->getPropertyItem( 'test', null, 'value', false ) );
56
	}
57
58
59
	public function testGetPropertyItems()
60
	{
61
		$expected = [$this->propItem, $this->propItem2];
62
		$this->assertEquals( $expected, array_values( $this->object->getPropertyItems( null, false ) ) );
63
	}
64
65
66
	public function testGetPropertyItemsActive()
67
	{
68
		$this->assertEquals( [$this->propItem], array_values( $this->object->getPropertyItems() ) );
69
	}
70
71
72
	public function testGetPropertyItemsWithType()
73
	{
74
		$this->assertEquals( [$this->propItem2], array_values( $this->object->getPropertyItems( 'test2', false ) ) );
75
	}
76
77
78
	public function testGetPropertyItemsWithTypes()
79
	{
80
		$expected = [$this->propItem, $this->propItem2];
81
		$this->assertEquals( $expected, array_values( $this->object->getPropertyItems( ['test', 'test2'], false ) ) );
82
	}
83
84
85
	public function testGetPropertyItemsDeleted()
86
	{
87
		$this->assertEquals( [], $this->object->getPropertyItemsDeleted() );
88
	}
89
90
91
	public function testAddPropertyItem()
92
	{
93
		$object = new TraitsClass();
94
		$object->addPropertyItem( $this->propItem );
95
96
		$this->assertEquals( ['_id_test__value' => $this->propItem], $object->getPropertyItems() );
97
	}
98
99
100
	public function testDeletePropertyItem()
101
	{
102
		$this->object->deletePropertyItem( $this->propItem->setId( 123 ) );
103
104
		$this->assertEquals( [$this->propItem2], array_values( $this->object->getPropertyItems( null, false ) ) );
105
		$this->assertEquals( [$this->propItem], array_values( $this->object->getPropertyItemsDeleted() ) );
106
	}
107
}
108