MessageTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\tests\cases\net\http;
  9. use lithium\net\http\Message;
  10. class MessageTest extends \lithium\test\Unit {
  11. public $request = null;
  12. public function setUp() {
  13. $this->message = new Message();
  14. }
  15. public function testHeaderKey() {
  16. $expected = array('Host: localhost:80');
  17. $result = $this->message->headers('Host: localhost:80');
  18. $this->assertEqual($expected, $result);
  19. $expected = 'localhost:80';
  20. $result = $this->message->headers('Host');
  21. $this->assertEqual($expected, $result);
  22. $result = $this->message->headers('Host', false);
  23. $this->assertFalse($result);
  24. }
  25. public function testHeaderKeyValue() {
  26. $expected = array('Connection: Close');
  27. $result = $this->message->headers('Connection', 'Close');
  28. $this->assertEqual($expected, $result);
  29. }
  30. public function testHeaderArrayValue() {
  31. $expected = array('User-Agent: Mozilla/5.0');
  32. $result = $this->message->headers(array('User-Agent: Mozilla/5.0'));
  33. $this->assertEqual($expected, $result);
  34. }
  35. public function testHeaderArrayKeyValue() {
  36. $expected = array('Cache-Control: no-cache');
  37. $result = $this->message->headers(array('Cache-Control' => 'no-cache'));
  38. $this->assertEqual($expected, $result);
  39. }
  40. public function testMultiValueHeader() {
  41. $expected = array(
  42. 'Cache-Control: no-store, no-cache, must-revalidate',
  43. 'Cache-Control: post-check=0, pre-check=0',
  44. 'Cache-Control: max-age=0'
  45. );
  46. $result = $this->message->headers(array(
  47. 'Cache-Control' => array(
  48. 'no-store, no-cache, must-revalidate',
  49. 'post-check=0, pre-check=0',
  50. 'max-age=0'
  51. )
  52. ));
  53. $this->assertEqual($expected, $result);
  54. }
  55. public function testType() {
  56. $this->assertEqual('json', $this->message->type("json"));
  57. $this->assertEqual('json', $this->message->type());
  58. $expected = 'json';
  59. $result = $this->message->type("application/json; charset=UTF-8");
  60. $this->assertEqual($expected, $result);
  61. }
  62. public function testReturnStringIfNoBufferAndEmptyBody() {
  63. $this->message->type("json");
  64. $result = $this->message->body(array(""), array('encode' => true));
  65. $this->assertIdentical("", $result);
  66. }
  67. }
  68. ?>