Completed
Push — master ( cc4116...af69dd )
by Aimeos
05:02
created

FlowTest::testTransformConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4286
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2014
6
 */
7
8
9
namespace Aimeos\MW\View\Helper\Url;
10
11
12
/**
13
 * Test class for \Aimeos\MW\View\Helper\Url\Flow.
14
 */
15
class FlowTest extends \PHPUnit_Framework_TestCase
16
{
17
	private $object;
18
	private $mockRouter;
19
20
21
	/**
22
	 * Sets up the fixture, for example, opens a network connection.
23
	 * This method is called before a test is executed.
24
	 *
25
	 * @access protected
26
	 */
27
	protected function setUp()
28
	{
29
		if( !class_exists( '\\TYPO3\\Flow\\Mvc\\Routing\\UriBuilder' ) ) {
30
			$this->markTestSkipped( '\\TYPO3\\Flow\\Mvc\\Routing\\UriBuilder is not available' );
31
		}
32
33
		$view = new \Aimeos\MW\View\Standard();
34
35
		$mockHttpRequest = $this->getMockBuilder( 'TYPO3\Flow\Http\Request' )
36
			->disableOriginalConstructor()
37
			->setMethods( array( 'getBaseUri' ) )
38
			->getMock();
39
		$mockHttpRequest->expects( $this->any() )
40
			->method( 'getBaseUri' )
41
			->will( $this->returnValue( 'http://localhost/' ) );
42
43
		$mockMainRequest = $this->getMock( 'TYPO3\Flow\Mvc\ActionRequest', array( 'getControllerObjectName' ), array( $mockHttpRequest ) );
44
		$mockMainRequest->expects( $this->any() )
45
			->method( 'getArgumentNamespace' )
46
			->will( $this->returnValue( 'ai' ) );
47
48
		$this->mockRouter = $this->getMock( 'TYPO3\Flow\Mvc\Routing\Router' );
49
		$mockEnv = $this->getMock( 'TYPO3\Flow\Utility\Environment', array( 'isRewriteEnabled' ), array(), '', false );
50
51
		$builder = new \TYPO3\Flow\Mvc\Routing\UriBuilder();
52
		$builder->setRequest( $mockMainRequest );
53
54
		$objectReflection = new \ReflectionObject( $builder );
55
56
		$property = $objectReflection->getProperty( 'router' );
57
		$property->setAccessible( true );
58
		$property->setValue( $builder, $this->mockRouter );
59
60
		$property = $objectReflection->getProperty( 'environment' );
61
		$property->setAccessible( true );
62
		$property->setValue( $builder, $mockEnv );
63
64
		$this->object = new \Aimeos\MW\View\Helper\Url\Flow( $view, $builder, array( 'site' => 'unittest' ) );
65
	}
66
67
68
	/**
69
	 * Tears down the fixture, for example, closes a network connection.
70
	 * This method is called after a test is executed.
71
	 *
72
	 * @access protected
73
	 */
74
	protected function tearDown()
75
	{
76
		$this->object = null;
77
	}
78
79
80
	public function testTransform()
81
	{
82
		$this->mockRouter->expects( $this->once() )->method( 'resolve' )
83
			->will( $this->returnValue( 'shop/catalog/lists') );
84
85
		$this->assertEquals( '/index.php/shop/catalog/lists', $this->object->transform( 'shop', 'catalog', 'lists' ) );
86
	}
87
88
89 View Code Duplication
	public function testTransformSlashes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
	{
91
		$this->mockRouter->expects( $this->once() )->method( 'resolve' )
92
			->will( $this->returnValue( 'shop/catalog/lists?test=a%2Fb') );
93
94
		$this->assertEquals( '/index.php/shop/catalog/lists?test=a%2Fb', $this->object->transform( 'shop', 'catalog', 'lists', array( 'test' => 'a/b' ) ) );
95
	}
96
97
98 View Code Duplication
	public function testTransformArrays()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
	{
100
		$this->mockRouter->expects( $this->once() )->method( 'resolve' )
101
			->will( $this->returnValue( 'shop/catalog/list?test%5B0%5D=a&test%5B1%5D=b') );
102
103
		$this->assertEquals( '/index.php/shop/catalog/list?test%5B0%5D=a&test%5B1%5D=b', $this->object->transform( 'shop', 'catalog', 'lists', array( 'test' => array( 'a', 'b' ) ) ) );
104
	}
105
106
107 View Code Duplication
	public function testTransformTrailing()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
	{
109
		$this->mockRouter->expects( $this->once() )->method( 'resolve' )
110
			->will( $this->returnValue( 'shop/catalog/lists') );
111
112
		$this->assertEquals( '/index.php/shop/catalog/lists#a/b', $this->object->transform( 'shop', 'catalog', 'lists', array(), array( 'a', 'b' ) ) );
113
	}
114
115
116
	public function testTransformAbsolute()
117
	{
118
		$this->mockRouter->expects( $this->once() )->method( 'resolve' )
119
			->will( $this->returnValue( 'shop/catalog/lists') );
120
121
		$options = array( 'absoluteUri' => true );
122
		$result = $this->object->transform( 'shop', 'catalog', 'lists', array(), array(), $options );
123
124
		$this->assertEquals( 'http://localhost/index.php/shop/catalog/lists', $result );
125
	}
126
127
128
	public function testTransformConfig()
129
	{
130
		$this->mockRouter->expects( $this->once() )->method( 'resolve' )
131
			->will( $this->returnValue( 'shop/catalog/lists') );
132
133
		$options = array( 'package' => 'test', 'subpackage' => 'subtest', 'format' => 'fmt' );
134
		$result = $this->object->transform( 'shop', 'catalog', 'lists', array(), array(), $options );
135
136
		$this->assertEquals( '/index.php/shop/catalog/lists', $result );
137
	}
138
}
139