Passed
Push — master ( 5a0518...247ea4 )
by Aimeos
14:19
created

BaseTest::testDelete()   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), 2023
6
 */
7
8
9
namespace Aimeos\MShop\Test\Manager;
10
11
12
class BaseTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
	private $stub;
0 ignored issues
show
introduced by
The private property $stub is not used, and could be removed.
Loading history...
17
18
19
	protected function setUp() : void
20
	{
21
		$this->context = \TestHelper::context();
22
		$this->object = new \Aimeos\MShop\Test\Manager\Standard( $this->context );
23
	}
24
25
26
	protected function tearDown() : void
27
	{
28
		unset( $this->context, $this->object );
29
	}
30
31
32
	public function testClear()
33
	{
34
		$result = $this->object->clear( [$this->context->locale()->getSiteId()] );
35
		$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $result );
36
	}
37
38
39
	public function testCreate()
40
	{
41
		$item = $this->object->create( [
42
			'id' => 123,
43
			'siteid' => '1.',
44
			'key' => 'somekey',
45
			'value' => 'someval',
46
			'mtime' => '2000-01-01 00:00:00',
47
			'ctime' => '2000-01-01 00:00:00',
48
			'editor' => 'testeditor'
49
		] );
50
51
		$this->assertEquals( 123, $item->getId() );
52
		$this->assertEquals( '1.', $item->getSiteId() );
53
		$this->assertEquals( 'somekey', $item->get( 'key' ) );
54
		$this->assertEquals( 'someval', $item->get( 'value' ) );
55
		$this->assertEquals( '2000-01-01 00:00:00', $item->getTimeModified() );
56
		$this->assertEquals( '2000-01-01 00:00:00', $item->getTimeCreated() );
57
		$this->assertEquals( 'testeditor', $item->editor() );
58
	}
59
60
61
	public function testDelete()
62
	{
63
		$result = $this->object->delete( -1 );
64
		$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $result );
65
	}
66
67
68
	public function testFilter()
69
	{
70
		$result = $this->object->filter();
71
		$this->assertInstanceOf( \Aimeos\Base\Criteria\Iface::class, $result );
72
	}
73
74
75
	public function testSave()
76
	{
77
		$item = $this->object->create()
78
			->set( 'key', 'somekey' )
79
			->set( 'value', 'someval' );
80
81
		$result = $this->object->save( $item );
82
83
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $result );
84
85
		$this->object->clear( [$this->context->locale()->getSiteId()] );
86
	}
87
88
89
	public function testSearch()
90
	{
91
		$item = $this->object->create()
92
			->set( 'key', 'somekey' )
93
			->set( 'value', 'someval' );
94
95
		$item = $this->object->save( $item );
0 ignored issues
show
Unused Code introduced by
The assignment to $item is dead and can be removed.
Loading history...
96
		$result = $this->object->search( $this->object->filter() );
97
98
		$this->assertInstanceOf( \Aimeos\Map::class, $result );
99
		$this->assertEquals( 'somekey', $result->first()?->get( 'key' ) );
100
		$this->assertEquals( 'someval', $result->first()?->get( 'value' ) );
101
102
		$this->object->clear( [$this->context->locale()->getSiteId()] );
103
	}
104
105
106
	public function testIterate()
107
	{
108
		$item = $this->object->create()
109
			->set( 'key', 'somekey' )
110
			->set( 'value', 'someval' );
111
112
		$item = $this->object->save( $item );
0 ignored issues
show
Unused Code introduced by
The assignment to $item is dead and can be removed.
Loading history...
113
114
		$cursor = $this->object->cursor( $this->object->filter() );
115
		$result = $this->object->iterate( $cursor );
116
117
		$this->assertInstanceOf( \Aimeos\Map::class, $result );
118
		$this->assertEquals( 'somekey', $result->first()?->get( 'key' ) );
119
		$this->assertEquals( 'someval', $result->first()?->get( 'value' ) );
120
121
		$this->object->clear( [$this->context->locale()->getSiteId()] );
122
	}
123
124
125
	public function testGet()
126
	{
127
		$item = $this->object->create()
128
			->set( 'key', 'somekey' )
129
			->set( 'value', 'someval' );
130
131
		$item = $this->object->save( $item );
132
		$result = $this->object->get( $item->getId() );
133
134
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $result );
135
		$this->assertEquals( 'somekey', $result->get( 'key' ) );
136
		$this->assertEquals( 'someval', $result->get( 'value' ) );
137
138
		$this->object->clear( [$this->context->locale()->getSiteId()] );
139
	}
140
141
142
	public function testGetResourceType()
143
	{
144
		$this->assertEquals( ['test'], $this->object->getResourceType() );
145
	}
146
}
147
148
149
150
class Standard extends \Aimeos\MShop\Common\Manager\Base implements \Aimeos\MShop\Common\Manager\Iface
151
{
152
	public function getSaveAttributes() : array
153
	{
154
		return $this->createAttributes( [
155
			'key' => [],
156
			'value' => [],
157
		] );
158
	}
159
}