Passed
Push — master ( 01022c...6528d3 )
by Aimeos
06:28 queued 03:51
created

Typo3Test   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 180
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 13
eloc 80
c 5
b 0
f 0
dl 0
loc 180
rs 10

13 Methods

Rating   Name   Duplication   Size   Complexity  
A testTransformNocache() 0 12 1
A testTransform() 0 11 1
A testTransformAbsolute() 0 12 1
A tearDown() 0 3 1
A setUp() 0 3 1
A testTransformType() 0 12 1
A testTransformNoNamespace() 0 13 1
A testTransformParams() 0 11 1
A testTransformEID() 0 14 1
A testTransformFormat() 0 12 1
A testTransformUnchangedOriginalUriBuilder() 0 11 1
A testTransformBackend() 0 11 1
A testTransformLocale() 0 14 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2014-2021
7
 */
8
9
10
namespace Aimeos\MW\View\Helper\Url;
11
12
13
require_once __DIR__ . DIRECTORY_SEPARATOR . 'UriBuilder';
14
15
16
class Typo3Test extends \PHPUnit\Framework\TestCase
17
{
18
	private $view;
19
20
21
	protected function setUp() : void
22
	{
23
		$this->view = new \Aimeos\MW\View\Standard();
24
	}
25
26
27
	protected function tearDown() : void
28
	{
29
		unset( $this->view );
30
	}
31
32
33
	public function testTransform()
34
	{
35
		$mock = $this->getMockBuilder( 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder' )
36
			->setMethods( array( 'buildFrontendUri' ) )->getMock();
37
38
		$mock->expects( $this->once() )->method( 'buildFrontendUri' );
39
40
		$fixed = array( 'site' => 'unittest' );
41
		$object = new \Aimeos\MW\View\Helper\Url\Typo3( $this->view, $mock, $fixed );
42
43
		$this->assertEquals( '', $object->transform() );
44
	}
45
46
47
	public function testTransformAbsolute()
48
	{
49
		$mock = $this->getMockBuilder( 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder' )
50
			->setMethods( array( 'setCreateAbsoluteUri' ) )->getMock();
51
52
		$mock->expects( $this->once() )->method( 'setCreateAbsoluteUri' )
53
			->with( $this->equalTo( true ) )->will( $this->returnValue( $mock ) );
54
55
		$object = new \Aimeos\MW\View\Helper\Url\Typo3( $this->view, $mock, [] );
56
57
		$config = array( 'absoluteUri' => 1 );
58
		$this->assertEquals( '', $object->transform( null, null, null, [], [], $config ) );
59
	}
60
61
62
	public function testTransformNocache()
63
	{
64
		$mock = $this->getMockBuilder( 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder' )
65
			->setMethods( array( 'setNoCache' ) )->getMock();
66
67
		$mock->expects( $this->once() )->method( 'setNoCache' )
68
			->with( $this->equalTo( true ) )->will( $this->returnValue( $mock ) );
69
70
		$object = new \Aimeos\MW\View\Helper\Url\Typo3( $this->view, $mock, [] );
71
72
		$config = array( 'nocache' => 1 );
73
		$this->assertEquals( '', $object->transform( null, null, null, [], [], $config ) );
74
	}
75
76
77
	public function testTransformType()
78
	{
79
		$mock = $this->getMockBuilder( 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder' )
80
			->setMethods( array( 'setTargetPageType' ) )->getMock();
81
82
		$mock->expects( $this->once() )->method( 'setTargetPageType' )
83
			->with( $this->equalTo( 123 ) )->will( $this->returnValue( $mock ) );
84
85
		$object = new \Aimeos\MW\View\Helper\Url\Typo3( $this->view, $mock, [] );
86
87
		$config = array( 'type' => 123 );
88
		$this->assertEquals( '', $object->transform( null, null, null, [], [], $config ) );
89
	}
90
91
92
	public function testTransformFormat()
93
	{
94
		$mock = $this->getMockBuilder( 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder' )
95
			->setMethods( array( 'setFormat' ) )->getMock();
96
97
		$mock->expects( $this->once() )->method( 'setFormat' )
98
			->with( $this->equalTo( 'xml' ) )->will( $this->returnValue( $mock ) );
99
100
		$object = new \Aimeos\MW\View\Helper\Url\Typo3( $this->view, $mock, [] );
101
102
		$config = array( 'format' => 'xml' );
103
		$this->assertEquals( '', $object->transform( null, null, null, [], [], $config ) );
104
	}
105
106
107
	public function testTransformEID()
108
	{
109
		$mock = $this->getMockBuilder( 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder' )
110
			->setMethods( array( 'setArguments' ) )->getMock();
111
112
		$param = array( 'eID' => 123, 'ai' => array( 'controller' => '', 'action' => null ) );
113
114
		$mock->expects( $this->once() )->method( 'setArguments' )
115
			->with( $this->equalTo( $param ) )->will( $this->returnValue( $mock ) );
116
117
		$object = new \Aimeos\MW\View\Helper\Url\Typo3( $this->view, $mock, [] );
118
119
		$config = array( 'eID' => 123 );
120
		$this->assertEquals( '', $object->transform( null, null, null, [], [], $config ) );
121
	}
122
123
124
	public function testTransformLocale()
125
	{
126
		$mock = $this->getMockBuilder( 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder' )
127
			->setMethods( array( 'setArguments' ) )->getMock();
128
129
		$param = array( 'L' => 'de', 'ai' => ['controller' => '', 'action' => null, 'locale' => 'de'] );
130
131
		$mock->expects( $this->once() )->method( 'setArguments' )
132
			->with( $this->equalTo( $param ) )->will( $this->returnValue( $mock ) );
133
134
		$object = new \Aimeos\MW\View\Helper\Url\Typo3( $this->view, $mock, [] );
135
136
		$params = array( 'locale' => 'de' );
137
		$this->assertEquals( '', $object->transform( null, null, null, $params ) );
138
	}
139
140
141
	public function testTransformBackend()
142
	{
143
		$mock = $this->getMockBuilder( 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder' )
144
		->setMethods( array( 'buildBackendUri' ) )->getMock();
145
146
		$mock->expects( $this->once() )->method( 'buildBackendUri' );
147
148
		$object = new \Aimeos\MW\View\Helper\Url\Typo3( $this->view, $mock, array( 'site' => 'unittest' ) );
149
150
		$params = array( 'test' => 'my/value' );
151
		$this->assertEquals( '', $object->transform( null, null, null, $params, [], array( 'BE' => 1 ) ) );
152
	}
153
154
155
	public function testTransformParams()
156
	{
157
		$mock = $this->getMockBuilder( 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder' )
158
			->setMethods( array( 'buildFrontendUri' ) )->getMock();
159
160
		$mock->expects( $this->once() )->method( 'buildFrontendUri' );
161
162
		$object = new \Aimeos\MW\View\Helper\Url\Typo3( $this->view, $mock, array( 'site' => 'unittest' ) );
163
164
		$params = array( 'test' => 'my/value' );
165
		$this->assertEquals( '', $object->transform( null, null, null, $params ) );
166
	}
167
168
169
	public function testTransformNoNamespace()
170
	{
171
		$mock = $this->getMockBuilder( 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder' )
172
			->setMethods( array( 'buildFrontendUri', 'getArgumentPrefix' ) )->getMock();
173
174
		$mock->expects( $this->once() )->method( 'buildFrontendUri' );
175
		$mock->expects( $this->once() )->method( 'getArgumentPrefix' )->will( $this->returnValue( 'ai' ) );
176
177
		$object = new \Aimeos\MW\View\Helper\Url\Typo3( $this->view, $mock, array( 'site' => 'unittest' ) );
178
179
		$params = array( 'test' => 'my/value' );
180
		$config = array( 'namespace' => false );
181
		$this->assertEquals( '', $object->transform( null, null, null, $params, [], $config ) );
182
	}
183
184
185
	public function testTransformUnchangedOriginalUriBuilder()
186
	{
187
		$mock = $this->getMockBuilder( 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder' )
188
			->setMethods( array( 'reset' ) )->getMock();
189
190
		$mock->expects( $this->once() )->method( 'reset' )->will( $this->returnValue( $mock ) );
191
192
		$object = new \Aimeos\MW\View\Helper\Url\Typo3( $this->view, $mock, [] );
193
194
		$mock->expects( $this->never() )->method( 'reset' );
195
		$this->assertEquals( '', $object->transform( null, null, null, [], [], [] ) );
196
	}
197
}
198