removed docs and test from main repository.

This commit is contained in:
Taylor Otwell
2011-07-16 10:58:49 -05:00
parent 60ff3bf840
commit 7d50f5f96d
32 changed files with 0 additions and 3146 deletions

View File

@@ -1,31 +0,0 @@
<?php
// --------------------------------------------------------------
// Define the framework paths.
// --------------------------------------------------------------
define('BASE_PATH', realpath('../').'/');
define('APP_PATH', realpath('../application').'/');
define('SYS_PATH', realpath('../system').'/');
define('PUBLIC_PATH', realpath('../public').'/');
define('PACKAGE_PATH', APP_PATH.'packages/');
// --------------------------------------------------------------
// Define the PHP file extension.
// --------------------------------------------------------------
define('EXT', '.php');
// --------------------------------------------------------------
// Load the classes used by the auto-loader.
// --------------------------------------------------------------
require SYS_PATH.'config'.EXT;
require SYS_PATH.'arr'.EXT;
// --------------------------------------------------------------
// Load the test utilities.
// --------------------------------------------------------------
require 'utils'.EXT;
// --------------------------------------------------------------
// Register the auto-loader.
// --------------------------------------------------------------
spl_autoload_register(require SYS_PATH.'loader'.EXT);

View File

@@ -1,7 +0,0 @@
<phpunit colors="true" bootstrap="bootstrap.php">
<testsuites>
<testsuite name="Laravel Tests">
<directory>suite</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@@ -1,17 +0,0 @@
<?php
class ArrTest extends PHPUnit_Framework_TestCase {
public function testReturnsDefaultWhenItemNotPresentInArray()
{
$this->assertNull(System\Arr::get(array(), 'name'));
$this->assertEquals(System\Arr::get(array(), 'name', 'test'), 'test');
$this->assertEquals(System\Arr::get(array(), 'name', function() {return 'test';}), 'test');
}
public function testReturnsItemWhenPresentInArray()
{
$this->assertEquals(System\Arr::get(array('name' => 'test'), 'name'), 'test');
}
}

View File

