<commit_before><?php
use PhpProxy\Keyserver;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class KeyserverTest extends PHPUnit_Framework_TestCase
{
    public function testErrno404()
    {
      $request = Request::createFromGlobals();
      $request->query->set('ERRNO', '404');
      Keyserver::$request_instance = $request;
      $response = Keyserver::getResponse();

      $this->assertTrue($response instanceof Response);
      $this->assertEquals(404, $response->getStatusCode());
      $this->assertSame(0, strpos($response->getContent(), '<!DOCTYPE html>'));
    }

    public function testErrno505()
    {
      $request = Request::createFromGlobals();
      $request->query->set('ERRNO', '500');
      Keyserver::$request_instance = $request;
      $response = Keyserver::getResponse();

      $this->assertTrue($response instanceof Response);
      $this->assertEquals(500, $response->getStatusCode());
      $this->assertSame(0, strpos($response->getContent(), '<!DOCTYPE html>'));
    }

    public function testIndex()
    {
      $request = Request::createFromGlobals();
      $request->server->set('REQUEST_URI', '/');
      Keyserver::$request_instance = $request;
      $response = Keyserver::getResponse();

      $this->assertTrue($response instanceof Response);
      $this->assertEquals(200, $response->getStatusCode());
      $this->assertSame(0, strpos($response->getContent(), '<!DOCTYPE html>'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'GNU/Linux Inside!'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'Submit this key'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'Remove my key!'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'Please send bug reports'));
    }

    public function testFaq()
    {
      $request = Request::createFromGlobals();
      $request->server->set('REQUEST_URI', '/doc/faq');
      Keyserver::$request_instance = $request;
      $response = Keyserver::getResponse();

      $this->assertTrue($response instanceof Response);
      $this->assertEquals(200, $response->getStatusCode());
      $this->assertSame(0, strpos($response->getContent(), '<!DOCTYPE html>'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'GNU/Linux Inside!'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'Can you delete my key from the key server?'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'No.'));
      $this->assertSame(FALSE, strpos($response->getContent(), 'Remove my key!'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'Please send bug reports'));
    }

    public function testMissing()
    {
      $request = Request::createFromGlobals();
      $request->server->set('REQUEST_URI', '/doc/missing');
      Keyserver::$request_instance = $request;
      $response = Keyserver::getResponse();

      $this->assertTrue($response instanceof Response);
      $this->assertEquals(404, $response->getStatusCode());
      $this->assertSame(0, strpos($response->getContent(), '<!DOCTYPE html>'));
    }
}<commit_msg>Added test units for static files.<commit_after><?php
use PhpProxy\Keyserver;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class KeyserverTest extends PHPUnit_Framework_TestCase
{
    public function testErrno404()
    {
      $request = Request::createFromGlobals();
      $request->query->set('ERRNO', '404');
      Keyserver::$request_instance = $request;
      $response = Keyserver::getResponse();

      $this->assertTrue($response instanceof Response);
      $this->assertEquals(404, $response->getStatusCode());
      $this->assertEquals('text/html;charset=UTF-8', $response->headers->get('content-type'));
      $this->assertSame(0, strpos($response->getContent(), '<!DOCTYPE html>'));
    }

    public function testErrno505()
    {
      $request = Request::createFromGlobals();
      $request->query->set('ERRNO', '500');
      Keyserver::$request_instance = $request;
      $response = Keyserver::getResponse();

      $this->assertTrue($response instanceof Response);
      $this->assertEquals(500, $response->getStatusCode());
      $this->assertEquals('text/html;charset=UTF-8', $response->headers->get('content-type'));
      $this->assertSame(0, strpos($response->getContent(), '<!DOCTYPE html>'));
    }

    public function testIndex()
    {
      $request = Request::createFromGlobals();
      $request->server->set('REQUEST_URI', '/');
      Keyserver::$request_instance = $request;
      $response = Keyserver::getResponse();

      $this->assertTrue($response instanceof Response);
      $this->assertEquals(200, $response->getStatusCode());
      $this->assertEquals('text/html;charset=UTF-8', $response->headers->get('content-type'));
      $this->assertSame(0, strpos($response->getContent(), '<!DOCTYPE html>'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'GNU/Linux Inside!'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'Submit this key'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'Remove my key!'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'Please send bug reports'));
    }

    public function testFaq()
    {
      $request = Request::createFromGlobals();
      $request->server->set('REQUEST_URI', '/doc/faq');
      Keyserver::$request_instance = $request;
      $response = Keyserver::getResponse();

      $this->assertTrue($response instanceof Response);
      $this->assertEquals(200, $response->getStatusCode());
      $this->assertEquals('text/html;charset=UTF-8', $response->headers->get('content-type'));
      $this->assertSame(0, strpos($response->getContent(), '<!DOCTYPE html>'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'GNU/Linux Inside!'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'Can you delete my key from the key server?'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'No.'));
      $this->assertSame(FALSE, strpos($response->getContent(), 'Remove my key!'));
      $this->assertGreaterThan(21, strpos($response->getContent(), 'Please send bug reports'));
    }

    public function testMissing()
    {
      $request = Request::createFromGlobals();
      $request->server->set('REQUEST_URI', '/doc/missing');
      Keyserver::$request_instance = $request;
      $response = Keyserver::getResponse();

      $this->assertTrue($response instanceof Response);
      $this->assertEquals(404, $response->getStatusCode());
      $this->assertEquals('text/html;charset=UTF-8', $response->headers->get('content-type'));
      $this->assertSame(0, strpos($response->getContent(), '<!DOCTYPE html>'));
    }

    public function testRobots()
    {
      $request = Request::createFromGlobals();
      $request->server->set('REQUEST_URI', '/robots.txt');
      Keyserver::$request_instance = $request;
      file_put_contents('../skin/default/robots.txt', file_get_contents('../pub/robots.txt'));
      $response = Keyserver::getResponse();
      unlink('../skin/default/robots.txt');

      $this->assertTrue($response instanceof Response);
      $this->assertEquals(200, $response->getStatusCode());
      $this->assertEquals('text/plain', $response->headers->get('content-type'));
      $this->assertSame(0, strpos($response->getContent(), 'User-agent: *'));
      $this->assertGreaterThan(10, strpos($response->getContent(), 'Disallow: /pks/'));
    }

    public function testFavicon()
    {
      $request = Request::createFromGlobals();
      $request->server->set('REQUEST_URI', '/favicon.ico');
      Keyserver::$request_instance = $request;
      file_put_contents('../skin/default/favicon.ico', file_get_contents('../pub/favicon.ico'));
      $response = Keyserver::getResponse();
      unlink('../skin/default/favicon.ico');

      $this->assertTrue($response instanceof Response);
      $this->assertEquals(200, $response->getStatusCode());
      $this->assertEquals('image/x-icon', $response->headers->get('content-type'));
      $this->assertSame(1, strpos($response->getContent(), 'PNG'));
      $this->assertEquals(193, strlen($response->getContent()));
    }
}
{'fraction_non_alphanumeric': 0.1839328537170264, 'fraction_numerical': 0.013669064748201438, 'mean_word_length': 4.388242894056847, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 158, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1643998', 'n_tokens_mistral': 2445, 'n_tokens_neox': 2357, 'n_words': 387}