-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.php
More file actions
121 lines (97 loc) · 1.92 KB
/
tests.php
File metadata and controls
121 lines (97 loc) · 1.92 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* JSObject tests
*
* Requires simpletest - Either in PHP path,
* or in the folder with the test file
*/
// --------------------------------------------------------------------------
// Include simpletest
// it has to be set in your php path, or put in the tests folder
require_once('simpletest/autorun.php');
// Include JSObject
require_once('JSObject.php');
class JSObjectTests extends UnitTestCase {
function TestIsA()
{
$obj = new JSObject([
'x' => [0,1,2]
]);
$this->assertIsA($obj, 'ArrayObject');
$this->assertIsA($obj, 'JSObject');
}
function TestClosure()
{
$obj = new JSObject([
'a' => 10,
'b' => 5,
'c' => 0,
'x' => function() {
return $this->a * $this->b;
}
]);
$this->assertEqual($obj->x(), 50);
}
// List of blacklisted array functions
/*
'array_change_key_case',
'array_count_values',
'array_combine',
'array_fill_keys',
'array_fill',
'array_key_exists',
'array_map',
'array_merge',
'array_merge_recursive',
'array_search',
'array_unshift',
*/
function TestArrayFlip()
{
$obj = new JSObject([
'x' => 'foo',
'y' => 'bar'
]);
$this->assertEqual($obj->array_flip(), ['foo' => 'x', 'bar' => 'y']);
}
function TestArrayKeys()
{
$obj = new JSObject([
'x' => 'foo',
'y' => 'bar'
]);
$this->assertEqual($obj->array_keys(), ['x','y']);
}
function TestArrayValues()
{
$obj = new JSObject([
'x' => 'foo',
'y' => 'bar'
]);
$this->assertEqual($obj->array_values(), ['foo','bar']);
}
function TestJSObjectFunc()
{
$obj1 = new JSObject([
'x' => 'foo',
'y' => 'bar'
]);
$obj2 = JSObject([
'x' => 'foo',
'y' => 'bar'
]);
$this->assertEqual($obj1, $obj2);
}
function TestFuncClosure()
{
$obj = JSObject([
'a' => 10,
'b' => 5,
'c' => 0,
'x' => function() {
return $this->a * $this->b;
}
]);
$this->assertEqual($obj->x(), 50);
}
}