|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Torpedo\Test; |
|
4
|
|
|
use \Torpedo\Http\Request; |
|
5
|
|
|
|
|
6
|
|
|
class RequestTest extends \PHPUnit_Framework_TestCase { |
|
7
|
|
|
protected $request; |
|
8
|
|
|
protected $server = [ |
|
9
|
|
|
'SERVER_PROTOCOL' => '1.0', |
|
10
|
|
|
'REQUEST_METHOD' => 'GET', |
|
11
|
|
|
'REQUEST_URI' => '/index.php', |
|
12
|
|
|
'REQUEST_URI_PATH' => '/index.php', |
|
13
|
|
|
'HTTPS' => FALSE, |
|
14
|
|
|
'HTTP_MY_HEADER' => 'my value' |
|
15
|
|
|
]; |
|
16
|
|
|
|
|
17
|
|
|
protected $get = [ |
|
18
|
|
|
'name' => 'nascho' |
|
19
|
|
|
]; |
|
20
|
|
|
|
|
21
|
|
|
// set up value for global scope |
|
22
|
|
|
public function setup(){ |
|
23
|
|
|
$this->request = new \Torpedo\Http\Request( |
|
24
|
|
|
$this->get, [], [], $this->server, [] |
|
25
|
|
|
); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
// check if HTTP method is get |
|
29
|
|
|
public function testHttpRequestMethodIsGet(){ |
|
30
|
|
|
$this->assertEquals($this->request->isGet(), true); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
// check if HTTP method is POST |
|
34
|
|
|
public function testHttpRequestMethodIsPost(){ |
|
35
|
|
|
$this->assertEquals($this->request->isPost(), false); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
// check if HTTP method is PUT |
|
39
|
|
|
public function testHttpRequestMethodIsPut(){ |
|
40
|
|
|
$this->assertEquals($this->request->isPost(), false); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
// check if HTTP method is delete |
|
44
|
|
|
public function testHttpRequestMethodIsDelete(){ |
|
45
|
|
|
$this->assertEquals($this->request->isPost(), false); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
// check if GET value is same as assigned |
|
49
|
|
|
public function testGetVariableFromGetRequest(){ |
|
50
|
|
|
$this->assertEquals($this->request->get('name'), 'nascho'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
// test that POST value is null |
|
54
|
|
|
// request method is GET only for this example |
|
55
|
|
|
public function testPostVariableFromPostRequest(){ |
|
56
|
|
|
$this->assertEquals($this->request->post('name'), null); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
// test server protocol returns the correct version |
|
60
|
|
|
public function testServerProtocolReturnsResult(){ |
|
61
|
|
|
$this->assertEquals($this->request->server('SERVER_PROTOCOL'), '1.0'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
// test reques URI is same as assigned |
|
65
|
|
|
public function testRequestUriReturnsResult(){ |
|
66
|
|
|
$this->assertEquals($this->request->server('REQUEST_URI'), '/index.php'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
// http referer is not declared, so check this test returns null |
|
70
|
|
|
public function testServerRefererReturnsNull(){ |
|
71
|
|
|
$this->assertEquals($this->request->server('HTTP_REFERER'), null); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
// check request type returns GET method. |
|
75
|
|
|
public function testGetMethodReturnsRequestMethodResult(){ |
|
76
|
|
|
$this->assertEquals($this->request->server('REQUEST_METHOD'), 'GET'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
// test if connection is authenticated / HTTPS |
|
80
|
|
|
public function testConnectionIsViaHTTPS(){ |
|
81
|
|
|
$this->assertEquals($this->request->server('HTTPS'), FALSE); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
// assert false that this is an AJAX request. |
|
85
|
|
|
public function testRequestMethodHasNoHxrObject(){ |
|
86
|
|
|
$this->assertNotEquals($this->request->server('REQUEST_METHOD'), 'XMLHttpRequest'); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
} |