@@ -1,178 +0,0 @@
<?php
class InputTest extends PHPUnit_Framework_TestCase {
public static function setUpBeforeClass()
{
System\Input::$input = null;
}
public static function tearDownAfterClass()
{
System\Config::set('session.driver', '');
System\Session::$session = array();
}
public function setUp()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
}
public function tearDown()
{
System\Input::$input = null;
}
/**
* @dataProvider inputByMethodProvider
*/
public function testInputShouldHydrateBasedOnRequestMethod($method, $data)
{
$_SERVER['REQUEST_METHOD'] = $method;
$_GET = $data;
$_POST = $data;
$this->assertEquals(System\Input::get(), $data);
}
public function inputByMethodProvider()
{
return array(
array('GET', array('method' => 'GET')),
array('POST', array('method' => 'POST')),
);
}
/**
* @dataProvider inputBySpoofedMethodProvider
*/
public function testInputShouldHydrateBasedOnSpoofedRequestMethod($method, $data)
{
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST = $data;
$this->assertEquals(System\Input::get(), $data);
}
public function inputBySpoofedMethodProvider()
{
return array(
array('PUT', array('request_method' => 'PUT', 'method' => 'PUT')),
array('DELETE', array('request_method' => 'DELETE', 'method' => 'DELETE')),
);
}
public function testHasMethodReturnsTrueIfItemIsPresentInInputData()
{
System\Input::$input = array('name' => 'taylor');
$this->assertTrue(System\Input::has('name'));
}
public function testHasMethodReturnsFalseIfItemIsNotPresentInInputData()
{
System\Input::$input = array();
$this->assertFalse(System\Input::has('name'));
}
public function testHasMethodReturnsFalseIfItemIsInInputButIsEmptyString()
{
System\Input::$input = array('name' => '');
$this->assertFalse(System\Input::has('name'));
}
public function testGetMethodReturnsItemByInputKey()
{
System\Input::$input = array('name' => 'taylor');
$this->assertEquals(System\Input::get('name'), 'taylor');
}
public function testGetMethodReturnsDefaultValueWhenItemDoesntExist()
{
System\Input::$input = array();
$this->assertNull(System\Input::get('name'));
$this->assertEquals(System\Input::get('name', 'test'), 'test');
$this->assertEquals(System\Input::get('name', function() {return 'test';}), 'test');
$this->assertTrue(is_array(System\Input::get()) and count(System\Input::get()) == 0);
}
public function testGetMethodReturnsEntireInputArrayWhenNoKeyGiven()
{
System\Input::$input = array('name' => 'taylor', 'age' => 25);
$this->assertEquals(System\Input::get(), System\Input::$input);
}
public function testFileMethodReturnsItemFromGlobalFilesArray()
{
$_FILES['test'] = array('name' => 'taylor');
$this->assertEquals(System\Input::file('test'), $_FILES['test']);
}
public function testFileMethodReturnsSpecificItemFromFileArrayWhenSpecified()
{
$_FILES['test'] = array('size' => 500);
$this->assertEquals(System\Input::file('test.size'), 500);
}
public function testAllMethodReturnsBothGetAndFileArrays()
{
$_GET['name'] = 'test';
$_FILES['picture'] = array();
$this->assertArrayHasKey('name', System\Input::all());
$this->assertArrayHasKey('picture', System\Input::all());
}
/**
* @expectedException Exception
*/
public function testOldMethodShouldThrowExceptionWhenSessionsArentEnabled()
{
System\Input::old();
}
/**
* @expectedException Exception
*/
public function testHadMethodShouldThrowExceptionWhenSessionsArentEnabled()
{
System\Input::has();
}
public function testOldMethodShouldReturnOldInputDataFromSession()
{
System\Config::set('session.driver', 'test');
System\Session::$session['data']['laravel_old_input'] = array('name' => 'taylor');
$this->assertEquals(System\Input::old('name'), 'taylor');
}
public function testOldMethodReturnsDefaultValueWhenItemDoesntExist()
{
System\Config::set('session.driver', 'test');
System\Session::$session['data']['laravel_old_input'] = array();
$this->assertNull(System\Input::old('name'));
$this->assertEquals(System\Input::old('name', 'test'), 'test');
$this->assertEquals(System\Input::old('name', function() {return 'test';}), 'test');
$this->assertTrue(is_array(System\Input::old()) and count(System\Input::old()) == 0);
}
public function testHadMethodReturnsTrueIfItemIsPresentInOldInputData()
{
System\Config::set('session.driver', 'test');
System\Session::$session['data']['laravel_old_input'] = array('name' => 'taylor');
$this->assertTrue(System\Input::had('name'));
}
public function testHadMethodReturnsFalseIfItemIsNotPresentInOldInputData()
{
System\Config::set('session.driver', 'test');
System\Session::$session['data']['laravel_old_input'] = array();
$this->assertFalse(System\Input::had('name'));
}
}

View File

