-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPsa_Router_Test.php
More file actions
152 lines (101 loc) · 3.8 KB
/
Copy pathPsa_Router_Test.php
File metadata and controls
152 lines (101 loc) · 3.8 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
include_once 'psa_init.php';
class Psa_Router_Test extends PHPUnit_Framework_TestCase{
public function testExplodeUrl(){
$r = new Psa_Router();
$exp[] = 'mycontroller';
$exp[] = 'mymethod';
$exp[] = 'abc';
$exp[] = '123';
$url_arr = $r->explode_url('/mycontroller/mymethod/abc/123/');
$this->assertEquals(json_encode($exp), json_encode($url_arr));
$url_arr = $r->explode_url('mycontroller/mymethod/abc/123/');
$this->assertEquals(json_encode($exp), json_encode($url_arr));
$url_arr = $r->explode_url('mycontroller/mymethod/abc/123');
$this->assertEquals(json_encode($exp), json_encode($url_arr));
$url_arr = $r->explode_url(' /mycontroller/mymethod/abc/123');
$this->assertEquals(json_encode($exp), json_encode($url_arr));
$url_arr = $r->explode_url(' /mycontroller/mymethod/abc/123 ');
$this->assertEquals(json_encode($exp), json_encode($url_arr));
$url_arr = $r->explode_url('/mycontroller/mymethod/abc/123?aaaa=rrerw/ssdsd');
$this->assertEquals(json_encode($exp), json_encode($url_arr));
Psa_Registry::get_instance()->basedir_web = '/aaaa/bbbb';
$url_arr = $r->explode_url('/aaaa/bbbb/mycontroller/mymethod/abc/123?aaaa=rrerw/ssdsd');
$this->assertEquals(json_encode($exp), json_encode($url_arr));
Psa_Registry::get_instance()->basedir_web = 'aaaa/bbbb';
$url_arr = $r->explode_url('/aaaa/bbbb/mycontroller/mymethod/abc/123?aaaa=rrerw/ssdsd');
$this->assertEquals(json_encode($exp), json_encode($url_arr));
Psa_Registry::get_instance()->basedir_web = '/aaaa/bbbb/';
$url_arr = $r->explode_url('/aaaa/bbbb/mycontroller/mymethod/abc/123?aaaa=rrerw/ssdsd');
$this->assertEquals(json_encode($exp), json_encode($url_arr));
$exp = array();
$url_arr = $r->explode_url('');
$this->assertEquals(json_encode($exp), json_encode($url_arr));
$url_arr = $r->explode_url(' ');
$this->assertEquals(json_encode($exp), json_encode($url_arr));
$url_arr = $r->explode_url('/');
$this->assertEquals(json_encode($exp), json_encode($url_arr));
}
public function testGetDispatchData(){
$r = new Psa_Router();
$exp['controller'] = 'Mycontroller_Controller';
$exp['action'] = 'mymethod_action';
$exp['arguments'] = array('abc', '123');
$dt = $r->get_dispatch_data('/mycontroller/mymethod/abc/123/');
$this->assertEquals(json_encode($exp), json_encode($dt));
$exp['controller'] = 'Default_Controller';
$exp['action'] = 'default_action';
$exp['arguments'] = array();
$dt = $r->get_dispatch_data('');
$this->assertEquals(json_encode($exp), json_encode($dt));
$dt = $r->get_dispatch_data('/');
$this->assertEquals(json_encode($exp), json_encode($dt));
}
public function testDispach(){
Psa_Registry::get_instance()->basedir_web = '';
$r = new Psa_Router();
try{
$r->dispach('TestClass', 'test_method', array('1234'));
}catch(Exception $e){
$this->assertEquals('1234', $e->getMessage());
}
$_SERVER["REQUEST_URI"] = '/test/test/abc/123/';
try{
$r->dispach();
}catch(Exception $e){
$this->assertEquals('abc', $e->getMessage());
}
// test return
$this->assertEquals('test_method1', $r->dispach('TestClass', 'test_method1', array('aaabbbcc')));
}
public function testDispachUnexising(){
$r = new Psa_Router();
// unexisting method
try{
$r->dispach('TestClass', 'test_method_unexisitng', array('1234'));
}
catch(Exception $e){
$this->assertEquals(102, $e->getCode());
}
// unexisting class
try{
$r->dispach('TestClass_unexisitng', 'test_method_unexisitng', array('1234', '789'));
}
catch(Exception $e){
$this->assertEquals(101, $e->getCode());
}
}
}
class TestClass{
public function test_method($msq){
throw new Exception($msq);
}
public function test_method1(){
return 'test_method1';
}
}
class Test_Controller{
public function test_action($msq){
throw new Exception($msq);
}
}