Completed
Push — master ( 31758c...fcf74b )
by Aimeos
08:54
created

StandardTest::testResolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
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, 2012
6
 * @copyright Aimeos (aimeos.org), 2015-2017
7
 */
8
9
10
namespace Aimeos\MW\View;
11
12
13
class StandardTest extends \PHPUnit_Framework_TestCase
14
{
15
	private $object;
16
	private $translate;
17
18
19
	protected function setUp()
20
	{
21
		$this->object = new \Aimeos\MW\View\Standard( array( __DIR__ => array( '_testfiles' . DIRECTORY_SEPARATOR . 'php' ) ) );
22
		$this->translate = new \Aimeos\MW\View\Helper\Translate\Standard( $this->object, new \Aimeos\MW\Translation\None( 'en_GB' ) );
23
	}
24
25
26
	protected function tearDown()
27
	{
28
		unset( $this->object, $this->translate );
29
	}
30
31
32
	public function testMagicMethods()
33
	{
34
		$this->assertEquals( false, isset( $this->object->test ) );
35
36
		$this->object->test = 10;
37
		$this->assertEquals( 10, $this->object->test );
38
		$this->assertEquals( true, isset( $this->object->test ) );
39
40
		unset( $this->object->test );
41
		$this->assertEquals( false, isset( $this->object->test ) );
42
43
		$this->setExpectedException( '\\Aimeos\\MW\\View\\Exception' );
44
		$this->object->test;
45
	}
46
47
48
	public function testGet()
49
	{
50
		$this->assertEquals( null, $this->object->get( 'test' ) );
51
		$this->assertEquals( 1, $this->object->get( 'test', 1 ) );
52
53
		$this->object->test = 10;
54
		$this->assertEquals( 10, $this->object->get( 'test' ) );
55
56
		$this->object->test = array( 'key' => 'val' );
57
		$this->assertEquals( 'val', $this->object->get( 'test/key' ) );
58
59
		$this->object->test = new \stdClass();
60
		$this->assertEquals( null, $this->object->get( 'test/key' ) );
61
	}
62
63
64
	public function testCallCreateHelper()
65
	{
66
		$enc = $this->object->encoder();
67
		$this->assertInstanceOf( '\\Aimeos\\MW\\View\\Helper\\Iface', $enc );
68
	}
69
70
71
	public function testCallInvalidName()
72
	{
73
		$this->setExpectedException( '\\Aimeos\\MW\\View\\Exception' );
74
		$this->object->invalid();
75
	}
76
77
78
	public function testCallUnknown()
79
	{
80
		$this->setExpectedException( '\\Aimeos\\MW\\View\\Exception' );
81
		$this->object->unknown();
82
	}
83
84
85
	public function testCallAddHelper()
86
	{
87
		$this->object->addHelper( 'translate', $this->translate );
88
		$this->assertEquals( 'File', $this->object->translate( 'test', 'File', 'Files', 1 ) );
89
	}
90
91
92
	public function testAssignRender()
93
	{
94
		$this->object->addHelper( 'translate', $this->translate );
95
96
		$ds = DIRECTORY_SEPARATOR;
97
		$filenames = array( 'notexisting', __DIR__ . $ds . '_testfiles'. $ds . 'php' . $ds . 'template.php' );
98
99
100
		$this->object->assign( array( 'quantity' => 1 ) );
101
		$output = $this->object->render( $filenames );
102
103
		$expected = "Number of files:\n1 File";
104
		$this->assertEquals( $expected, $output );
105
106
107
		$this->object->assign( array( 'quantity' => 0 ) );
108
		$output = $this->object->render( $filenames );
109
110
		$expected = "Number of files:\n0 Files";
111
		$this->assertEquals( $expected, $output );
112
	}
113
114
115
	public function testAssignRenderRelativePath()
116
	{
117
		$this->object->addHelper( 'translate', $this->translate );
118
119
120
		$this->object->assign( array( 'quantity' => 1 ) );
121
		$output = $this->object->render( array( 'notexisting', 'template.php' ) );
122
123
		$expected = "Number of files:\n1 File";
124
		$this->assertEquals( $expected, $output );
125
126
127
		$this->object->assign( array( 'quantity' => 0 ) );
128
		$output = $this->object->render( array( 'notexisting', 'template.php' ) );
129
130
		$expected = "Number of files:\n0 Files";
131
		$this->assertEquals( $expected, $output );
132
	}
133
}
134