-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathUtilTest.php
69 lines (59 loc) · 3.32 KB
/
UtilTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Sitepod;
class UtilTest extends \PHPUnit_Framework_TestCase
{
function testStringToVariableName()
{
$this->assertEquals('', Util::stringToVariableName(''));
$this->assertEquals('something', Util::stringToVariableName('something'));
$this->assertEquals('something with \"', Util::stringToVariableName('something with "'));
$this->assertEquals("something with \'", Util::stringToVariableName("something with '"));
$this->assertEquals('something with \"\"', Util::stringToVariableName('something with ""'));
$this->assertEquals("something with \'\'", Util::stringToVariableName("something with ''"));
}
function testVariableNameToString()
{
$this->assertEquals('', Util::variableNameToString(''));
$this->assertEquals('something', Util::variableNameToString('something'));
/**
* @FIXME: I guess there are some unexpected behaviours here. Could you explain what is the expected behaviour?
* @FIXME: The name of method (variableNameToString()) suggests it is the reverse of the stringToVariableName() method, but it is not.
*/
$this->assertEquals('something with \"', Util::variableNameToString('something with \"'));
$this->assertEquals("something with \\", Util::variableNameToString("something with \'"));
$this->assertEquals('something with \"\"', Util::variableNameToString('something with \"\"'));
$this->assertEquals("something with \'\\", Util::variableNameToString("something with \'\'"));
}
function testToArray()
{
$this->assertCount(1, Util::toArray('', ':'));
$this->assertCount(2, Util::toArray('foo:bar', ':'));
}
function testToArrayShouldTrimElements()
{
$fooBar = Util::toArray('foo : bar', ':');
$this->assertCount(2, $fooBar);
$this->assertEquals('foo', $fooBar[0]);
$this->assertEquals('bar', $fooBar[1]);
}
function testArrToStringReadable()
{
$this->assertEquals('', Util::arrToStringReadable([], ','));
$this->assertEquals('foo: bar', Util::arrToStringReadable(['foo' => 'bar'], ','));
/** @FIXME: These should be more readable */
/** @FIXME: Need a space after the delimiter */
$this->assertEquals('foo: bar,foo2: baz', Util::arrToStringReadable(['foo' => 'bar', 'foo2' => 'baz'], ','));
$this->assertEquals('foo: bar: baz', Util::arrToStringReadable(['foo' => ['bar' => 'baz']], ','));
/** @FIXME: In the second one I can't understand that 'foo2: bar' inside 'foo' */
$this->assertEquals('foo: bar: baz,foo2: bar2', Util::arrToStringReadable(['foo' => ['bar' => 'baz'], 'foo2' => 'bar2'], ','));
$this->assertEquals('foo: bar: baz,foo2: bar2,foo3: bar3', Util::arrToStringReadable(['foo' => ['bar' => 'baz', 'foo2' => 'bar2'], 'foo3' => 'bar3'], ','));
/** @FIXME: I suppose print_r() or var_dump() kind of thing would be better. Or simple use the short array format inside the string. */
}
function testArrToString()
{
$this->assertEquals('', Util::arrToString([], ','));
$this->assertEquals('foo', Util::arrToString(['foo'], ','));
$this->assertEquals('foo,bar', Util::arrToString(['foo','bar'], ','));
/** @FIXME: Doesn't work with associative array or multi dimension array */
}
}