StandardTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 34
c 1
b 0
f 0
dl 0
loc 85
rs 10

8 Methods

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