@@ -1,172 +0,0 @@
<?php
class RequestTest extends PHPUnit_Framework_TestCase {
public function setUp()
{
unset($_SERVER['PATH_INFO'], $_SERVER['REQUEST_METHOD']);
$route = new System\Route(null, null);
$route->callback = array('name' => 'test', 'do' => function() {});
System\Request::$route = $route;
}
public function tearDown()
{
System\Request::$route = null;
}
/**
* @expectedException Exception
*/
public function testUriMethodThrowsExceptionWhenCantDetermineUri()
{
System\Request::uri();
}
public function testUriMethodReturnsPathInfoWhenSet()
{
$_SERVER['PATH_INFO'] = 'test';
$_SERVER['REQUEST_METHOD'] = 'blah';
$this->assertEquals(System\Request::uri(), 'test');
}
/**
* @dataProvider rootUriProvider1
*/
public function testUriMethodReturnsSingleSlashOnRequestForRoot($uri)
{
Config::set('application.url', 'http://example.com');
Config::set('appliation.index', '');
$_SERVER['REQUEST_URI'] = $uri;
$this->assertEquals(System\Request::uri(), '/');
}
public function rootUriProvider1()
{
return array(
array(''),
array('/'),
array('/index.php'),
array('/index.php/'),
array('/index.php///'),
array('http://example.com'),
array('http://example.com/'),
);
}
/**
* @dataProvider rootUriProvider2
*/
public function testUriMethodReturnsSingleSlashOnRequestForFolderNestedRoot($uri)
{
Config::set('application.url', 'http://example.com/laravel/public');
Config::set('appliation.index', 'index.php');
$_SERVER['REQUEST_URI'] = $uri;
$this->assertEquals(System\Request::uri(), '/');
}
public function rootUriProvider2()
{
return array(
array('http://example.com/laravel/public'),
array('http://example.com/laravel/public/index.php'),
array('http://example.com/laravel/public/index.php/'),
array('http://example.com/laravel/public/index.php///'),
array(''),
array('/'),
array('/index.php'),
array('/index.php/'),
array('/index.php///'),
array('http://example.com'),
array('http://example.com/'),
);
}
/**
* @dataProvider segmentedUriProvider1
*/
public function testUriMethodReturnsSegmentForSingleSegmentUri($uri)
{
Config::set('application.url', 'http://example.com');
Config::set('appliation.index', '');
$_SERVER['REQUEST_URI'] = $uri;
$this->assertEquals(System\Request::uri(), 'user');
}
public function segmentedUriProvider1()
{
return array(
array('http://example.com/user'),
array('http://example.com/user/'),
array('http://example.com/user//'),
);
}
/**
* @dataProvider segmentedUriProvider2
*/
public function testUriMethodReturnsSegmentsForMultiSegmentUri($uri)
{
Config::set('application.url', 'http://example.com');
Config::set('appliation.index', '');
$_SERVER['REQUEST_URI'] = $uri;
$this->assertEquals(System\Request::uri(), 'user/something');
}
public function segmentedUriProvider2()
{
return array(
array('http://example.com/user/something'),
array('http://example.com/user/something/'),
array('http://example.com/user/something//'),
);
}
public function testMethodForNonSpoofedRequests()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
$this->assertEquals(System\Request::method(), 'GET');
}
public function testMethodForSpoofedRequests()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
$_POST['REQUEST_METHOD'] = 'PUT';
$this->assertEquals(System\Request::method(), 'PUT');
$_POST['REQUEST_METHOD'] = 'DELETE';
$this->assertEquals(System\Request::method(), 'DELETE');
}
public function testRouteIsReturnsFalseWhenNoSuchNamedRouteExists()
{
$route = new System\Route(null, null);
$route->callback = function() {};
System\Request::$route = $route;
$this->assertFalse(System\Request::route_is('test'));
$this->assertFalse(System\Request::route_is_test());
}
public function testRouteIsReturnsFalseWhenWrongRouteNameIsGiven()
{
$this->assertFalse(System\Request::route_is('something'));
$this->assertFalse(System\Request::route_is_something());
}
public function testRouteIsReturnsTrueWhenNamedRouteExists()
{
$this->assertTrue(System\Request::route_is('test'));
$this->assertTrue(System\Request::route_is_test());
}
}

View File

