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 setPropertyItems( $list ) |
17
|
|
|
{ |
18
|
|
|
$this->propItems = $list; |
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']); |
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->setPropertyItems( [$this->propItem, $this->propItem2] ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
protected function tearDown() |
41
|
|
|
{ |
42
|
|
|
unset( $this->object, $this->propItem, $this->propItem2 ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testGetPropertyItems() |
47
|
|
|
{ |
48
|
|
|
$expected = [$this->propItem, $this->propItem2]; |
49
|
|
|
$this->assertEquals( $expected, $this->object->getPropertyItems( null, false ) ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function testGetPropertyItemsActive() |
54
|
|
|
{ |
55
|
|
|
$this->assertEquals( [$this->propItem], $this->object->getPropertyItems() ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
public function testGetPropertyItemsWithType() |
60
|
|
|
{ |
61
|
|
|
$this->assertEquals( [1 => $this->propItem2], $this->object->getPropertyItems( 'test2', false ) ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
public function testGetPropertyItemsWithTypes() |
66
|
|
|
{ |
67
|
|
|
$expected = [$this->propItem, $this->propItem2]; |
68
|
|
|
$this->assertEquals( $expected, $this->object->getPropertyItems( ['test', 'test2'], false ) ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
public function testGetPropertyItemsDeleted() |
73
|
|
|
{ |
74
|
|
|
$this->assertEquals( [], $this->object->getPropertyItemsDeleted() ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testAddPropertyItem() |
79
|
|
|
{ |
80
|
|
|
$object = new TraitsClass(); |
81
|
|
|
$object->addPropertyItem( $this->propItem ); |
82
|
|
|
|
83
|
|
|
$this->assertEquals( ['id-0' => $this->propItem], $object->getPropertyItems() ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
public function testDeletePropertyItem() |
88
|
|
|
{ |
89
|
|
|
$this->object->deletePropertyItem( $this->propItem->setId( 123 ) ); |
90
|
|
|
|
91
|
|
|
$this->assertEquals( [1 => $this->propItem2], $this->object->getPropertyItems( null, false ) ); |
92
|
|
|
$this->assertEquals( [123 => $this->propItem], $this->object->getPropertyItemsDeleted() ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
public function testDeletePropertyItemException() |
97
|
|
|
{ |
98
|
|
|
$object = new TraitsClass(); |
99
|
|
|
|
100
|
|
|
$this->setExpectedException( '\Aimeos\MShop\Exception' ); |
101
|
|
|
$object->deletePropertyItem( $this->propItem ); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.