source: trunk/server/www/vendors/simpletest/test/live_test.php @ 6

Last change on this file since 6 was 6, checked in by sander, 12 years ago

Added SimpleTest? test framework

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