Moved tests and updated to use namespaces
This commit is contained in:
parent
302f400dcb
commit
0cfc2c7979
26 changed files with 686 additions and 683 deletions
|
@ -1,31 +1,31 @@
|
|||
<?php
|
||||
|
||||
class BrowserTest extends PHPUnit_Framework_TestCase
|
||||
class BrowserTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testRemoteIPNone()
|
||||
{
|
||||
$this->assertFalse(Browser::remoteIP());
|
||||
$this->assertFalse(Pickles\Browser::remoteIP());
|
||||
}
|
||||
|
||||
public function testRemoteIPRemoteAddress()
|
||||
{
|
||||
$_SERVER['REMOTE_ADDR'] = '1.2.3.4';
|
||||
|
||||
$this->assertEquals('1.2.3.4', Browser::remoteIP());
|
||||
$this->assertEquals('1.2.3.4', Pickles\Browser::remoteIP());
|
||||
}
|
||||
|
||||
public function testRemoteIPHTTPXForwardedFor()
|
||||
{
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '2.3.4.5';
|
||||
|
||||
$this->assertEquals('2.3.4.5', Browser::remoteIP());
|
||||
$this->assertEquals('2.3.4.5', Pickles\Browser::remoteIP());
|
||||
}
|
||||
|
||||
public function testRemoteIPHTTPClientIP()
|
||||
{
|
||||
$_SERVER['HTTP_CLIENT_IP'] = '3.4.5.6';
|
||||
|
||||
$this->assertEquals('3.4.5.6', Browser::remoteIP());
|
||||
$this->assertEquals('3.4.5.6', Pickles\Browser::remoteIP());
|
||||
}
|
||||
|
||||
public function testRemoteIPWithComma()
|
||||
|
@ -35,31 +35,31 @@ class BrowserTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testStatus1xx()
|
||||
{
|
||||
Browser::status(100);
|
||||
Pickles\Browser::status(100);
|
||||
$this->assertTrue(in_array('Status: 100 Continue', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testStatus2xx()
|
||||
{
|
||||
Browser::status(200);
|
||||
Pickles\Browser::status(200);
|
||||
$this->assertTrue(in_array('Status: 200 OK', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testStatus3xx()
|
||||
{
|
||||
Browser::status(300);
|
||||
Pickles\Browser::status(300);
|
||||
$this->assertTrue(in_array('Status: 300 Multiple Choices', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testStatus4xx()
|
||||
{
|
||||
Browser::status(400);
|
||||
Pickles\Browser::status(400);
|
||||
$this->assertTrue(in_array('Status: 400 Bad Request', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testStatus5xx()
|
||||
{
|
||||
Browser::status(500);
|
||||
Pickles\Browser::status(500);
|
||||
$this->assertTrue(in_array('Status: 500 Internal Server Error', xdebug_get_headers()));
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ class CacheTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
$this->config = Pickles\Config::getInstance();
|
||||
$this->config->data['pickles']['cache'] = 'mc';
|
||||
$this->config->data['datasources']['mc'] = [
|
||||
'type' => 'memcache',
|
||||
|
@ -16,18 +16,18 @@ class CacheTest extends PHPUnit_Framework_TestCase
|
|||
'namespace' => 'ns',
|
||||
];
|
||||
|
||||
$this->cache = Cache::getInstance();
|
||||
$this->cache = Pickles\Cache::getInstance();
|
||||
}
|
||||
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->assertInstanceOf('Cache', $this->cache);
|
||||
$this->assertInstanceOf('Pickles\\Cache', $this->cache);
|
||||
}
|
||||
|
||||
public function testSetAndGet()
|
||||
{
|
||||
$key = String::random();
|
||||
$value = String::random();
|
||||
$key = Pickles\String::random();
|
||||
$value = Pickles\String::random();
|
||||
|
||||
$this->cache->set($key, $value);
|
||||
|
||||
|
@ -40,8 +40,8 @@ class CacheTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
for ($i = 0; $i < 5; $i++)
|
||||
{
|
||||
$keys[] = String::random();
|
||||
$values[] = String::random();
|
||||
$keys[] = Pickles\String::random();
|
||||
$values[] = Pickles\String::random();
|
||||
}
|
||||
|
||||
foreach ($keys as $key => $key_name)
|
||||
|
@ -56,8 +56,8 @@ class CacheTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testDelete()
|
||||
{
|
||||
$key = String::random();
|
||||
$value = String::random();
|
||||
$key = Pickles\String::random();
|
||||
$value = Pickles\String::random();
|
||||
|
||||
$this->cache->set($key, $value);
|
||||
$this->cache->delete($key);
|
||||
|
@ -67,7 +67,7 @@ class CacheTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testIncrement()
|
||||
{
|
||||
$key = String::random();
|
||||
$key = Pickles\String::random();
|
||||
|
||||
$this->assertFalse($this->cache->increment($key));
|
||||
|
|
@ -6,7 +6,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
$this->config = Pickles\Config::getInstance();
|
||||
setupConfig([]);
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
|
@ -14,14 +14,14 @@ class ConfigTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testConfigProperty()
|
||||
{
|
||||
$config = new Config();
|
||||
$config = new Pickles\Config();
|
||||
|
||||
$this->assertTrue(PHPUnit_Framework_Assert::readAttribute($config, 'config'));
|
||||
}
|
||||
|
||||
public function testInstanceOf()
|
||||
{
|
||||
$this->assertInstanceOf('Config', $this->config);
|
||||
$this->assertInstanceOf('Pickles\\Config', $this->config);
|
||||
}
|
||||
|
||||
public function testUndefined()
|
||||
|
@ -35,7 +35,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
|
|||
'environment' => 'local',
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Pickles\Config();
|
||||
|
||||
$this->assertEquals('local', $config->environment);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
|
|||
],
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Pickles\Config();
|
||||
|
||||
$this->assertEquals('local', $config->environment);
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
|
|||
],
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Pickles\Config();
|
||||
|
||||
$this->assertEquals('prod', $config->environment);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
|
|||
],
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Pickles\Config();
|
||||
|
||||
$this->assertEquals('prod', $config->environment);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
setUpConfig(['environments' => []]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Pickles\Config();
|
||||
}
|
||||
|
||||
public function testProfiler()
|
||||
|
@ -106,7 +106,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
|
|||
'pickles' => ['profiler' => true],
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Pickles\Config();
|
||||
|
||||
$this->assertTrue($config->pickles['profiler']);
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
|
|||
'pickles' => ['profiler' => ['objects', 'timers']],
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Pickles\Config();
|
||||
|
||||
$this->assertEquals('objects,timers', $config->pickles['profiler']);
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
|
|||
'security' => ['levels' => [10 => 'level']],
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Pickles\Config();
|
||||
|
||||
$this->assertEquals(10, SECURITY_LEVEL_USER);
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
|
|||
'security' => ['levels' => [10 => 'level']],
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Pickles\Config();
|
||||
|
||||
$this->assertEquals(10, SECURITY_LEVEL_USER);
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
|
|||
public function testConfigArrayMissing()
|
||||
{
|
||||
file_put_contents(SITE_PATH . 'config.php', '');
|
||||
new Config();
|
||||
new Pickles\Config();
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ class ConvertTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testArrayToXML($a, $b, $c)
|
||||
{
|
||||
$this->assertEquals(Convert::arrayToXML($a, $b), $c);
|
||||
$this->assertEquals(Pickles\Convert::arrayToXML($a, $b), $c);
|
||||
}
|
||||
|
||||
public function providerArrayToXML()
|
|
@ -4,7 +4,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
|
|||
{
|
||||
public function testGetInstanceFalse()
|
||||
{
|
||||
$this->assertFalse(Database::getInstance());
|
||||
$this->assertFalse(Pickles\Database::getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,9 +13,9 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testGetInstanceDatasourceNotDefined()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config = Pickles\Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'bad';
|
||||
Database::getInstance();
|
||||
Pickles\Database::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,13 +24,13 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testGetInstanceDatasourceLacksDriver()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config = Pickles\Config::getInstance();
|
||||
$config->data['datasources'] = [
|
||||
'bad' => [
|
||||
'type' => 'mysql',
|
||||
],
|
||||
];
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
$this->assertInstanceOf('Pickles\\Database', Pickles\Database::getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,7 +39,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testOpenConfigError()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config = Pickles\Config::getInstance();
|
||||
$config->data['datasources'] = [
|
||||
'bad' => [
|
||||
'type' => 'mysql',
|
||||
|
@ -47,13 +47,13 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
|
|||
'database' => 'test',
|
||||
],
|
||||
];
|
||||
$db = Database::getInstance();
|
||||
$db = Pickles\Database::getInstance();
|
||||
$db->open();
|
||||
}
|
||||
|
||||
public function testGetInstanceDatasourcesArray()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config = Pickles\Config::getInstance();
|
||||
$config->data['datasources'] = [
|
||||
'mysql' => [
|
||||
'type' => 'mysql',
|
||||
|
@ -64,28 +64,28 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
|
|||
'database' => 'test',
|
||||
],
|
||||
];
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
$this->assertInstanceOf('Pickles\\Database', Pickles\Database::getInstance());
|
||||
}
|
||||
|
||||
// Also tests the datasource being missing and selecting the first one
|
||||
public function testGetInstanceMySQL()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config = Pickles\Config::getInstance();
|
||||
unset($config->data['pickles']['datasource']);
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
$this->assertInstanceOf('Pickles\\Database', Pickles\Database::getInstance());
|
||||
}
|
||||
|
||||
public function testOpenMySQL()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config = Pickles\Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'mysql';
|
||||
$db = Database::getInstance();
|
||||
$db = Pickles\Database::getInstance();
|
||||
$db->open();
|
||||
}
|
||||
|
||||
public function testExecute()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$db = Pickles\Database::getInstance();
|
||||
$this->assertEquals('0', $db->execute('SHOW TABLES'));
|
||||
}
|
||||
|
||||
|
@ -95,35 +95,35 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testExecuteNoQuery()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$db = Pickles\Database::getInstance();
|
||||
$db->execute(' ');
|
||||
}
|
||||
|
||||
public function testFetch()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config = Pickles\Config::getInstance();
|
||||
$config->data['pickles']['logging'] = true;
|
||||
$config->data['pickles']['profiler'] = true;
|
||||
$db = Database::getInstance();
|
||||
$db = Pickles\Database::getInstance();
|
||||
$this->assertEquals([], $db->fetch('SELECT * FROM pickles WHERE id != ?', ['0']));
|
||||
}
|
||||
|
||||
public function testExplainNoInput()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$db = Database::getInstance();
|
||||
$config = Pickles\Config::getInstance();
|
||||
$db = Pickles\Database::getInstance();
|
||||
$this->assertEquals([], $db->fetch('SELECT * FROM pickles WHERE id != 0'));
|
||||
}
|
||||
|
||||
public function testSlowQuery()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$db = Pickles\Database::getInstance();
|
||||
$this->assertEquals('0', $db->execute('SHOW DATABASES', null, true));
|
||||
}
|
||||
|
||||
public function testCloseMySQL()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$db = Pickles\Database::getInstance();
|
||||
$db->open();
|
||||
|
||||
$this->assertTrue($db->close());
|
||||
|
@ -131,7 +131,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testGetInstancePostgreSQL()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config = Pickles\Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'pgsql';
|
||||
$config->data['datasources']['pgsql'] = [
|
||||
'type' => 'pgsql',
|
||||
|
@ -141,7 +141,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
|
|||
'password' => '',
|
||||
'database' => 'test',
|
||||
];
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
$this->assertInstanceOf('Pickles\\Database', Pickles\Database::getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,14 +151,14 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
|
|||
public function testOpenPostgreSQL()
|
||||
{
|
||||
// Also throws an exception since I don't have PostgreSQL set up
|
||||
$config = Config::getInstance();
|
||||
$db = Database::getInstance();
|
||||
$config = Pickles\Config::getInstance();
|
||||
$db = Pickles\Database::getInstance();
|
||||
$db->open();
|
||||
}
|
||||
|
||||
public function testGetInstanceSQLite()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config = Pickles\Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'sqlite';
|
||||
$config->data['datasources']['sqlite'] = [
|
||||
'type' => 'sqlite',
|
||||
|
@ -168,7 +168,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
|
|||
'password' => '',
|
||||
'database' => 'test',
|
||||
];
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
$this->assertInstanceOf('Pickles\\Database', Pickles\Database::getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,7 +177,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testGetInstanceInvalidDriver()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config = Pickles\Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'invalid';
|
||||
$config->data['datasources']['invalid'] = [
|
||||
'type' => 'invalid',
|
||||
|
@ -187,7 +187,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
|
|||
'password' => '',
|
||||
'database' => 'test',
|
||||
];
|
||||
Database::getInstance();
|
||||
Pickles\Database::getInstance();
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ class DateTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testAge($a, $b)
|
||||
{
|
||||
$this->assertEquals(Date::age($a), $b);
|
||||
$this->assertEquals(Pickles\Date::age($a), $b);
|
||||
}
|
||||
|
||||
public function providerAge()
|
||||
|
@ -22,7 +22,7 @@ class DateTest extends PHPUnit_Framework_TestCase
|
|||
[date('r', $time), '25'],
|
||||
['today', '0'],
|
||||
['400 days ago', '1'],
|
||||
[true, Date::age('1969-12-31')],
|
||||
[true, Pickles\Date::age('1969-12-31')],
|
||||
];
|
||||
}
|
||||
}
|
75
tests/DistanceTest.php
Normal file
75
tests/DistanceTest.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
class DistanceTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConvertKilometersToMiles()
|
||||
{
|
||||
$this->assertEquals(0.621371, Pickles\Distance::kilometersToMiles(1));
|
||||
}
|
||||
|
||||
public function testConvertKilometersToMeters()
|
||||
{
|
||||
$this->assertEquals(1000, Pickles\Distance::kilometersToMeters(1));
|
||||
}
|
||||
|
||||
public function testConvertKilometersToYards()
|
||||
{
|
||||
$this->assertEquals(1093.61, Pickles\Distance::kilometersToYards(1));
|
||||
}
|
||||
|
||||
public function testConvertMilesToKilometers()
|
||||
{
|
||||
$this->assertEquals(1.60934, Pickles\Distance::milesToKilometers(1));
|
||||
}
|
||||
|
||||
public function testConvertMilesToMeters()
|
||||
{
|
||||
$this->assertEquals(1609.34, Pickles\Distance::milesToMeters(1));
|
||||
}
|
||||
|
||||
public function testConvertMilesToYards()
|
||||
{
|
||||
$this->assertEquals(1760, Pickles\Distance::milesToYards(1));
|
||||
}
|
||||
|
||||
public function testConvertMetersToKilometers()
|
||||
{
|
||||
$this->assertEquals(0.001, Pickles\Distance::metersToKilometers(1));
|
||||
}
|
||||
|
||||
public function testConvertMetersToMiles()
|
||||
{
|
||||
$this->assertEquals(0.000621371, Pickles\Distance::metersToMiles(1));
|
||||
}
|
||||
|
||||
public function testConvertMetersToYards()
|
||||
{
|
||||
$this->assertEquals(1.09361, Pickles\Distance::metersToYards(1));
|
||||
}
|
||||
|
||||
public function testCalculateDistanceMiles()
|
||||
{
|
||||
$this->assertEquals(1003.2646776326, Pickles\Distance::calculateDistance(27.947222, -82.458611, 40.67, -73.94));
|
||||
}
|
||||
|
||||
public function testCalculateDistanceKilometers()
|
||||
{
|
||||
$this->assertEquals(1614.5939763012, Pickles\Distance::calculateDistance(27.947222, -82.458611, 40.67, -73.94, 'kilometers'));
|
||||
}
|
||||
|
||||
public function testCalculateDistanceMeters()
|
||||
{
|
||||
$this->assertEquals(1614593.9763012, Pickles\Distance::calculateDistance(27.947222, -82.458611, 40.67, -73.94, 'meters'), '', 0.2);
|
||||
}
|
||||
|
||||
public function testCalculateDistanceYards()
|
||||
{
|
||||
$this->assertEquals(1765745.8326334, Pickles\Distance::calculateDistance(27.947222, -82.458611, 40.67, -73.94, 'yards'), '', 0.2);
|
||||
}
|
||||
|
||||
public function testNotEnoughUnits()
|
||||
{
|
||||
$this->assertFalse(Pickles\Distance::milesTo(123));
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ class FileTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
File::removeDirectory('/tmp/pickles-fs');
|
||||
Pickles\File::removeDirectory('/tmp/pickles-fs');
|
||||
}
|
||||
|
||||
public function testRemoveDirectory()
|
||||
|
@ -26,7 +26,7 @@ class FileTest extends PHPUnit_Framework_TestCase
|
|||
touch($directory . 'test/ing');
|
||||
touch($directory . 'test/test/ing');
|
||||
|
||||
File::removeDirectory($directory);
|
||||
Pickles\File::removeDirectory($directory);
|
||||
|
||||
$this->assertFalse(file_exists($directory));
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class FileTest extends PHPUnit_Framework_TestCase
|
|||
mkdir($directory, 0777, true);
|
||||
touch(SITE_PATH . 'missing/slash');
|
||||
|
||||
File::removeDirectory($directory);
|
||||
Pickles\File::removeDirectory($directory);
|
||||
|
||||
$this->assertFalse(file_exists($directory));
|
||||
}
|
||||
|
@ -51,11 +51,11 @@ class FileTest extends PHPUnit_Framework_TestCase
|
|||
mkdir($directory, 0777, true);
|
||||
touch($file);
|
||||
|
||||
File::removeDirectory($file);
|
||||
Pickles\File::removeDirectory($file);
|
||||
|
||||
$this->assertFalse(file_exists($file));
|
||||
|
||||
File::removeDirectory($directory);
|
||||
Pickles\File::removeDirectory($directory);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +1,20 @@
|
|||
<?php
|
||||
|
||||
class MockModelWithoutColumns extends Model
|
||||
class MockModelWithoutColumns extends Pickles\Model
|
||||
{
|
||||
public $table = 'pickles';
|
||||
public $columns = false;
|
||||
}
|
||||
|
||||
// InnoDB
|
||||
class MockModel extends Model
|
||||
class MockModel extends Pickles\Model
|
||||
{
|
||||
public $table = 'pickles';
|
||||
public $columns = ['created_at' => 'created_at'];
|
||||
}
|
||||
|
||||
// MyISAM
|
||||
class MyMockModel extends Model
|
||||
class MyMockModel extends Pickles\Model
|
||||
{
|
||||
public $table = 'mypickles';
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
public static function setUpBeforeClass()
|
||||
{
|
||||
// Clears out the Config for ease of testing
|
||||
Object::$instances = [];
|
||||
$config = Config::getInstance();
|
||||
Pickles\Object::$instances = [];
|
||||
$config = Pickles\Config::getInstance();
|
||||
|
||||
$config->data = [
|
||||
'pickles' => [
|
||||
|
@ -69,7 +69,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testNoTable()
|
||||
{
|
||||
new Model();
|
||||
new Pickles\Model();
|
||||
}
|
||||
|
||||
public function testWithoutColumns()
|
||||
|
@ -232,7 +232,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
for ($i = 1; $i <= 5; $i++)
|
||||
{
|
||||
$model->record['field' . $i] = String::random();
|
||||
$model->record['field' . $i] = Pickles\String::random();
|
||||
}
|
||||
|
||||
$model->commit();
|
||||
|
@ -246,7 +246,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
{
|
||||
for ($j = 1; $j <= 5; $j++)
|
||||
{
|
||||
$model->record['field' . $j] = String::random();
|
||||
$model->record['field' . $j] = Pickles\String::random();
|
||||
}
|
||||
|
||||
$model->queue();
|
||||
|
@ -365,7 +365,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testCommitSingleRecord()
|
||||
{
|
||||
$value = String::random();
|
||||
$value = Pickles\String::random();
|
||||
$model = new MockModel(1);
|
||||
$model->record['field1'] = $value;
|
||||
$model->commit();
|
||||
|
@ -379,7 +379,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
// else it just takes a shit because the ID isn't injected back in.
|
||||
public function testCommitSingleRecordReplace()
|
||||
{
|
||||
$value = String::random();
|
||||
$value = Pickles\String::random();
|
||||
$model = new MockModel(1);
|
||||
$model->replace = true;
|
||||
$model->record['field1'] = $value;
|
||||
|
@ -389,7 +389,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testCommitInsertPriority()
|
||||
{
|
||||
$value = String::random();
|
||||
$value = Pickles\String::random();
|
||||
$model = new MockModel();
|
||||
$model->priority = 'low';
|
||||
$model->record['field1'] = $value;
|
||||
|
@ -400,7 +400,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testCommitInsertDelayed()
|
||||
{
|
||||
$value = String::random();
|
||||
$value = Pickles\String::random();
|
||||
$model = new MyMockModel();
|
||||
$model->delayed = true;
|
||||
$model->record['field1'] = $value;
|
||||
|
@ -411,7 +411,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testCommitInsertIgnore()
|
||||
{
|
||||
$value = String::random();
|
||||
$value = Pickles\String::random();
|
||||
$model = new MockModel();
|
||||
$model->ignore = true;
|
||||
$model->record['field1'] = $value;
|
||||
|
@ -422,7 +422,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testCommitReplacePriority()
|
||||
{
|
||||
$value = String::random();
|
||||
$value = Pickles\String::random();
|
||||
$model = new MockModel();
|
||||
$model->replace = true;
|
||||
$model->priority = 'low';
|
||||
|
@ -434,7 +434,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testCommitReplaceDelayed()
|
||||
{
|
||||
$value = String::random();
|
||||
$value = Pickles\String::random();
|
||||
$model = new MyMockModel();
|
||||
$model->replace = true;
|
||||
$model->delayed = true;
|
||||
|
@ -446,7 +446,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testCommitReplaceIgnore()
|
||||
{
|
||||
$value = String::random();
|
||||
$value = Pickles\String::random();
|
||||
$model = new MockModel();
|
||||
$model->replace = true;
|
||||
$model->ignore = true;
|
||||
|
@ -458,8 +458,8 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testCommitMultipleFields()
|
||||
{
|
||||
$value1 = String::random();
|
||||
$value2 = String::random();
|
||||
$value1 = Pickles\String::random();
|
||||
$value2 = Pickles\String::random();
|
||||
$model = new MockModelWithoutColumns(1);
|
||||
$model->record['field1'] = $value1;
|
||||
$model->record['field2'] = $value2;
|
||||
|
@ -484,7 +484,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
public function testCommitUpdatedID()
|
||||
{
|
||||
$_SESSION['__pickles']['security']['user_id'] = 1;
|
||||
$value = String::random();
|
||||
$value = Pickles\String::random();
|
||||
$model = new MockModel(1);
|
||||
$model->record['field1'] = $value;
|
||||
$model->commit();
|
||||
|
@ -496,7 +496,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
public function testCommitCreatedID()
|
||||
{
|
||||
$_SESSION['__pickles']['security']['user_id'] = 1;
|
||||
$value = String::random();
|
||||
$value = Pickles\String::random();
|
||||
$model = new MockModel();
|
||||
$model->record['field1'] = $value;
|
||||
$id = $model->commit();
|
||||
|
@ -508,7 +508,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
public function testCommitInsertPostgreSQL()
|
||||
{
|
||||
$_SESSION['__pickles']['security']['user_id'] = 1;
|
||||
$value = String::random();
|
||||
$value = Pickles\String::random();
|
||||
$model = new MockModel();
|
||||
$model->mysql = false;
|
||||
$model->postgresql = true;
|
||||
|
@ -530,7 +530,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
public function testCommitUpdatePostgreSQL()
|
||||
{
|
||||
$_SESSION['__pickles']['security']['user_id'] = 1;
|
||||
$value = String::random();
|
||||
$value = Pickles\String::random();
|
||||
$model = new MockModel(1);
|
||||
$model->mysql = false;
|
||||
$model->postgresql = true;
|
||||
|
@ -593,7 +593,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
for ($i = 0; $i < 5; $i++)
|
||||
{
|
||||
$model->record['field1'] = String::random();
|
||||
$model->record['field1'] = Pickles\String::random();
|
||||
$model->record['updated_id'] = 1;
|
||||
$model->queue();
|
||||
}
|
||||
|
@ -611,7 +611,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||
for ($i = 3; $i <= 5; $i++)
|
||||
{
|
||||
$model->record['id'] = $i;
|
||||
$model->record['field1'] = String::random();
|
||||
$model->record['field1'] = Pickles\String::random();
|
||||
$model->record['updated_id'] = 1;
|
||||
$model->queue();
|
||||
}
|
|
@ -7,7 +7,7 @@ class NumberTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testOrdinalIndicatorNoSuper($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, Number::ordinalIndicator($a));
|
||||
$this->assertEquals($b, Pickles\Number::ordinalIndicator($a));
|
||||
}
|
||||
|
||||
public function providerOrginalIndicatorNoSuper()
|
||||
|
@ -29,7 +29,7 @@ class NumberTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testOrdinalIndicatorSuper($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, Number::ordinalIndicator($a, true));
|
||||
$this->assertEquals($b, Pickles\Number::ordinalIndicator($a, true));
|
||||
}
|
||||
|
||||
public function providerOrginalIndicatorSuper()
|
24
tests/ObjectTest.php
Normal file
24
tests/ObjectTest.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
class ObjectTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructorWithoutObjects()
|
||||
{
|
||||
$object = new Pickles\Object();
|
||||
|
||||
$this->assertInstanceOf('Pickles\Config', PHPUnit_Framework_Assert::readAttribute($object, 'config'));
|
||||
}
|
||||
|
||||
public function testConstructorWithObjects()
|
||||
{
|
||||
$object = new Pickles\Object('cache');
|
||||
|
||||
$this->assertInstanceOf('Pickles\Cache', PHPUnit_Framework_Assert::readAttribute($object, 'cache'));
|
||||
}
|
||||
|
||||
public function testGetInstanceWithoutClass()
|
||||
{
|
||||
$this->assertFalse(Pickles\Object::getInstance());
|
||||
}
|
||||
}
|
||||
|
81
tests/ProfilerTest.php
Normal file
81
tests/ProfilerTest.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
class ProfilerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testReport()
|
||||
{
|
||||
$this->expectOutputRegex('//');
|
||||
|
||||
Pickles\Profiler::report();
|
||||
}
|
||||
|
||||
public function testDisabledType()
|
||||
{
|
||||
$config = Pickles\Config::getInstance();
|
||||
$config->data['pickles']['profiler'] = false;
|
||||
|
||||
$this->assertFalse(Pickles\Profiler::enabled('timers'));
|
||||
}
|
||||
|
||||
public function testTimerDisabled()
|
||||
{
|
||||
$this->assertFalse(Pickles\Profiler::timer('disabled'));
|
||||
}
|
||||
|
||||
public function testReportNothing()
|
||||
{
|
||||
$this->expectOutputRegex('/There is nothing to profile/');
|
||||
|
||||
Pickles\Profiler::report();
|
||||
}
|
||||
|
||||
public function testEnabled()
|
||||
{
|
||||
$config = Pickles\Config::getInstance();
|
||||
$config->data['pickles']['profiler'] = true;
|
||||
|
||||
$this->assertTrue(Pickles\Profiler::enabled());
|
||||
}
|
||||
|
||||
public function testEnabledType()
|
||||
{
|
||||
$config = Pickles\Config::getInstance();
|
||||
$config->data['pickles']['profiler'] = 'timers';
|
||||
|
||||
$this->assertTrue(Pickles\Profiler::enabled('timers'));
|
||||
}
|
||||
|
||||
public function testLogAndTimer()
|
||||
{
|
||||
Pickles\Profiler::log('timer', 'timer-one');
|
||||
Pickles\Profiler::log(['foo' => 'bar']);
|
||||
Pickles\Profiler::log(new Pickles\Object);
|
||||
Pickles\Profiler::log('string');
|
||||
Pickles\Profiler::log(3.14, 'method', true);
|
||||
Pickles\Profiler::log('timer', 'timer-one');
|
||||
}
|
||||
|
||||
public function testLogQuery()
|
||||
{
|
||||
$explain = [
|
||||
[
|
||||
'key' => '',
|
||||
'possible_keys' => '',
|
||||
'type' => '',
|
||||
'rows' => '',
|
||||
'Extra' => '',
|
||||
],
|
||||
];
|
||||
|
||||
Pickles\Profiler::logQuery('SELECT * FROM table;');
|
||||
Pickles\Profiler::logQuery('SELECT * FROM table WHERE column = ?;', ['foo']);
|
||||
Pickles\Profiler::logQuery('SELECT * FROM table;', false, $explain);
|
||||
}
|
||||
|
||||
public function testTimer()
|
||||
{
|
||||
Pickles\Profiler::timer('timer-two');
|
||||
Pickles\Profiler::timer('timer-two');
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ $_POST['field2'] = 'short';
|
|||
$_GET['field2'] = 'short';
|
||||
$_REQUEST['field2'] = 'short';
|
||||
|
||||
class MockParentResource extends Resource
|
||||
class MockParentResource extends Pickles\Resource
|
||||
{
|
||||
public $validate = [
|
||||
'field1',
|
||||
|
@ -24,7 +24,7 @@ class ResourceTest extends PHPUnit_Framework_TestCase
|
|||
{
|
||||
public function testAutoRun()
|
||||
{
|
||||
$this->assertInstanceOf('Resource', new Resource(true));
|
||||
$this->assertInstanceOf('Pickles\\Resource', new Pickles\Resource(true));
|
||||
}
|
||||
|
||||
public function testAutoRunParentError()
|
||||
|
@ -35,14 +35,14 @@ class ResourceTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testSetGetReturn()
|
||||
{
|
||||
$module = new Resource();
|
||||
$module = new Pickles\Resource();
|
||||
$module->foo = 'bar';
|
||||
$this->assertEquals('bar', $module->foo);
|
||||
}
|
||||
|
||||
public function testGetMissing()
|
||||
{
|
||||
$module = new Resource();
|
||||
$module = new Pickles\Resource();
|
||||
$this->assertFalse($module->missing);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ class RouterTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
$this->config = Pickles\Config::getInstance();
|
||||
$this->config->data['pickles']['disabled'] = false;
|
||||
$this->config->data['pickles']['profiler'] = false;
|
||||
|
||||
|
@ -25,7 +25,7 @@ class RouterTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
file_put_contents(SITE_MODULE_PATH . 'secure.php', $module);
|
||||
|
||||
new Router();
|
||||
new Pickles\Router();
|
||||
|
||||
$this->assertTrue(in_array('Location: https://testsite.com/secure', xdebug_get_headers()));
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class RouterTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
file_put_contents(SITE_MODULE_PATH . 'insecure.php', $module);
|
||||
|
||||
new Router();
|
||||
new Pickles\Router();
|
||||
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/insecure', xdebug_get_headers()));
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class RouterTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
file_put_contents(SITE_MODULE_PATH . 'validationerrors.php', $module);
|
||||
|
||||
new Router();
|
||||
new Pickles\Router();
|
||||
|
||||
$this->expectOutputString('{"status":"error","message":"The test field is required."}');
|
||||
}
|
|
@ -20,7 +20,7 @@ class SortTest extends PHPUnit_Framework_TestCase
|
|||
['name' => 'gamma'],
|
||||
];
|
||||
|
||||
Sort::by('name', $shuffled);
|
||||
Pickles\Sort::by('name', $shuffled);
|
||||
|
||||
$this->assertEquals($sorted, $shuffled);
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ class SortTest extends PHPUnit_Framework_TestCase
|
|||
['name' => 'alpha'],
|
||||
];
|
||||
|
||||
Sort::by('name', $shuffled, Sort::DESC);
|
||||
Pickles\Sort::by('name', $shuffled, Pickles\Sort::DESC);
|
||||
|
||||
$this->assertEquals($sorted, $shuffled);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class SortTest extends PHPUnit_Framework_TestCase
|
|||
$shuffled = [['foo' => 'bar', 'bar' => 'foo']];
|
||||
$sorted = [['foo' => 'bar', 'bar' => 'foo']];
|
||||
|
||||
Sort::by('name', $shuffled);
|
||||
Pickles\Sort::by('name', $shuffled);
|
||||
|
||||
$this->assertEquals($sorted, $shuffled);
|
||||
}
|
|
@ -7,7 +7,7 @@ class StringTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testFormatPhoneNumber($a, $b)
|
||||
{
|
||||
$this->assertEquals(String::formatPhoneNumber($a), $b);
|
||||
$this->assertEquals(Pickles\String::formatPhoneNumber($a), $b);
|
||||
}
|
||||
|
||||
public function providerFormatPhoneNumber()
|
||||
|
@ -27,35 +27,35 @@ class StringTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testIsEmpty()
|
||||
{
|
||||
$this->assertTrue(String::isEmpty(''));
|
||||
$this->assertTrue(String::isEmpty(' '));
|
||||
$this->assertTrue(String::isEmpty(false));
|
||||
$this->assertTrue(String::isEmpty(null));
|
||||
$this->assertTrue(String::isEmpty(true, false));
|
||||
$this->assertTrue(Pickles\String::isEmpty(''));
|
||||
$this->assertTrue(Pickles\String::isEmpty(' '));
|
||||
$this->assertTrue(Pickles\String::isEmpty(false));
|
||||
$this->assertTrue(Pickles\String::isEmpty(null));
|
||||
$this->assertTrue(Pickles\String::isEmpty(true, false));
|
||||
|
||||
$this->assertFalse(String::isEmpty(0));
|
||||
$this->assertFalse(String::isEmpty('foo'));
|
||||
$this->assertFalse(String::isEmpty(' bar '));
|
||||
$this->assertFalse(String::isEmpty(true));
|
||||
$this->assertFalse(Pickles\String::isEmpty(0));
|
||||
$this->assertFalse(Pickles\String::isEmpty('foo'));
|
||||
$this->assertFalse(Pickles\String::isEmpty(' bar '));
|
||||
$this->assertFalse(Pickles\String::isEmpty(true));
|
||||
}
|
||||
|
||||
public function testRandom()
|
||||
{
|
||||
$this->assertEquals(strlen(String::random()), 8);
|
||||
$this->assertEquals(strlen(String::random(16)), 16);
|
||||
$this->assertEquals(strlen(Pickles\String::random()), 8);
|
||||
$this->assertEquals(strlen(Pickles\String::random(16)), 16);
|
||||
|
||||
$this->assertEquals(preg_match('/[a-z0-9]/', String::random(32, true, true)), 1);
|
||||
$this->assertEquals(preg_match('/[a-z]/', String::random(32, true, false)), 1);
|
||||
$this->assertEquals(preg_match('/[0-9]/', String::random(32, false, true)), 1);
|
||||
$this->assertEquals(preg_match('/[a-z0-9]/', Pickles\String::random(32, true, true)), 1);
|
||||
$this->assertEquals(preg_match('/[a-z]/', Pickles\String::random(32, true, false)), 1);
|
||||
$this->assertEquals(preg_match('/[0-9]/', Pickles\String::random(32, false, true)), 1);
|
||||
|
||||
$this->assertEquals(preg_match('/[0-9]/', String::random(32, true, false)), 0);
|
||||
$this->assertEquals(preg_match('/[a-z]/', String::random(32, false, true)), 0);
|
||||
$this->assertEquals(preg_match('/[a-z0-9]/', String::random(32, false, false)), 0);
|
||||
$this->assertEquals(preg_match('/[0-9]/', Pickles\String::random(32, true, false)), 0);
|
||||
$this->assertEquals(preg_match('/[a-z]/', Pickles\String::random(32, false, true)), 0);
|
||||
$this->assertEquals(preg_match('/[a-z0-9]/', Pickles\String::random(32, false, false)), 0);
|
||||
}
|
||||
|
||||
public function testRandomSimilarFalse()
|
||||
{
|
||||
$this->assertRegExp('/[a-hj-np-z2-9]{8}/', String::random(8, true, true, false));
|
||||
$this->assertRegExp('/[a-hj-np-z2-9]{8}/', Pickles\String::random(8, true, true, false));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +63,7 @@ class StringTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testTruncate($a, $b, $c, $d)
|
||||
{
|
||||
$this->assertEquals(String::truncate($a, $b, $c), $d);
|
||||
$this->assertEquals(Pickles\String::truncate($a, $b, $c), $d);
|
||||
}
|
||||
|
||||
public function providerTruncate()
|
||||
|
@ -81,7 +81,7 @@ class StringTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testUpperWords($a, $b)
|
||||
{
|
||||
$this->assertEquals(String::upperWords($a), $b);
|
||||
$this->assertEquals(Pickles\String::upperWords($a), $b);
|
||||
}
|
||||
|
||||
public function providerUpperWords()
|
||||
|
@ -100,7 +100,7 @@ class StringTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testGenerateSlug($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, String::generateSlug($a));
|
||||
$this->assertEquals($b, Pickles\String::generateSlug($a));
|
||||
}
|
||||
|
||||
public function providerGenerateSlug()
|
||||
|
@ -116,10 +116,10 @@ class StringTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testPluralize()
|
||||
{
|
||||
$this->assertEquals('test', String::pluralize('test', 1, false));
|
||||
$this->assertEquals('1 test', String::pluralize('test', 1, true));
|
||||
$this->assertEquals('tests', String::pluralize('test', 2, false));
|
||||
$this->assertEquals('2 tests', String::pluralize('test', 2, true));
|
||||
$this->assertEquals('test', Pickles\String::pluralize('test', 1, false));
|
||||
$this->assertEquals('1 test', Pickles\String::pluralize('test', 1, true));
|
||||
$this->assertEquals('tests', Pickles\String::pluralize('test', 2, false));
|
||||
$this->assertEquals('2 tests', Pickles\String::pluralize('test', 2, true));
|
||||
}
|
||||
}
|
||||
|
160
tests/TimeTest.php
Normal file
160
tests/TimeTest.php
Normal file
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
|
||||
class TimeTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
date_default_timezone_set('GMT');
|
||||
}
|
||||
|
||||
public function testAgePastTime()
|
||||
{
|
||||
$this->assertEquals(18, Pickles\Time::age(date('Y-m-d', strtotime('-18 years'))));
|
||||
}
|
||||
|
||||
public function testAgeFutureTime()
|
||||
{
|
||||
$this->assertEquals(-18, Pickles\Time::age(date('Y-m-d', strtotime('18 years'))));
|
||||
}
|
||||
|
||||
public function testAgeWrongFormat()
|
||||
{
|
||||
$this->assertEquals(17, Pickles\Time::age(date('Ymd', strtotime('December 31st -18 years'))));
|
||||
}
|
||||
|
||||
public function testAgoJustNow()
|
||||
{
|
||||
$this->assertEquals('just now', Pickles\Time::ago(Pickles\Time::timestamp()));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeSeconds()
|
||||
{
|
||||
$this->assertEquals('seconds ago', Pickles\Time::ago(strtotime('-30 seconds')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeMinute()
|
||||
{
|
||||
$this->assertEquals('a minute ago', Pickles\Time::ago(strtotime('-1 minutes')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeMinutes()
|
||||
{
|
||||
$this->assertEquals('5 minutes ago', Pickles\Time::ago(strtotime('-5 minutes')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeHour()
|
||||
{
|
||||
$this->assertEquals('an hour ago', Pickles\Time::ago(strtotime('-1 hours')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeHours()
|
||||
{
|
||||
$this->assertEquals('2 hours ago', Pickles\Time::ago(strtotime('-2 hours')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeDay()
|
||||
{
|
||||
$this->assertEquals('a day ago', Pickles\Time::ago(strtotime('-1 days')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeDays()
|
||||
{
|
||||
$this->assertEquals('2 days ago', Pickles\Time::ago(strtotime('-2 days')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeWeek()
|
||||
{
|
||||
$this->assertEquals('a week ago', Pickles\Time::ago(strtotime('-1 weeks')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeWeeks()
|
||||
{
|
||||
$this->assertEquals('2 weeks ago', Pickles\Time::ago(strtotime('-2 weeks')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeMonth()
|
||||
{
|
||||
$this->assertEquals('a month ago', Pickles\Time::ago(strtotime('-1 months')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeMonths()
|
||||
{
|
||||
$this->assertEquals('2 months ago', Pickles\Time::ago(strtotime('-2 months')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeYear()
|
||||
{
|
||||
$this->assertEquals('a year ago', Pickles\Time::ago(strtotime('-1 years')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeYears()
|
||||
{
|
||||
$this->assertEquals('2 years ago', Pickles\Time::ago(strtotime('-2 years')));
|
||||
}
|
||||
|
||||
public function testAgoFutureTimeSeconds()
|
||||
{
|
||||
$this->assertEquals('seconds from now', Pickles\Time::ago(strtotime('+30 seconds')));
|
||||
}
|
||||
|
||||
public function testAgoFutureTimeMinutes()
|
||||
{
|
||||
$this->assertEquals('5 minutes from now', Pickles\Time::ago(strtotime('+5 minutes')));
|
||||
}
|
||||
|
||||
public function testAgoFutureTimeHours()
|
||||
{
|
||||
$this->assertEquals('an hour from now', Pickles\Time::ago(strtotime('+1 hour')));
|
||||
}
|
||||
|
||||
public function testAgoFutureTimeDays()
|
||||
{
|
||||
$this->assertEquals('a day from now', Pickles\Time::ago(strtotime('+1 day')));
|
||||
}
|
||||
|
||||
public function testAgoFutureTimeWeeks()
|
||||
{
|
||||
$this->assertEquals('a week from now', Pickles\Time::ago(strtotime('+1 week')));
|
||||
}
|
||||
|
||||
public function testAgoFutureTimeMonths()
|
||||
{
|
||||
$this->assertEquals('a month from now', Pickles\Time::ago(strtotime('+1 month')));
|
||||
}
|
||||
|
||||
public function testAgoFutureTimeYears()
|
||||
{
|
||||
$this->assertEquals('a year from now', Pickles\Time::ago(strtotime('+1 year')));
|
||||
}
|
||||
|
||||
public function testTimestamp()
|
||||
{
|
||||
$this->assertEquals(gmdate('Y-m-d H:i:s'), Pickles\Time::timestamp());
|
||||
}
|
||||
|
||||
public function testRoundUpHour()
|
||||
{
|
||||
$this->assertEquals('an hour ago', Pickles\Time::ago(strtotime('-59 minutes -55 seconds')));
|
||||
}
|
||||
|
||||
public function testRoundUpDay()
|
||||
{
|
||||
$this->assertEquals('a day ago', Pickles\Time::ago(strtotime('-23 hours -55 minutes')));
|
||||
}
|
||||
|
||||
public function testRoundUpWeek()
|
||||
{
|
||||
$this->assertEquals('a week ago', Pickles\Time::ago(strtotime('-6 days -23 hours')));
|
||||
}
|
||||
|
||||
public function testRoundUpMonth()
|
||||
{
|
||||
$this->assertEquals('a month ago', Pickles\Time::ago(strtotime('-29 days')));
|
||||
}
|
||||
|
||||
public function testRoundUpYear()
|
||||
{
|
||||
$this->assertEquals('a year ago', Pickles\Time::ago(strtotime('-364 days')));
|
||||
}
|
||||
}
|
||||
|
199
tests/ValidateTest.php
Normal file
199
tests/ValidateTest.php
Normal file
|
@ -0,0 +1,199 @@
|
|||
<?php
|
||||
|
||||
// class ValidateTest extends PHPUnit_Framework_TestCase
|
||||
// {
|
||||
// public function testFilterBoolean()
|
||||
// {
|
||||
// $this->assertTrue(Validate::isValid(true, ['filter:boolean' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testFilterBooleanError()
|
||||
// {
|
||||
// $this->assertEquals(['error'], Validate::isValid(false, ['filter:boolean' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testFilterEmail()
|
||||
// {
|
||||
// $this->assertTrue(Validate::isValid('foo@bar.com', ['filter:email' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testFilterEmailError()
|
||||
// {
|
||||
// $this->assertEquals(['error'], Validate::isValid('invalid', ['filter:email' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testFilterFloat()
|
||||
// {
|
||||
// $this->assertTrue(Validate::isValid(2.231981, ['filter:float' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testFilterFloatError()
|
||||
// {
|
||||
// $this->assertEquals(['error'], Validate::isValid('invalid', ['filter:float' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testFilterInt()
|
||||
// {
|
||||
// $this->assertTrue(Validate::isValid(2231981, ['filter:int' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testFilterIntError()
|
||||
// {
|
||||
// $this->assertEquals(['error'], Validate::isValid('invalid', ['filter:int' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testFilterIP()
|
||||
// {
|
||||
// $this->assertTrue(Validate::isValid('2.23.19.81', ['filter:ip' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testFilterIPError()
|
||||
// {
|
||||
// $this->assertEquals(['error'], Validate::isValid('invalid', ['filter:ip' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testFilterURL()
|
||||
// {
|
||||
// $this->assertTrue(Validate::isValid('http://foo.com/bar?stuff', ['filter:url' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testFilterURLError()
|
||||
// {
|
||||
// $this->assertEquals(['error'], Validate::isValid('invalid', ['filter:url' => 'error']));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @expectedException Exception
|
||||
// * @expectedExceptionMessage Invalid validation rule, expected: "validate:boolean|email|float|int|ip|url".
|
||||
// */
|
||||
// public function testFilterVarInvalidRule()
|
||||
// {
|
||||
// Validate::isValid('value', ['filter' => 'foo']);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @expectedException Exception
|
||||
// * @expectedExceptionMessage Invalid filter, expecting boolean, email, float, int, ip or url.
|
||||
// */
|
||||
// public function testFilterVarInvalidFilter()
|
||||
// {
|
||||
// Validate::isValid('value', ['filter:foo' => 'bar']);
|
||||
// }
|
||||
//
|
||||
// public function testLengthLessThan()
|
||||
// {
|
||||
// $this->assertTrue(Validate::isValid('value', ['length:<:10' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testLengthLessThanError()
|
||||
// {
|
||||
// $this->assertEquals(['error'], Validate::isValid('value', ['length:<:1' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testLengthLessThanOrEqual()
|
||||
// {
|
||||
// $this->assertTrue(Validate::isValid('value', ['length:<=:10' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testLengthLessThanOrEqualError()
|
||||
// {
|
||||
// $this->assertEquals(['error'], Validate::isValid('value', ['length:<=:1' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testLengthEqual()
|
||||
// {
|
||||
// $this->assertTrue(Validate::isValid('value', ['length:==:5' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testLengthEqualError()
|
||||
// {
|
||||
// $this->assertEquals(['error'], Validate::isValid('value', ['length:==:1' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testLengthNotEqual()
|
||||
// {
|
||||
// $this->assertTrue(Validate::isValid('value', ['length:!=:1' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testLengthNotEqualError()
|
||||
// {
|
||||
// $this->assertEquals(['error'], Validate::isValid('value', ['length:!=:5' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testLengthGreaterThanOrEqual()
|
||||
// {
|
||||
// $this->assertTrue(Validate::isValid('value', ['length:>=:1' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testLengthGreaterThanOrEqualError()
|
||||
// {
|
||||
// $this->assertEquals(['error'], Validate::isValid('value', ['length:>=:10' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testLengthGreaterThan()
|
||||
// {
|
||||
// $this->assertTrue(Validate::isValid('value', ['length:>:1' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testLengthGreaterThanError()
|
||||
// {
|
||||
// $this->assertEquals(['error'], Validate::isValid('value', ['length:>:10' => 'error']));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @expectedException Exception
|
||||
// * @expectedExceptionMessage Invalid validation rule, expected: "length:<|<=|==|!=|>=|>:integer".
|
||||
// */
|
||||
// public function testLengthInvalidRule()
|
||||
// {
|
||||
// Validate::isValid('value', ['length:16' => 'bar']);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @expectedException Exception
|
||||
// * @expectedExceptionMessage Invalid length value, expecting an integer.
|
||||
// */
|
||||
// public function testLengthInvalidLength()
|
||||
// {
|
||||
// Validate::isValid('value', ['length:==:foo' => 'bar']);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @expectedException Exception
|
||||
// * @expectedExceptionMessage Invalid operator, expecting <, <=, ==, !=, >= or >.
|
||||
// */
|
||||
// public function testLengthInvalidOperator()
|
||||
// {
|
||||
// Validate::isValid('value', ['length:&&:10' => 'foo']);
|
||||
// }
|
||||
//
|
||||
// public function testRegexIs()
|
||||
// {
|
||||
// $this->assertTrue(Validate::isValid('value', ['regex:is:/^va7ue$/' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testRegexIsError()
|
||||
// {
|
||||
// $this->assertEquals(['error'], Validate::isValid('value', ['regex:is:/^value$/' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testRegexNot()
|
||||
// {
|
||||
// $this->assertTrue(Validate::isValid('value', ['regex:not:/^value$/' => 'error']));
|
||||
// }
|
||||
//
|
||||
// public function testRegexNotError()
|
||||
// {
|
||||
// $this->assertEquals(['error'], Validate::isValid('value', ['regex:not:/^va7ue$/' => 'error']));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @expectedException Exception
|
||||
// * @expectedExceptionMessage Invalid validation rule, expected: "regex:is|not:string".
|
||||
// */
|
||||
// public function testRegexInvalidRule()
|
||||
// {
|
||||
// Validate::isValid('value', ['regex:/foo/' => 'bar']);
|
||||
// }
|
||||
// }
|
||||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
uopz_overload(ZEND_EXIT, function(){});
|
||||
|
||||
ob_start();
|
||||
@session_start();
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
$root = org\bovigo\vfs\vfsStream::setup('site');
|
||||
|
@ -16,10 +11,13 @@ if (!defined('SITE_PATH'))
|
|||
|
||||
require_once 'src/pickles.php';
|
||||
|
||||
/*
|
||||
// @todo Update to resources path??
|
||||
if (!file_exists(SITE_MODULE_PATH))
|
||||
{
|
||||
mkdir(SITE_MODULE_PATH, 0644);
|
||||
}
|
||||
*/
|
||||
|
||||
$_SERVER['HTTP_HOST'] = 'testsite.com';
|
||||
$_SERVER['SERVER_NAME'] = 'Test Server';
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
<?php
|
||||
|
||||
class DistanceTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConvertKilometersToMiles()
|
||||
{
|
||||
$this->assertEquals(0.621371, Distance::kilometersToMiles(1));
|
||||
}
|
||||
|
||||
public function testConvertKilometersToMeters()
|
||||
{
|
||||
$this->assertEquals(1000, Distance::kilometersToMeters(1));
|
||||
}
|
||||
|
||||
public function testConvertKilometersToYards()
|
||||
{
|
||||
$this->assertEquals(1093.61, Distance::kilometersToYards(1));
|
||||
}
|
||||
|
||||
public function testConvertMilesToKilometers()
|
||||
{
|
||||
$this->assertEquals(1.60934, Distance::milesToKilometers(1));
|
||||
}
|
||||
|
||||
public function testConvertMilesToMeters()
|
||||
{
|
||||
$this->assertEquals(1609.34, Distance::milesToMeters(1));
|
||||
}
|
||||
|
||||
public function testConvertMilesToYards()
|
||||
{
|
||||
$this->assertEquals(1760, Distance::milesToYards(1));
|
||||
}
|
||||
|
||||
public function testConvertMetersToKilometers()
|
||||
{
|
||||
$this->assertEquals(0.001, Distance::metersToKilometers(1));
|
||||
}
|
||||
|
||||
public function testConvertMetersToMiles()
|
||||
{
|
||||
$this->assertEquals(0.000621371, Distance::metersToMiles(1));
|
||||
}
|
||||
|
||||
public function testConvertMetersToYards()
|
||||
{
|
||||
$this->assertEquals(1.09361, Distance::metersToYards(1));
|
||||
}
|
||||
|
||||
public function testCalculateDistanceMiles()
|
||||
{
|
||||
$this->assertEquals(1003.2646776326, Distance::calculateDistance(27.947222, -82.458611, 40.67, -73.94));
|
||||
}
|
||||
|
||||
public function testCalculateDistanceKilometers()
|
||||
{
|
||||
$this->assertEquals(1614.5939763012, Distance::calculateDistance(27.947222, -82.458611, 40.67, -73.94, 'kilometers'));
|
||||
}
|
||||
|
||||
public function testCalculateDistanceMeters()
|
||||
{
|
||||
$this->assertEquals(1614593.9763012, Distance::calculateDistance(27.947222, -82.458611, 40.67, -73.94, 'meters'), '', 0.2);
|
||||
}
|
||||
|
||||
public function testCalculateDistanceYards()
|
||||
{
|
||||
$this->assertEquals(1765745.8326334, Distance::calculateDistance(27.947222, -82.458611, 40.67, -73.94, 'yards'), '', 0.2);
|
||||
}
|
||||
|
||||
public function testNotEnoughUnits()
|
||||
{
|
||||
$this->assertFalse(Distance::milesTo(123));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
class ObjectTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructorWithoutObjects()
|
||||
{
|
||||
$object = new Object();
|
||||
|
||||
$this->assertInstanceOf('Config', PHPUnit_Framework_Assert::readAttribute($object, 'config'));
|
||||
}
|
||||
|
||||
public function testConstructorWithObjects()
|
||||
{
|
||||
$object = new Object('cache');
|
||||
|
||||
$this->assertInstanceOf('Cache', PHPUnit_Framework_Assert::readAttribute($object, 'cache'));
|
||||
}
|
||||
|
||||
public function testGetInstanceWithoutClass()
|
||||
{
|
||||
$this->assertFalse(Object::getInstance());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
<?php
|
||||
|
||||
class ProfilerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testReport()
|
||||
{
|
||||
$this->expectOutputRegex('//');
|
||||
|
||||
Profiler::report();
|
||||
}
|
||||
|
||||
public function testDisabledType()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['profiler'] = false;
|
||||
|
||||
$this->assertFalse(Profiler::enabled('timers'));
|
||||
}
|
||||
|
||||
public function testTimerDisabled()
|
||||
{
|
||||
$this->assertFalse(Profiler::timer('disabled'));
|
||||
}
|
||||
|
||||
public function testReportNothing()
|
||||
{
|
||||
$this->expectOutputRegex('/There is nothing to profile/');
|
||||
|
||||
Profiler::report();
|
||||
}
|
||||
|
||||
public function testEnabled()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['profiler'] = true;
|
||||
|
||||
$this->assertTrue(Profiler::enabled());
|
||||
}
|
||||
|
||||
public function testEnabledType()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['profiler'] = 'timers';
|
||||
|
||||
$this->assertTrue(Profiler::enabled('timers'));
|
||||
}
|
||||
|
||||
public function testLogAndTimer()
|
||||
{
|
||||
Profiler::log('timer', 'timer-one');
|
||||
Profiler::log(['foo' => 'bar']);
|
||||
Profiler::log(new Object);
|
||||
Profiler::log('string');
|
||||
Profiler::log(3.14, 'method', true);
|
||||
Profiler::log('timer', 'timer-one');
|
||||
}
|
||||
|
||||
public function testLogQuery()
|
||||
{
|
||||
$explain = [
|
||||
[
|
||||
'key' => '',
|
||||
'possible_keys' => '',
|
||||
'type' => '',
|
||||
'rows' => '',
|
||||
'Extra' => '',
|
||||
],
|
||||
];
|
||||
|
||||
Profiler::logQuery('SELECT * FROM table;');
|
||||
Profiler::logQuery('SELECT * FROM table WHERE column = ?;', ['foo']);
|
||||
Profiler::logQuery('SELECT * FROM table;', false, $explain);
|
||||
}
|
||||
|
||||
public function testTimer()
|
||||
{
|
||||
Profiler::timer('timer-two');
|
||||
Profiler::timer('timer-two');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,160 +0,0 @@
|
|||
<?php
|
||||
|
||||
class TimeTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
date_default_timezone_set('GMT');
|
||||
}
|
||||
|
||||
public function testAgePastTime()
|
||||
{
|
||||
$this->assertEquals(18, Time::age(date('Y-m-d', strtotime('-18 years'))));
|
||||
}
|
||||
|
||||
public function testAgeFutureTime()
|
||||
{
|
||||
$this->assertEquals(-18, Time::age(date('Y-m-d', strtotime('18 years'))));
|
||||
}
|
||||
|
||||
public function testAgeWrongFormat()
|
||||
{
|
||||
$this->assertEquals(17, Time::age(date('Ymd', strtotime('December 31st -18 years'))));
|
||||
}
|
||||
|
||||
public function testAgoJustNow()
|
||||
{
|
||||
$this->assertEquals('just now', Time::ago(Time::timestamp()));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeSeconds()
|
||||
{
|
||||
$this->assertEquals('seconds ago', Time::ago(strtotime('-30 seconds')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeMinute()
|
||||
{
|
||||
$this->assertEquals('a minute ago', Time::ago(strtotime('-1 minutes')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeMinutes()
|
||||
{
|
||||
$this->assertEquals('5 minutes ago', Time::ago(strtotime('-5 minutes')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeHour()
|
||||
{
|
||||
$this->assertEquals('an hour ago', Time::ago(strtotime('-1 hours')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeHours()
|
||||
{
|
||||
$this->assertEquals('2 hours ago', Time::ago(strtotime('-2 hours')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeDay()
|
||||
{
|
||||
$this->assertEquals('a day ago', Time::ago(strtotime('-1 days')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeDays()
|
||||
{
|
||||
$this->assertEquals('2 days ago', Time::ago(strtotime('-2 days')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeWeek()
|
||||
{
|
||||
$this->assertEquals('a week ago', Time::ago(strtotime('-1 weeks')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeWeeks()
|
||||
{
|
||||
$this->assertEquals('2 weeks ago', Time::ago(strtotime('-2 weeks')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeMonth()
|
||||
{
|
||||
$this->assertEquals('a month ago', Time::ago(strtotime('-1 months')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeMonths()
|
||||
{
|
||||
$this->assertEquals('2 months ago', Time::ago(strtotime('-2 months')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeYear()
|
||||
{
|
||||
$this->assertEquals('a year ago', Time::ago(strtotime('-1 years')));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeYears()
|
||||
{
|
||||
$this->assertEquals('2 years ago', Time::ago(strtotime('-2 years')));
|
||||
}
|
||||
|
||||
public function testAgoFutureTimeSeconds()
|
||||
{
|
||||
$this->assertEquals('seconds from now', Time::ago(strtotime('+30 seconds')));
|
||||
}
|
||||
|
||||
public function testAgoFutureTimeMinutes()
|
||||
{
|
||||
$this->assertEquals('5 minutes from now', Time::ago(strtotime('+5 minutes')));
|
||||
}
|
||||
|
||||
public function testAgoFutureTimeHours()
|
||||
{
|
||||
$this->assertEquals('an hour from now', Time::ago(strtotime('+1 hour')));
|
||||
}
|
||||
|
||||
public function testAgoFutureTimeDays()
|
||||
{
|
||||
$this->assertEquals('a day from now', Time::ago(strtotime('+1 day')));
|
||||
}
|
||||
|
||||
public function testAgoFutureTimeWeeks()
|
||||
{
|
||||
$this->assertEquals('a week from now', Time::ago(strtotime('+1 week')));
|
||||
}
|
||||
|
||||
public function testAgoFutureTimeMonths()
|
||||
{
|
||||
$this->assertEquals('a month from now', Time::ago(strtotime('+1 month')));
|
||||
}
|
||||
|
||||
public function testAgoFutureTimeYears()
|
||||
{
|
||||
$this->assertEquals('a year from now', Time::ago(strtotime('+1 year')));
|
||||
}
|
||||
|
||||
public function testTimestamp()
|
||||
{
|
||||
$this->assertEquals(gmdate('Y-m-d H:i:s'), Time::timestamp());
|
||||
}
|
||||
|
||||
public function testRoundUpHour()
|
||||
{
|
||||
$this->assertEquals('an hour ago', Time::ago(strtotime('-59 minutes -55 seconds')));
|
||||
}
|
||||
|
||||
public function testRoundUpDay()
|
||||
{
|
||||
$this->assertEquals('a day ago', Time::ago(strtotime('-23 hours -55 minutes')));
|
||||
}
|
||||
|
||||
public function testRoundUpWeek()
|
||||
{
|
||||
$this->assertEquals('a week ago', Time::ago(strtotime('-6 days -23 hours')));
|
||||
}
|
||||
|
||||
public function testRoundUpMonth()
|
||||
{
|
||||
$this->assertEquals('a month ago', Time::ago(strtotime('-29 days')));
|
||||
}
|
||||
|
||||
public function testRoundUpYear()
|
||||
{
|
||||
$this->assertEquals('a year ago', Time::ago(strtotime('-364 days')));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,199 +0,0 @@
|
|||
<?php
|
||||
|
||||
class ValidateTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFilterBoolean()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid(true, ['filter:boolean' => 'error']));
|
||||
}
|
||||
|
||||
public function testFilterBooleanError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid(false, ['filter:boolean' => 'error']));
|
||||
}
|
||||
|
||||
public function testFilterEmail()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('foo@bar.com', ['filter:email' => 'error']));
|
||||
}
|
||||
|
||||
public function testFilterEmailError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('invalid', ['filter:email' => 'error']));
|
||||
}
|
||||
|
||||
public function testFilterFloat()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid(2.231981, ['filter:float' => 'error']));
|
||||
}
|
||||
|
||||
public function testFilterFloatError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('invalid', ['filter:float' => 'error']));
|
||||
}
|
||||
|
||||
public function testFilterInt()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid(2231981, ['filter:int' => 'error']));
|
||||
}
|
||||
|
||||
public function testFilterIntError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('invalid', ['filter:int' => 'error']));
|
||||
}
|
||||
|
||||
public function testFilterIP()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('2.23.19.81', ['filter:ip' => 'error']));
|
||||
}
|
||||
|
||||
public function testFilterIPError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('invalid', ['filter:ip' => 'error']));
|
||||
}
|
||||
|
||||
public function testFilterURL()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('http://foo.com/bar?stuff', ['filter:url' => 'error']));
|
||||
}
|
||||
|
||||
public function testFilterURLError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('invalid', ['filter:url' => 'error']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid validation rule, expected: "validate:boolean|email|float|int|ip|url".
|
||||
*/
|
||||
public function testFilterVarInvalidRule()
|
||||
{
|
||||
Validate::isValid('value', ['filter' => 'foo']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid filter, expecting boolean, email, float, int, ip or url.
|
||||
*/
|
||||
public function testFilterVarInvalidFilter()
|
||||
{
|
||||
Validate::isValid('value', ['filter:foo' => 'bar']);
|
||||
}
|
||||
|
||||
public function testLengthLessThan()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('value', ['length:<:10' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthLessThanError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('value', ['length:<:1' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthLessThanOrEqual()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('value', ['length:<=:10' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthLessThanOrEqualError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('value', ['length:<=:1' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthEqual()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('value', ['length:==:5' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthEqualError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('value', ['length:==:1' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthNotEqual()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('value', ['length:!=:1' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthNotEqualError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('value', ['length:!=:5' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthGreaterThanOrEqual()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('value', ['length:>=:1' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthGreaterThanOrEqualError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('value', ['length:>=:10' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthGreaterThan()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('value', ['length:>:1' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthGreaterThanError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('value', ['length:>:10' => 'error']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid validation rule, expected: "length:<|<=|==|!=|>=|>:integer".
|
||||
*/
|
||||
public function testLengthInvalidRule()
|
||||
{
|
||||
Validate::isValid('value', ['length:16' => 'bar']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid length value, expecting an integer.
|
||||
*/
|
||||
public function testLengthInvalidLength()
|
||||
{
|
||||
Validate::isValid('value', ['length:==:foo' => 'bar']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid operator, expecting <, <=, ==, !=, >= or >.
|
||||
*/
|
||||
public function testLengthInvalidOperator()
|
||||
{
|
||||
Validate::isValid('value', ['length:&&:10' => 'foo']);
|
||||
}
|
||||
|
||||
public function testRegexIs()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('value', ['regex:is:/^va7ue$/' => 'error']));
|
||||
}
|
||||
|
||||
public function testRegexIsError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('value', ['regex:is:/^value$/' => 'error']));
|
||||
}
|
||||
|
||||
public function testRegexNot()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('value', ['regex:not:/^value$/' => 'error']));
|
||||
}
|
||||
|
||||
public function testRegexNotError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('value', ['regex:not:/^va7ue$/' => 'error']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid validation rule, expected: "regex:is|not:string".
|
||||
*/
|
||||
public function testRegexInvalidRule()
|
||||
{
|
||||
Validate::isValid('value', ['regex:/foo/' => 'bar']);
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue