Passed
Push — master ( 49f6b0...199364 )
by Aimeos
09:07
created

Typo3Test::testGetSubManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
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-2021
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::getContext();
23
		$this->editor = $this->context->getEditor();
24
		$manager = \Aimeos\MShop\Customer\Manager\Factory::create( \TestHelper::getContext(), 'Typo3' );
25
		$this->object = $manager->getSubManager( 'lists', 'Typo3' );
26
	}
27
28
29
	protected function tearDown() : void
30
	{
31
		unset( $this->object );
32
	}
33
34
35
	public function testAggregate()
36
	{
37
		$search = $this->object->filter( true );
38
		$result = $this->object->aggregate( $search, 'customer.lists.domain' )->toArray();
39
40
		$this->assertEquals( 2, count( $result ) );
41
		$this->assertArrayHasKey( 'text', $result );
42
		$this->assertEquals( 4, $result['text'] );
43
	}
44
45
46
	public function testCreateItem()
47
	{
48
		$item = $this->object->create();
49
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $item );
50
	}
51
52
53
	public function testGetItem()
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
		$this->assertEquals( $item, $this->object->get( $item->getId() ) );
62
	}
63
64
65
	public function testSaveUpdateDeleteItem()
66
	{
67
		$search = $this->object->filter()->slice( 0, 1 );
68
69
		if( ( $item = $this->object->search( $search )->first() ) === null ) {
70
			throw new \RuntimeException( 'No item found' );
71
		}
72
73
		$item->setId( null );
74
		$item->setDomain( 'unittest' );
75
		$resultSaved = $this->object->save( $item );
76
		$itemSaved = $this->object->get( $item->getId() );
77
78
		$itemExp = clone $itemSaved;
79
		$itemExp->setDomain( 'unittest2' );
80
		$resultUpd = $this->object->save( $itemExp );
81
		$itemUpd = $this->object->get( $itemExp->getId() );
82
83
		$this->object->delete( $itemSaved->getId() );
84
85
86
		$this->assertTrue( $item->getId() !== null );
87
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
88
		$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() );
89
		$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() );
90
		$this->assertEquals( $item->getType(), $itemSaved->getType() );
91
		$this->assertEquals( $item->getRefId(), $itemSaved->getRefId() );
92
		$this->assertEquals( $item->getDomain(), $itemSaved->getDomain() );
93
		$this->assertEquals( $item->getDateStart(), $itemSaved->getDateStart() );
94
		$this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() );
95
		$this->assertEquals( $item->getPosition(), $itemSaved->getPosition() );
96
		$this->assertEquals( $this->editor, $itemSaved->getEditor() );
97
		$this->assertStringStartsWith( date( 'Y-m-d', time() ), $itemSaved->getTimeCreated() );
98
		$this->assertStringStartsWith( date( 'Y-m-d', time() ), $itemSaved->getTimeModified() );
99
100
		$this->assertEquals( $this->editor, $itemSaved->getEditor() );
101
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
102
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
103
104
		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
105
		$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() );
106
		$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() );
107
		$this->assertEquals( $itemExp->getType(), $itemUpd->getType() );
108
		$this->assertEquals( $itemExp->getRefId(), $itemUpd->getRefId() );
109
		$this->assertEquals( $itemExp->getDomain(), $itemUpd->getDomain() );
110
		$this->assertEquals( $itemExp->getDateStart(), $itemUpd->getDateStart() );
111
		$this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() );
112
		$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() );
113
114
		$this->assertEquals( $this->editor, $itemUpd->getEditor() );
115
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
116
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
117
118
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved );
119
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd );
120
121
		$this->expectException( '\\Aimeos\\MShop\\Exception' );
122
		$this->object->get( $itemSaved->getId() );
123
	}
124
125
126
	public function testSearchItems()
127
	{
128
		$total = 0;
129
		$search = $this->object->filter();
130
131
		$expr = [];
132
		$expr[] = $search->compare( '!=', 'customer.lists.id', null );
133
		$expr[] = $search->compare( '!=', 'customer.lists.siteid', null );
134
		$expr[] = $search->compare( '!=', 'customer.lists.parentid', null );
135
		$expr[] = $search->compare( '!=', 'customer.lists.key', null );
136
		$expr[] = $search->compare( '==', 'customer.lists.domain', 'text' );
137
		$expr[] = $search->compare( '==', 'customer.lists.type', 'default' );
138
		$expr[] = $search->compare( '>', 'customer.lists.refid', 0 );
139
		$expr[] = $search->compare( '==', 'customer.lists.datestart', '2010-01-01 00:00:00' );
140
		$expr[] = $search->compare( '==', 'customer.lists.dateend', '2098-01-01 00:00:00' );
141
		$expr[] = $search->compare( '!=', 'customer.lists.config', null );
142
		$expr[] = $search->compare( '>', 'customer.lists.position', 0 );
143
		$expr[] = $search->compare( '==', 'customer.lists.status', 1 );
144
		$expr[] = $search->compare( '>=', 'customer.lists.mtime', '1970-01-01 00:00:00' );
145
		$expr[] = $search->compare( '>=', 'customer.lists.ctime', '1970-01-01 00:00:00' );
146
		$expr[] = $search->compare( '==', 'customer.lists.editor', $this->editor );
147
148
		$search->setConditions( $search->and( $expr ) );
149
		$search->slice( 0, 2 );
150
		$results = $this->object->search( $search, [], $total );
151
		$this->assertEquals( 2, count( $results ) );
152
		$this->assertEquals( 3, $total );
153
154
		foreach( $results as $itemId => $item ) {
155
			$this->assertEquals( $itemId, $item->getId() );
156
		}
157
	}
158
159
160
	public function testSearchItemsAll()
161
	{
162
		//search without base criteria
163
		$search = $this->object->filter();
164
		$search->setConditions( $search->compare( '==', 'customer.lists.editor', $this->editor ) );
165
		$result = $this->object->search( $search );
166
		$this->assertEquals( 5, count( $result ) );
167
	}
168
169
170
	public function testSearchItemsBase()
171
	{
172
		//search with base criteria
173
		$search = $this->object->filter( true );
174
		$conditions = array(
175
			$search->compare( '==', 'customer.lists.editor', $this->editor ),
176
			$search->getConditions()
177
		);
178
		$search->setConditions( $search->and( $conditions ) );
179
		$this->assertEquals( 5, count( $this->object->search( $search ) ) );
180
	}
181
182
183
	public function testGetSubManager()
184
	{
185
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'type' ) );
186
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'type', 'Typo3' ) );
187
188
		$this->expectException( '\\Aimeos\\MShop\\Exception' );
189
		$this->object->getSubManager( 'unknown' );
190
	}
191
}
192