Passed
Push — master ( fa79ba...4fcbee )
by Aimeos
08:39 queued 05:58
created

Typo3Test::testTransform()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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