<commit_before><?php
    // $Id$
    
    if (!defined("SIMPLE_TEST")) {
        define("SIMPLE_TEST", "../");
    }
    require_once(SIMPLE_TEST . 'unit_tester.php');
    require_once(SIMPLE_TEST . 'socket.php');
    require_once(SIMPLE_TEST . 'http.php');
    require_once(SIMPLE_TEST . 'web_tester.php');

    class LiveHttpTestCase extends UnitTestCase {
        function LiveHttpTestCase() {
            $this->UnitTestCase();
        }
        function testBadSocket() {
            @$socket = &new SimpleSocket("bad_url", 111);
            $this->swallowErrors();
            $this->assertTrue($socket->isError(), "Error [" . $socket->getError(). "]");
            $this->assertFalse($socket->isOpen());
            $this->assertFalse($socket->write("A message"));
        }
        function testSocket() {
            $socket = &new SimpleSocket("www.lastcraft.com", 80);
            $this->assertFalse($socket->isError(), "Error [" . $socket->getError(). "]");
            $this->assertTrue($socket->isOpen());
            $this->assertTrue($socket->write("GET www.lastcraft.com/test/network_confirm.php HTTP/1.0\r\n"));
            $socket->write("Host: localhost\r\n");
            $socket->write("Connection: close\r\n\r\n");
            $this->assertEqual($socket->read(8), "HTTP/1.1");
            $socket->close();
            $this->assertEqual($socket->read(8), "");
        }
        function testHttpGet() {
            $http = &new SimpleHttpRequest(new SimpleUrl(
                    "www.lastcraft.com/test/network_confirm.php?gkey=gvalue"));
            $http->setCookie(new SimpleCookie("ckey", "cvalue"));
            $this->assertIsA($response = &$http->fetch(), "SimpleHttpResponse");
            $this->assertEqual($response->getResponseCode(), 200);
            $this->assertEqual($response->getMimeType(), "text/html");
            $this->assertWantedPattern(
                    '/A target for the SimpleTest test suite/',
                    $response->getContent());
            $this->assertWantedPattern(
                    '/Request method.*?<dd>GET<\/dd>/',
                    $response->getContent());
            $this->assertWantedPattern(
                    '/gkey=\[gvalue\]/',
                    $response->getContent());
            $this->assertWantedPattern(
                    '/ckey=\[cvalue\]/',
                    $response->getContent());
        }
        function testHttpHead() {
            $http = &new SimpleHttpRequest(
                    new SimpleUrl("www.lastcraft.com/test/network_confirm.php"),
                    "HEAD");
            $this->assertIsA($response = &$http->fetch(), "SimpleHttpResponse");
            $this->assertEqual($response->getResponseCode(), 200);
            $this->assertIdentical($response->getContent(), "");
        }
        function testHttpPost() {
            $http = &new SimpleHttpPushRequest(
                    new SimpleUrl("www.lastcraft.com/test/network_confirm.php"),
                    "Some post data");
            $this->assertIsA($response = &$http->fetch(), "SimpleHttpResponse");
            $this->assertWantedPattern(
                    '/Request method.*?<dd>POST<\/dd>/',
                    $response->getContent());
            $this->assertWantedPattern(
                    '/Raw POST data.*?\s+\[Some post data\]/',
                    $response->getContent());
        }
        function testHttpFormPost() {
            $http = &new SimpleHttpPushRequest(
                    new SimpleUrl("www.lastcraft.com/test/network_confirm.php"),
                    "pkey=pvalue");
            $http->addHeaderLine('Content-Type: application/x-www-form-urlencoded');
            $response = &$http->fetch();
            $this->assertWantedPattern(
                    '/Request method.*?<dd>POST<\/dd>/',
                    $response->getContent());
            $this->assertWantedPattern(
                    '/pkey=\[pvalue\]/',
                    $response->getContent());
        }
    }
    
    class TestOfLiveFetching extends WebTestCase {
        function TestOfLiveFetching() {
            $this->WebTestCase();
        }
        function testGet() {
            $this->assertTrue($this->get('http://www.lastcraft.com/test/network_confirm.php'));
            $this->assertWantedPattern('/target for the SimpleTest/');
            $this->assertWantedPattern('/Request method.*?<dd>GET<\/dd>/');
            $this->assertTitle('Simple test target file');
            $this->assertResponse(200);
            $this->assertMime("text/html");
        }
        function testPost() {
            $this->assertTrue($this->post('http://www.lastcraft.com/test/network_confirm.php'));
            $this->assertWantedPattern('/target for the SimpleTest/');
            $this->assertWantedPattern('/Request method.*?<dd>POST<\/dd>/');
        }
        function testGetWithData() {
            $this->get('http://www.lastcraft.com/test/network_confirm.php', array("a" => "aaa"));
            $this->assertWantedPattern('/Request method.*?<dd>GET<\/dd>/');
            $this->assertWantedPattern('/a=\[aaa\]/');
        }
        function testPostWithData() {
            $this->post('http://www.lastcraft.com/test/network_confirm.php', array("a" => "aaa"));
            $this->assertWantedPattern('/Request method.*?<dd>POST<\/dd>/');
            $this->assertWantedPattern('/a=\[aaa\]/');
        }
        function testRelativeGet() {
            $this->get('http://www.lastcraft.com/test/link_confirm.php');
            $this->assertTrue($this->get('network_confirm.php'));
            $this->assertWantedPattern('/target for the SimpleTest/');
        }
        function testRelativePost() {
            $this->post('http://www.lastcraft.com/test/link_confirm.php');
            $this->assertTrue($this->post('network_confirm.php'));
            $this->assertWantedPattern('/target for the SimpleTest/');
        }
        function testAbsoluteLinkFollowing() {
            $this->get('http://www.lastcraft.com/test/link_confirm.php');
            $this->assertTrue($this->clickLink('Absolute'));
            $this->assertWantedPattern('/target for the SimpleTest/');
        }
        function testRelativeLinkFollowing() {
            $this->get('http://www.lastcraft.com/test/link_confirm.php');
            $this->assertTrue($this->clickLink('Relative'));
            $this->assertWantedPattern('/target for the SimpleTest/');
        }
        function testIdFollowing() {
            $this->get('http://www.lastcraft.com/test/link_confirm.php');
            $this->assertTrue($this->clickLinkId(1));
            $this->assertWantedPattern('/target for the SimpleTest/');
        }
    }
    
    class TestOfLiveRedirects extends WebTestCase {
        function TestOfLiveRedirects() {
            $this->WebTestCase();
        }
        function testNoRedirects() {
            $this->setMaximumRedirects(0);
            $this->get('http://www.lastcraft.com/test/redirect.php');
            $this->assertTitle('Redirection test');
        }
        function testRedirects() {
            $this->setMaximumRedirects(1);
            $this->get('http://www.lastcraft.com/test/redirect.php');
            $this->assertTitle('Simple test target file');
        }
    }
    
    class TestOfLiveCookies extends WebTestCase {
        function TestOfLiveCookies() {
            $this->WebTestCase();
        }
        function testCookieSetting() {
            $this->setCookie("a", "Test cookie a", "www.lastcraft.com");
            $this->setCookie("b", "Test cookie b", "www.lastcraft.com", "test");
            $this->get('http://www.lastcraft.com/test/network_confirm.php');
            $this->assertWantedPattern('/Test cookie a/');
            $this->assertWantedPattern('/Test cookie b/');
            $this->assertCookie("a");
            $this->assertCookie("b", "Test cookie b");
        }
        function testCookieReading() {
            $this->get('http://www.lastcraft.com/test/set_cookies.php');
            $this->assertCookie("session_cookie", "A");
            $this->assertCookie("short_cookie", "B");
            $this->assertCookie("day_cookie", "C");
        }
        function testCookieExpectation() {
            $this->expectCookie("session_cookie");
            $this->get('http://www.lastcraft.com/test/set_cookies.php');
        }
        function testCookieValueExpectation() {
            $this->expectCookie("session_cookie", "A");
            $this->get('http://www.lastcraft.com/test/set_cookies.php');
        }
        function testTemporaryCookieExpiry() {
            $this->get('http://www.lastcraft.com/test/set_cookies.php');
            $this->restartSession();
            $this->assertNoCookie("session_cookie");
            $this->assertCookie("short_cookie", "B");
            $this->assertCookie("day_cookie", "C");
        }
        function testTimedCookieExpiry() {
            $this->get('http://www.lastcraft.com/test/set_cookies.php');
            $this->restartSession(time() + 115);
            $this->assertNoCookie("session_cookie");
            $this->assertNoCookie("short_cookie");
            $this->assertCookie("day_cookie", "C");
        }<commit_msg>Test fixes<commit_after><?php
    // $Id$
    
    if (!defined("SIMPLE_TEST")) {
        define("SIMPLE_TEST", "../");
    }
    require_once(SIMPLE_TEST . 'unit_tester.php');
    require_once(SIMPLE_TEST . 'socket.php');
    require_once(SIMPLE_TEST . 'http.php');
    require_once(SIMPLE_TEST . 'web_tester.php');

    class LiveHttpTestCase extends UnitTestCase {
        function LiveHttpTestCase() {
            $this->UnitTestCase();
        }
        function testBadSocket() {
            @$socket = &new SimpleSocket("bad_url", 111);
            $this->swallowErrors();
            $this->assertTrue($socket->isError(), "Error [" . $socket->getError(). "]");
            $this->assertFalse($socket->isOpen());
            $this->assertFalse($socket->write("A message"));
        }
        function testSocket() {
            $socket = &new SimpleSocket("www.lastcraft.com", 80);
            $this->assertFalse($socket->isError(), "Error [" . $socket->getError(). "]");
            $this->assertTrue($socket->isOpen());
            $this->assertTrue($socket->write("GET www.lastcraft.com/test/network_confirm.php HTTP/1.0\r\n"));
            $socket->write("Host: localhost\r\n");
            $socket->write("Connection: close\r\n\r\n");
            $this->assertEqual($socket->read(8), "HTTP/1.1");
            $socket->close();
            $this->assertEqual($socket->read(8), "");
        }
        function testHttpGet() {
            $http = &new SimpleHttpRequest(new SimpleUrl(
                    "www.lastcraft.com/test/network_confirm.php?gkey=gvalue"));
            $http->setCookie(new SimpleCookie("ckey", "cvalue"));
            $this->assertIsA($response = &$http->fetch(), "SimpleHttpResponse");
            $this->assertEqual($response->getResponseCode(), 200);
            $this->assertEqual($response->getMimeType(), "text/html");
            $this->assertWantedPattern(
                    '/A target for the SimpleTest test suite/',
                    $response->getContent());
            $this->assertWantedPattern(
                    '/Request method.*?<dd>GET<\/dd>/',
                    $response->getContent());
            $this->assertWantedPattern(
                    '/gkey=\[gvalue\]/',
                    $response->getContent());
            $this->assertWantedPattern(
                    '/ckey=\[cvalue\]/',
                    $response->getContent());
        }
        function testHttpHead() {
            $http = &new SimpleHttpRequest(
                    new SimpleUrl("www.lastcraft.com/test/network_confirm.php"),
                    "HEAD");
            $this->assertIsA($response = &$http->fetch(), "SimpleHttpResponse");
            $this->assertEqual($response->getResponseCode(), 200);
            $this->assertIdentical($response->getContent(), "");
        }
        function testHttpPost() {
            $http = &new SimpleHttpPushRequest(
                    new SimpleUrl("www.lastcraft.com/test/network_confirm.php"),
                    "Some post data");
            $this->assertIsA($response = &$http->fetch(), "SimpleHttpResponse");
            $this->assertWantedPattern(
                    '/Request method.*?<dd>POST<\/dd>/',
                    $response->getContent());
            $this->assertWantedPattern(
                    '/Raw POST data.*?\s+\[Some post data\]/',
                    $response->getContent());
        }
        function testHttpFormPost() {
            $http = &new SimpleHttpPushRequest(
                    new SimpleUrl("www.lastcraft.com/test/network_confirm.php"),
                    "pkey=pvalue");
            $http->addHeaderLine('Content-Type: application/x-www-form-urlencoded');
            $response = &$http->fetch();
            $this->assertWantedPattern(
                    '/Request method.*?<dd>POST<\/dd>/',
                    $response->getContent());
            $this->assertWantedPattern(
                    '/pkey=\[pvalue\]/',
                    $response->getContent());
        }
    }
    
    class TestOfLiveFetching extends WebTestCase {
        function TestOfLiveFetching() {
            $this->WebTestCase();
        }
        function testGet() {
            $this->assertTrue($this->get('http://www.lastcraft.com/test/network_confirm.php'));
            $this->assertWantedPattern('/target for the SimpleTest/');
            $this->assertWantedPattern('/Request method.*?<dd>GET<\/dd>/');
            $this->assertTitle('Simple test target file');
            $this->assertResponse(200);
            $this->assertMime("text/html");
        }
        function testPost() {
            $this->assertTrue($this->post('http://www.lastcraft.com/test/network_confirm.php'));
            $this->assertWantedPattern('/target for the SimpleTest/');
            $this->assertWantedPattern('/Request method.*?<dd>POST<\/dd>/');
        }
        function testGetWithData() {
            $this->get('http://www.lastcraft.com/test/network_confirm.php', array("a" => "aaa"));
            $this->assertWantedPattern('/Request method.*?<dd>GET<\/dd>/');
            $this->assertWantedPattern('/a=\[aaa\]/');
        }
        function testPostWithData() {
            $this->post('http://www.lastcraft.com/test/network_confirm.php', array("a" => "aaa"));
            $this->assertWantedPattern('/Request method.*?<dd>POST<\/dd>/');
            $this->assertWantedPattern('/a=\[aaa\]/');
        }
        function testRelativeGet() {
            $this->get('http://www.lastcraft.com/test/link_confirm.php');
            $this->assertTrue($this->get('network_confirm.php'));
            $this->assertWantedPattern('/target for the SimpleTest/');
        }
        function testRelativePost() {
            $this->post('http://www.lastcraft.com/test/link_confirm.php');
            $this->assertTrue($this->post('network_confirm.php'));
            $this->assertWantedPattern('/target for the SimpleTest/');
        }
        function testAbsoluteLinkFollowing() {
            $this->get('http://www.lastcraft.com/test/link_confirm.php');
            $this->assertTrue($this->clickLink('Absolute'));
            $this->assertWantedPattern('/target for the SimpleTest/');
        }
        function testRelativeLinkFollowing() {
            $this->get('http://www.lastcraft.com/test/link_confirm.php');
            $this->assertTrue($this->clickLink('Relative'));
            $this->assertWantedPattern('/target for the SimpleTest/');
        }
        function testIdFollowing() {
            $this->get('http://www.lastcraft.com/test/link_confirm.php');
            $this->assertTrue($this->clickLinkId(1));
            $this->assertWantedPattern('/target for the SimpleTest/');
        }
    }
    
    class TestOfLiveRedirects extends WebTestCase {
        function TestOfLiveRedirects() {
            $this->WebTestCase();
        }
        function testNoRedirects() {
            $this->setMaximumRedirects(0);
            $this->get('http://www.lastcraft.com/test/redirect.php');
            $this->assertTitle('Redirection test');
        }
        function testRedirects() {
            $this->setMaximumRedirects(1);
            $this->get('http://www.lastcraft.com/test/redirect.php');
            $this->assertTitle('Simple test target file');
        }
    }
    
    class TestOfLiveCookies extends WebTestCase {
        function TestOfLiveCookies() {
            $this->WebTestCase();
        }
        function testCookieSetting() {
            $this->setCookie("a", "Test cookie a", "www.lastcraft.com");
            $this->setCookie("b", "Test cookie b", "www.lastcraft.com", "test");
            $this->get('http://www.lastcraft.com/test/network_confirm.php');
            $this->assertWantedPattern('/Test cookie a/');
            $this->assertWantedPattern('/Test cookie b/');
            $this->assertCookie("a");
            $this->assertCookie("b", "Test cookie b");
        }
        function testCookieReading() {
            $this->get('http://www.lastcraft.com/test/set_cookies.php');
            $this->assertCookie("session_cookie", "A");
            $this->assertCookie("short_cookie", "B");
            $this->assertCookie("day_cookie", "C");
        }
        function testCookieExpectation() {
            $this->expectCookie("session_cookie");
            $this->get('http://www.lastcraft.com/test/set_cookies.php');
        }
        function testCookieValueExpectation() {
            $this->expectCookie("session_cookie", "A");
            $this->get('http://www.lastcraft.com/test/set_cookies.php');
        }
        function testTemporaryCookieExpiry() {
            $this->get('http://www.lastcraft.com/test/set_cookies.php');
            $this->restartSession();
            $this->assertNoCookie("session_cookie");
            $this->assertCookie("short_cookie", "B");
            $this->assertCookie("day_cookie", "C");
        }
        function testTimedCookieExpiry() {
            $this->get('http://www.lastcraft.com/test/set_cookies.php');
            $this->restartSession(time() + 3600 + 60);    // Includes a 60 sec. clock drift margin.
            $this->assertNoCookie("session_cookie");
            $this->assertNoCookie("hour_cookie");
            $this->assertCookie("day_cookie", "C");
        }
        function testOfClockOverDrift() {
            $this->get('http://www.lastcraft.com/test/set_cookies.php');
            $this->restartSession(time() + 110);        // Allows ten second wire time.
            $this->assertNoCookie(
                    "short_cookie",
                    "%s->Please check you computer clock setting if you are not using NTP");
        }
        function testOfClockUnderDrift() {
            $this->get('http://www.lastcraft.com/test/set_cookies.php');
            $this->restartSession(time() + 90);         // Allows ten second wire time.
            $this->assertCookie(
                    "short_cookie",
                    "B",
                    "%s->Please check you computer clock setting if you are not using NTP");
        }
{'fraction_non_alphanumeric': 0.16791837157507639, 'fraction_numerical': 0.0032112705236442742, 'mean_word_length': 2.0565141681177774, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 297, 'https://': 0, 'lorem ipsum': 0, 'www.': 54, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3665532', 'n_tokens_mistral': 5338, 'n_tokens_neox': 5225, 'n_words': 704}