live_test.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. // $Id: live_test.php 1748 2008-04-14 01:50:41Z lastcraft $
  3. require_once(dirname(__FILE__) . '/../autorun.php');
  4. require_once(dirname(__FILE__) . '/../socket.php');
  5. require_once(dirname(__FILE__) . '/../http.php');
  6. require_once(dirname(__FILE__) . '/../compatibility.php');
  7. if (SimpleTest::getDefaultProxy()) {
  8. SimpleTest::ignore('LiveHttpTestCase');
  9. }
  10. class LiveHttpTestCase extends UnitTestCase {
  11. function testBadSocket() {
  12. $socket = new SimpleSocket('bad_url', 111, 5);
  13. $this->assertTrue($socket->isError());
  14. $this->assertPattern(
  15. '/Cannot open \\[bad_url:111\\] with \\[/',
  16. $socket->getError());
  17. $this->assertFalse($socket->isOpen());
  18. $this->assertFalse($socket->write('A message'));
  19. }
  20. function testSocketClosure() {
  21. $socket = new SimpleSocket('www.lastcraft.com', 80, 15, 8);
  22. $this->assertTrue($socket->isOpen());
  23. $this->assertTrue($socket->write("GET /test/network_confirm.php HTTP/1.0\r\n"));
  24. $socket->write("Host: www.lastcraft.com\r\n");
  25. $socket->write("Connection: close\r\n\r\n");
  26. $this->assertEqual($socket->read(), "HTTP/1.1");
  27. $socket->close();
  28. $this->assertIdentical($socket->read(), false);
  29. }
  30. function testRecordOfSentCharacters() {
  31. $socket = new SimpleSocket('www.lastcraft.com', 80, 15);
  32. $this->assertTrue($socket->write("GET /test/network_confirm.php HTTP/1.0\r\n"));
  33. $socket->write("Host: www.lastcraft.com\r\n");
  34. $socket->write("Connection: close\r\n\r\n");
  35. $socket->close();
  36. $this->assertEqual($socket->getSent(),
  37. "GET /test/network_confirm.php HTTP/1.0\r\n" .
  38. "Host: www.lastcraft.com\r\n" .
  39. "Connection: close\r\n\r\n");
  40. }
  41. }
  42. ?>