@@ -1,45 +0,0 @@
<?php
class RouteFilerTest extends PHPUnit_Framework_TestCase {
public static function setUpBeforeClass()
{
$filters = array(
'test' => function() {return 'test';},
'vars' => function($var) {return $var;},
'vars2' => function($var1, $var2) {return $var1.$var2;},
);
System\Route\Filter::$filters = $filters;
}
public static function tearDownAfterClass()
{
System\Route\Filter::$filters = require APP_PATH.'filters'.EXT;
}
/**
* @expectedException Exception
*/
public function testCallingUndefinedFilterThrowsException()
{
System\Route\Filter::call('not-found');
}
public function testCallingFilterWithoutOverrideReturnsNull()
{
$this->assertNull(System\Route\Filter::call('test'));
}
public function testCallingFilterWithOverrideReturnsResult()
{
$this->assertEquals(System\Route\Filter::call('test', array(), true), 'test');
}
public function testCallingFilterWithParametersPassesParametersToFilter()
{
$this->assertEquals(System\Route\Filter::call('vars', array('test'), true), 'test');
$this->assertEquals(System\Route\Filter::call('vars2', array('test1', 'test2'), true), 'test1test2');
}
}

View File

@@ -1,42 +0,0 @@
<?php
class RouteFinderTest extends PHPUnit_Framework_TestCase {
public static function setUpBeforeClass()
{
$routes = array();
$routes['GET /home'] = array('GET /home' => array('name' => 'home', 'do' => function() {}));
$routes['GET /user'] = array('GET /user' => array('name' => 'user', 'do' => function() {}));
System\Route\Finder::$routes = $routes;
}
public function testRouteFinderReturnsNullWhenRouteIsNotFound()
{
$this->assertNull(System\Route\Finder::find('doesnt-exist'));
}
public function testRouteFinderReturnsRouteWhenFoundInSingleRoutesFile()
{
$this->assertArrayHasKey('GET /home', System\Route\Finder::find('home'));
$this->assertArrayHasKey('GET /user', System\Route\Finder::find('user'));
}
public function testRouteFinderLoadsRoutesFromRouteDirectoryToFindRoutes()
{
System\Route\Finder::$routes = null;
$this->setupRoutesDirectory();
$this->assertArrayHasKey('GET /user', System\Route\Finder::find('user'));
Utils::rrmdir(APP_PATH.'routes');
}
private function setupRoutesDirectory()
{
mkdir(APP_PATH.'routes', 0777);
file_put_contents(APP_PATH.'routes/user.php', "<?php return array('GET /user' => array('name' => 'user', 'do' => function() {return '/user';})); ?>", LOCK_EX);
}
}

View File

@@ -1,56 +0,0 @@
<?php
class RouteTest extends PHPUnit_Framework_TestCase {
public function testSimpleRouteCallbackReturnsResponseInstance()
{
$route = new System\Route('GET /', function() {return 'test';});
$this->assertInstanceOf('System\\Response', $route->call());
$this->assertEquals($route->call()->content, 'test');
}
public function testRouteCallPassesParametersToCallback()
{
$route = new System\Route('GET /', function($parameter) {return $parameter;}, array('test'));
$this->assertEquals($route->call()->content, 'test');
$route = new System\Route('GET /', function($parameter1, $parameter2) {return $parameter1.$parameter2;}, array('test1', 'test2'));
$this->assertEquals($route->call()->content, 'test1test2');
}
public function testRouteCallWithNullBeforeFilterReturnsRouteResponse()
{
$route = new System\Route('GET /', array('before' => 'test', 'do' => function() {return 'route';}));
System\Route\Filter::$filters = array('test' => function() {return null;});
$this->assertEquals($route->call()->content, 'route');
}
public function testRouteCallWithOverridingBeforeFilterReturnsFilterResponse()
{
$route = new System\Route('GET /', array('before' => 'test', 'do' => function() {return 'route';}));
System\Route\Filter::$filters = array('test' => function() {return 'filter';});
$this->assertEquals($route->call()->content, 'filter');
}
public function testRouteAfterFilterIsCalled()
{
$route = new System\Route('GET /', array('after' => 'test', 'do' => function() {return 'route';}));
System\Route\Filter::$filters = array('test' => function() {define('LARAVEL_TEST_AFTER_FILTER', 'ran');});
$route->call();
$this->assertTrue(defined('LARAVEL_TEST_AFTER_FILTER'));
}
public function testRouteAfterFilterDoesNotAffectResponse()
{
$route = new System\Route('GET /', array('after' => 'test', 'do' => function() {return 'route';}));
System\Route\Filter::$filters = array('test' => function() {return 'filter';});
$this->assertEquals($route->call()->content, 'route');
}
}

