Passed
Push — master ( bfe54d...3b86c0 )
by Aimeos
06:31 queued 01:17
created

StandardTest::testTransformVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 15
rs 9.9666
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2014
6
 * @copyright Aimeos (aimeos.org), 2015-2022
7
 */
8
9
10
namespace Aimeos\MW\View\Helper\Content;
11
12
13
class StandardTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $object;
16
17
18
	protected function setUp() : void
19
	{
20
		$view = new \Aimeos\MW\View\Standard();
21
22
		$helper = new \Aimeos\MW\View\Helper\Encoder\Standard( $view );
23
		$view->addHelper( 'encoder', $helper );
24
25
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, \TestHelperMw::getConfig() );
26
		$view->addHelper( 'config', $helper );
27
28
		$this->object = new \Aimeos\MW\View\Helper\Content\Standard( $view );
29
	}
30
31
32
	protected function tearDown() : void
33
	{
34
		unset( $this->object );
35
	}
36
37
38
	public function testTransform()
39
	{
40
		$this->assertEquals( '', $this->object->transform( null ) );
41
	}
42
43
44
	public function testTransformRelativeUrl()
45
	{
46
		$view = new \Aimeos\MW\View\Standard();
47
48
		$helper = new \Aimeos\MW\View\Helper\Encoder\Standard( $view );
49
		$view->addHelper( 'encoder', $helper );
50
51
		$config = new \Aimeos\MW\Config\PHPArray( ['resource' => ['fs-test' => ['baseurl' => 'base/url']]] );
52
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
53
		$view->addHelper( 'config', $helper );
54
55
		$object = new \Aimeos\MW\View\Helper\Content\Standard( $view );
56
57
		$output = $object->transform( 'path/to/resource', 'fs-test' );
58
		$this->assertEquals( 'base/url/path/to/resource', $output );
59
	}
60
61
62
	public function testTransformVersion()
63
	{
64
		$view = new \Aimeos\MW\View\Standard();
65
66
		$helper = new \Aimeos\MW\View\Helper\Encoder\Standard( $view );
67
		$view->addHelper( 'encoder', $helper );
68
69
		$config = new \Aimeos\MW\Config\PHPArray( ['resource' => ['fs-test' => ['baseurl' => 'base/url']]] );
70
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
71
		$view->addHelper( 'config', $helper );
72
73
		$object = new \Aimeos\MW\View\Helper\Content\Standard( $view );
74
75
		$output = $object->transform( 'path/to/resource', 'fs-test', true );
76
		$this->assertEquals( 'base/url/path/to/resource?v=1', $output );
77
	}
78
79
80
	public function testTransformAbsoluteUrl()
81
	{
82
		$output = $this->object->transform( '/path/to/resource' );
83
		$this->assertEquals( '/path/to/resource', $output );
84
	}
85
86
87
	public function testTransformDataUrl()
88
	{
89
		$output = $this->object->transform( 'data:image/gif;base64,R0lGODdhAQABAIAAAAAAAAAAACwAAAAAAQABAAACAkQBADs=' );
90
		$this->assertEquals( 'data:image/gif;base64,R0lGODdhAQABAIAAAAAAAAAAACwAAAAAAQABAAACAkQBADs=', $output );
91
	}
92
93
94
	public function testTransformHttpUrl()
95
	{
96
		$output = $this->object->transform( 'https://host:443/path/to/resource' );
97
		$this->assertEquals( 'https://host:443/path/to/resource', $output );
98
	}
99
}
100