summaryrefslogtreecommitdiff
path: root/tests/unit/Web/THttpResponseTest.php
blob: 6cc453e4111f045b1fb73b6177f6f3b2611f5f82 (plain)
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
153
154
155
156
157
158
159
160
161
162
163
<?php
require_once dirname(__FILE__).'/../phpunit.php';
require_once 'PHPUnit/Extensions/OutputTestCase.php';

Prado::using('System.Web.THttpResponse');


/**
 * @package System.Web
 */
class THttpResponseTest extends PHPUnit_Framework_TestCase {
  
  public static $app=null;

  public function setUp () {
    if (self::$app===null) self::$app=new TApplication(dirname(__FILE__).'/app');
    ob_start();
  }
  
  public function tearDown () {
    ob_end_flush();
  }
  
  public function testInit() {
    $response=new THttpResponse ();
    $response->init (null);
    self::assertEquals ($response, self::$app->getResponse());
  }

  public function testSetCacheExpire() {
    $response=new THttpResponse ();
    $response->init (null);
    $response->setCacheExpire (300);
    self::assertEquals(300, $response->getCacheExpire());
  }

  public function testSetCacheControl() {
    $response=new THttpResponse ();
    $response->init (null);
    foreach (array ('none','nocache','private','private_no_expire','public') as $cc) {
      $response->setCacheControl($cc);
      self::assertEquals($cc, $response->getCacheControl());
    }
    try {
      $response->setCacheControl('invalid');
      self::fail ('Expected TInvalidDataValueException not thrown');
    } catch (TInvalidDataValueException $e) {}
    
  }

  public function testSetContentType() {
    $response=new THttpResponse ();
    $response->init (null);
    $response->setContentType('image/jpeg');
    self::assertEquals('image/jpeg', $response->getContentType());
    $response->setContentType('text/plain');
    self::assertEquals('text/plain', $response->getContentType());
  }

  public function testSetCharset() {
    $response=new THttpResponse ();
    $response->init (null);
    $response->setCharset ('UTF-8');
    self::assertEquals('UTF-8', $response->getCharset());
    $response->setCharset ('ISO8859-1');
    self::assertEquals('ISO8859-1', $response->getCharset());
    
  }

  public function testSetBufferOutput() {
    $response=new THttpResponse ();
    $response->setBufferOutput(true);
    self::assertTrue($response->getBufferOutput());
    $response->init (null);
    try {
      $response->setBufferOutput(false);
      self::fail ('Expected TInvalidOperationException not thrown');
    } catch (TInvalidOperationException $e) {}
  }

  public function testSetStatusCode() {
    $response=new THttpResponse ();
    $response->init (null);
    $response->setStatusCode(401);
    self::assertEquals(401, $response->getStatusCode());
    $response->setStatusCode(200);
    self::assertEquals(200, $response->getStatusCode());
  }

  public function testGetCookies() {
    $response=new THttpResponse ();
    $response->init (null);
    self::assertType('THttpCookieCollection', $response->getCookies());
    self::assertEquals(0, $response->getCookies()->getCount());
  }

  public function testWrite() {
    $response=new THttpResponse ();
	//self::expectOutputString("test string");
    $response->write("test string");
    self::assertContains ('test string', ob_get_clean());

  }

  public function testWriteFile() {
    
  	 // Don't know how to test headers :(( ...
	throw new PHPUnit_Framework_IncompleteTestError();
  	
    $response=new THttpResponse ();
    $response->setBufferOutput(true);
    // Suppress warning with headers
    $response->writeFile(dirname(__FILE__).'/data/aTarFile.md5', null, 'text/plain', array ('Pragma: public', 'Expires: 0'));
	
    self::assertContains('4b1ecb0b243918a8bbfbb4515937be98  aTarFile.tar', ob_get_clean());
	
  }

  public function testRedirect() {
    throw new PHPUnit_Framework_IncompleteTestError();
  }

  public function testReload() {
    throw new PHPUnit_Framework_IncompleteTestError();
  }

  public function testFlush() {
    throw new PHPUnit_Framework_IncompleteTestError();
  }

  public function testSendContentTypeHeader() {
    throw new PHPUnit_Framework_IncompleteTestError();
  }

  public function testClear() {
    throw new PHPUnit_Framework_IncompleteTestError();
  }

  public function testAppendHeader() {
    throw new PHPUnit_Framework_IncompleteTestError();
  }

  public function testAppendLog() {
    throw new PHPUnit_Framework_IncompleteTestError();
  }

  public function testAddCookie() {
    throw new PHPUnit_Framework_IncompleteTestError();
  }

  public function testRemoveCookie() {
    throw new PHPUnit_Framework_IncompleteTestError();
  }

  public function testSetHtmlWriterType() {
    throw new PHPUnit_Framework_IncompleteTestError();
  }

  public function testCreateHtmlWriter() {
    throw new PHPUnit_Framework_IncompleteTestError();
  }
}
?>