View File

@@ -1,125 +0,0 @@
<?php
class RoutingTest extends PHPUnit_Framework_TestCase {
public static function setUpBeforeClass()
{
$routes = array();
$routes['GET /'] = array('name' => 'root', 'do' => function() {});
$routes['GET /home'] = array('name' => 'home', 'do' => function() {});
$routes['POST /home'] = array('name' => 'post-home', 'do' => function() {});
$routes['GET /user/(:num)'] = array('name' => 'user', 'do' => function() {});
$routes['GET /user/(:any)/(:num)/edit'] = array('name' => 'edit', 'do' => function() {});
$routes['GET /cart/(:num?)'] = array('name' => 'cart', 'do' => function() {});
$routes['GET /download/(:num?)/(:any?)'] = array('name' => 'download', 'do' => function() {});
System\Router::$routes = $routes;
}
public static function tearDownAfterClass()
{
System\Router::$routes = null;
}
public function tearDown()
{
Utils::rrmdir(APP_PATH.'routes');
}
public function testRouterReturnsNullWhenNotFound()
{
$this->assertNull(System\Router::route('GET', 'doesnt-exist'));
}
public function testRouterRoutesToRootWhenItIsRequest()
{
$this->assertEquals(System\Router::route('GET', '/')->callback['name'], 'root');
}
public function testRouterRoutesToProperRouteWhenSegmentsArePresent()
{
$this->assertEquals(System\Router::route('GET', 'home')->callback['name'], 'home');
$this->assertEquals(System\Router::route('GET', 'user/1')->callback['name'], 'user');
$this->assertEquals(System\Router::route('GET', 'user/taylor/25/edit')->callback['name'], 'edit');
$this->assertEquals(System\Router::route('POST', 'home')->callback['name'], 'post-home');
}
public function testRouterGivesRouteProperSegmentsWhenTheyArePresent()
{
$this->assertEquals(System\Router::route('GET', 'user/1')->parameters[0], 1);
$this->assertEquals(count(System\Router::route('GET', 'user/1')->parameters), 1);
$this->assertEquals(System\Router::route('GET', 'user/taylor/25/edit')->parameters[0], 'taylor');
$this->assertEquals(System\Router::route('GET', 'user/taylor/25/edit')->parameters[1], 25);
$this->assertEquals(count(System\Router::route('GET', 'user/taylor/25/edit')->parameters), 2);
}
public function testRouterRoutesToProperRouteWhenUsingOptionalSegments()
{
$this->assertEquals(System\Router::route('GET', 'cart')->callback['name'], 'cart');
$this->assertEquals(System\Router::route('GET', 'cart/1')->callback['name'], 'cart');
$this->assertEquals(System\Router::route('GET', 'download')->callback['name'], 'download');
$this->assertEquals(System\Router::route('GET', 'download/1')->callback['name'], 'download');
$this->assertEquals(System\Router::route('GET', 'download/1/a')->callback['name'], 'download');
}
public function testRouterGivesRouteProperOptionalSegmentsWhenTheyArePresent()
{
$this->assertTrue(is_array(System\Router::route('GET', 'cart')->parameters));
$this->assertEquals(count(System\Router::route('GET', 'cart')->parameters), 0);
$this->assertEquals(System\Router::route('GET', 'cart/1')->parameters[0], 1);
$this->assertEquals(count(System\Router::route('GET', 'download')->parameters), 0);
$this->assertEquals(System\Router::route('GET', 'download/1')->parameters[0], 1);
$this->assertEquals(count(System\Router::route('GET', 'download/1')->parameters), 1);
$this->assertEquals(System\Router::route('GET', 'download/1/a')->parameters[0], 1);
$this->assertEquals(System\Router::route('GET', 'download/1/a')->parameters[1], 'a');
$this->assertEquals(count(System\Router::route('GET', 'download/1/a')->parameters), 2);
}
public function testRouterReturnsNullWhenRouteNotFound()
{
$this->assertNull(System\Router::route('GET', 'user/taylor/taylor/edit'));
$this->assertNull(System\Router::route('GET', 'user/taylor'));
$this->assertNull(System\Router::route('GET', 'user/12-3'));
$this->assertNull(System\Router::route('GET', 'cart/a'));
$this->assertNull(System\Router::route('GET', 'cart/12-3'));
$this->assertNull(System\Router::route('GET', 'download/a'));
$this->assertNull(System\Router::route('GET', 'download/1a'));
$this->assertNull(System\Router::route('POST', 'user/taylor/25/edit'));
}
public function testRouteLoaderShouldReturnSingleRoutesFileWhenNoFolderIsPresent()
{
$routes = System\Router::load('test');
// Only the Laravel default route should be returned.
$this->assertArrayHasKey('GET /', $routes);
}
public function testRouteLoaderLoadsRouteFilesInRouteDirectoryByURI()
{
$this->setupRoutesDirectory();
$this->assertArrayHasKey('GET /user', System\Router::load('user'));
$this->assertArrayHasKey('GET /cart/edit', System\Router::load('cart'));
$this->assertArrayHasKey('GET /cart/edit', System\Router::load('cart/edit'));
}
public function testRouteLoaderLoadsBaseRoutesFileForEveryRequest()
{
$this->setupRoutesDirectory();
$this->assertArrayHasKey('GET /', System\Router::load('user'));
}
private function setupRoutesDirectory()
{
mkdir(APP_PATH.'routes', 0777);
file_put_contents(APP_PATH.'routes/user.php', "<?php return array('GET /user' => function() {return '/user';}); ?>", LOCK_EX);
file_put_contents(APP_PATH.'routes/cart.php', "<?php return array('GET /cart/edit' => function() {return '/cart/edit';}); ?>", LOCK_EX);
}
}

