StandardTest::testGetSubManagerInvalidName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021-2022
6
 */
7
8
namespace Aimeos\MShop\Cms\Manager;
9
10
11
class StandardTest 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...
12
{
13
	private $context;
14
	private $object;
15
16
17
	protected function setUp() : void
18
	{
19
		$this->context = \TestHelper::context();
20
		$this->object = new \Aimeos\MShop\Cms\Manager\Standard( $this->context );
21
	}
22
23
24
	protected function tearDown() : void
25
	{
26
		unset( $this->object, $this->context );
27
	}
28
29
30
	public function testClear()
31
	{
32
		$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( [-1] ) );
33
	}
34
35
36
	public function testDeleteItems()
37
	{
38
		$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->delete( [-1] ) );
39
	}
40
41
42
	public function testCreateItem()
43
	{
44
		$cmsItem = $this->object->create();
45
		$this->assertInstanceOf( \Aimeos\MShop\Cms\Item\Iface::class, $cmsItem );
46
	}
47
48
49
	public function testCreateItemType()
50
	{
51
		$item = $this->object->create( ['cms.url' => '/test'] );
52
		$this->assertEquals( '/test', $item->getUrl() );
53
	}
54
55
56
	public function testGetResourceType()
57
	{
58
		$result = $this->object->getResourceType();
59
60
		$this->assertContains( 'cms', $result );
61
		$this->assertContains( 'cms/lists', $result );
62
	}
63
64
65
	public function testGetSearchAttributes()
66
	{
67
		foreach( $this->object->getSearchAttributes() as $attribute ) {
68
			$this->assertInstanceOf( \Aimeos\Base\Criteria\Attribute\Iface::class, $attribute );
69
		}
70
	}
71
72
73
	public function testSearchItems()
74
	{
75
		$item = $this->object->find( '/contact', ['text'] );
76
		$listItem = $item->getListItems( 'text', 'default' )->first( new \RuntimeException( 'No list item found' ) );
77
78
		$total = 0;
79
		$search = $this->object->filter();
80
81
		$expr = [];
82
		$expr[] = $search->compare( '!=', 'cms.id', null );
83
		$expr[] = $search->compare( '!=', 'cms.siteid', null );
84
		$expr[] = $search->compare( '==', 'cms.url', '/contact' );
85
		$expr[] = $search->compare( '==', 'cms.label', 'Contact' );
86
		$expr[] = $search->compare( '==', 'cms.status', 1 );
87
		$expr[] = $search->compare( '>=', 'cms.mtime', '1970-01-01 00:00:00' );
88
		$expr[] = $search->compare( '>=', 'cms.ctime', '1970-01-01 00:00:00' );
89
		$expr[] = $search->compare( '!=', 'cms.editor', '' );
90
91
		$param = ['text', 'default', $listItem->getRefId()];
92
		$expr[] = $search->compare( '!=', $search->make( 'cms:has', $param ), null );
93
94
		$param = ['text', 'default'];
95
		$expr[] = $search->compare( '!=', $search->make( 'cms:has', $param ), null );
96
97
		$param = ['text'];
98
		$expr[] = $search->compare( '!=', $search->make( 'cms:has', $param ), null );
99
100
		$search->setConditions( $search->and( $expr ) );
101
		$result = $this->object->search( $search, [], $total )->toArray();
102
		$this->assertEquals( 1, count( $result ) );
103
		$this->assertEquals( 1, $total );
104
	}
105
106
107
	public function testSearchItemsAll()
108
	{
109
		$search = $this->object->filter();
110
		$this->assertEquals( 3, count( $this->object->search( $search )->toArray() ) );
111
	}
112
113
114
	public function testSearchItemsBase()
115
	{
116
		$total = 0;
117
		$search = $this->object->filter( true )->slice( 0, 1 );
118
		$results = $this->object->search( $search, [], $total )->toArray();
119
120
		$this->assertEquals( 1, count( $results ) );
121
		$this->assertEquals( 3, $total );
122
123
		foreach( $results as $itemId => $item ) {
124
			$this->assertEquals( $itemId, $item->getId() );
125
		}
126
	}
127
128
129
	public function testGetItem()
130
	{
131
		$item = $this->object->find( '/contact' );
132
133
		$actual = $this->object->get( $item->getId() );
134
		$this->assertEquals( $item, $actual );
135
	}
136
137
138
	public function testSaveUpdateDeleteItem()
139
	{
140
		$item = $this->object->find( '/contact' );
141
142
		$item->setId( null );
143
		$item->setUrl( '/contact-test' );
144
		$item->setLabel( 'Contact test' );
145
		$resultSaved = $this->object->save( $item );
146
		$itemSaved = $this->object->get( $item->getId() );
147
148
		$itemExp = clone $itemSaved;
149
		$itemExp->setLabel( 'Contact test 2' );
150
		$resultUpd = $this->object->save( $itemExp );
151
		$itemUpd = $this->object->get( $itemExp->getId() );
152
153
		$this->object->delete( $itemSaved->getId() );
154
155
156
		$this->assertTrue( $item->getId() !== null );
157
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
158
		$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() );
159
		$this->assertEquals( $item->getUrl(), $itemSaved->getUrl() );
160
		$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() );
161
		$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() );
162
163
		$this->assertEquals( $this->context->editor(), $itemSaved->editor() );
164
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
165
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
166
167
		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
168
		$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() );
169
		$this->assertEquals( $itemExp->getUrl(), $itemUpd->getUrl() );
170
		$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() );
171
		$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() );
172
173
		$this->assertEquals( $this->context->editor(), $itemUpd->editor() );
174
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
175
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
176
177
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved );
178
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd );
179
180
		$this->expectException( \Aimeos\MShop\Exception::class );
181
		$this->object->get( $itemSaved->getId() );
182
	}
183
184
185
	public function testGetSubManager()
186
	{
187
		$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'lists' ) );
188
		$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'lists', 'Standard' ) );
189
190
		$this->expectException( \Aimeos\MShop\Exception::class );
191
		$this->object->getSubManager( 'unknown' );
192
	}
193
194
195
	public function testGetSubManagerInvalidName()
196
	{
197
		$this->expectException( \Aimeos\MShop\Exception::class );
198
		$this->object->getSubManager( 'lists', 'unknown' );
199
	}
200
}
201