Passed
Push — master ( 4355c9...98ef81 )
by Aimeos
09:27
created

StandardTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2022
6
 */
7
8
9
namespace Aimeos\MShop\Customer\Manager\Group;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object = null;
15
	private $editor = '';
16
17
18
	protected function setUp() : void
19
	{
20
		$context = \TestHelper::context();
21
		$this->editor = $context->editor();
22
23
		$this->object = new \Aimeos\MShop\Customer\Manager\Group\Standard( $context );
24
	}
25
26
27
	protected function tearDown() : void
28
	{
29
		unset( $this->object );
30
	}
31
32
33
	public function testClear()
34
	{
35
		$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( [-1] ) );
36
	}
37
38
39
	public function testDeleteItems()
40
	{
41
		$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->delete( [-1] ) );
42
	}
43
44
45
	public function testGetResourceType()
46
	{
47
		$this->assertContains( 'customer/group', $this->object->getResourceType() );
48
	}
49
50
51
	public function testGetSearchAttributes()
52
	{
53
		foreach( $this->object->getSearchAttributes() as $attribute ) {
54
			$this->assertInstanceOf( \Aimeos\Base\Criteria\Attribute\Iface::class, $attribute );
55
		}
56
	}
57
58
59
	public function testCreateItem()
60
	{
61
		$item = $this->object->create();
62
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Group\Iface::class, $item );
63
	}
64
65
66
	public function testFindItem()
67
	{
68
		$item = $this->object->find( 'unitgroup' );
69
70
		$this->assertEquals( 'unitgroup', $item->getCode() );
71
	}
72
73
74
	public function testGetItem()
75
	{
76
		$search = $this->object->filter()->slice( 0, 1 );
77
		$search->setConditions( $search->compare( '==', 'customer.group.label', 'Unitgroup' ) );
78
79
		$items = $this->object->search( $search )->toArray();
80
81
		if( ( $item = reset( $items ) ) === false ) {
82
			throw new \RuntimeException( 'No group item with label "Unitgroup" found' );
83
		}
84
85
		$this->assertEquals( $item, $this->object->get( $item->getId() ) );
86
	}
87
88
89
	public function testSaveUpdateDeleteItem()
90
	{
91
		$item = $this->object->create();
92
		$item->setCode( 'unittest-group' );
93
		$item->setLabel( 'unittest group' );
94
95
		$resultSaved = $this->object->save( $item );
96
		$itemSaved = $this->object->get( $item->getId() );
97
98
		$itemExp = clone $itemSaved;
99
		$itemExp->setLabel( 'unittest 2. group' );
100
101
		$resultUpd = $this->object->save( $itemExp );
102
		$itemUpd = $this->object->get( $itemExp->getId() );
103
104
		$this->object->delete( $itemSaved->getId() );
105
106
107
		$this->assertTrue( $item->getId() !== null );
108
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
109
		$this->assertEquals( $item->getCode(), $itemSaved->getCode() );
110
		$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() );
111
112
		$this->assertEquals( $this->editor, $itemSaved->editor() );
113
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
114
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
115
116
		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
117
		$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() );
118
		$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() );
119
120
		$this->assertEquals( $this->editor, $itemUpd->editor() );
121
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
122
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
123
124
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved );
125
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd );
126
127
		$this->expectException( \Aimeos\MShop\Exception::class );
128
		$this->object->get( $itemSaved->getId() );
129
	}
130
131
132
	public function testCreateSearch()
133
	{
134
		$this->assertInstanceOf( \Aimeos\Base\Criteria\Iface::class, $this->object->filter() );
135
	}
136
137
138
	public function testSearchItem()
139
	{
140
		$total = 0;
141
		$search = $this->object->filter()->add( 'customer.group.code', '~=', 'unitgroup' )->slice( 0, 1 );
142
		$results = $this->object->search( $search, [], $total )->toArray();
143
144
		$this->assertEquals( 1, count( $results ) );
145
		$this->assertEquals( 2, $total );
146
	}
147
148
}
149