View File

@@ -1,51 +0,0 @@
<?php
class ViewTest extends PHPUnit_Framework_TestCase {
public function testConstructorSetsViewNameAndData()
{
$view = new System\View('view', array('name' => 'test'));
$this->assertEquals($view->view, 'view');
$this->assertEquals($view->data, array('name' => 'test'));
$view = new System\View('view');
$this->assertEquals($view->data, array());
}
public function testMakeMethodReturnsNewViewInstance()
{
$this->assertInstanceOf('System\\View', System\View::make('test'));
}
public function testBindMethodAddsItemToViewData()
{
$view = System\View::make('test')->bind('name', 'test');
$this->assertEquals($view->data, array('name' => 'test'));
}
public function testBoundViewDataCanBeRetrievedThroughMagicMethods()
{
$view = System\View::make('test')->bind('name', 'test');
$this->assertTrue(isset($view->name));
$this->assertEquals($view->name, 'test');
unset($view->name);
$this->assertFalse(isset($view->name));
}
public function testGetMethodReturnsStringContentOfView()
{
$this->assertTrue(is_string(System\View::make('home/index')->get()));
}
/**
* @expectedException Exception
*/
public function testExceptionIsThrownWhenViewDoesntExist()
{
System\View::make('doesnt-exist')->get();
}
}

View File

@@ -1,30 +0,0 @@
<?php
class Utils {
/**
* Recursively remove a directory.
*
* @param string $directory
* @return void
*/
public static function rrmdir($directory)
{
if (is_dir($directory))
{
$objects = scandir($directory);
foreach ($objects as $object)
{
if ($object != "." && $object != "..")
{
if (filetype($directory."/".$object) == "dir") static::rrmdir($directory."/".$object); else unlink($directory."/".$object);
}
}
reset($objects);
rmdir($directory);
}
}
}