Completed
Push — master ( 921503...9109fd )
by Aimeos
02:03
created

BaseTest::testGetPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
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-2018
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()
20
	{
21
		$this->context = \TestHelperFrontend::getContext();
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()
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->setExpectedException( \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
		$expected = \Aimeos\Controller\Frontend\Catalog\Iface::class;
71
72
		$this->stub->expects( $this->once() )->method( 'compare' )
73
			->will( $this->returnValue( $this->stub ) );
74
75
		$this->assertInstanceOf( $expected, $this->object->compare( '==', 'catalog.code', 'test' ) );
76
	}
77
78
79
	public function testGet()
80
	{
81
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->createItem();
82
		$expected = \Aimeos\MShop\Catalog\Item\Iface::class;
83
84
		$this->stub->expects( $this->once() )->method( 'get' )
85
			->will( $this->returnValue( $item ) );
86
87
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
88
	}
89
90
91
	public function testFind()
92
	{
93
		$item = \Aimeos\MShop::create( $this->context, 'catalog' )->createItem();
94
		$expected = \Aimeos\MShop\Catalog\Item\Iface::class;
95
96
		$this->stub->expects( $this->once() )->method( 'find' )
97
			->will( $this->returnValue( $item ) );
98
99
		$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'] ) );
100
	}
101
102
103
	public function testParse()
104
	{
105
		$expected = \Aimeos\Controller\Frontend\Catalog\Iface::class;
106
107
		$this->stub->expects( $this->once() )->method( 'parse' )
108
			->will( $this->returnValue( $this->stub ) );
109
110
		$this->assertInstanceOf( $expected, $this->object->parse( [] ) );
111
	}
112
113
114
	public function testGetPath()
115
	{
116
		$this->stub->expects( $this->once() )->method( 'getPath' )
117
			->will( $this->returnValue( [] ) );
118
119
		$this->assertEquals( [], $this->object->getPath( -1 ) );
120
	}
121
122
123
	public function testGetTree()
124
	{
125
		$catItem = \Aimeos\MShop::create( $this->context, 'catalog' )->createItem();
126
127
		$this->stub->expects( $this->once() )->method( 'getTree' )
128
			->will( $this->returnValue( $catItem ) );
129
130
		$this->assertInstanceOf( \Aimeos\MShop\Catalog\Item\Iface::class, $this->object->getTree() );
131
	}
132
133
134
	public function testRoot()
135
	{
136
		$expected = \Aimeos\Controller\Frontend\Catalog\Iface::class;
137
138
		$this->stub->expects( $this->once() )->method( 'root' )
139
			->will( $this->returnValue( $this->stub ) );
140
141
		$this->assertInstanceOf( $expected, $this->object->root( -1 ) );
142
	}
143
144
145
	public function testVisible()
146
	{
147
		$expected = \Aimeos\Controller\Frontend\Catalog\Iface::class;
148
149
		$this->stub->expects( $this->once() )->method( 'visible' )
150
			->will( $this->returnValue( $this->stub ) );
151
152
		$this->assertInstanceOf( $expected, $this->object->visible( [1, 2] ) );
153
	}
154
155
156
	public function testGetController()
157
	{
158
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
159
160
		$this->assertSame( $this->stub, $result );
161
	}
162
163
164
	protected function access( $name )
165
	{
166
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Catalog\Decorator\Base::class );
167
		$method = $class->getMethod( $name );
168
		$method->setAccessible( true );
169
170
		return $method;
171
	}
172
}
173