Passed
Push — master ( 91b6db...c8efcd )
by Aimeos
27:02 queued 24:35
created

BaseTest::testVisible()   A

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 Aimeos (aimeos.org), 2017-2021
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Catalog\Decorator;
10
11
12
class BaseTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
	private $stub;
17
18
19
	protected function setUp() : void
20
	{
21
		$this->context = \TestHelperFrontend::context();
22
23
		$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Catalog\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Catalog\Decorator\Base::class )
28
			->setConstructorArgs( [$this->stub, $this->context] )
29
			->getMockForAbstractClass();
30
	}
31
32
33
	protected function tearDown() : void
34
	{
35
		unset( $this->context, $this->object, $this->stub );
36
	}
37
38
39
	public function testConstructException()
40
	{
41
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Iface::class )->getMock();
42
43
		$this->expectException( \Aimeos\MW\Common\Exception::class );
44
45
		$this->getMockBuilder( \Aimeos\Controller\Frontend\Catalog\Decorator\Base::class )
46
			->setConstructorArgs( [$stub, $this->context] )
47
			->getMockForAbstractClass();
48
	}
49
50
51
	public function testCall()
52
	{
53
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Catalog\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Catalog\Decorator\Base::class )
59
			->setConstructorArgs( [$stub, $this->context] )
60
			->getMockForAbstractClass();
61
62
		$stub->expects( $this->once() )->method( 'invalid' )->will( $this->returnValue( true ) );
63
64
		$this->assertTrue( $object->invalid() );
65
	}
66
67
68
	public function testCompare()
69
	{
70
		$this->assertSame( $this->object, $this->object->compare( '==', 'catalog.code', 'test' ) );
71
	}
72
73
74
	public function testFind()
75
	{
76
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
77
		$expected = \Aimeos\MShop\Catalog\Item\Iface::class;
78
79
		$this->stub->expects( $this->once() )->method( 'find' )
80
			->will( $this->returnValue( $item ) );
81
82
		$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'] ) );
83
	}
84
85
86
	public function testFunction()
87
	{
88
		$this->stub->expects( $this->once() )->method( 'function' )
89
			->will( $this->returnValue( 'catalog:has("domain","type","refid")' ) );
90
91
		$str = $this->object->function( 'catalog:has', ['domain', 'type', 'refid'] );
92
		$this->assertEquals( 'catalog:has("domain","type","refid")', $str );
93
	}
94
95
96
	public function testGet()
97
	{
98
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
99
		$expected = \Aimeos\MShop\Catalog\Item\Iface::class;
100
101
		$this->stub->expects( $this->once() )->method( 'get' )
102
			->will( $this->returnValue( $item ) );
103
104
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
105
	}
106
107
108
	public function testHas()
109
	{
110
		$this->assertSame( $this->object, $this->object->has( 'media', 'default', -1 ) );
111
	}
112
113
114
	public function testParse()
115
	{
116
		$this->assertSame( $this->object, $this->object->parse( [] ) );
117
	}
118
119
120
	public function testGetPath()
121
	{
122
		$this->stub->expects( $this->once() )->method( 'getPath' )
123
			->will( $this->returnValue( [] ) );
124
125
		$this->assertEquals( [], $this->object->getPath( -1 ) );
126
	}
127
128
129
	public function testGetTree()
130
	{
131
		$catItem = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
132
133
		$this->stub->expects( $this->once() )->method( 'getTree' )
134
			->will( $this->returnValue( $catItem ) );
135
136
		$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $this->object->getTree() );
137
	}
138
139
140
	public function testRoot()
141
	{
142
		$this->assertSame( $this->object, $this->object->root( -1 ) );
143
	}
144
145
146
	public function testSearch()
147
	{
148
		$total = 0;
149
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
150
151
		$this->stub->expects( $this->once() )->method( 'search' )
152
			->will( $this->returnValue( map( [$item] ) ) );
153
154
		$this->assertEquals( [$item], $this->object->search( $total )->toArray() );
155
	}
156
157
158
	public function testSlice()
159
	{
160
		$this->assertSame( $this->object, $this->object->slice( 0, 1 ) );
161
	}
162
163
164
	public function testSort()
165
	{
166
		$this->assertSame( $this->object, $this->object->sort( 'catalog.label' ) );
167
	}
168
169
170
	public function testVisible()
171
	{
172
		$this->assertSame( $this->object, $this->object->visible( [1, 2] ) );
173
	}
174
175
176
	public function testGetController()
177
	{
178
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
179
180
		$this->assertSame( $this->stub, $result );
181
	}
182
183
184
	protected function access( $name )
185
	{
186
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Catalog\Decorator\Base::class );
187
		$method = $class->getMethod( $name );
188
		$method->setAccessible( true );
189
190
		return $method;
191
	}
192
}
193