This commit is contained in:
2022-11-25 21:21:30 +01:00
parent 2d6df0d5f0
commit 94deb06f52
132 changed files with 44887 additions and 41368 deletions

View File

@@ -1,4 +1,5 @@
<?php
/** DomFramework - Tests
* @package domframework
* @author Dominique Fournier <dominique@fournier38.fr>
@@ -10,72 +11,76 @@ namespace Domframework\Tests;
use Domframework\Tcpclient;
/** Test the TCP client */
class TcpclientTest extends \PHPUnit_Framework_TestCase
class TcpclientTest extends \PHPUnit_Framework_TestCase
{
public function test_GoogleIPv4 ()
{
$tcpclient = new Tcpclient ("www.google.fr", 80);
$tcpclient->preferIPv4 (true);
$tcpclient->connect ();
$tcpclient->send ("GET / HTTP/1.1\r\n".
"Host: www.google.fr\r\n".
"User-Agent: DomFramework\r\n".
"Accept: *"."/*\r\n".
"\r\n");
$res = "";
while (($read = $tcpclient->read ()) !== "")
$res .= $read."\r\n";
$tcpclient->disconnect ();
$this->assertSame (substr ($res, 0, 15), "HTTP/1.1 200 OK");
}
public function test_GoogleIPv4()
{
$tcpclient = new Tcpclient("www.google.fr", 80);
$tcpclient->preferIPv4(true);
$tcpclient->connect();
$tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: www.google.fr\r\n" .
"User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" .
"\r\n");
$res = "";
while (($read = $tcpclient->read()) !== "") {
$res .= $read . "\r\n";
}
$tcpclient->disconnect();
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
}
public function test_GoogleIPv4orIpv6 ()
{
$tcpclient = new Tcpclient ("www.google.fr", 80);
$tcpclient->connect ();
$tcpclient->send ("GET / HTTP/1.1\r\n".
"Host: www.google.fr\r\n".
"User-Agent: DomFramework\r\n".
"Accept: *"."/*\r\n".
"\r\n");
$res = "";
while (($read = $tcpclient->read ()) !== "")
$res .= $read."\r\n";
$tcpclient->disconnect ();
$this->assertSame (substr ($res, 0, 15), "HTTP/1.1 200 OK");
}
public function test_GoogleIPv4orIpv6()
{
$tcpclient = new Tcpclient("www.google.fr", 80);
$tcpclient->connect();
$tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: www.google.fr\r\n" .
"User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" .
"\r\n");
$res = "";
while (($read = $tcpclient->read()) !== "") {
$res .= $read . "\r\n";
}
$tcpclient->disconnect();
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
}
public function test_GoogleSSL ()
{
$tcpclient = new Tcpclient ("www.google.fr", 443);
$tcpclient->connect ();
$tcpclient->cryptoEnable (true);
$tcpclient->send ("GET / HTTP/1.1\r\n".
"Host: www.google.fr\r\n".
"User-Agent: DomFramework\r\n".
"Accept: *"."/*\r\n".
"\r\n");
$res = "";
while (($read = $tcpclient->read ()) !== "")
$res .= $read."\r\n";
$tcpclient->disconnect ();
$this->assertSame (substr ($res, 0, 15), "HTTP/1.1 200 OK");
}
public function test_GoogleSSL()
{
$tcpclient = new Tcpclient("www.google.fr", 443);
$tcpclient->connect();
$tcpclient->cryptoEnable(true);
$tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: www.google.fr\r\n" .
"User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" .
"\r\n");
$res = "";
while (($read = $tcpclient->read()) !== "") {
$res .= $read . "\r\n";
}
$tcpclient->disconnect();
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
}
public function test_GoogleSSLIPv6 ()
{
$tcpclient = new Tcpclient ("ipv6.google.com", 443);
$tcpclient->connect ();
$tcpclient->cryptoEnable (true);
$tcpclient->send ("GET / HTTP/1.1\r\n".
"Host: www.google.fr\r\n".
"User-Agent: DomFramework\r\n".
"Accept: *"."/*\r\n".
"\r\n");
$res = "";
while (($read = $tcpclient->read ()) !== "")
$res .= $read."\r\n";
$tcpclient->disconnect ();
$this->assertSame (substr ($res, 0, 15), "HTTP/1.1 200 OK");
}
public function test_GoogleSSLIPv6()
{
$tcpclient = new Tcpclient("ipv6.google.com", 443);
$tcpclient->connect();
$tcpclient->cryptoEnable(true);
$tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: www.google.fr\r\n" .
"User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" .
"\r\n");
$res = "";
while (($read = $tcpclient->read()) !== "") {
$res .= $read . "\r\n";
}
$tcpclient->disconnect();
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
}
}