Typo3Test::tearDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
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), 2015-2025
6
 */
7
8
9
namespace Aimeos\MShop\Group\Manager;
10
11
12
class Typo3Test 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\Group\Manager\Typo3( $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( array( -1 ) ) );
36
	}
37
38
39
	public function testCreateItem()
40
	{
41
		$item = $this->object->create();
42
		$this->assertInstanceOf( \Aimeos\MShop\Group\Item\Iface::class, $item );
43
	}
44
45
46
	public function testCreateSearch()
47
	{
48
		$this->assertInstanceOf( \Aimeos\Base\Criteria\Iface::class, $this->object->filter() );
49
	}
50
51
52
	public function testDeleteItems()
53
	{
54
		$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->delete( [-1] ) );
55
	}
56
57
58
	public function testGetSearchAttributes()
59
	{
60
		foreach( $this->object->getSearchAttributes() as $attribute ) {
61
			$this->assertInstanceOf( \Aimeos\Base\Criteria\Attribute\Iface::class, $attribute );
62
		}
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
		$item = $this->object->find( 'unitgroup' );
77
78
		$this->assertEquals( $item, $this->object->get( $item->getId() ) );
79
	}
80
81
82
	public function testSaveUpdateDeleteItem()
83
	{
84
		$item = $this->object->create();
85
		$item->setCode( 'unittest-group' );
86
87
		$resultSaved = $this->object->save( $item );
88
		$itemSaved = $this->object->get( $item->getId() );
89
90
		$itemExp = clone $itemSaved;
91
		$itemExp->setCode( 'unittest-group-2' );
92
93
		$resultUpd = $this->object->save( $itemExp );
94
		$itemUpd = $this->object->get( $itemExp->getId() );
95
96
		$this->object->delete( $itemSaved->getId() );
97
98
99
		$this->assertTrue( $item->getId() !== null );
100
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
101
		$this->assertEquals( $item->getCode(), $itemSaved->getCode() );
102
		$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() );
103
104
		$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
105
		$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
106
107
		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
108
		$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() );
109
		$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() );
110
111
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
112
		$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
113
114
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved );
115
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd );
116
117
		$this->expectException( \Aimeos\MShop\Exception::class );
118
		$this->object->get( $itemSaved->getId() );
119
	}
120
121
122
	public function testSearchItem()
123
	{
124
		$search = $this->object->filter();
125
		$search->setConditions( $search->compare( '==', 'group.label', 'Unitgroup' ) );
126
		$search->slice( 0, 1 );
127
128
		$total = 0;
129
		$results = $this->object->search( $search, [], $total );
130
131
		$this->assertEquals( 1, count( $results ) );
132
		$this->assertEquals( 1, $total );
133
	}
134
135
}
136