Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.

Commit

Permalink
Add server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leblanc-simon committed Sep 22, 2013
1 parent 168141d commit 23abcda
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ class ServerTest extends PHPUnit_Framework_TestCase
{
protected static $location = null;

public function testOptions()
{
$_SERVER['HTTP_Final-Length'] = 180;
$_SERVER['REQUEST_METHOD'] = 'OPTIONS';
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['SERVER_NAME'] = 'localhost';
$_SERVER['SERVER_PORT'] = 80;

$server = new PhpTus\Server(__DIR__.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'server',
'/files/',
array('prefix' => 'php-tus-test-')
);

$response = $server->process(false);

$this->assertInstanceOf('\\Symfony\\Component\\HttpFoundation\\Response', $response);
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->headers->has('Allow'));
$this->assertRegExp('#^OPTIONS,GET,HEAD,POST,PATCH$#', $response->headers->get('Allow'));
}


public function testPost()
{
$_SERVER['HTTP_Final-Length'] = 180;
Expand Down Expand Up @@ -61,4 +83,51 @@ public function testHead($location)
$this->assertTrue($response->headers->has('Offset'));
$this->assertEquals(0, $response->headers->get('Offset'));
}


/**
* @depends testPost
*/
public function testGet($location)
{
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['SERVER_NAME'] = 'localhost';
$_SERVER['SERVER_PORT'] = 80;
$_SERVER['REQUEST_URI'] = str_replace('http://localhost', '', $location);

$server = new PhpTus\Server(__DIR__.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'server',
'/files/',
array('prefix' => 'php-tus-test-')
);

$response = $server->process(false);

$this->assertInstanceOf('\\Symfony\\Component\\HttpFoundation\\Response', $response);
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->headers->has('Content-disposition'));
$this->assertEquals('attachment; filename="'.basename($location).'"', $response->headers->get('Content-disposition'));
}


/**
* @depends testPost
* @expectedException \PhpTus\Exception\Request
* @expectedExceptionCode 404
*/
public function testFailGet($location)
{
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['SERVER_NAME'] = 'localhost';
$_SERVER['SERVER_PORT'] = 80;
$_SERVER['REQUEST_URI'] = str_replace('http://localhost', '', substr($location, 0, -1));

$server = new PhpTus\Server(__DIR__.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'server',
'/files/',
array('prefix' => 'php-tus-test-')
);

$response = $server->process(false);
}
}

0 comments on commit 23abcda

Please sign in to comment.