Passed
Push — master ( 31d769...359d0b )
by Aimeos
02:26
created

LaravelTest::testGetSubManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2018
6
 */
7
8
9
 namespace Aimeos\MShop\Customer\Manager\Lists;
10
11
12
class LaravelTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
{
14
	private $object;
15
	private $context;
16
	private $editor = 'ai-laravel:lib/custom';
17
18
19
	protected function setUp()
20
	{
21
		$this->context = \TestHelper::getContext();
22
		$this->editor = $this->context->getEditor();
23
		$manager = \Aimeos\MShop\Customer\Manager\Factory::create( $this->context, 'Laravel' );
24
		$this->object = $manager->getSubManager( 'lists', 'Laravel' );
25
	}
26
27
28
	protected function tearDown()
29
	{
30
		unset( $this->object, $this->context );
31
	}
32
33
34
	public function testCleanup()
35
	{
36
		$this->object->cleanup( array( -1 ) );
37
	}
38
39
40
	public function testAggregate()
41
	{
42
		$search = $this->object->createSearch( true );
43
		$expr = array(
44
			$search->getConditions(),
45
			$search->compare( '==', 'customer.lists.editor', 'ai-laravel:lib/custom' ),
46
		);
47
		$search->setConditions( $search->combine( '&&', $expr ) );
48
49
		$result = $this->object->aggregate( $search, 'customer.lists.domain' );
50
51
		$this->assertEquals( 2, count( $result ) );
52
		$this->assertArrayHasKey( 'text', $result );
53
		$this->assertEquals( 4, $result['text'] );
54
	}
55
56
57
	public function testCreateItem()
58
	{
59
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $this->object->createItem() );
60
	}
61
62
63
	public function testGetItem()
64
	{
65
		$search = $this->object->createSearch();
66
		$search->setSlice(0, 1);
67
		$results = $this->object->searchItems( $search );
68
69
		if( ( $item = reset( $results ) ) === false ) {
70
			throw new \RuntimeException( 'No item found' );
71
		}
72
73
		$this->assertEquals( $item, $this->object->getItem( $item->getId() ) );
74
	}
75
76
77
	public function testSaveUpdateDeleteItem()
78
	{
79
		$search = $this->object->createSearch();
80
		$search->setSlice(0, 1);
81
		$items = $this->object->searchItems( $search );
82
83
		if( ( $item = reset( $items ) ) === false ) {
84
			throw new \RuntimeException( 'No item found' );
85
		}
86
87
		$item->setId( null );
88
		$item->setDomain( 'unittest' );
89
		$resultSaved = $this->object->saveItem( $item );
90
		$itemSaved = $this->object->getItem( $item->getId() );
91
92
		$itemExp = clone $itemSaved;
93
		$itemExp->setDomain( 'unittest2' );
94
		$resultUpd = $this->object->saveItem( $itemExp );
95
		$itemUpd = $this->object->getItem( $itemExp->getId() );
96
97
		$this->object->deleteItem( $itemSaved->getId() );
98
99
100
		$this->assertTrue( $item->getId() !== null );
101
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
102
		$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() );
103
		$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() );
104
		$this->assertEquals( $item->getType(), $itemSaved->getType() );
105
		$this->assertEquals( $item->getRefId(), $itemSaved->getRefId() );
106
		$this->assertEquals( $item->getDomain(), $itemSaved->getDomain() );
107
		$this->assertEquals( $item->getDateStart(), $itemSaved->getDateStart() );
108
		$this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() );
109
		$this->assertEquals( $item->getPosition(), $itemSaved->getPosition() );
110
		$this->assertEquals( $this->editor, $itemSaved->getEditor() );
111
		$this->assertStringStartsWith(date('Y-m-d', time()), $itemSaved->getTimeCreated());
112
		$this->assertStringStartsWith(date('Y-m-d', time()), $itemSaved->getTimeModified());
113
114
		$this->assertEquals( $this->editor, $itemSaved->getEditor() );
115
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
116
		$this->assertRegExp('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
117
118
		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
119
		$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() );
120
		$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() );
121
		$this->assertEquals( $itemExp->getType(), $itemUpd->getType() );
122
		$this->assertEquals( $itemExp->getRefId(), $itemUpd->getRefId() );
123
		$this->assertEquals( $itemExp->getDomain(), $itemUpd->getDomain() );
124
		$this->assertEquals( $itemExp->getDateStart(), $itemUpd->getDateStart() );
125
		$this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() );
126
		$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() );
127
128
		$this->assertEquals( $this->editor, $itemUpd->getEditor() );
129
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
130
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
131
132
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved );
133
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd );
134
135
		$this->setExpectedException('\\Aimeos\\MShop\\Exception');
136
		$this->object->getItem( $itemSaved->getId() );
137
	}
138
139
140
	public function testSearchItems()
141
	{
142
		$total = 0;
143
		$search = $this->object->createSearch();
144
145
		$expr = [];
146
		$expr[] = $search->compare( '!=', 'customer.lists.id', null );
147
		$expr[] = $search->compare( '!=', 'customer.lists.siteid', null );
148
		$expr[] = $search->compare( '>', 'customer.lists.parentid', 0 );
149
		$expr[] = $search->compare( '==', 'customer.lists.domain', 'text' );
150
		$expr[] = $search->compare( '==', 'customer.lists.type', 'default' );
151
		$expr[] = $search->compare( '>', 'customer.lists.refid', 0 );
152
		$expr[] = $search->compare( '==', 'customer.lists.datestart', '2010-01-01 00:00:00' );
153
		$expr[] = $search->compare( '==', 'customer.lists.dateend', '2098-01-01 00:00:00' );
154
		$expr[] = $search->compare( '!=', 'customer.lists.config', null );
155
		$expr[] = $search->compare( '>', 'customer.lists.position', 0 );
156
		$expr[] = $search->compare( '==', 'customer.lists.status', 1 );
157
		$expr[] = $search->compare( '>=', 'customer.lists.mtime', '1970-01-01 00:00:00' );
158
		$expr[] = $search->compare( '>=', 'customer.lists.ctime', '1970-01-01 00:00:00' );
159
		$expr[] = $search->compare( '==', 'customer.lists.editor', $this->editor );
160
161
		$search->setConditions( $search->combine( '&&', $expr ) );
162
		$search->setSlice( 0, 2 );
163
		$results = $this->object->searchItems( $search, [], $total );
164
		$this->assertEquals( 2, count( $results ) );
165
		$this->assertEquals( 3, $total );
166
167
		foreach( $results as $itemId => $item ) {
168
			$this->assertEquals( $itemId, $item->getId() );
169
		}
170
	}
171
172
173
	public function testSearchItemsAll()
174
	{
175
		//search without base criteria
176
		$search = $this->object->createSearch();
177
		$search->setConditions( $search->compare( '==', 'customer.lists.editor', $this->editor ) );
178
		$result = $this->object->searchItems( $search );
179
		$this->assertEquals( 5, count( $result ) );
180
	}
181
182
183
	public function testSearchItemsBase()
184
	{
185
		//search with base criteria
186
		$search = $this->object->createSearch( true );
187
		$conditions = array(
188
			$search->compare( '==', 'customer.lists.editor', $this->editor ),
189
			$search->getConditions()
190
		);
191
		$search->setConditions( $search->combine( '&&', $conditions ) );
192
		$this->assertEquals( 5, count( $this->object->searchItems( $search ) ) );
193
	}
194
195
196
	public function testGetSubManager()
197
	{
198
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager('type') );
199
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager('type', 'Standard') );
200
201
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
202
		$this->object->getSubManager( 'unknown' );
203
	}
204
}
205