Passed
Push — master ( d6e4b0...5d8aa0 )
by Aimeos
22:21 queued 08:52
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-2023
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 = \TestHelper::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 testCall()
40
	{
41
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Catalog\Standard::class )
42
			->disableOriginalConstructor()
43
			->onlyMethods( ['__call'] )
44
			->getMock();
45
46
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Catalog\Decorator\Base::class )
47
			->setConstructorArgs( [$stub, $this->context] )
48
			->getMockForAbstractClass();
49
50
		$stub->expects( $this->once() )->method( '__call' )->will( $this->returnValue( true ) );
51
52
		$this->assertTrue( $object->invalid() );
53
	}
54
55
56
	public function testCompare()
57
	{
58
		$this->assertSame( $this->object, $this->object->compare( '==', 'catalog.code', 'test' ) );
59
	}
60
61
62
	public function testFind()
63
	{
64
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
65
		$expected = \Aimeos\MShop\Catalog\Item\Iface::class;
66
67
		$this->stub->expects( $this->once() )->method( 'find' )
68
			->will( $this->returnValue( $item ) );
69
70
		$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'] ) );
71
	}
72
73
74
	public function testFunction()
75
	{
76
		$this->stub->expects( $this->once() )->method( 'function' )
77
			->will( $this->returnValue( 'catalog:has("domain","type","refid")' ) );
78
79
		$str = $this->object->function( 'catalog:has', ['domain', 'type', 'refid'] );
80
		$this->assertEquals( 'catalog:has("domain","type","refid")', $str );
81
	}
82
83
84
	public function testGet()
85
	{
86
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
87
		$expected = \Aimeos\MShop\Catalog\Item\Iface::class;
88
89
		$this->stub->expects( $this->once() )->method( 'get' )
90
			->will( $this->returnValue( $item ) );
91
92
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
93
	}
94
95
96
	public function testHas()
97
	{
98
		$this->assertSame( $this->object, $this->object->has( 'media', 'default', -1 ) );
99
	}
100
101
102
	public function testParse()
103
	{
104
		$this->assertSame( $this->object, $this->object->parse( [] ) );
105
	}
106
107
108
	public function testGetPath()
109
	{
110
		$this->stub->expects( $this->once() )->method( 'getPath' )
111
			->will( $this->returnValue( [] ) );
112
113
		$this->assertEquals( [], $this->object->getPath( -1 ) );
114
	}
115
116
117
	public function testGetTree()
118
	{
119
		$catItem = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
120
121
		$this->stub->expects( $this->once() )->method( 'getTree' )
122
			->will( $this->returnValue( $catItem ) );
123
124
		$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $this->object->getTree() );
125
	}
126
127
128
	public function testResolve()
129
	{
130
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
131
132
		$this->stub->expects( $this->once() )->method( 'resolve' )
133
			->will( $this->returnValue( $item ) );
134
135
		$this->assertEquals( $item, $this->object->resolve( 'test' ) );
136
	}
137
138
139
	public function testRoot()
140
	{
141
		$this->assertSame( $this->object, $this->object->root( -1 ) );
142
	}
143
144
145
	public function testSearch()
146
	{
147
		$total = 0;
148
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
149
150
		$this->stub->expects( $this->once() )->method( 'search' )
151
			->will( $this->returnValue( map( [$item] ) ) );
152
153
		$this->assertEquals( [$item], $this->object->search( $total )->toArray() );
154
	}
155
156
157
	public function testSlice()
158
	{
159
		$this->assertSame( $this->object, $this->object->slice( 0, 1 ) );
160
	}
161
162
163
	public function testSort()
164
	{
165
		$this->assertSame( $this->object, $this->object->sort( 'catalog.label' ) );
166
	}
167
168
169
	public function testVisible()
170
	{
171
		$this->assertSame( $this->object, $this->object->visible( [1, 2] ) );
172
	}
173
174
175
	public function testGetController()
176
	{
177
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
178
179
		$this->assertSame( $this->stub, $result );
180
	}
181
182
183
	protected function access( $name )
184
	{
185
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Catalog\Decorator\Base::class );
186
		$method = $class->getMethod( $name );
187
		$method->setAccessible( true );
188
189
		return $method;
190
	}
191
}
192