1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MW\View; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class ComposeTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $translate; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
$engines = array( |
21
|
|
|
'.php' => new \Aimeos\MW\View\Standard( array( __DIR__ => array( '_testfiles' . DIRECTORY_SEPARATOR . 'php' ) ) ), |
22
|
|
|
'.phtml' => new \Aimeos\MW\View\Standard( array( __DIR__ => array( '_testfiles' . DIRECTORY_SEPARATOR . 'phtml' ) ) ), |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
$this->object = new \Aimeos\MW\View\Compose( $engines ); |
26
|
|
|
$this->translate = new \Aimeos\MW\View\Helper\Translate\Standard( $this->object, new \Aimeos\MW\Translation\None( 'en_GB' ) ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
protected function tearDown() |
31
|
|
|
{ |
32
|
|
|
unset( $this->object, $this->translate ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function testMagicMethods() |
37
|
|
|
{ |
38
|
|
|
$this->assertEquals( false, isset( $this->object->test ) ); |
39
|
|
|
|
40
|
|
|
$this->object->test = 10; |
|
|
|
|
41
|
|
|
$this->assertEquals( 10, $this->object->test ); |
|
|
|
|
42
|
|
|
$this->assertEquals( true, isset( $this->object->test ) ); |
43
|
|
|
|
44
|
|
|
unset( $this->object->test ); |
45
|
|
|
$this->assertEquals( false, isset( $this->object->test ) ); |
46
|
|
|
|
47
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\View\\Exception' ); |
48
|
|
|
$this->object->test; |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
public function testGet() |
53
|
|
|
{ |
54
|
|
|
$this->assertEquals( null, $this->object->get( 'test' ) ); |
55
|
|
|
$this->assertEquals( 1, $this->object->get( 'test', 1 ) ); |
56
|
|
|
|
57
|
|
|
$this->object->test = 10; |
|
|
|
|
58
|
|
|
$this->assertEquals( 10, $this->object->get( 'test' ) ); |
59
|
|
|
|
60
|
|
|
$this->object->test = array( 'key' => 'val' ); |
|
|
|
|
61
|
|
|
$this->assertEquals( 'val', $this->object->get( 'test/key' ) ); |
62
|
|
|
|
63
|
|
|
$this->object->test = new \stdClass(); |
|
|
|
|
64
|
|
|
$this->assertEquals( null, $this->object->get( 'test/key' ) ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testCallCreateHelper() |
69
|
|
|
{ |
70
|
|
|
$enc = $this->object->encoder(); |
71
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\View\\Helper\\Iface', $enc ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function testCallInvalidName() |
76
|
|
|
{ |
77
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\View\\Exception' ); |
78
|
|
|
$this->object->invalid(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testCallUnknown() |
83
|
|
|
{ |
84
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\View\\Exception' ); |
85
|
|
|
$this->object->unknown(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
public function testCallAddHelper() |
90
|
|
|
{ |
91
|
|
|
$this->object->addHelper( 'translate', $this->translate ); |
92
|
|
|
$this->assertEquals( 'File', $this->object->translate( 'test', 'File', 'Files', 1 ) ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
public function testAssignRender() |
97
|
|
|
{ |
98
|
|
|
$this->object->addHelper( 'translate', $this->translate ); |
99
|
|
|
|
100
|
|
|
$ds = DIRECTORY_SEPARATOR; |
101
|
|
|
$phpList = array( 'notexisting', __DIR__ . $ds . '_testfiles' . $ds . 'php' . $ds . 'template.php' ); |
102
|
|
|
$phtmlList = array( 'notexisting', __DIR__ . $ds . '_testfiles' . $ds . 'phtml' . $ds . 'template.phtml' ); |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
$this->object->assign( array( 'quantity' => 1 ) ); |
106
|
|
|
$output = $this->object->render( $phpList ); |
|
|
|
|
107
|
|
|
|
108
|
|
|
$expected = "Number of files:\n1 File"; |
109
|
|
|
$this->assertEquals( $expected, $output ); |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
$this->object->assign( array( 'quantity' => 0 ) ); |
113
|
|
|
$output = $this->object->render( $phtmlList ); |
|
|
|
|
114
|
|
|
|
115
|
|
|
$expected = "Number of directories:\n0 Files"; |
116
|
|
|
$this->assertEquals( $expected, $output ); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
public function testAssignRenderRelativePath() |
121
|
|
|
{ |
122
|
|
|
$this->object->addHelper( 'translate', $this->translate ); |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
$this->object->assign( array( 'quantity' => 1 ) ); |
126
|
|
|
$output = $this->object->render( array( 'notexisting', 'template.php' ) ); |
|
|
|
|
127
|
|
|
|
128
|
|
|
$expected = "Number of files:\n1 File"; |
129
|
|
|
$this->assertEquals( $expected, $output ); |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
$this->object->assign( array( 'quantity' => 0 ) ); |
133
|
|
|
$output = $this->object->render( array( 'notexisting', 'template.phtml' ) ); |
|
|
|
|
134
|
|
|
|
135
|
|
|
$expected = "Number of directories:\n0 Files"; |
136
|
|
|
$this->assertEquals( $expected, $output ); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.