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
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2013
6
 * @copyright Aimeos (aimeos.org), 2014-2025
7
 */
8
9
10
namespace Aimeos\MShop\Customer\Manager\Lists;
11
12
13
class Typo3Test extends \PHPUnit\Framework\TestCase
14
{
15
	private $object;
16
	private $context;
17
	private $editor = '';
18
19
20
	protected function setUp() : void
21
	{
22
		$this->context = \TestHelper::context();
23
		$this->editor = $this->context->editor();
24
		$this->object = new \Aimeos\MShop\Customer\Manager\Lists\Typo3( \TestHelper::context() );
25
	}
26
27
28
	protected function tearDown() : void
29
	{
30
		unset( $this->object );
31
	}
32
33
34
	public function testCreateItem()
35
	{
36
		$item = $this->object->create();
37
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $item );
38
	}
39
40
41
	public function testGetItem()
42
	{
43
		$search = $this->object->filter()->slice( 0, 1 );
44
45
		if( ( $item = $this->object->search( $search )->first() ) === null ) {
46
			throw new \RuntimeException( 'No item found' );
47
		}
48
49
		$this->assertEquals( $item, $this->object->get( $item->getId() ) );
50
	}
51
52
53
	public function testSaveUpdateDeleteItem()
54
	{
55
		$search = $this->object->filter()->slice( 0, 1 );
56
57
		if( ( $item = $this->object->search( $search )->first() ) === null ) {
58
			throw new \RuntimeException( 'No item found' );
59
		}
60
61
		$item->setId( null );
62
		$item->setDomain( 'unittest' );
63
		$resultSaved = $this->object->save( $item );
64
		$itemSaved = $this->object->get( $item->getId() );
65
66
		$itemExp = clone $itemSaved;
67
		$itemExp->setDomain( 'unittest2' );
68
		$resultUpd = $this->object->save( $itemExp );
69
		$itemUpd = $this->object->get( $itemExp->getId() );
70
71
		$this->object->delete( $itemSaved->getId() );
72
73
74
		$this->assertTrue( $item->getId() !== null );
75
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
76
		$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() );
77
		$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() );
78
		$this->assertEquals( $item->getType(), $itemSaved->getType() );
79
		$this->assertEquals( $item->getRefId(), $itemSaved->getRefId() );
80
		$this->assertEquals( $item->getDomain(), $itemSaved->getDomain() );
81
		$this->assertEquals( $item->getDateStart(), $itemSaved->getDateStart() );
82
		$this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() );
83
		$this->assertEquals( $item->getPosition(), $itemSaved->getPosition() );
84
		$this->assertEquals( $this->editor, $itemSaved->editor() );
85
		$this->assertStringStartsWith( date( 'Y-m-d', time() ), $itemSaved->getTimeCreated() );
86
		$this->assertStringStartsWith( date( 'Y-m-d', time() ), $itemSaved->getTimeModified() );
87
88
		$this->assertEquals( $this->editor, $itemSaved->editor() );
89
		$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
90
		$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
91
92
		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
93
		$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() );
94
		$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() );
95
		$this->assertEquals( $itemExp->getType(), $itemUpd->getType() );
96
		$this->assertEquals( $itemExp->getRefId(), $itemUpd->getRefId() );
97
		$this->assertEquals( $itemExp->getDomain(), $itemUpd->getDomain() );
98
		$this->assertEquals( $itemExp->getDateStart(), $itemUpd->getDateStart() );
99
		$this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() );
100
		$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() );
101
102
		$this->assertEquals( $this->editor, $itemUpd->editor() );
103
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
104
		$this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
105
106
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved );
107
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd );
108
109
		$this->expectException( '\\Aimeos\\MShop\\Exception' );
110
		$this->object->get( $itemSaved->getId() );
111
	}
112
113
114
	public function testSearchItems()
115
	{
116
		$total = 0;
117
		$search = $this->object->filter();
118
119
		$expr = [];
120
		$expr[] = $search->compare( '!=', 'customer.lists.id', null );
121
		$expr[] = $search->compare( '!=', 'customer.lists.siteid', null );
122
		$expr[] = $search->compare( '!=', 'customer.lists.parentid', null );
123
		$expr[] = $search->compare( '!=', 'customer.lists.key', null );
124
		$expr[] = $search->compare( '==', 'customer.lists.domain', 'text' );
125
		$expr[] = $search->compare( '==', 'customer.lists.type', 'default' );
126
		$expr[] = $search->compare( '>', 'customer.lists.refid', 0 );
127
		$expr[] = $search->compare( '==', 'customer.lists.datestart', '2010-01-01 00:00:00' );
128
		$expr[] = $search->compare( '==', 'customer.lists.dateend', '2098-01-01 00:00:00' );
129
		$expr[] = $search->compare( '!=', 'customer.lists.config', null );
130
		$expr[] = $search->compare( '>', 'customer.lists.position', 0 );
131
		$expr[] = $search->compare( '==', 'customer.lists.status', 1 );
132
		$expr[] = $search->compare( '>=', 'customer.lists.mtime', '1970-01-01 00:00:00' );
133
		$expr[] = $search->compare( '>=', 'customer.lists.ctime', '1970-01-01 00:00:00' );
134
		$expr[] = $search->compare( '==', 'customer.lists.editor', $this->editor );
135
136
		$search->setConditions( $search->and( $expr ) );
137
		$search->slice( 0, 2 );
138
		$results = $this->object->search( $search, [], $total );
139
		$this->assertEquals( 2, count( $results ) );
140
		$this->assertEquals( 3, $total );
141
142
		foreach( $results as $itemId => $item ) {
143
			$this->assertEquals( $itemId, $item->getId() );
144
		}
145
	}
146
147
148
	public function testSearchItemsAll()
149
	{
150
		//search without base criteria
151
		$search = $this->object->filter()->add( ['customer.lists.editor' => $this->editor] );
152
		$this->assertGreaterThanOrEqual( 5, count( $this->object->search( $search ) ) );
153
	}
154
155
156
	public function testSearchItemsBase()
157
	{
158
		//search with base criteria
159
		$search = $this->object->filter( true )->add( ['customer.lists.editor' => $this->editor] );
160
		$this->assertGreaterThanOrEqual( 5, count( $this->object->search( $search ) ) );
161
	}
162
163
164
	public function testGetSubManager()
165
	{
166
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'type' ) );
167
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'type', 'Typo3' ) );
168
169
		$this->expectException( \LogicException::class );
170
		$this->object->getSubManager( 'unknown' );
171
	}
172
}
173