Completed
Push — master ( bd6c18...ae56ac )
by Stefano
02:51
created

RequestTest::testGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
class RequestTest extends PHPUnit_Framework_TestCase {
4
5
  function request_set_clear_data(){
6
    $_GET       = [];
7
    $_POST      = [];
8
    $_COOKIE    = [];
9
    $_FILES     = [];
10
    $_REQUEST   = [];
11
    $_ENV       = [];
12
  }
13
14
  function request_set_get_data($data){
15
    $_GET = $data;
16
  }
17
18
  function request_set_post_data($data){
19
    $_POST = $data;
20
  }
21
22
  function request_set_cookie_data($data){
23
    $_COOKIE = $data;
24
  }
25
26
  function request_set_files_data($data){
27
    $_FILES = $data;
28
  }
29
30
  function request_set_env_data($data){
31
    $_ENV = $data;
32
  }
33
34
  public function testGet(){
35
    $this->request_set_get_data(['alpha'=>'beta']);
36
    $this->assertEquals(Request::get()['alpha'],'beta');
37
  }
38
39
  public function testPost(){
40
    $this->request_set_post_data(['alpha'=>'beta']);
41
    $this->assertEquals(Request::post()['alpha'],'beta');
42
  }
43
44
  public function testCookie(){
45
    $this->request_set_cookie_data(['alpha'=>'beta']);
46
    $this->assertEquals(Request::cookie()['alpha'],'beta');
47
  }
48
49
  public function testFiles(){
50
    $this->request_set_files_data(['alpha'=>'beta']);
51
    $this->assertEquals(Request::files()['alpha'],'beta');
52
  }
53
54
  public function testEnv(){
55
    $this->request_set_env_data(['alpha'=>'beta']);
56
    $this->assertEquals(Request::env()['alpha'],'beta');
57
  }
58
59
  public function testURL(){
60
    $this->assertEquals(Request::URL(),'http:///');
61
  }
62
63
  public function testURI(){
64
    $this->assertEquals(Request::URI(),'/');
65
  }
66
67
  public function testNegotiation(){
68
    $_SERVER['HTTP_ACCEPT']          = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
69
    $_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate, sdch=0.5';
70
    $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en;q=0.6,it,en-US;q=0.8';
71
    // $_SERVER['HTTP_CHARSET']      = '';
72
73
    $this->assertEquals (Request::accept('language','en,es'),'en');
74
    $this->assertEquals (Request::accept('language','en,it;q=0.1'),'it');
75
    $this->assertFalse  (Request::accept('type','svg'));
76
    $this->assertEquals (Request::accept('encoding','deflate;q=0.6,gzip;q=0.1'),'gzip');
77
    $this->assertEquals (Request::accept('charset','utf-8,*;q=0.1'),'utf-8');
78
    $this->assertEquals (Request::accept('type','application/xml,application/xhtml+xml'),'application/xhtml+xml');
79
80
  }
81
82
83
84
}
85
86