Converted tabs to spaces.
This commit is contained in:
parent
3e08d173a1
commit
617eb21614
60 changed files with 9220 additions and 9277 deletions
|
@ -11,26 +11,26 @@ $root = org\bovigo\vfs\vfsStream::setup('site');
|
|||
|
||||
if (!defined('SITE_PATH'))
|
||||
{
|
||||
define('SECURITY_LEVEL_USER', 10);
|
||||
define('SECURITY_LEVEL_ADMIN', 20);
|
||||
define('SITE_PATH', org\bovigo\vfs\vfsStream::url('site/'));
|
||||
define('SECURITY_LEVEL_USER', 10);
|
||||
define('SECURITY_LEVEL_ADMIN', 20);
|
||||
define('SITE_PATH', org\bovigo\vfs\vfsStream::url('site/'));
|
||||
}
|
||||
|
||||
require_once 'src/pickles.php';
|
||||
|
||||
if (!file_exists(SITE_MODULE_PATH))
|
||||
{
|
||||
mkdir(SITE_MODULE_PATH, 0644);
|
||||
mkdir(SITE_MODULE_PATH, 0644);
|
||||
}
|
||||
|
||||
if (!file_exists(SITE_TEMPLATE_PATH))
|
||||
{
|
||||
mkdir(SITE_TEMPLATE_PATH, 0644);
|
||||
mkdir(SITE_TEMPLATE_PATH, 0644);
|
||||
}
|
||||
|
||||
if (!file_exists(SITE_TEMPLATE_PATH . '__shared/'))
|
||||
{
|
||||
mkdir(SITE_TEMPLATE_PATH . '__shared/', 0644);
|
||||
mkdir(SITE_TEMPLATE_PATH . '__shared/', 0644);
|
||||
}
|
||||
|
||||
$_SERVER['HTTP_HOST'] = 'testsite.com';
|
||||
|
@ -39,17 +39,17 @@ $_SERVER['SERVER_ADDR'] = '127.0.0.1';
|
|||
|
||||
function setUpRequest($request, $method = 'GET')
|
||||
{
|
||||
$_SERVER['REQUEST_URI'] = '/' . $request;
|
||||
$_SERVER['REQUEST_METHOD'] = $method;
|
||||
$_REQUEST['request'] = $request;
|
||||
$_SERVER['REQUEST_URI'] = '/' . $request;
|
||||
$_SERVER['REQUEST_METHOD'] = $method;
|
||||
$_REQUEST['request'] = $request;
|
||||
}
|
||||
|
||||
function setUpConfig($config)
|
||||
{
|
||||
file_put_contents(
|
||||
SITE_PATH . 'config.php',
|
||||
'<?php $config = ' . var_export($config, true) . '; ?>'
|
||||
);
|
||||
file_put_contents(
|
||||
SITE_PATH . 'config.php',
|
||||
'<?php $config = ' . var_export($config, true) . '; ?>'
|
||||
);
|
||||
}
|
||||
|
||||
`mysql -e 'TRUNCATE TABLE test.pickles;'`;
|
||||
|
@ -57,4 +57,3 @@ function setUpConfig($config)
|
|||
`mysql -e 'TRUNCATE TABLE test.users;'`;
|
||||
`echo 'flush_all' | nc localhost 11211`;
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,40 +2,39 @@
|
|||
|
||||
class API_AYAHTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Missing API configuration
|
||||
*/
|
||||
public function testGetHTMLMissingConfig()
|
||||
{
|
||||
API_AYAH::getHTML();
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Missing API configuration
|
||||
*/
|
||||
public function testGetHTMLMissingConfig()
|
||||
{
|
||||
API_AYAH::getHTML();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Missing API configuration
|
||||
*/
|
||||
public function testIsHumanMissingConfig()
|
||||
{
|
||||
API_AYAH::isHuman();
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Missing API configuration
|
||||
*/
|
||||
public function testIsHumanMissingConfig()
|
||||
{
|
||||
API_AYAH::isHuman();
|
||||
}
|
||||
|
||||
public function testGetHTML()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['api']['ayah'] = [
|
||||
'publisher_key' => '01f70454bada303692be5f36a8fd104eba8b00dd',
|
||||
'scoring_key' => '80cc3f9c6e1da29369c238d55bd8528a968473ad',
|
||||
];
|
||||
public function testGetHTML()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['api']['ayah'] = [
|
||||
'publisher_key' => '01f70454bada303692be5f36a8fd104eba8b00dd',
|
||||
'scoring_key' => '80cc3f9c6e1da29369c238d55bd8528a968473ad',
|
||||
];
|
||||
|
||||
$this->assertRegExp('/<div id=\'AYAH\'><\/div><script src=\'https:\/\/ws.areyouahuman.com\/ws\/script\/[a-z0-9]{40}(\/[a-zA-Z0-9]{45})?\' type=\'text\/javascript\' language=\'JavaScript\'><\/script>/', API_AYAH::getHTML());
|
||||
}
|
||||
$this->assertRegExp('/<div id=\'AYAH\'><\/div><script src=\'https:\/\/ws.areyouahuman.com\/ws\/script\/[a-z0-9]{40}(\/[a-zA-Z0-9]{45})?\' type=\'text\/javascript\' language=\'JavaScript\'><\/script>/', API_AYAH::getHTML());
|
||||
}
|
||||
|
||||
public function testIsNotHuman()
|
||||
{
|
||||
// Unfortunately there's no way to test a true response (mock maybe?)
|
||||
$this->assertFalse(API_AYAH::isHuman());
|
||||
}
|
||||
public function testIsNotHuman()
|
||||
{
|
||||
// Unfortunately there's no way to test a true response (mock maybe?)
|
||||
$this->assertFalse(API_AYAH::isHuman());
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,41 +2,40 @@
|
|||
|
||||
class API_Google_ProfanityTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerFormatPhoneNumber
|
||||
*/
|
||||
public function testCheck($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, API_Google_Profanity::check($a));
|
||||
}
|
||||
/**
|
||||
* @dataProvider providerFormatPhoneNumber
|
||||
*/
|
||||
public function testCheck($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, API_Google_Profanity::check($a));
|
||||
}
|
||||
|
||||
public function providerFormatPhoneNumber()
|
||||
{
|
||||
return [
|
||||
['alpha', false],
|
||||
['beta', false],
|
||||
['joshtronic', false],
|
||||
['god', false],
|
||||
['fck', false],
|
||||
['fuck', true],
|
||||
['shit', true],
|
||||
['cocksucker', true],
|
||||
['cuntface', false], // Unsure why not...
|
||||
];
|
||||
}
|
||||
public function providerFormatPhoneNumber()
|
||||
{
|
||||
return [
|
||||
['alpha', false],
|
||||
['beta', false],
|
||||
['joshtronic', false],
|
||||
['god', false],
|
||||
['fck', false],
|
||||
['fuck', true],
|
||||
['shit', true],
|
||||
['cocksucker', true],
|
||||
['cuntface', false], // Unsure why not...
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid response from API.
|
||||
*/
|
||||
public function testInvalidResponse()
|
||||
{
|
||||
$file = SITE_PATH . 'null-';
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid response from API.
|
||||
*/
|
||||
public function testInvalidResponse()
|
||||
{
|
||||
$file = SITE_PATH . 'null-';
|
||||
|
||||
file_put_contents($file . 'test', null);
|
||||
file_put_contents($file . 'test', null);
|
||||
|
||||
API_Google_Profanity::check('test', $file);
|
||||
}
|
||||
API_Google_Profanity::check('test', $file);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,97 +2,96 @@
|
|||
|
||||
class API_Gravatar_Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerHash
|
||||
*/
|
||||
public function testHash($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, API_Gravatar::hash($a));
|
||||
}
|
||||
/**
|
||||
* @dataProvider providerHash
|
||||
*/
|
||||
public function testHash($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, API_Gravatar::hash($a));
|
||||
}
|
||||
|
||||
public function providerHash()
|
||||
{
|
||||
return [
|
||||
['foo@bar.com', 'f3ada405ce890b6f8204094deb12d8a8'],
|
||||
['FOO@BAR.COM', 'f3ada405ce890b6f8204094deb12d8a8'],
|
||||
];
|
||||
}
|
||||
public function providerHash()
|
||||
{
|
||||
return [
|
||||
['foo@bar.com', 'f3ada405ce890b6f8204094deb12d8a8'],
|
||||
['FOO@BAR.COM', 'f3ada405ce890b6f8204094deb12d8a8'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid email address.
|
||||
*/
|
||||
public function testImgInvalidEmail()
|
||||
{
|
||||
API_Gravatar::img('invalidemail');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid email address.
|
||||
*/
|
||||
public function testImgInvalidEmail()
|
||||
{
|
||||
API_Gravatar::img('invalidemail');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid size parameter, expecting an integer between 1 and 2048.
|
||||
*/
|
||||
public function testImgInvalidSize()
|
||||
{
|
||||
API_Gravatar::img('foo@bar.com', 2050);
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid size parameter, expecting an integer between 1 and 2048.
|
||||
*/
|
||||
public function testImgInvalidSize()
|
||||
{
|
||||
API_Gravatar::img('foo@bar.com', 2050);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid default parameter, expecting gravatar, 404, mm, identicon, monsterid, wavatar, retro, blank or a valid URL.
|
||||
*/
|
||||
public function testImgInvalidDefault()
|
||||
{
|
||||
API_Gravatar::img('foo@bar.com', 80, 'invalid');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid default parameter, expecting gravatar, 404, mm, identicon, monsterid, wavatar, retro, blank or a valid URL.
|
||||
*/
|
||||
public function testImgInvalidDefault()
|
||||
{
|
||||
API_Gravatar::img('foo@bar.com', 80, 'invalid');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid rating parameter, expecting g, pg, r or x.
|
||||
*/
|
||||
public function testImgInvalidRating()
|
||||
{
|
||||
API_Gravatar::img('foo@bar.com', 80, 'gravatar', 'sexytime');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid rating parameter, expecting g, pg, r or x.
|
||||
*/
|
||||
public function testImgInvalidRating()
|
||||
{
|
||||
API_Gravatar::img('foo@bar.com', 80, 'gravatar', 'sexytime');
|
||||
}
|
||||
|
||||
public function testURLDefault()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<img src="http://www.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8?s=80&d=http%253A%252F%252Fexample.org%252Ficon&r=g">',
|
||||
API_Gravatar::img('foo@bar.com', 80, 'http://example.org/icon')
|
||||
);
|
||||
}
|
||||
public function testURLDefault()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<img src="http://www.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8?s=80&d=http%253A%252F%252Fexample.org%252Ficon&r=g">',
|
||||
API_Gravatar::img('foo@bar.com', 80, 'http://example.org/icon')
|
||||
);
|
||||
}
|
||||
|
||||
public function testForce()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<img src="http://www.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8?s=80&d=&r=g&f=y">',
|
||||
API_Gravatar::img('foo@bar.com', 80, 'gravatar', 'g', true)
|
||||
);
|
||||
}
|
||||
public function testForce()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<img src="http://www.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8?s=80&d=&r=g&f=y">',
|
||||
API_Gravatar::img('foo@bar.com', 80, 'gravatar', 'g', true)
|
||||
);
|
||||
}
|
||||
|
||||
public function testSecure()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<img src="https://secure.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8?s=80&d=&r=g">',
|
||||
API_Gravatar::img('foo@bar.com', 80, 'gravatar', 'g', false, true)
|
||||
);
|
||||
}
|
||||
public function testSecure()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<img src="https://secure.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8?s=80&d=&r=g">',
|
||||
API_Gravatar::img('foo@bar.com', 80, 'gravatar', 'g', false, true)
|
||||
);
|
||||
}
|
||||
|
||||
public function testImg()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<img src="http://www.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8?s=80&d=&r=g">',
|
||||
API_Gravatar::img('foo@bar.com')
|
||||
);
|
||||
}
|
||||
public function testImg()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<img src="http://www.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8?s=80&d=&r=g">',
|
||||
API_Gravatar::img('foo@bar.com')
|
||||
);
|
||||
}
|
||||
|
||||
public function testImgWithParameters()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<img src="http://www.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8?s=80&d=&r=g" class="gravatar">',
|
||||
API_Gravatar::img('foo@bar.com', 80, 'gravatar', 'g', false, false, ['class' => 'gravatar'])
|
||||
);
|
||||
}
|
||||
public function testImgWithParameters()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<img src="http://www.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8?s=80&d=&r=g" class="gravatar">',
|
||||
API_Gravatar::img('foo@bar.com', 80, 'gravatar', 'g', false, false, ['class' => 'gravatar'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,67 +2,66 @@
|
|||
|
||||
class API_PlaceholdIt_Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $placeholdit;
|
||||
private $placeholdit;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->placeholdit = new API_PlaceholdIt();
|
||||
}
|
||||
public function setUp()
|
||||
{
|
||||
$this->placeholdit = new API_PlaceholdIt();
|
||||
}
|
||||
|
||||
public function testInstantiateObject()
|
||||
{
|
||||
$this->assertInstanceOf('API_PlaceholdIt', $this->placeholdit);
|
||||
}
|
||||
public function testInstantiateObject()
|
||||
{
|
||||
$this->assertInstanceOf('API_PlaceholdIt', $this->placeholdit);
|
||||
}
|
||||
|
||||
public function testURL()
|
||||
{
|
||||
$expected = 'http://placehold.it/350x150.png/ffffff/000000&text=PICKLES+Rules%21';
|
||||
$url = $this->placeholdit->url(350, 150, 'png', 'ffffff', '000000', 'PICKLES Rules!');
|
||||
$this->assertEquals($expected, $url);
|
||||
}
|
||||
public function testURL()
|
||||
{
|
||||
$expected = 'http://placehold.it/350x150.png/ffffff/000000&text=PICKLES+Rules%21';
|
||||
$url = $this->placeholdit->url(350, 150, 'png', 'ffffff', '000000', 'PICKLES Rules!');
|
||||
$this->assertEquals($expected, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid format. Valid formats: gif, jpeg, jpg and png.
|
||||
*/
|
||||
public function testInvalidFormat()
|
||||
{
|
||||
$this->placeholdit->url(350, 150, 'invalid');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid format. Valid formats: gif, jpeg, jpg and png.
|
||||
*/
|
||||
public function testInvalidFormat()
|
||||
{
|
||||
$this->placeholdit->url(350, 150, 'invalid');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage You must specify a background color if you wish to specify a foreground color.
|
||||
*/
|
||||
public function testForegroundNoBackground()
|
||||
{
|
||||
$this->placeholdit->url(350, 150, 'png', false, '000000');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage You must specify a background color if you wish to specify a foreground color.
|
||||
*/
|
||||
public function testForegroundNoBackground()
|
||||
{
|
||||
$this->placeholdit->url(350, 150, 'png', false, '000000');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The background color must be a 6 character hex code.
|
||||
*/
|
||||
public function testInvalidBackground()
|
||||
{
|
||||
$this->placeholdit->url(350, 150, 'png', 'fff');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The background color must be a 6 character hex code.
|
||||
*/
|
||||
public function testInvalidBackground()
|
||||
{
|
||||
$this->placeholdit->url(350, 150, 'png', 'fff');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The foreground color must be a 6 character hex code.
|
||||
*/
|
||||
public function testInvalidForeground()
|
||||
{
|
||||
$this->placeholdit->url(350, 150, 'png', 'ffffff', '000');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The foreground color must be a 6 character hex code.
|
||||
*/
|
||||
public function testInvalidForeground()
|
||||
{
|
||||
$this->placeholdit->url(350, 150, 'png', 'ffffff', '000');
|
||||
}
|
||||
|
||||
public function testIMG()
|
||||
{
|
||||
$expected = '<img src="http://placehold.it/350x150.png/ffffff/000000&text=PICKLES+Rules%21">';
|
||||
$url = $this->placeholdit->img(350, 150, 'png', 'ffffff', '000000', 'PICKLES Rules!');
|
||||
$this->assertEquals($expected, $url);
|
||||
}
|
||||
public function testIMG()
|
||||
{
|
||||
$expected = '<img src="http://placehold.it/350x150.png/ffffff/000000&text=PICKLES+Rules%21">';
|
||||
$url = $this->placeholdit->img(350, 150, 'png', 'ffffff', '000000', 'PICKLES Rules!');
|
||||
$this->assertEquals($expected, $url);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,105 +2,104 @@
|
|||
|
||||
class BrowserTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->assertInstanceOf('Browser', Browser::getInstance());
|
||||
}
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->assertInstanceOf('Browser', Browser::getInstance());
|
||||
}
|
||||
|
||||
public function testSetAndGet()
|
||||
{
|
||||
$this->assertTrue(Browser::set('foo', 'bar'));
|
||||
$this->assertEquals('bar', Browser::get('foo'));
|
||||
}
|
||||
public function testSetAndGet()
|
||||
{
|
||||
$this->assertTrue(Browser::set('foo', 'bar'));
|
||||
$this->assertEquals('bar', Browser::get('foo'));
|
||||
}
|
||||
|
||||
public function testMissingVariable()
|
||||
{
|
||||
$this->assertFalse(Browser::get('missing'));
|
||||
}
|
||||
public function testMissingVariable()
|
||||
{
|
||||
$this->assertFalse(Browser::get('missing'));
|
||||
}
|
||||
|
||||
public function testGoHome()
|
||||
{
|
||||
Browser::goHome();
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/', xdebug_get_headers()));
|
||||
}
|
||||
public function testGoHome()
|
||||
{
|
||||
Browser::goHome();
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testIsMobile()
|
||||
{
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16';
|
||||
public function testIsMobile()
|
||||
{
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16';
|
||||
|
||||
$this->assertTrue(Browser::isMobile());
|
||||
}
|
||||
$this->assertTrue(Browser::isMobile());
|
||||
}
|
||||
|
||||
public function testIsNotMobile()
|
||||
{
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/537.73.11';
|
||||
public function testIsNotMobile()
|
||||
{
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/537.73.11';
|
||||
|
||||
$this->assertFalse(Browser::isMobile());
|
||||
}
|
||||
$this->assertFalse(Browser::isMobile());
|
||||
}
|
||||
|
||||
public function testRemoteIPNone()
|
||||
{
|
||||
$this->assertFalse(Browser::remoteIP());
|
||||
}
|
||||
public function testRemoteIPNone()
|
||||
{
|
||||
$this->assertFalse(Browser::remoteIP());
|
||||
}
|
||||
|
||||
public function testRemoteIPRemoteAddress()
|
||||
{
|
||||
$_SERVER['REMOTE_ADDR'] = '1.2.3.4';
|
||||
public function testRemoteIPRemoteAddress()
|
||||
{
|
||||
$_SERVER['REMOTE_ADDR'] = '1.2.3.4';
|
||||
|
||||
$this->assertEquals('1.2.3.4', Browser::remoteIP());
|
||||
}
|
||||
$this->assertEquals('1.2.3.4', Browser::remoteIP());
|
||||
}
|
||||
|
||||
public function testRemoteIPHTTPXForwardedFor()
|
||||
{
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '2.3.4.5';
|
||||
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', Browser::remoteIP());
|
||||
}
|
||||
|
||||
public function testRemoteIPHTTPClientIP()
|
||||
{
|
||||
$_SERVER['HTTP_CLIENT_IP'] = '3.4.5.6';
|
||||
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', Browser::remoteIP());
|
||||
}
|
||||
|
||||
public function testStatus1xx()
|
||||
{
|
||||
Browser::status(100);
|
||||
$this->assertTrue(in_array('Status: 100 Continue', xdebug_get_headers()));
|
||||
}
|
||||
public function testStatus1xx()
|
||||
{
|
||||
Browser::status(100);
|
||||
$this->assertTrue(in_array('Status: 100 Continue', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testStatus2xx()
|
||||
{
|
||||
Browser::status(200);
|
||||
$this->assertTrue(in_array('Status: 200 OK', xdebug_get_headers()));
|
||||
}
|
||||
public function testStatus2xx()
|
||||
{
|
||||
Browser::status(200);
|
||||
$this->assertTrue(in_array('Status: 200 OK', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testStatus3xx()
|
||||
{
|
||||
Browser::status(300);
|
||||
$this->assertTrue(in_array('Status: 300 Multiple Choices', xdebug_get_headers()));
|
||||
}
|
||||
public function testStatus3xx()
|
||||
{
|
||||
Browser::status(300);
|
||||
$this->assertTrue(in_array('Status: 300 Multiple Choices', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testStatus4xx()
|
||||
{
|
||||
Browser::status(400);
|
||||
$this->assertTrue(in_array('Status: 400 Bad Request', xdebug_get_headers()));
|
||||
}
|
||||
public function testStatus4xx()
|
||||
{
|
||||
Browser::status(400);
|
||||
$this->assertTrue(in_array('Status: 400 Bad Request', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testStatus5xx()
|
||||
{
|
||||
Browser::status(500);
|
||||
$this->assertTrue(in_array('Status: 500 Internal Server Error', xdebug_get_headers()));
|
||||
}
|
||||
public function testStatus5xx()
|
||||
{
|
||||
Browser::status(500);
|
||||
$this->assertTrue(in_array('Status: 500 Internal Server Error', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testRefresh()
|
||||
{
|
||||
$_SERVER['REQUEST_URI'] = '/some/uri';
|
||||
Browser::goHome();
|
||||
Browser::refresh();
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/some/uri', xdebug_get_headers()));
|
||||
}
|
||||
public function testRefresh()
|
||||
{
|
||||
$_SERVER['REQUEST_URI'] = '/some/uri';
|
||||
Browser::goHome();
|
||||
Browser::refresh();
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/some/uri', xdebug_get_headers()));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,87 +2,86 @@
|
|||
|
||||
class CacheTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $config;
|
||||
private $cache;
|
||||
private $config;
|
||||
private $cache;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
$this->config->data['pickles']['cache'] = 'mc';
|
||||
$this->config->data['datasources']['mc'] = [
|
||||
'type' => 'memcache',
|
||||
'hostname' => 'localhost',
|
||||
'port' => 11211,
|
||||
'namespace' => 'ns',
|
||||
];
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
$this->config->data['pickles']['cache'] = 'mc';
|
||||
$this->config->data['datasources']['mc'] = [
|
||||
'type' => 'memcache',
|
||||
'hostname' => 'localhost',
|
||||
'port' => 11211,
|
||||
'namespace' => 'ns',
|
||||
];
|
||||
|
||||
$this->cache = Cache::getInstance();
|
||||
}
|
||||
$this->cache = Cache::getInstance();
|
||||
}
|
||||
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->assertInstanceOf('Cache', $this->cache);
|
||||
}
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->assertInstanceOf('Cache', $this->cache);
|
||||
}
|
||||
|
||||
public function testSetAndGet()
|
||||
{
|
||||
$key = String::random();
|
||||
$value = String::random();
|
||||
public function testSetAndGet()
|
||||
{
|
||||
$key = String::random();
|
||||
$value = String::random();
|
||||
|
||||
$this->cache->set($key, $value);
|
||||
$this->cache->set($key, $value);
|
||||
|
||||
$this->assertEquals($value, $this->cache->get($key));
|
||||
}
|
||||
$this->assertEquals($value, $this->cache->get($key));
|
||||
}
|
||||
|
||||
public function testSetAndGetMultiple()
|
||||
{
|
||||
$keys = $values = $expected = [];
|
||||
public function testSetAndGetMultiple()
|
||||
{
|
||||
$keys = $values = $expected = [];
|
||||
|
||||
for ($i = 0; $i < 5; $i++)
|
||||
{
|
||||
$keys[] = String::random();
|
||||
$values[] = String::random();
|
||||
}
|
||||
for ($i = 0; $i < 5; $i++)
|
||||
{
|
||||
$keys[] = String::random();
|
||||
$values[] = String::random();
|
||||
}
|
||||
|
||||
foreach ($keys as $key => $key_name)
|
||||
{
|
||||
$value = $values[$key];
|
||||
$expected['NS-' . strtoupper($key_name)] = $value;
|
||||
$this->cache->set($key_name, $value);
|
||||
}
|
||||
foreach ($keys as $key => $key_name)
|
||||
{
|
||||
$value = $values[$key];
|
||||
$expected['NS-' . strtoupper($key_name)] = $value;
|
||||
$this->cache->set($key_name, $value);
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, $this->cache->get($keys));
|
||||
}
|
||||
$this->assertEquals($expected, $this->cache->get($keys));
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$key = String::random();
|
||||
$value = String::random();
|
||||
public function testDelete()
|
||||
{
|
||||
$key = String::random();
|
||||
$value = String::random();
|
||||
|
||||
$this->cache->set($key, $value);
|
||||
$this->cache->delete($key);
|
||||
$this->cache->set($key, $value);
|
||||
$this->cache->delete($key);
|
||||
|
||||
$this->assertFalse($this->cache->get($key));
|
||||
}
|
||||
$this->assertFalse($this->cache->get($key));
|
||||
}
|
||||
|
||||
public function testIncrement()
|
||||
{
|
||||
$key = String::random();
|
||||
public function testIncrement()
|
||||
{
|
||||
$key = String::random();
|
||||
|
||||
$this->assertFalse($this->cache->increment($key));
|
||||
$this->assertFalse($this->cache->increment($key));
|
||||
|
||||
$this->cache->set($key, 1);
|
||||
$this->cache->set($key, 1);
|
||||
|
||||
$this->assertEquals(2, $this->cache->increment($key));
|
||||
$this->assertEquals(3, $this->cache->increment($key));
|
||||
$this->assertEquals(4, $this->cache->increment($key));
|
||||
}
|
||||
$this->assertEquals(2, $this->cache->increment($key));
|
||||
$this->assertEquals(3, $this->cache->increment($key));
|
||||
$this->assertEquals(4, $this->cache->increment($key));
|
||||
}
|
||||
|
||||
// Doesn't do much but test that the destructor doesn't explode
|
||||
public function testDestructor()
|
||||
{
|
||||
$this->cache->__destruct();
|
||||
}
|
||||
// Doesn't do much but test that the destructor doesn't explode
|
||||
public function testDestructor()
|
||||
{
|
||||
$this->cache->__destruct();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,161 +2,160 @@
|
|||
|
||||
class ConfigTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $config;
|
||||
private $config;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
setupConfig([]);
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
setupConfig([]);
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
}
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
}
|
||||
|
||||
public function testConfigProperty()
|
||||
{
|
||||
$config = new Config();
|
||||
public function testConfigProperty()
|
||||
{
|
||||
$config = new Config();
|
||||
|
||||
$this->assertTrue(PHPUnit_Framework_Assert::readAttribute($config, 'config'));
|
||||
}
|
||||
$this->assertTrue(PHPUnit_Framework_Assert::readAttribute($config, 'config'));
|
||||
}
|
||||
|
||||
public function testInstanceOf()
|
||||
{
|
||||
$this->assertInstanceOf('Config', $this->config);
|
||||
}
|
||||
public function testInstanceOf()
|
||||
{
|
||||
$this->assertInstanceOf('Config', $this->config);
|
||||
}
|
||||
|
||||
public function testUndefined()
|
||||
{
|
||||
$this->assertFalse($this->config->undefined);
|
||||
}
|
||||
public function testUndefined()
|
||||
{
|
||||
$this->assertFalse($this->config->undefined);
|
||||
}
|
||||
|
||||
public function testDefinedEnvironment()
|
||||
{
|
||||
setUpConfig([
|
||||
'environment' => 'local',
|
||||
]);
|
||||
public function testDefinedEnvironment()
|
||||
{
|
||||
setUpConfig([
|
||||
'environment' => 'local',
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Config();
|
||||
|
||||
$this->assertEquals('local', $config->environment);
|
||||
}
|
||||
$this->assertEquals('local', $config->environment);
|
||||
}
|
||||
|
||||
public function testMultipleEnvironmentsByIP()
|
||||
{
|
||||
setUpConfig([
|
||||
'environments' => [
|
||||
'local' => '127.0.0.1',
|
||||
'prod' => '123.456.789.0',
|
||||
],
|
||||
]);
|
||||
public function testMultipleEnvironmentsByIP()
|
||||
{
|
||||
setUpConfig([
|
||||
'environments' => [
|
||||
'local' => '127.0.0.1',
|
||||
'prod' => '123.456.789.0',
|
||||
],
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Config();
|
||||
|
||||
$this->assertEquals('local', $config->environment);
|
||||
}
|
||||
$this->assertEquals('local', $config->environment);
|
||||
}
|
||||
|
||||
public function testMultipleEnvironmentsByRegex()
|
||||
{
|
||||
setUpConfig([
|
||||
'environments' => [
|
||||
'local' => '/^local\.testsite\.com$/',
|
||||
'prod' => '/^testsite\.com$/',
|
||||
],
|
||||
]);
|
||||
public function testMultipleEnvironmentsByRegex()
|
||||
{
|
||||
setUpConfig([
|
||||
'environments' => [
|
||||
'local' => '/^local\.testsite\.com$/',
|
||||
'prod' => '/^testsite\.com$/',
|
||||
],
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Config();
|
||||
|
||||
$this->assertEquals('prod', $config->environment);
|
||||
}
|
||||
$this->assertEquals('prod', $config->environment);
|
||||
}
|
||||
|
||||
public function testCLIEnvironment()
|
||||
{
|
||||
unset($_SERVER['REQUEST_METHOD']);
|
||||
$_SERVER['argv'][1] = 'prod';
|
||||
public function testCLIEnvironment()
|
||||
{
|
||||
unset($_SERVER['REQUEST_METHOD']);
|
||||
$_SERVER['argv'][1] = 'prod';
|
||||
|
||||
setUpConfig([
|
||||
'environments' => [
|
||||
'local' => '127.0.0.1',
|
||||
'prod' => '123.456.789.0',
|
||||
],
|
||||
]);
|
||||
setUpConfig([
|
||||
'environments' => [
|
||||
'local' => '127.0.0.1',
|
||||
'prod' => '123.456.789.0',
|
||||
],
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Config();
|
||||
|
||||
$this->assertEquals('prod', $config->environment);
|
||||
}
|
||||
$this->assertEquals('prod', $config->environment);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage You must pass an environment (e.g. php script.php <environment>)
|
||||
*/
|
||||
public function testCLIMissingEnvironment()
|
||||
{
|
||||
unset($_SERVER['REQUEST_METHOD']);
|
||||
$_SERVER['argc'] = 1;
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage You must pass an environment (e.g. php script.php <environment>)
|
||||
*/
|
||||
public function testCLIMissingEnvironment()
|
||||
{
|
||||
unset($_SERVER['REQUEST_METHOD']);
|
||||
$_SERVER['argc'] = 1;
|
||||
|
||||
setUpConfig(['environments' => []]);
|
||||
setUpConfig(['environments' => []]);
|
||||
|
||||
$config = new Config();
|
||||
}
|
||||
$config = new Config();
|
||||
}
|
||||
|
||||
public function testProfiler()
|
||||
{
|
||||
setUpConfig([
|
||||
'environment' => 'local',
|
||||
'pickles' => ['profiler' => true],
|
||||
]);
|
||||
public function testProfiler()
|
||||
{
|
||||
setUpConfig([
|
||||
'environment' => 'local',
|
||||
'pickles' => ['profiler' => true],
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Config();
|
||||
|
||||
$this->assertTrue($config->pickles['profiler']);
|
||||
}
|
||||
$this->assertTrue($config->pickles['profiler']);
|
||||
}
|
||||
|
||||
public function testProfilerArray()
|
||||
{
|
||||
setUpConfig([
|
||||
'environment' => 'local',
|
||||
'pickles' => ['profiler' => ['objects', 'timers']],
|
||||
]);
|
||||
public function testProfilerArray()
|
||||
{
|
||||
setUpConfig([
|
||||
'environment' => 'local',
|
||||
'pickles' => ['profiler' => ['objects', 'timers']],
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Config();
|
||||
|
||||
$this->assertEquals('objects,timers', $config->pickles['profiler']);
|
||||
}
|
||||
$this->assertEquals('objects,timers', $config->pickles['profiler']);
|
||||
}
|
||||
|
||||
public function testSecurityConstant()
|
||||
{
|
||||
setUpConfig([
|
||||
'environment' => 'local',
|
||||
'security' => ['levels' => [10 => 'level']],
|
||||
]);
|
||||
public function testSecurityConstant()
|
||||
{
|
||||
setUpConfig([
|
||||
'environment' => 'local',
|
||||
'security' => ['levels' => [10 => 'level']],
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Config();
|
||||
|
||||
$this->assertEquals(10, SECURITY_LEVEL_USER);
|
||||
}
|
||||
$this->assertEquals(10, SECURITY_LEVEL_USER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The constant SECURITY_LEVEL_LEVEL is already defined
|
||||
*/
|
||||
public function testSecurityConstantAlreadyDefined()
|
||||
{
|
||||
setUpConfig([
|
||||
'environment' => 'local',
|
||||
'security' => ['levels' => [10 => 'level']],
|
||||
]);
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The constant SECURITY_LEVEL_LEVEL is already defined
|
||||
*/
|
||||
public function testSecurityConstantAlreadyDefined()
|
||||
{
|
||||
setUpConfig([
|
||||
'environment' => 'local',
|
||||
'security' => ['levels' => [10 => 'level']],
|
||||
]);
|
||||
|
||||
$config = new Config();
|
||||
$config = new Config();
|
||||
|
||||
$this->assertEquals(10, SECURITY_LEVEL_USER);
|
||||
}
|
||||
$this->assertEquals(10, SECURITY_LEVEL_USER);
|
||||
}
|
||||
|
||||
// This test is just for coverage
|
||||
public function testConfigArrayMissing()
|
||||
{
|
||||
file_put_contents(SITE_PATH . 'config.php', '');
|
||||
new Config();
|
||||
}
|
||||
// This test is just for coverage
|
||||
public function testConfigArrayMissing()
|
||||
{
|
||||
file_put_contents(SITE_PATH . 'config.php', '');
|
||||
new Config();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,358 +2,357 @@
|
|||
|
||||
class ControllerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $config;
|
||||
private $config;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
$this->config->data['pickles']['disabled'] = false;
|
||||
$this->config->data['pickles']['profiler'] = false;
|
||||
$this->config->data['security']['levels'][10] = 'USER';
|
||||
$this->config->data['security']['levels'][20] = 'ADMIN';
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
$this->config->data['pickles']['disabled'] = false;
|
||||
$this->config->data['pickles']['profiler'] = false;
|
||||
$this->config->data['security']['levels'][10] = 'USER';
|
||||
$this->config->data['security']['levels'][20] = 'ADMIN';
|
||||
|
||||
setUpRequest('home');
|
||||
setUpRequest('home');
|
||||
|
||||
$module = '<?php class home extends Module { } ?>';
|
||||
$module = '<?php class home extends Module { }';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'home.php', $module);
|
||||
}
|
||||
file_put_contents(SITE_MODULE_PATH . 'home.php', $module);
|
||||
}
|
||||
|
||||
public function testSiteDown()
|
||||
{
|
||||
$this->config->data['pickles']['disabled'] = true;
|
||||
public function testSiteDown()
|
||||
{
|
||||
$this->config->data['pickles']['disabled'] = true;
|
||||
|
||||
$this->expectOutputRegex('/Test Server is currently down for maintenance/');
|
||||
$this->expectOutputRegex('/Test Server is currently down for maintenance/');
|
||||
|
||||
new Controller();
|
||||
}
|
||||
new Controller();
|
||||
}
|
||||
|
||||
public function testCustomSiteDown()
|
||||
{
|
||||
$this->config->data['pickles']['disabled'] = true;
|
||||
public function testCustomSiteDown()
|
||||
{
|
||||
$this->config->data['pickles']['disabled'] = true;
|
||||
|
||||
file_put_contents(SITE_TEMPLATE_PATH . '__shared/maintenance.phtml', '<h1>Custom Down for Maintenance</h1>');
|
||||
file_put_contents(SITE_TEMPLATE_PATH . '__shared/maintenance.phtml', '<h1>Custom Down for Maintenance</h1>');
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
$this->expectOutputRegex('/<h1>Custom Down for Maintenance<\/h1>/');
|
||||
}
|
||||
$this->expectOutputRegex('/<h1>Custom Down for Maintenance<\/h1>/');
|
||||
}
|
||||
|
||||
public function testAttributesInURI()
|
||||
{
|
||||
setUpRequest('home/id:123');
|
||||
public function testAttributesInURI()
|
||||
{
|
||||
setUpRequest('home/id:123');
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
$this->assertEquals(123, Browser::get('id'));
|
||||
$this->assertEquals(123, Browser::get('id'));
|
||||
|
||||
setUpRequest('home/id:456/foo:bar');
|
||||
setUpRequest('home/id:456/foo:bar');
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
// Compensates for 2 empty template executions of the Controller
|
||||
$this->expectOutputString('[][]');
|
||||
$this->assertEquals(456, Browser::get('id'));
|
||||
$this->assertEquals('bar', Browser::get('foo'));
|
||||
}
|
||||
// Compensates for 2 empty template executions of the Controller
|
||||
$this->expectOutputString('[][]');
|
||||
$this->assertEquals(456, Browser::get('id'));
|
||||
$this->assertEquals('bar', Browser::get('foo'));
|
||||
}
|
||||
|
||||
public function testUpperCaseURI()
|
||||
{
|
||||
setUpRequest('TESTING');
|
||||
public function testUpperCaseURI()
|
||||
{
|
||||
setUpRequest('TESTING');
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
$this->assertTrue(in_array('Location: /testing', xdebug_get_headers()));
|
||||
}
|
||||
$this->assertTrue(in_array('Location: /testing', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testForceSecure()
|
||||
{
|
||||
setUpRequest('secure');
|
||||
public function testForceSecure()
|
||||
{
|
||||
setUpRequest('secure');
|
||||
|
||||
$module = '<?php class secure extends Module { public $secure = true; } ?>';
|
||||
$module = '<?php class secure extends Module { public $secure = true; }';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'secure.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'secure.php', $module);
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
$this->assertTrue(in_array('Location: https://testsite.com/secure', xdebug_get_headers()));
|
||||
}
|
||||
$this->assertTrue(in_array('Location: https://testsite.com/secure', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testForceInsecure()
|
||||
{
|
||||
setUpRequest('insecure');
|
||||
$_SERVER['HTTPS'] = 'on';
|
||||
public function testForceInsecure()
|
||||
{
|
||||
setUpRequest('insecure');
|
||||
$_SERVER['HTTPS'] = 'on';
|
||||
|
||||
$module = '<?php class insecure extends Module { public $secure = false; } ?>';
|
||||
$module = '<?php class insecure extends Module { public $secure = false; }';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'insecure.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'insecure.php', $module);
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/insecure', xdebug_get_headers()));
|
||||
}
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/insecure', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testNotAuthenticated()
|
||||
{
|
||||
setUpRequest('notauth');
|
||||
public function testNotAuthenticated()
|
||||
{
|
||||
setUpRequest('notauth');
|
||||
|
||||
$module = '<?php class notauth extends Module { public $security = SECURITY_LEVEL_USER; } ?>';
|
||||
$module = '<?php class notauth extends Module { public $security = SECURITY_LEVEL_USER; }';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'notauth.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'notauth.php', $module);
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
// Compensates for an empty template due to exit() being skipped
|
||||
$this->expectOutputString('[]');
|
||||
// Compensates for an empty template due to exit() being skipped
|
||||
$this->expectOutputString('[]');
|
||||
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers()));
|
||||
}
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testSecurityArray()
|
||||
{
|
||||
setUpRequest('securityarray');
|
||||
public function testSecurityArray()
|
||||
{
|
||||
setUpRequest('securityarray');
|
||||
|
||||
$module = '<?php class securityarray extends Module { public $security = [SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]; } ?>';
|
||||
$module = '<?php class securityarray extends Module { public $security = [SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]; }';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'securityarray.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'securityarray.php', $module);
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
// Compensates for an empty template due to exit() being skipped
|
||||
$this->expectOutputString('[]');
|
||||
// Compensates for an empty template due to exit() being skipped
|
||||
$this->expectOutputString('[]');
|
||||
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers()));
|
||||
}
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testSecurityArrayTypeString()
|
||||
{
|
||||
setUpRequest('securityarraytypestring');
|
||||
public function testSecurityArrayTypeString()
|
||||
{
|
||||
setUpRequest('securityarraytypestring');
|
||||
|
||||
$module = '<?php class securityarraytypestring extends Module { public $security = ["type" => "IS", "level" => SECURITY_LEVEL_USER]; } ?>';
|
||||
$module = '<?php class securityarraytypestring extends Module { public $security = ["type" => "IS", "level" => SECURITY_LEVEL_USER]; }';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'securityarraytypestring.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'securityarraytypestring.php', $module);
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
// Compensates for an empty template due to exit() being skipped
|
||||
$this->expectOutputString('[]');
|
||||
// Compensates for an empty template due to exit() being skipped
|
||||
$this->expectOutputString('[]');
|
||||
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers()));
|
||||
}
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testSecurityArrayTypeArray()
|
||||
{
|
||||
setUpRequest('securityarraytypearray');
|
||||
public function testSecurityArrayTypeArray()
|
||||
{
|
||||
setUpRequest('securityarraytypearray');
|
||||
|
||||
$module = '<?php class securityarraytypearray extends Module { public $security = ["type" => "IS", "level" => [SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]]; } ?>';
|
||||
$module = '<?php class securityarraytypearray extends Module { public $security = ["type" => "IS", "level" => [SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]]; }';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'securityarraytypearray.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'securityarraytypearray.php', $module);
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
// Compensates for an empty template due to exit() being skipped
|
||||
$this->expectOutputString('[]');
|
||||
// Compensates for an empty template due to exit() being skipped
|
||||
$this->expectOutputString('[]');
|
||||
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers()));
|
||||
}
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testSecurityArrayTypeBetween()
|
||||
{
|
||||
setUpRequest('securityarraytypebetween');
|
||||
public function testSecurityArrayTypeBetween()
|
||||
{
|
||||
setUpRequest('securityarraytypebetween');
|
||||
|
||||
$module = '<?php class securityarraytypebetween extends Module { public $security = ["type" => "BETWEEN", "levels" => [SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]]; } ?>';
|
||||
$module = '<?php class securityarraytypebetween extends Module { public $security = ["type" => "BETWEEN", "levels" => [SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]]; }';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'securityarraytypebetween.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'securityarraytypebetween.php', $module);
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
// Compensates for an empty template due to exit() being skipped
|
||||
$this->expectOutputString('[]');
|
||||
// Compensates for an empty template due to exit() being skipped
|
||||
$this->expectOutputString('[]');
|
||||
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers()));
|
||||
}
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testSecurityArrayTypeHas()
|
||||
{
|
||||
setUpRequest('securityarraytypehas');
|
||||
public function testSecurityArrayTypeHas()
|
||||
{
|
||||
setUpRequest('securityarraytypehas');
|
||||
|
||||
$module = '<?php class securityarraytypehas extends Module { public $security = ["type" => "HAS", "level" => SECURITY_LEVEL_USER]; } ?>';
|
||||
$module = '<?php class securityarraytypehas extends Module { public $security = ["type" => "HAS", "level" => SECURITY_LEVEL_USER]; }';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'securityarraytypehas.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'securityarraytypehas.php', $module);
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
// Compensates for an empty template due to exit() being skipped
|
||||
$this->expectOutputString('[]');
|
||||
// Compensates for an empty template due to exit() being skipped
|
||||
$this->expectOutputString('[]');
|
||||
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers()));
|
||||
}
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
public function testNotAuthenticatedPOST()
|
||||
{
|
||||
setUpRequest('notauthpost', 'POST');
|
||||
public function testNotAuthenticatedPOST()
|
||||
{
|
||||
setUpRequest('notauthpost', 'POST');
|
||||
|
||||
$module = '<?php class notauthpost extends Module { public $security = SECURITY_LEVEL_USER; } ?>';
|
||||
$module = '<?php class notauthpost extends Module { public $security = SECURITY_LEVEL_USER; }';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'notauthpost.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'notauthpost.php', $module);
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
$this->expectOutputRegex('/You are not properly authenticated/');
|
||||
}
|
||||
$this->expectOutputRegex('/You are not properly authenticated/');
|
||||
}
|
||||
|
||||
public function testAuthenticated()
|
||||
{
|
||||
setUpRequest('auth');
|
||||
public function testAuthenticated()
|
||||
{
|
||||
setUpRequest('auth');
|
||||
|
||||
$module = '<?php class auth extends Module { '
|
||||
. 'public $security = SECURITY_LEVEL_USER;'
|
||||
. 'public function __default() { return ["foo" => "bar"]; }'
|
||||
. '} ?>';
|
||||
$module = '<?php class auth extends Module { '
|
||||
. 'public $security = SECURITY_LEVEL_USER;'
|
||||
. 'public function __default() { return ["foo" => "bar"]; }'
|
||||
. '}';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'auth.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'auth.php', $module);
|
||||
|
||||
Security::login(1, 10, 'USER');
|
||||
new Controller();
|
||||
Security::login(1, 10, 'USER');
|
||||
new Controller();
|
||||
|
||||
$this->expectOutputString('{"foo":"bar"}');
|
||||
}
|
||||
$this->expectOutputString('{"foo":"bar"}');
|
||||
}
|
||||
|
||||
public function testRoleDefaultMethod()
|
||||
{
|
||||
setUpRequest('rolemethod');
|
||||
public function testRoleDefaultMethod()
|
||||
{
|
||||
setUpRequest('rolemethod');
|
||||
|
||||
$module = '<?php class rolemethod extends Module { '
|
||||
. 'public $security = SECURITY_LEVEL_USER;'
|
||||
. 'public function __default() { return ["foo" => "bar"]; }'
|
||||
. 'public function __default_USER() { return ["user" => "me"]; }'
|
||||
. '} ?>';
|
||||
$module = '<?php class rolemethod extends Module { '
|
||||
. 'public $security = SECURITY_LEVEL_USER;'
|
||||
. 'public function __default() { return ["foo" => "bar"]; }'
|
||||
. 'public function __default_USER() { return ["user" => "me"]; }'
|
||||
. '}';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'rolemethod.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'rolemethod.php', $module);
|
||||
|
||||
Security::login(1, 10, 'USER');
|
||||
new Controller();
|
||||
Security::login(1, 10, 'USER');
|
||||
new Controller();
|
||||
|
||||
$this->expectOutputString('{"user":"me"}');
|
||||
}
|
||||
$this->expectOutputString('{"user":"me"}');
|
||||
}
|
||||
|
||||
public function testValidRequestMethod()
|
||||
{
|
||||
setUpRequest('validrequestmethod');
|
||||
public function testValidRequestMethod()
|
||||
{
|
||||
setUpRequest('validrequestmethod');
|
||||
|
||||
$module = '<?php class validrequestmethod extends Module { '
|
||||
. 'public $method = "GET";'
|
||||
. 'public function __default() { return ["foo" => "bar"]; }'
|
||||
. '} ?>';
|
||||
$module = '<?php class validrequestmethod extends Module { '
|
||||
. 'public $method = "GET";'
|
||||
. 'public function __default() { return ["foo" => "bar"]; }'
|
||||
. '}';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'validrequestmethod.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'validrequestmethod.php', $module);
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
$this->expectOutputString('{"foo":"bar"}');
|
||||
}
|
||||
$this->expectOutputString('{"foo":"bar"}');
|
||||
}
|
||||
|
||||
public function testInvalidRequestMethod()
|
||||
{
|
||||
setUpRequest('invalidrequestmethod');
|
||||
public function testInvalidRequestMethod()
|
||||
{
|
||||
setUpRequest('invalidrequestmethod');
|
||||
|
||||
$module = '<?php class invalidrequestmethod extends Module { '
|
||||
. 'public $method = "POST";'
|
||||
. 'public function __default() { return ["foo" => "bar"]; }'
|
||||
. '} ?>';
|
||||
$module = '<?php class invalidrequestmethod extends Module { '
|
||||
. 'public $method = "POST";'
|
||||
. 'public function __default() { return ["foo" => "bar"]; }'
|
||||
. '}';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'invalidrequestmethod.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'invalidrequestmethod.php', $module);
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
$this->expectOutputString('{"status":"error","message":"There was a problem with your request method."}');
|
||||
}
|
||||
$this->expectOutputString('{"status":"error","message":"There was a problem with your request method."}');
|
||||
}
|
||||
|
||||
public function testValidationErrors()
|
||||
{
|
||||
setUpRequest('validationerrors');
|
||||
public function testValidationErrors()
|
||||
{
|
||||
setUpRequest('validationerrors');
|
||||
|
||||
$module = '<?php class validationerrors extends Module { '
|
||||
. 'public $validate = ["test"];'
|
||||
. 'public function __default() { return ["foo" => "bar"]; }'
|
||||
. '} ?>';
|
||||
$module = '<?php class validationerrors extends Module { '
|
||||
. 'public $validate = ["test"];'
|
||||
. 'public function __default() { return ["foo" => "bar"]; }'
|
||||
. '}';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'validationerrors.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'validationerrors.php', $module);
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
$this->expectOutputString('{"status":"error","message":"The test field is required."}');
|
||||
}
|
||||
$this->expectOutputString('{"status":"error","message":"The test field is required."}');
|
||||
}
|
||||
|
||||
public function testError404()
|
||||
{
|
||||
setUpRequest('fourohfour');
|
||||
public function testError404()
|
||||
{
|
||||
setUpRequest('fourohfour');
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
$this->assertTrue(in_array('Status: 404 Not Found', xdebug_get_headers()));
|
||||
$this->expectOutputRegex('/<h1>Not Found<\/h1>/');
|
||||
}
|
||||
$this->assertTrue(in_array('Status: 404 Not Found', xdebug_get_headers()));
|
||||
$this->expectOutputRegex('/<h1>Not Found<\/h1>/');
|
||||
}
|
||||
|
||||
public function testCustomError404()
|
||||
{
|
||||
setUpRequest('customfourohfour');
|
||||
public function testCustomError404()
|
||||
{
|
||||
setUpRequest('customfourohfour');
|
||||
|
||||
file_put_contents(SITE_TEMPLATE_PATH . '__shared/404.phtml', '<h1>Custom Not Found</h1>');
|
||||
file_put_contents(SITE_TEMPLATE_PATH . '__shared/404.phtml', '<h1>Custom Not Found</h1>');
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
$this->assertTrue(in_array('Status: 404 Not Found', xdebug_get_headers()));
|
||||
$this->expectOutputRegex('/<h1>Custom Not Found<\/h1>/');
|
||||
}
|
||||
$this->assertTrue(in_array('Status: 404 Not Found', xdebug_get_headers()));
|
||||
$this->expectOutputRegex('/<h1>Custom Not Found<\/h1>/');
|
||||
}
|
||||
|
||||
public function testProfilerOutput()
|
||||
{
|
||||
$this->config->data['pickles']['profiler'] = true;
|
||||
public function testProfilerOutput()
|
||||
{
|
||||
$this->config->data['pickles']['profiler'] = true;
|
||||
|
||||
$this->expectOutputRegex('/id="pickles-profiler"/');
|
||||
$this->expectOutputRegex('/id="pickles-profiler"/');
|
||||
|
||||
new Controller();
|
||||
}
|
||||
new Controller();
|
||||
}
|
||||
|
||||
public function testTwoValidTemplates()
|
||||
{
|
||||
$this->config->data['pickles']['profiler'] = true;
|
||||
public function testTwoValidTemplates()
|
||||
{
|
||||
$this->config->data['pickles']['profiler'] = true;
|
||||
|
||||
setUpRequest('validtemplates');
|
||||
setUpRequest('validtemplates');
|
||||
|
||||
$module = '<?php class validtemplates extends Module { } ?>';
|
||||
$module = '<?php class validtemplates extends Module { }';
|
||||
|
||||
file_put_contents(SITE_MODULE_PATH . 'validtemplates.php', $module);
|
||||
file_put_contents(SITE_MODULE_PATH . 'validtemplates.php', $module);
|
||||
|
||||
$child_template = SITE_TEMPLATE_PATH . 'validtemplates.phtml';
|
||||
file_put_contents($child_template, '<div>child template</div>');
|
||||
$child_template = SITE_TEMPLATE_PATH . 'validtemplates.phtml';
|
||||
file_put_contents($child_template, '<div>child template</div>');
|
||||
|
||||
// Vim syntax highlighting borks unless ----v
|
||||
$child = '<?php require $this->template; ?' . '>' . "\n";
|
||||
// Vim syntax highlighting borks unless ----v
|
||||
$child = '<?php require $this->template; ?' . '>' . "\n";
|
||||
|
||||
$html = <<<HTML
|
||||
$html = <<<HTML
|
||||
<!doctype html>
|
||||
<html>
|
||||
<body>
|
||||
<h1>parent template</h1>
|
||||
{$child}
|
||||
</body>
|
||||
<body>
|
||||
<h1>parent template</h1>
|
||||
{$child}
|
||||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
|
||||
file_put_contents(SITE_TEMPLATE_PATH . '__shared/index.phtml', $html);
|
||||
file_put_contents(SITE_TEMPLATE_PATH . '__shared/index.phtml', $html);
|
||||
|
||||
new Controller();
|
||||
new Controller();
|
||||
|
||||
$this->expectOutputRegex('/^<!doctype html>
|
||||
$this->expectOutputRegex('/^<!doctype html>
|
||||
<html>
|
||||
<body>
|
||||
<h1>parent template<\/h1>
|
||||
<div>child template<\/div>
|
||||
<\/body>
|
||||
<\/html>.+<style>/');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,27 +2,26 @@
|
|||
|
||||
class ConvertTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerArrayToXML
|
||||
*/
|
||||
public function testArrayToXML($a, $b, $c)
|
||||
{
|
||||
$this->assertEquals(Convert::arrayToXML($a, $b), $c);
|
||||
}
|
||||
/**
|
||||
* @dataProvider providerArrayToXML
|
||||
*/
|
||||
public function testArrayToXML($a, $b, $c)
|
||||
{
|
||||
$this->assertEquals(Convert::arrayToXML($a, $b), $c);
|
||||
}
|
||||
|
||||
public function providerArrayToXML()
|
||||
{
|
||||
return [
|
||||
['foo', false, ''],
|
||||
[['foo', 'bar'], false, '<0>foo</0><1>bar</1>'],
|
||||
[['foo', 'bar'], true, "<0>foo</0>\n<1>bar</1>\n"],
|
||||
[['foo' => 'bar'], false, '<foo>bar</foo>'],
|
||||
[['foo' => 'b & r'], false, '<foo><![CDATA[b & r]]></foo>'],
|
||||
[['children' => ['child' => ['foo', 'bar']]], false, '<children><child>foo</child><child>bar</child></children>'],
|
||||
[['children' => ['child' => ['foo & bar']]], false, '<children><child><![CDATA[foo & bar]]></child></children>'],
|
||||
[['children' => ['child' => ['foo', 'bar']]], true, "<children>\n\t<child>foo</child>\n\t<child>bar</child>\n</children>\n"],
|
||||
];
|
||||
}
|
||||
public function providerArrayToXML()
|
||||
{
|
||||
return [
|
||||
['foo', false, ''],
|
||||
[['foo', 'bar'], false, '<0>foo</0><1>bar</1>'],
|
||||
[['foo', 'bar'], true, "<0>foo</0>\n<1>bar</1>\n"],
|
||||
[['foo' => 'bar'], false, '<foo>bar</foo>'],
|
||||
[['foo' => 'b & r'], false, '<foo><![CDATA[b & r]]></foo>'],
|
||||
[['children' => ['child' => ['foo', 'bar']]], false, '<children><child>foo</child><child>bar</child></children>'],
|
||||
[['children' => ['child' => ['foo & bar']]], false, '<children><child><![CDATA[foo & bar]]></child></children>'],
|
||||
[['children' => ['child' => ['foo', 'bar']]], true, "<children>\n\t<child>foo</child>\n\t<child>bar</child>\n</children>\n"],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,193 +2,192 @@
|
|||
|
||||
class DatabaseTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetInstanceFalse()
|
||||
{
|
||||
$this->assertFalse(Database::getInstance());
|
||||
}
|
||||
public function testGetInstanceFalse()
|
||||
{
|
||||
$this->assertFalse(Database::getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The specified datasource is not defined in the config.
|
||||
*/
|
||||
public function testGetInstanceDatasourceNotDefined()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'bad';
|
||||
Database::getInstance();
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The specified datasource is not defined in the config.
|
||||
*/
|
||||
public function testGetInstanceDatasourceNotDefined()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'bad';
|
||||
Database::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The specified datasource lacks a driver.
|
||||
*/
|
||||
public function testGetInstanceDatasourceLacksDriver()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['datasources'] = [
|
||||
'bad' => [
|
||||
'type' => 'mysql',
|
||||
],
|
||||
];
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The specified datasource lacks a driver.
|
||||
*/
|
||||
public function testGetInstanceDatasourceLacksDriver()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['datasources'] = [
|
||||
'bad' => [
|
||||
'type' => 'mysql',
|
||||
],
|
||||
];
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage There was an error loading the database configuration.
|
||||
*/
|
||||
public function testOpenConfigError()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['datasources'] = [
|
||||
'bad' => [
|
||||
'type' => 'mysql',
|
||||
'driver' => 'pdo_mysql',
|
||||
'database' => 'test',
|
||||
],
|
||||
];
|
||||
$db = Database::getInstance();
|
||||
$db->open();
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage There was an error loading the database configuration.
|
||||
*/
|
||||
public function testOpenConfigError()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['datasources'] = [
|
||||
'bad' => [
|
||||
'type' => 'mysql',
|
||||
'driver' => 'pdo_mysql',
|
||||
'database' => 'test',
|
||||
],
|
||||
];
|
||||
$db = Database::getInstance();
|
||||
$db->open();
|
||||
}
|
||||
|
||||
public function testGetInstanceDatasourcesArray()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['datasources'] = [
|
||||
'mysql' => [
|
||||
'type' => 'mysql',
|
||||
'driver' => 'pdo_mysql',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => '',
|
||||
'database' => 'test',
|
||||
],
|
||||
];
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
}
|
||||
public function testGetInstanceDatasourcesArray()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['datasources'] = [
|
||||
'mysql' => [
|
||||
'type' => 'mysql',
|
||||
'driver' => 'pdo_mysql',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => '',
|
||||
'database' => 'test',
|
||||
],
|
||||
];
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
}
|
||||
|
||||
// Also tests the datasource being missing and selecting the first one
|
||||
public function testGetInstanceMySQL()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
unset($config->data['pickles']['datasource']);
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
}
|
||||
// Also tests the datasource being missing and selecting the first one
|
||||
public function testGetInstanceMySQL()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
unset($config->data['pickles']['datasource']);
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
}
|
||||
|
||||
public function testOpenMySQL()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'mysql';
|
||||
$db = Database::getInstance();
|
||||
$db->open();
|
||||
}
|
||||
public function testOpenMySQL()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'mysql';
|
||||
$db = Database::getInstance();
|
||||
$db->open();
|
||||
}
|
||||
|
||||
public function testExecute()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$this->assertEquals('0', $db->execute('SHOW TABLES'));
|
||||
}
|
||||
public function testExecute()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$this->assertEquals('0', $db->execute('SHOW TABLES'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage No query to execute.
|
||||
*/
|
||||
public function testExecuteNoQuery()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$db->execute(' ');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage No query to execute.
|
||||
*/
|
||||
public function testExecuteNoQuery()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$db->execute(' ');
|
||||
}
|
||||
|
||||
public function testFetch()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['logging'] = true;
|
||||
$config->data['pickles']['profiler'] = true;
|
||||
$db = Database::getInstance();
|
||||
$this->assertEquals([], $db->fetch('SELECT * FROM pickles WHERE id != ?', ['0']));
|
||||
}
|
||||
public function testFetch()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['logging'] = true;
|
||||
$config->data['pickles']['profiler'] = true;
|
||||
$db = Database::getInstance();
|
||||
$this->assertEquals([], $db->fetch('SELECT * FROM pickles WHERE id != ?', ['0']));
|
||||
}
|
||||
|
||||
public function testExplainNoInput()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$db = Database::getInstance();
|
||||
$this->assertEquals([], $db->fetch('SELECT * FROM pickles WHERE id != 0'));
|
||||
}
|
||||
public function testExplainNoInput()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$db = Database::getInstance();
|
||||
$this->assertEquals([], $db->fetch('SELECT * FROM pickles WHERE id != 0'));
|
||||
}
|
||||
|
||||
public function testSlowQuery()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$this->assertEquals('0', $db->execute('SHOW DATABASES', null, true));
|
||||
}
|
||||
public function testSlowQuery()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$this->assertEquals('0', $db->execute('SHOW DATABASES', null, true));
|
||||
}
|
||||
|
||||
public function testCloseMySQL()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$db->open();
|
||||
public function testCloseMySQL()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$db->open();
|
||||
|
||||
$this->assertTrue($db->close());
|
||||
}
|
||||
$this->assertTrue($db->close());
|
||||
}
|
||||
|
||||
public function testGetInstancePostgreSQL()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'pgsql';
|
||||
$config->data['datasources']['pgsql'] = [
|
||||
'type' => 'pgsql',
|
||||
'driver' => 'pdo_pgsql',
|
||||
'hostname' => 'localhost',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => 'test',
|
||||
];
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
}
|
||||
public function testGetInstancePostgreSQL()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'pgsql';
|
||||
$config->data['datasources']['pgsql'] = [
|
||||
'type' => 'pgsql',
|
||||
'driver' => 'pdo_pgsql',
|
||||
'hostname' => 'localhost',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => 'test',
|
||||
];
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PDOException
|
||||
* @expectedExceptionCode 7
|
||||
*/
|
||||
public function testOpenPostgreSQL()
|
||||
{
|
||||
// Also throws an exception since I don't have PostgreSQL set up
|
||||
$config = Config::getInstance();
|
||||
$db = Database::getInstance();
|
||||
$db->open();
|
||||
}
|
||||
/**
|
||||
* @expectedException PDOException
|
||||
* @expectedExceptionCode 7
|
||||
*/
|
||||
public function testOpenPostgreSQL()
|
||||
{
|
||||
// Also throws an exception since I don't have PostgreSQL set up
|
||||
$config = Config::getInstance();
|
||||
$db = Database::getInstance();
|
||||
$db->open();
|
||||
}
|
||||
|
||||
public function testGetInstanceSQLite()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'sqlite';
|
||||
$config->data['datasources']['sqlite'] = [
|
||||
'type' => 'sqlite',
|
||||
'driver' => 'pdo_sqlite',
|
||||
'hostname' => 'localhost',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => 'test',
|
||||
];
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
}
|
||||
public function testGetInstanceSQLite()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'sqlite';
|
||||
$config->data['datasources']['sqlite'] = [
|
||||
'type' => 'sqlite',
|
||||
'driver' => 'pdo_sqlite',
|
||||
'hostname' => 'localhost',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => 'test',
|
||||
];
|
||||
$this->assertInstanceOf('Database', Database::getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Datasource driver "pdo_invalid" is invalid
|
||||
*/
|
||||
public function testGetInstanceInvalidDriver()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'invalid';
|
||||
$config->data['datasources']['invalid'] = [
|
||||
'type' => 'invalid',
|
||||
'driver' => 'pdo_invalid',
|
||||
'hostname' => 'localhost',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => 'test',
|
||||
];
|
||||
Database::getInstance();
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Datasource driver "pdo_invalid" is invalid
|
||||
*/
|
||||
public function testGetInstanceInvalidDriver()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['datasource'] = 'invalid';
|
||||
$config->data['datasources']['invalid'] = [
|
||||
'type' => 'invalid',
|
||||
'driver' => 'pdo_invalid',
|
||||
'hostname' => 'localhost',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => 'test',
|
||||
];
|
||||
Database::getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,29 +2,28 @@
|
|||
|
||||
class DateTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerAge
|
||||
*/
|
||||
public function testAge($a, $b)
|
||||
{
|
||||
$this->assertEquals(Date::age($a), $b);
|
||||
}
|
||||
/**
|
||||
* @dataProvider providerAge
|
||||
*/
|
||||
public function testAge($a, $b)
|
||||
{
|
||||
$this->assertEquals(Date::age($a), $b);
|
||||
}
|
||||
|
||||
public function providerAge()
|
||||
{
|
||||
ini_set('date.timezone', 'America/New_York');
|
||||
public function providerAge()
|
||||
{
|
||||
ini_set('date.timezone', 'America/New_York');
|
||||
|
||||
$time = strtotime('-25 years');
|
||||
$time = strtotime('-25 years');
|
||||
|
||||
return [
|
||||
[date('Y-m-d', $time), '25'],
|
||||
[date('m/d/Y', $time), '25'],
|
||||
[date('r', $time), '25'],
|
||||
['today', '0'],
|
||||
['400 days ago', '1'],
|
||||
[true, Date::age('1969-12-31')],
|
||||
];
|
||||
}
|
||||
return [
|
||||
[date('Y-m-d', $time), '25'],
|
||||
[date('m/d/Y', $time), '25'],
|
||||
[date('r', $time), '25'],
|
||||
['today', '0'],
|
||||
['400 days ago', '1'],
|
||||
[true, Date::age('1969-12-31')],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,85 +2,85 @@
|
|||
|
||||
class DisplayTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $display, $shared_templates;
|
||||
private $display, $shared_templates;
|
||||
|
||||
private $child_html = '<div>child template</div>';
|
||||
private $child_html = '<div>child template</div>';
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->shared_templates = SITE_TEMPLATE_PATH . '__shared/';
|
||||
$this->shared_templates = SITE_TEMPLATE_PATH . '__shared/';
|
||||
|
||||
if (!file_exists($this->shared_templates))
|
||||
{
|
||||
mkdir($this->shared_templates, 0644, true);
|
||||
}
|
||||
if (!file_exists($this->shared_templates))
|
||||
{
|
||||
mkdir($this->shared_templates, 0644, true);
|
||||
}
|
||||
|
||||
$_SERVER['REQUEST_URI'] = '/test';
|
||||
$_REQUEST['request'] = 'test';
|
||||
$_SERVER['REQUEST_URI'] = '/test';
|
||||
$_REQUEST['request'] = 'test';
|
||||
|
||||
$this->display = new Display();
|
||||
$this->display->module = [
|
||||
'pickles' => [
|
||||
'yummy' => 'gherkin',
|
||||
'delish' => 'kosher dill',
|
||||
'yucky' => 'bread & butter'
|
||||
]
|
||||
];
|
||||
}
|
||||
$this->display = new Display();
|
||||
$this->display->module = [
|
||||
'pickles' => [
|
||||
'yummy' => 'gherkin',
|
||||
'delish' => 'kosher dill',
|
||||
'yucky' => 'bread & butter'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
unlink(SITE_TEMPLATE_PATH . 'test.phtml');
|
||||
unlink($this->shared_templates . 'index.phtml');
|
||||
}
|
||||
protected function tearDown()
|
||||
{
|
||||
unlink(SITE_TEMPLATE_PATH . 'test.phtml');
|
||||
unlink($this->shared_templates . 'index.phtml');
|
||||
}
|
||||
|
||||
public function testInvalidReturnType()
|
||||
{
|
||||
$this->display->return = 'invalid';
|
||||
$this->assertEquals('Invalid return type.', $this->display->render());
|
||||
public function testInvalidReturnType()
|
||||
{
|
||||
$this->display->return = 'invalid';
|
||||
$this->assertEquals('Invalid return type.', $this->display->render());
|
||||
|
||||
// Gotta do this or the test will be considered "risky"
|
||||
ob_end_clean();
|
||||
}
|
||||
// Gotta do this or the test will be considered "risky"
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
public function testPHPSESSID()
|
||||
{
|
||||
$request_uri = $_SERVER['REQUEST_URI'];
|
||||
$_SERVER['REQUEST_URI'] .= '?PHPSESSID=session_id';
|
||||
$return = $this->display->render();
|
||||
public function testPHPSESSID()
|
||||
{
|
||||
$request_uri = $_SERVER['REQUEST_URI'];
|
||||
$_SERVER['REQUEST_URI'] .= '?PHPSESSID=session_id';
|
||||
$return = $this->display->render();
|
||||
|
||||
$this->assertTrue(in_array('Location: ' . $request_uri, xdebug_get_headers()));
|
||||
$this->assertEquals('Requested URI contains PHPSESSID, redirecting.', $return);
|
||||
$this->assertTrue(in_array('Location: ' . $request_uri, xdebug_get_headers()));
|
||||
$this->assertEquals('Requested URI contains PHPSESSID, redirecting.', $return);
|
||||
|
||||
// Gotta do this or the test will be considered "risky"
|
||||
ob_end_clean();
|
||||
}
|
||||
// Gotta do this or the test will be considered "risky"
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
public function testNoParentTemplate()
|
||||
{
|
||||
$child_template = SITE_TEMPLATE_PATH . 'test.phtml';
|
||||
file_put_contents($child_template, $this->child_html);
|
||||
public function testNoParentTemplate()
|
||||
{
|
||||
$child_template = SITE_TEMPLATE_PATH . 'test.phtml';
|
||||
file_put_contents($child_template, $this->child_html);
|
||||
|
||||
$this->display->templates = [$child_template];
|
||||
$this->display->templates = [$child_template];
|
||||
|
||||
$this->assertEquals($this->child_html, $this->display->render());
|
||||
}
|
||||
$this->assertEquals($this->child_html, $this->display->render());
|
||||
}
|
||||
|
||||
public function testRenderJSON()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'{"pickles":{"yummy":"gherkin","delish":"kosher dill","yucky":"bread & butter"}}',
|
||||
$this->display->render()
|
||||
);
|
||||
}
|
||||
public function testRenderJSON()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'{"pickles":{"yummy":"gherkin","delish":"kosher dill","yucky":"bread & butter"}}',
|
||||
$this->display->render()
|
||||
);
|
||||
}
|
||||
|
||||
public function testRenderJSONPrettyPrint()
|
||||
{
|
||||
$_REQUEST['pretty'] = 'true';
|
||||
public function testRenderJSONPrettyPrint()
|
||||
{
|
||||
$_REQUEST['pretty'] = 'true';
|
||||
|
||||
$pretty_json = <<<JSON
|
||||
$pretty_json = <<<JSON
|
||||
{
|
||||
"pickles": {
|
||||
"yummy": "gherkin",
|
||||
|
@ -90,44 +90,43 @@ class DisplayTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
JSON;
|
||||
|
||||
$this->assertEquals($pretty_json, $this->display->render());
|
||||
}
|
||||
$this->assertEquals($pretty_json, $this->display->render());
|
||||
}
|
||||
|
||||
public function testRenderXML()
|
||||
{
|
||||
$this->display->return = ['template', 'xml'];
|
||||
$this->assertEquals(
|
||||
'<yummy>gherkin</yummy><delish>kosher dill</delish><yucky><![CDATA[bread & butter]]></yucky>',
|
||||
$this->display->render()
|
||||
);
|
||||
}
|
||||
public function testRenderXML()
|
||||
{
|
||||
$this->display->return = ['template', 'xml'];
|
||||
$this->assertEquals(
|
||||
'<yummy>gherkin</yummy><delish>kosher dill</delish><yucky><![CDATA[bread & butter]]></yucky>',
|
||||
$this->display->render()
|
||||
);
|
||||
}
|
||||
|
||||
public function testRenderXMLPrettyPrint()
|
||||
{
|
||||
$_REQUEST['pretty'] = 'true';
|
||||
public function testRenderXMLPrettyPrint()
|
||||
{
|
||||
$_REQUEST['pretty'] = 'true';
|
||||
|
||||
$pretty_xml = <<<XML
|
||||
$pretty_xml = <<<XML
|
||||
<yummy>gherkin</yummy>
|
||||
<delish>kosher dill</delish>
|
||||
<yucky><![CDATA[bread & butter]]></yucky>
|
||||
|
||||
XML;
|
||||
|
||||
$this->display->return = ['template', 'xml'];
|
||||
$this->assertEquals($pretty_xml, $this->display->render());
|
||||
}
|
||||
$this->display->return = ['template', 'xml'];
|
||||
$this->assertEquals($pretty_xml, $this->display->render());
|
||||
}
|
||||
|
||||
/*
|
||||
public function testRenderRSS()
|
||||
{
|
||||
$this->fail('Not yet implemented.');
|
||||
}
|
||||
/*
|
||||
public function testRenderRSS()
|
||||
{
|
||||
$this->fail('Not yet implemented.');
|
||||
}
|
||||
|
||||
public function testRenderRSSPrettyPrint()
|
||||
{
|
||||
$this->fail('Not yet implemented.');
|
||||
}
|
||||
*/
|
||||
public function testRenderRSSPrettyPrint()
|
||||
{
|
||||
$this->fail('Not yet implemented.');
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,75 +2,74 @@
|
|||
|
||||
class DistanceTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConvertKilometersToMiles()
|
||||
{
|
||||
$this->assertEquals(0.621371, Distance::kilometersToMiles(1));
|
||||
}
|
||||
public function testConvertKilometersToMiles()
|
||||
{
|
||||
$this->assertEquals(0.621371, Distance::kilometersToMiles(1));
|
||||
}
|
||||
|
||||
public function testConvertKilometersToMeters()
|
||||
{
|
||||
$this->assertEquals(1000, Distance::kilometersToMeters(1));
|
||||
}
|
||||
public function testConvertKilometersToMeters()
|
||||
{
|
||||
$this->assertEquals(1000, Distance::kilometersToMeters(1));
|
||||
}
|
||||
|
||||
public function testConvertKilometersToYards()
|
||||
{
|
||||
$this->assertEquals(1093.61, Distance::kilometersToYards(1));
|
||||
}
|
||||
public function testConvertKilometersToYards()
|
||||
{
|
||||
$this->assertEquals(1093.61, Distance::kilometersToYards(1));
|
||||
}
|
||||
|
||||
public function testConvertMilesToKilometers()
|
||||
{
|
||||
$this->assertEquals(1.60934, Distance::milesToKilometers(1));
|
||||
}
|
||||
public function testConvertMilesToKilometers()
|
||||
{
|
||||
$this->assertEquals(1.60934, Distance::milesToKilometers(1));
|
||||
}
|
||||
|
||||
public function testConvertMilesToMeters()
|
||||
{
|
||||
$this->assertEquals(1609.34, Distance::milesToMeters(1));
|
||||
}
|
||||
public function testConvertMilesToMeters()
|
||||
{
|
||||
$this->assertEquals(1609.34, Distance::milesToMeters(1));
|
||||
}
|
||||
|
||||
public function testConvertMilesToYards()
|
||||
{
|
||||
$this->assertEquals(1760, Distance::milesToYards(1));
|
||||
}
|
||||
public function testConvertMilesToYards()
|
||||
{
|
||||
$this->assertEquals(1760, Distance::milesToYards(1));
|
||||
}
|
||||
|
||||
public function testConvertMetersToKilometers()
|
||||
{
|
||||
$this->assertEquals(0.001, Distance::metersToKilometers(1));
|
||||
}
|
||||
public function testConvertMetersToKilometers()
|
||||
{
|
||||
$this->assertEquals(0.001, Distance::metersToKilometers(1));
|
||||
}
|
||||
|
||||
public function testConvertMetersToMiles()
|
||||
{
|
||||
$this->assertEquals(0.000621371, Distance::metersToMiles(1));
|
||||
}
|
||||
public function testConvertMetersToMiles()
|
||||
{
|
||||
$this->assertEquals(0.000621371, Distance::metersToMiles(1));
|
||||
}
|
||||
|
||||
public function testConvertMetersToYards()
|
||||
{
|
||||
$this->assertEquals(1.09361, Distance::metersToYards(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 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 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 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 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));
|
||||
}
|
||||
public function testNotEnoughUnits()
|
||||
{
|
||||
$this->assertFalse(Distance::milesTo(123));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,236 +2,235 @@
|
|||
|
||||
class DynamicTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $dynamic;
|
||||
private $dynamic;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
// Using actual filesystem because you can't chdir with vfs://
|
||||
$public_path = '/tmp/pickles-fs/public/';
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
// Using actual filesystem because you can't chdir with vfs://
|
||||
$public_path = '/tmp/pickles-fs/public/';
|
||||
|
||||
foreach (['css', 'images', 'js'] as $directory)
|
||||
{
|
||||
mkdir($public_path . $directory, 0777, true);
|
||||
}
|
||||
foreach (['css', 'images', 'js'] as $directory)
|
||||
{
|
||||
mkdir($public_path . $directory, 0777, true);
|
||||
}
|
||||
|
||||
touch($public_path . 'images/image.png');
|
||||
touch($public_path . 'images/invalid');
|
||||
touch($public_path . 'images/image.png');
|
||||
touch($public_path . 'images/invalid');
|
||||
|
||||
$css = <<<CSS
|
||||
$css = <<<CSS
|
||||
body
|
||||
{
|
||||
color: #ffcc00;
|
||||
text-align: center;
|
||||
color: #ffcc00;
|
||||
text-align: center;
|
||||
}
|
||||
CSS;
|
||||
|
||||
foreach (['css', 'less', 'scss'] as $extension)
|
||||
{
|
||||
file_put_contents($public_path . 'css/stylesheet.' . $extension, $css);
|
||||
}
|
||||
foreach (['css', 'less', 'scss'] as $extension)
|
||||
{
|
||||
file_put_contents($public_path . 'css/stylesheet.' . $extension, $css);
|
||||
}
|
||||
|
||||
file_put_contents($public_path . 'css/alternate.css', $css);
|
||||
file_put_contents($public_path . 'css/alternate.css', $css);
|
||||
|
||||
$js = <<<JS
|
||||
$js = <<<JS
|
||||
function foo()
|
||||
{
|
||||
alert('bar');
|
||||
alert('bar');
|
||||
}
|
||||
|
||||
console.log('stuff');
|
||||
JS;
|
||||
|
||||
file_put_contents($public_path . 'js/script.js', $js);
|
||||
file_put_contents($public_path . 'js/script.js', $js);
|
||||
|
||||
chdir($public_path);
|
||||
}
|
||||
chdir($public_path);
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->dynamic = new Dynamic();
|
||||
}
|
||||
public function setUp()
|
||||
{
|
||||
$this->dynamic = new Dynamic();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$minified_file = '/tmp/pickles-fs/public/css/stylesheet.min.css';
|
||||
public function tearDown()
|
||||
{
|
||||
$minified_file = '/tmp/pickles-fs/public/css/stylesheet.min.css';
|
||||
|
||||
if (file_exists($minified_file))
|
||||
{
|
||||
unlink($minified_file);
|
||||
}
|
||||
}
|
||||
if (file_exists($minified_file))
|
||||
{
|
||||
unlink($minified_file);
|
||||
}
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
File::removeDirectory('/tmp/pickles-fs');
|
||||
}
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
File::removeDirectory('/tmp/pickles-fs');
|
||||
}
|
||||
|
||||
public function testReference()
|
||||
{
|
||||
$this->assertRegExp(
|
||||
'/^\/images\/image\.\d{10}\.png$/',
|
||||
$this->dynamic->reference('/images/image.png'
|
||||
));
|
||||
}
|
||||
public function testReference()
|
||||
{
|
||||
$this->assertRegExp(
|
||||
'/^\/images\/image\.\d{10}\.png$/',
|
||||
$this->dynamic->reference('/images/image.png'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Supplied reference does not exist (/images/missing.png)
|
||||
*/
|
||||
public function testReferenceMissingFileWithoutFailover()
|
||||
{
|
||||
$this->dynamic->reference('/images/missing.png');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Supplied reference does not exist (/images/missing.png)
|
||||
*/
|
||||
public function testReferenceMissingFileWithoutFailover()
|
||||
{
|
||||
$this->dynamic->reference('/images/missing.png');
|
||||
}
|
||||
|
||||
public function testReferenceMissingFileWithFailover()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'/images/failover.png',
|
||||
$this->dynamic->reference('/images/missing.png', '/images/failover.png')
|
||||
);
|
||||
}
|
||||
public function testReferenceMissingFileWithFailover()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'/images/failover.png',
|
||||
$this->dynamic->reference('/images/missing.png', '/images/failover.png')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Filename must have an extension (e.g. /path/to/file.png)
|
||||
*/
|
||||
public function testReferenceInvalidFilename()
|
||||
{
|
||||
$this->dynamic->reference('/images/invalid');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Filename must have an extension (e.g. /path/to/file.png)
|
||||
*/
|
||||
public function testReferenceInvalidFilename()
|
||||
{
|
||||
$this->dynamic->reference('/images/invalid');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Reference value must be absolute (e.g. /path/to/file.png)
|
||||
*/
|
||||
public function testReferenceNotAbsolute()
|
||||
{
|
||||
$this->dynamic->reference('../images/relative.png');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Reference value must be absolute (e.g. /path/to/file.png)
|
||||
*/
|
||||
public function testReferenceNotAbsolute()
|
||||
{
|
||||
$this->dynamic->reference('../images/relative.png');
|
||||
}
|
||||
|
||||
public function testReferenceWithQueryString()
|
||||
{
|
||||
$this->assertRegExp(
|
||||
'/^\/images\/image\.\d{10}\.png\?foo=bar$/',
|
||||
$this->dynamic->reference('/images/image.png?foo=bar'
|
||||
));
|
||||
}
|
||||
public function testReferenceWithQueryString()
|
||||
{
|
||||
$this->assertRegExp(
|
||||
'/^\/images\/image\.\d{10}\.png\?foo=bar$/',
|
||||
$this->dynamic->reference('/images/image.png?foo=bar'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Filename must have an extension (e.g. /path/to/file.css)
|
||||
*/
|
||||
public function testCSSMissingExtension()
|
||||
{
|
||||
$this->dynamic->css('/css/invalid');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Filename must have an extension (e.g. /path/to/file.css)
|
||||
*/
|
||||
public function testCSSMissingExtension()
|
||||
{
|
||||
$this->dynamic->css('/css/invalid');
|
||||
}
|
||||
|
||||
public function testCSSWithoutMinify()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = false;
|
||||
public function testCSSWithoutMinify()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = false;
|
||||
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.css'));
|
||||
}
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.css'));
|
||||
}
|
||||
|
||||
public function testCSSWithoutMinifyFileMinifiedFileExists()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = false;
|
||||
public function testCSSWithoutMinifyFileMinifiedFileExists()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = false;
|
||||
|
||||
touch('/tmp/pickles-fs/public/css/stylesheet.min.css');
|
||||
touch('/tmp/pickles-fs/public/css/stylesheet.min.css');
|
||||
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.css'));
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.css'));
|
||||
|
||||
unlink('/tmp/pickles-fs/public/css/stylesheet.min.css');
|
||||
}
|
||||
unlink('/tmp/pickles-fs/public/css/stylesheet.min.css');
|
||||
}
|
||||
|
||||
public function testCSSWithMinify()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = true;
|
||||
public function testCSSWithMinify()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = true;
|
||||
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.css'));
|
||||
}
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.css'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Supplied reference does not exist
|
||||
*/
|
||||
public function testCSSReferenceDoesNotExist()
|
||||
{
|
||||
$this->dynamic->css('/css/missing.css');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Supplied reference does not exist
|
||||
*/
|
||||
public function testCSSReferenceDoesNotExist()
|
||||
{
|
||||
$this->dynamic->css('/css/missing.css');
|
||||
}
|
||||
|
||||
public function testLESSWithoutMinify()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = false;
|
||||
public function testLESSWithoutMinify()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = false;
|
||||
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.\d{10}\.less$/', $this->dynamic->css('/css/stylesheet.less'));
|
||||
}
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.\d{10}\.less$/', $this->dynamic->css('/css/stylesheet.less'));
|
||||
}
|
||||
|
||||
public function testLESSWithMinify()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = true;
|
||||
public function testLESSWithMinify()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = true;
|
||||
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.less'));
|
||||
}
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.less'));
|
||||
}
|
||||
|
||||
public function testSCSSWithoutMinify()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = false;
|
||||
public function testSCSSWithoutMinify()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = false;
|
||||
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.\d{10}\.scss$/', $this->dynamic->css('/css/stylesheet.scss'));
|
||||
}
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.\d{10}\.scss$/', $this->dynamic->css('/css/stylesheet.scss'));
|
||||
}
|
||||
|
||||
public function testSCSSWithMinify()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = true;
|
||||
public function testSCSSWithMinify()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = true;
|
||||
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.scss'));
|
||||
}
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.scss'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Filename must have an extension (e.g. /path/to/file.js)
|
||||
*/
|
||||
public function testJSMissingExtension()
|
||||
{
|
||||
$this->dynamic->js('/js/invalid');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Filename must have an extension (e.g. /path/to/file.js)
|
||||
*/
|
||||
public function testJSMissingExtension()
|
||||
{
|
||||
$this->dynamic->js('/js/invalid');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Supplied reference does not exist
|
||||
*/
|
||||
public function testJSReferenceDoesNotExist()
|
||||
{
|
||||
$this->dynamic->js('/js/missing.js');
|
||||
}
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Supplied reference does not exist
|
||||
*/
|
||||
public function testJSReferenceDoesNotExist()
|
||||
{
|
||||
$this->dynamic->js('/js/missing.js');
|
||||
}
|
||||
|
||||
public function testJS()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = true;
|
||||
public function testJS()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = true;
|
||||
|
||||
$this->assertRegExp('/^\/js\/script\.min\.\d{10}\.js$/', $this->dynamic->js('/js/script.js'));
|
||||
}
|
||||
$this->assertRegExp('/^\/js\/script\.min\.\d{10}\.js$/', $this->dynamic->js('/js/script.js'));
|
||||
}
|
||||
|
||||
public function testJSWithoutMinifyFileMinifiedFileExists()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = false;
|
||||
public function testJSWithoutMinifyFileMinifiedFileExists()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = false;
|
||||
|
||||
touch('/tmp/pickles-fs/public/js/script.min.css');
|
||||
touch('/tmp/pickles-fs/public/js/script.min.css');
|
||||
|
||||
$this->assertRegExp('/^\/js\/script\.min\.\d{10}\.js$/', $this->dynamic->js('/js/script.js'));
|
||||
$this->assertRegExp('/^\/js\/script\.min\.\d{10}\.js$/', $this->dynamic->js('/js/script.js'));
|
||||
|
||||
unlink('/tmp/pickles-fs/public/js/script.min.css');
|
||||
}
|
||||
unlink('/tmp/pickles-fs/public/js/script.min.css');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,61 +2,60 @@
|
|||
|
||||
class FileTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
// Using actual filesystem because you can't chdir with vfs://
|
||||
$directory = '/tmp/pickles-fs/filetest/test/test';
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
// Using actual filesystem because you can't chdir with vfs://
|
||||
$directory = '/tmp/pickles-fs/filetest/test/test';
|
||||
|
||||
if (!file_exists($directory))
|
||||
{
|
||||
mkdir($directory, 0777, true);
|
||||
}
|
||||
}
|
||||
if (!file_exists($directory))
|
||||
{
|
||||
mkdir($directory, 0777, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
File::removeDirectory('/tmp/pickles-fs');
|
||||
}
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
File::removeDirectory('/tmp/pickles-fs');
|
||||
}
|
||||
|
||||
public function testRemoveDirectory()
|
||||
{
|
||||
$directory = '/tmp/pickles-fs/filetest/';
|
||||
public function testRemoveDirectory()
|
||||
{
|
||||
$directory = '/tmp/pickles-fs/filetest/';
|
||||
|
||||
touch($directory . 'ing');
|
||||
touch($directory . 'test/ing');
|
||||
touch($directory . 'test/test/ing');
|
||||
touch($directory . 'ing');
|
||||
touch($directory . 'test/ing');
|
||||
touch($directory . 'test/test/ing');
|
||||
|
||||
File::removeDirectory($directory);
|
||||
File::removeDirectory($directory);
|
||||
|
||||
$this->assertFalse(file_exists($directory));
|
||||
}
|
||||
$this->assertFalse(file_exists($directory));
|
||||
}
|
||||
|
||||
public function testMissingTrailingSlash()
|
||||
{
|
||||
$directory = SITE_PATH . 'missing';
|
||||
public function testMissingTrailingSlash()
|
||||
{
|
||||
$directory = SITE_PATH . 'missing';
|
||||
|
||||
mkdir($directory, 0777, true);
|
||||
touch(SITE_PATH . 'missing/slash');
|
||||
mkdir($directory, 0777, true);
|
||||
touch(SITE_PATH . 'missing/slash');
|
||||
|
||||
File::removeDirectory($directory);
|
||||
File::removeDirectory($directory);
|
||||
|
||||
$this->assertFalse(file_exists($directory));
|
||||
}
|
||||
$this->assertFalse(file_exists($directory));
|
||||
}
|
||||
|
||||
public function testRemoveFileNotDirectory()
|
||||
{
|
||||
$directory = SITE_PATH . 'dir';
|
||||
$file = SITE_PATH . 'dir/file';
|
||||
public function testRemoveFileNotDirectory()
|
||||
{
|
||||
$directory = SITE_PATH . 'dir';
|
||||
$file = SITE_PATH . 'dir/file';
|
||||
|
||||
mkdir($directory, 0777, true);
|
||||
touch($file);
|
||||
mkdir($directory, 0777, true);
|
||||
touch($file);
|
||||
|
||||
File::removeDirectory($file);
|
||||
File::removeDirectory($file);
|
||||
|
||||
$this->assertFalse(file_exists($file));
|
||||
$this->assertFalse(file_exists($file));
|
||||
|
||||
File::removeDirectory($directory);
|
||||
}
|
||||
File::removeDirectory($directory);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2,108 +2,107 @@
|
|||
|
||||
class HTMLTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $html;
|
||||
private $html;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->html = HTML::getInstance();
|
||||
}
|
||||
public function setUp()
|
||||
{
|
||||
$this->html = HTML::getInstance();
|
||||
}
|
||||
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->assertInstanceOf('HTML', $this->html);
|
||||
}
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->assertInstanceOf('HTML', $this->html);
|
||||
}
|
||||
|
||||
public function testInput()
|
||||
{
|
||||
$this->assertEquals('<input type="text">', $this->html->input());
|
||||
}
|
||||
public function testInput()
|
||||
{
|
||||
$this->assertEquals('<input type="text">', $this->html->input());
|
||||
}
|
||||
|
||||
public function testInputDateTimeLocal()
|
||||
{
|
||||
$this->assertEquals('<input type="datetime-local">', $this->html->inputDateTimeLocal());
|
||||
}
|
||||
public function testInputDateTimeLocal()
|
||||
{
|
||||
$this->assertEquals('<input type="datetime-local">', $this->html->inputDateTimeLocal());
|
||||
}
|
||||
|
||||
public function testInputEmail()
|
||||
{
|
||||
$this->assertEquals('<input type="email">', $this->html->inputEmail());
|
||||
}
|
||||
public function testInputEmail()
|
||||
{
|
||||
$this->assertEquals('<input type="email">', $this->html->inputEmail());
|
||||
}
|
||||
|
||||
public function testInputWithAttributes()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<input id="id" class="class" value="value" type="text">',
|
||||
$this->html->input([
|
||||
'id' => 'id',
|
||||
'class' => 'class',
|
||||
'value' => 'value',
|
||||
])
|
||||
);
|
||||
}
|
||||
public function testInputWithAttributes()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<input id="id" class="class" value="value" type="text">',
|
||||
$this->html->input([
|
||||
'id' => 'id',
|
||||
'class' => 'class',
|
||||
'value' => 'value',
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function testInputPasswordWithLabel()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<label for="password">Enter Password</label><input name="password" type="password">',
|
||||
$this->html->inputPassword([
|
||||
'name' => 'password',
|
||||
'label' => 'Enter Password',
|
||||
])
|
||||
);
|
||||
public function testInputPasswordWithLabel()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<label for="password">Enter Password</label><input name="password" type="password">',
|
||||
$this->html->inputPassword([
|
||||
'name' => 'password',
|
||||
'label' => 'Enter Password',
|
||||
])
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function testNestedElements()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<div><p>Nested!</p></div>',
|
||||
$this->html->div(
|
||||
$this->html->p('Nested!')
|
||||
)
|
||||
);
|
||||
}
|
||||
public function testNestedElements()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<div><p>Nested!</p></div>',
|
||||
$this->html->div(
|
||||
$this->html->p('Nested!')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testNestedElementsWithAttributes()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<div class="outer"><p class="inner">Nested!</p></div>',
|
||||
$this->html->div(
|
||||
['class' => 'outer'],
|
||||
$this->html->p(
|
||||
['class' => 'inner'],
|
||||
'Nested!'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
public function testNestedElementsWithAttributes()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<div class="outer"><p class="inner">Nested!</p></div>',
|
||||
$this->html->div(
|
||||
['class' => 'outer'],
|
||||
$this->html->p(
|
||||
['class' => 'inner'],
|
||||
'Nested!'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testClosingTag()
|
||||
{
|
||||
$this->assertEquals('<textarea></textarea>', $this->html->textarea());
|
||||
}
|
||||
public function testClosingTag()
|
||||
{
|
||||
$this->assertEquals('<textarea></textarea>', $this->html->textarea());
|
||||
}
|
||||
|
||||
public function testElement()
|
||||
{
|
||||
$this->assertEquals('<div></div>', $this->html->element('div'));
|
||||
}
|
||||
public function testElement()
|
||||
{
|
||||
$this->assertEquals('<div></div>', $this->html->element('div'));
|
||||
}
|
||||
|
||||
public function testReversedParameters()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<div class="fancy">string</div>',
|
||||
$this->html->div('string', ['class' => 'fancy'])
|
||||
);
|
||||
}
|
||||
public function testReversedParameters()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<div class="fancy">string</div>',
|
||||
$this->html->div('string', ['class' => 'fancy'])
|
||||
);
|
||||
}
|
||||
|
||||
public function testLabelWithInputWithoutName()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<label>Label</label><input type="text">',
|
||||
$this->html->input([
|
||||
'label' => 'Label',
|
||||
])
|
||||
);
|
||||
}
|
||||
public function testLabelWithInputWithoutName()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<label>Label</label><input type="text">',
|
||||
$this->html->input([
|
||||
'label' => 'Label',
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,102 +2,101 @@
|
|||
|
||||
class LogTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $config;
|
||||
private $config;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
$this->config->data['pickles']['logging'] = true;
|
||||
}
|
||||
public function setUp()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
$this->config->data['pickles']['logging'] = true;
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
File::removeDirectory(LOG_PATH);
|
||||
}
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
File::removeDirectory(LOG_PATH);
|
||||
}
|
||||
|
||||
public function testInformation()
|
||||
{
|
||||
Log::information('information');
|
||||
public function testInformation()
|
||||
{
|
||||
Log::information('information');
|
||||
|
||||
$file = LOG_PATH . date('Y/m/d/') . 'information.log';
|
||||
$data = file($file);
|
||||
$line = $data[count($data) - 1];
|
||||
$file = LOG_PATH . date('Y/m/d/') . 'information.log';
|
||||
$data = file($file);
|
||||
$line = $data[count($data) - 1];
|
||||
|
||||
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ information$/', $line);
|
||||
}
|
||||
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ information$/', $line);
|
||||
}
|
||||
|
||||
public function testWarning()
|
||||
{
|
||||
Log::warning('warning');
|
||||
public function testWarning()
|
||||
{
|
||||
Log::warning('warning');
|
||||
|
||||
$file = LOG_PATH . date('Y/m/d/') . 'warning.log';
|
||||
$data = file($file);
|
||||
$line = $data[count($data) - 1];
|
||||
$file = LOG_PATH . date('Y/m/d/') . 'warning.log';
|
||||
$data = file($file);
|
||||
$line = $data[count($data) - 1];
|
||||
|
||||
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ warning$/', $line);
|
||||
}
|
||||
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ warning$/', $line);
|
||||
}
|
||||
|
||||
public function testError()
|
||||
{
|
||||
Log::error('error');
|
||||
public function testError()
|
||||
{
|
||||
Log::error('error');
|
||||
|
||||
$file = LOG_PATH . date('Y/m/d/') . 'error.log';
|
||||
$data = file($file);
|
||||
$line = $data[count($data) - 1];
|
||||
$file = LOG_PATH . date('Y/m/d/') . 'error.log';
|
||||
$data = file($file);
|
||||
$line = $data[count($data) - 1];
|
||||
|
||||
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ error$/', $line);
|
||||
}
|
||||
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ error$/', $line);
|
||||
}
|
||||
|
||||
public function testSlowQuery()
|
||||
{
|
||||
Log::slowQuery('slow query');
|
||||
public function testSlowQuery()
|
||||
{
|
||||
Log::slowQuery('slow query');
|
||||
|
||||
$file = LOG_PATH . date('Y/m/d/') . 'slow_query.log';
|
||||
$data = file($file);
|
||||
$line = $data[count($data) - 1];
|
||||
$file = LOG_PATH . date('Y/m/d/') . 'slow_query.log';
|
||||
$data = file($file);
|
||||
$line = $data[count($data) - 1];
|
||||
|
||||
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ slow query$/', $line);
|
||||
}
|
||||
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ slow query$/', $line);
|
||||
}
|
||||
|
||||
public function testTransaction()
|
||||
{
|
||||
Log::transaction('transaction');
|
||||
public function testTransaction()
|
||||
{
|
||||
Log::transaction('transaction');
|
||||
|
||||
$file = LOG_PATH . date('Y/m/d/') . 'transaction.log';
|
||||
$data = file($file);
|
||||
$line = $data[count($data) - 1];
|
||||
$file = LOG_PATH . date('Y/m/d/') . 'transaction.log';
|
||||
$data = file($file);
|
||||
$line = $data[count($data) - 1];
|
||||
|
||||
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ transaction$/', $line);
|
||||
}
|
||||
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ transaction$/', $line);
|
||||
}
|
||||
|
||||
public function testPHPError()
|
||||
{
|
||||
Log::phperror('php error');
|
||||
public function testPHPError()
|
||||
{
|
||||
Log::phperror('php error');
|
||||
|
||||
$file = LOG_PATH . date('Y/m/d/') . 'php_error.log';
|
||||
$data = file($file);
|
||||
$line = $data[count($data) - 1];
|
||||
$file = LOG_PATH . date('Y/m/d/') . 'php_error.log';
|
||||
$data = file($file);
|
||||
$line = $data[count($data) - 1];
|
||||
|
||||
$this->assertRegExp('/^php error$/', $line);
|
||||
}
|
||||
$this->assertRegExp('/^php error$/', $line);
|
||||
}
|
||||
|
||||
public function testQuery()
|
||||
{
|
||||
Log::query('query');
|
||||
public function testQuery()
|
||||
{
|
||||
Log::query('query');
|
||||
|
||||
$file = LOG_PATH . date('Y/m/d/') . 'query.log';
|
||||
$data = file($file);
|
||||
$line = $data[count($data) - 1];
|
||||
$file = LOG_PATH . date('Y/m/d/') . 'query.log';
|
||||
$data = file($file);
|
||||
$line = $data[count($data) - 1];
|
||||
|
||||
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ query$/', $line);
|
||||
}
|
||||
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ query$/', $line);
|
||||
}
|
||||
|
||||
public function testLoggingDisabled()
|
||||
{
|
||||
$this->config->data['pickles']['logging'] = false;
|
||||
public function testLoggingDisabled()
|
||||
{
|
||||
$this->config->data['pickles']['logging'] = false;
|
||||
|
||||
$this->assertFalse(Log::error('should return false'));
|
||||
}
|
||||
$this->assertFalse(Log::error('should return false'));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -6,65 +6,64 @@ $_REQUEST['field2'] = 'short';
|
|||
|
||||
class MockParentModule extends Module
|
||||
{
|
||||
public $validate = [
|
||||
'field1',
|
||||
'field2' => [
|
||||
'length:<:10' => 'Too short',
|
||||
'length:>:50' => 'Too long',
|
||||
],
|
||||
];
|
||||
public $validate = [
|
||||
'field1',
|
||||
'field2' => [
|
||||
'length:<:10' => 'Too short',
|
||||
'length:>:50' => 'Too long',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
class MockChildModule extends MockParentModule
|
||||
{
|
||||
public $method = ['POST', 'GET'];
|
||||
public $method = ['POST', 'GET'];
|
||||
}
|
||||
|
||||
class ModuleTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testAutoRun()
|
||||
{
|
||||
$this->assertInstanceOf('Module', new Module(true));
|
||||
}
|
||||
public function testAutoRun()
|
||||
{
|
||||
$this->assertInstanceOf('Module', new Module(true));
|
||||
}
|
||||
|
||||
public function testAutoRunParentError()
|
||||
{
|
||||
$this->expectOutputString('');
|
||||
$model = new MockChildModule(true);
|
||||
}
|
||||
public function testAutoRunParentError()
|
||||
{
|
||||
$this->expectOutputString('');
|
||||
$model = new MockChildModule(true);
|
||||
}
|
||||
|
||||
public function testSetGetReturn()
|
||||
{
|
||||
$module = new Module();
|
||||
$module->foo = 'bar';
|
||||
$this->assertEquals('bar', $module->foo);
|
||||
}
|
||||
public function testSetGetReturn()
|
||||
{
|
||||
$module = new Module();
|
||||
$module->foo = 'bar';
|
||||
$this->assertEquals('bar', $module->foo);
|
||||
}
|
||||
|
||||
public function testGetMissing()
|
||||
{
|
||||
$module = new Module();
|
||||
$this->assertFalse($module->missing);
|
||||
}
|
||||
public function testGetMissing()
|
||||
{
|
||||
$module = new Module();
|
||||
$this->assertFalse($module->missing);
|
||||
}
|
||||
|
||||
public function testValidateGet()
|
||||
{
|
||||
$module = new MockParentModule();
|
||||
$module->method = 'GET';
|
||||
$this->assertEquals(['The field1 field is required.', 'Too long'], $module->__validate());
|
||||
}
|
||||
public function testValidateGet()
|
||||
{
|
||||
$module = new MockParentModule();
|
||||
$module->method = 'GET';
|
||||
$this->assertEquals(['The field1 field is required.', 'Too long'], $module->__validate());
|
||||
}
|
||||
|
||||
public function testValidatePost()
|
||||
{
|
||||
$module = new MockParentModule();
|
||||
$this->assertEquals(['The field1 field is required.', 'Too long'], $module->__validate());
|
||||
}
|
||||
public function testValidatePost()
|
||||
{
|
||||
$module = new MockParentModule();
|
||||
$this->assertEquals(['The field1 field is required.', 'Too long'], $module->__validate());
|
||||
}
|
||||
|
||||
public function testValidateRequest()
|
||||
{
|
||||
$module = new MockParentModule();
|
||||
$module->method = null;
|
||||
$this->assertEquals(['The field1 field is required.', 'Too long'], $module->__validate());
|
||||
}
|
||||
public function testValidateRequest()
|
||||
{
|
||||
$module = new MockParentModule();
|
||||
$module->method = null;
|
||||
$this->assertEquals(['The field1 field is required.', 'Too long'], $module->__validate());
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,49 +2,48 @@
|
|||
|
||||
class NumberTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerOrginalIndicatorNoSuper
|
||||
*/
|
||||
public function testOrdinalIndicatorNoSuper($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, Number::ordinalIndicator($a));
|
||||
}
|
||||
/**
|
||||
* @dataProvider providerOrginalIndicatorNoSuper
|
||||
*/
|
||||
public function testOrdinalIndicatorNoSuper($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, Number::ordinalIndicator($a));
|
||||
}
|
||||
|
||||
public function providerOrginalIndicatorNoSuper()
|
||||
{
|
||||
return [
|
||||
[1, '1st'],
|
||||
[2, '2nd'],
|
||||
[3, '3rd'],
|
||||
[4, '4th'],
|
||||
[51, '51st'],
|
||||
[52, '52nd'],
|
||||
[53, '53rd'],
|
||||
[54, '54th'],
|
||||
];
|
||||
}
|
||||
public function providerOrginalIndicatorNoSuper()
|
||||
{
|
||||
return [
|
||||
[1, '1st'],
|
||||
[2, '2nd'],
|
||||
[3, '3rd'],
|
||||
[4, '4th'],
|
||||
[51, '51st'],
|
||||
[52, '52nd'],
|
||||
[53, '53rd'],
|
||||
[54, '54th'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerOrginalIndicatorSuper
|
||||
*/
|
||||
public function testOrdinalIndicatorSuper($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, Number::ordinalIndicator($a, true));
|
||||
}
|
||||
/**
|
||||
* @dataProvider providerOrginalIndicatorSuper
|
||||
*/
|
||||
public function testOrdinalIndicatorSuper($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, Number::ordinalIndicator($a, true));
|
||||
}
|
||||
|
||||
public function providerOrginalIndicatorSuper()
|
||||
{
|
||||
return [
|
||||
[1, '1<sup>st</sup>'],
|
||||
[2, '2<sup>nd</sup>'],
|
||||
[3, '3<sup>rd</sup>'],
|
||||
[4, '4<sup>th</sup>'],
|
||||
[51, '51<sup>st</sup>'],
|
||||
[52, '52<sup>nd</sup>'],
|
||||
[53, '53<sup>rd</sup>'],
|
||||
[54, '54<sup>th</sup>'],
|
||||
];
|
||||
}
|
||||
public function providerOrginalIndicatorSuper()
|
||||
{
|
||||
return [
|
||||
[1, '1<sup>st</sup>'],
|
||||
[2, '2<sup>nd</sup>'],
|
||||
[3, '3<sup>rd</sup>'],
|
||||
[4, '4<sup>th</sup>'],
|
||||
[51, '51<sup>st</sup>'],
|
||||
[52, '52<sup>nd</sup>'],
|
||||
[53, '53<sup>rd</sup>'],
|
||||
[54, '54<sup>th</sup>'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,24 +2,23 @@
|
|||
|
||||
class ObjectTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructorWithoutObjects()
|
||||
{
|
||||
$object = new Object();
|
||||
public function testConstructorWithoutObjects()
|
||||
{
|
||||
$object = new Object();
|
||||
|
||||
$this->assertInstanceOf('Config', PHPUnit_Framework_Assert::readAttribute($object, 'config'));
|
||||
}
|
||||
$this->assertInstanceOf('Config', PHPUnit_Framework_Assert::readAttribute($object, 'config'));
|
||||
}
|
||||
|
||||
public function testConstructorWithObjects()
|
||||
{
|
||||
$object = new Object('cache');
|
||||
public function testConstructorWithObjects()
|
||||
{
|
||||
$object = new Object('cache');
|
||||
|
||||
$this->assertInstanceOf('Cache', PHPUnit_Framework_Assert::readAttribute($object, 'cache'));
|
||||
}
|
||||
$this->assertInstanceOf('Cache', PHPUnit_Framework_Assert::readAttribute($object, 'cache'));
|
||||
}
|
||||
|
||||
public function testGetInstanceWithoutClass()
|
||||
{
|
||||
$this->assertFalse(Object::getInstance());
|
||||
}
|
||||
public function testGetInstanceWithoutClass()
|
||||
{
|
||||
$this->assertFalse(Object::getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,81 +2,80 @@
|
|||
|
||||
class ProfilerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testReport()
|
||||
{
|
||||
$this->expectOutputRegex('//');
|
||||
public function testReport()
|
||||
{
|
||||
$this->expectOutputRegex('//');
|
||||
|
||||
Profiler::report();
|
||||
}
|
||||
Profiler::report();
|
||||
}
|
||||
|
||||
public function testDisabledType()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['profiler'] = false;
|
||||
public function testDisabledType()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['profiler'] = false;
|
||||
|
||||
$this->assertFalse(Profiler::enabled('timers'));
|
||||
}
|
||||
$this->assertFalse(Profiler::enabled('timers'));
|
||||
}
|
||||
|
||||
public function testTimerDisabled()
|
||||
{
|
||||
$this->assertFalse(Profiler::timer('disabled'));
|
||||
}
|
||||
public function testTimerDisabled()
|
||||
{
|
||||
$this->assertFalse(Profiler::timer('disabled'));
|
||||
}
|
||||
|
||||
public function testReportNothing()
|
||||
{
|
||||
$this->expectOutputRegex('/There is nothing to profile/');
|
||||
public function testReportNothing()
|
||||
{
|
||||
$this->expectOutputRegex('/There is nothing to profile/');
|
||||
|
||||
Profiler::report();
|
||||
}
|
||||
Profiler::report();
|
||||
}
|
||||
|
||||
public function testEnabled()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['profiler'] = true;
|
||||
public function testEnabled()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['profiler'] = true;
|
||||
|
||||
$this->assertTrue(Profiler::enabled());
|
||||
}
|
||||
$this->assertTrue(Profiler::enabled());
|
||||
}
|
||||
|
||||
public function testEnabledType()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['profiler'] = 'timers';
|
||||
public function testEnabledType()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['profiler'] = 'timers';
|
||||
|
||||
$this->assertTrue(Profiler::enabled('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 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' => '',
|
||||
],
|
||||
];
|
||||
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);
|
||||
}
|
||||
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');
|
||||
}
|
||||
public function testTimer()
|
||||
{
|
||||
Profiler::timer('timer-two');
|
||||
Profiler::timer('timer-two');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,153 +2,152 @@
|
|||
|
||||
class MockUserModel extends Model
|
||||
{
|
||||
public $table = 'users';
|
||||
public $table = 'users';
|
||||
}
|
||||
|
||||
class SecurityTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGenerateHashWithDefaultSalts()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'4940e793006aa897db22751bba80dff4cb6a3e08',
|
||||
Security::generateHash('source')
|
||||
);
|
||||
}
|
||||
public function testGenerateHashWithDefaultSalts()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'4940e793006aa897db22751bba80dff4cb6a3e08',
|
||||
Security::generateHash('source')
|
||||
);
|
||||
}
|
||||
|
||||
public function testGenerateHashWithCustomSalts()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['security']['salt'] = 'salt';
|
||||
public function testGenerateHashWithCustomSalts()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['security']['salt'] = 'salt';
|
||||
|
||||
$this->assertEquals(
|
||||
'4eac88c934c33cfa9a80c0b2eb322f23ac3b13c5',
|
||||
Security::generateHash('source')
|
||||
);
|
||||
}
|
||||
$this->assertEquals(
|
||||
'4eac88c934c33cfa9a80c0b2eb322f23ac3b13c5',
|
||||
Security::generateHash('source')
|
||||
);
|
||||
}
|
||||
|
||||
public function testGenerateSHA256Hash()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'3d04f805aff4838ecaf98c7260a813fffd2b7a8a7f957add8018908a1bbdad04',
|
||||
Security::generateSHA256Hash('source', 'salt')
|
||||
);
|
||||
}
|
||||
public function testGenerateSHA256Hash()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'3d04f805aff4838ecaf98c7260a813fffd2b7a8a7f957add8018908a1bbdad04',
|
||||
Security::generateSHA256Hash('source', 'salt')
|
||||
);
|
||||
}
|
||||
|
||||
public function testLogin()
|
||||
{
|
||||
$this->assertTrue(Security::login(1, 10, 'USER'));
|
||||
$this->assertTrue(isset($_SESSION['__pickles']['security']));
|
||||
}
|
||||
public function testLogin()
|
||||
{
|
||||
$this->assertTrue(Security::login(1, 10, 'USER'));
|
||||
$this->assertTrue(isset($_SESSION['__pickles']['security']));
|
||||
}
|
||||
|
||||
public function testLoginNoSession()
|
||||
{
|
||||
session_destroy();
|
||||
$this->assertFalse(Security::login(1, 10, 'USER'));
|
||||
}
|
||||
public function testLoginNoSession()
|
||||
{
|
||||
session_destroy();
|
||||
$this->assertFalse(Security::login(1, 10, 'USER'));
|
||||
}
|
||||
|
||||
public function testLogout()
|
||||
{
|
||||
session_start();
|
||||
Security::login(1, 10, 'USER');
|
||||
public function testLogout()
|
||||
{
|
||||
session_start();
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
$this->assertTrue(Security::logout());
|
||||
$this->assertFalse(isset($_SESSION['__pickles']['security']));
|
||||
}
|
||||
$this->assertTrue(Security::logout());
|
||||
$this->assertFalse(isset($_SESSION['__pickles']['security']));
|
||||
}
|
||||
|
||||
public function testIsLevel()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
public function testIsLevel()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
$this->assertTrue(Security::isLevel(SECURITY_LEVEL_USER));
|
||||
}
|
||||
$this->assertTrue(Security::isLevel(SECURITY_LEVEL_USER));
|
||||
}
|
||||
|
||||
public function testIsLevelArray()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
public function testIsLevelArray()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
$this->assertTrue(Security::isLevel([SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]));
|
||||
}
|
||||
$this->assertTrue(Security::isLevel([SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]));
|
||||
}
|
||||
|
||||
public function testHasLevel()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
public function testHasLevel()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
$this->assertTrue(Security::hasLevel(SECURITY_LEVEL_USER));
|
||||
}
|
||||
$this->assertTrue(Security::hasLevel(SECURITY_LEVEL_USER));
|
||||
}
|
||||
|
||||
public function testHasLevelArray()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
public function testHasLevelArray()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
$this->assertTrue(Security::hasLevel([SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]));
|
||||
}
|
||||
$this->assertTrue(Security::hasLevel([SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]));
|
||||
}
|
||||
|
||||
public function testBetweenLevel()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
public function testBetweenLevel()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
$this->assertTrue(Security::betweenLevel(SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN));
|
||||
}
|
||||
$this->assertTrue(Security::betweenLevel(SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN));
|
||||
}
|
||||
|
||||
public function testTokenMismatch()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
public function testTokenMismatch()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
$_SESSION['__pickles']['security']['token'] = 'foo';
|
||||
$_COOKIE['pickles_security_token'] = 'bar';
|
||||
$_SESSION['__pickles']['security']['token'] = 'foo';
|
||||
$_COOKIE['pickles_security_token'] = 'bar';
|
||||
|
||||
$this->assertFalse(Security::isLevel(SECURITY_LEVEL_USER));
|
||||
}
|
||||
$this->assertFalse(Security::isLevel(SECURITY_LEVEL_USER));
|
||||
}
|
||||
|
||||
public function testIsLevelDB()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
public function testIsLevelDB()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
|
||||
$config->data = [
|
||||
'pickles' => [
|
||||
'datasource' => 'mysql',
|
||||
'cache' => 'memcache',
|
||||
],
|
||||
'datasources' => [
|
||||
'mysql' => [
|
||||
'type' => 'mysql',
|
||||
'driver' => 'pdo_mysql',
|
||||
'hostname' => 'localhost',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => 'test',
|
||||
'cache' => true,
|
||||
],
|
||||
'memcache' => [
|
||||
'type' => 'memcache',
|
||||
'hostname' => 'localhost',
|
||||
'port' => 11211,
|
||||
'namespace' => '',
|
||||
],
|
||||
],
|
||||
'security' => ['model' => 'MockUserModel'],
|
||||
];
|
||||
$config->data = [
|
||||
'pickles' => [
|
||||
'datasource' => 'mysql',
|
||||
'cache' => 'memcache',
|
||||
],
|
||||
'datasources' => [
|
||||
'mysql' => [
|
||||
'type' => 'mysql',
|
||||
'driver' => 'pdo_mysql',
|
||||
'hostname' => 'localhost',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => 'test',
|
||||
'cache' => true,
|
||||
],
|
||||
'memcache' => [
|
||||
'type' => 'memcache',
|
||||
'hostname' => 'localhost',
|
||||
'port' => 11211,
|
||||
'namespace' => '',
|
||||
],
|
||||
],
|
||||
'security' => ['model' => 'MockUserModel'],
|
||||
];
|
||||
|
||||
$model = new MockUserModel();
|
||||
$model->record['username'] = 'pickles';
|
||||
$model->commit();
|
||||
$model = new MockUserModel();
|
||||
$model->record['username'] = 'pickles';
|
||||
$model->commit();
|
||||
|
||||
setUpConfig([
|
||||
setUpConfig([
|
||||
|
||||
]);
|
||||
]);
|
||||
|
||||
new Config();
|
||||
new Config();
|
||||
|
||||
Security::login(1, 10, 'USER');
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
unset(
|
||||
$_SESSION['__pickles']['security']['token'],
|
||||
$_COOKIE['pickles_security_token'],
|
||||
$_SESSION['__pickles']['security']['level']
|
||||
);
|
||||
unset(
|
||||
$_SESSION['__pickles']['security']['token'],
|
||||
$_COOKIE['pickles_security_token'],
|
||||
$_SESSION['__pickles']['security']['level']
|
||||
);
|
||||
|
||||
$this->assertFalse(Security::isLevel([SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]));
|
||||
}
|
||||
$this->assertFalse(Security::isLevel([SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,98 +2,97 @@
|
|||
|
||||
class SessionTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (session_id())
|
||||
{
|
||||
session_destroy();
|
||||
}
|
||||
public function setUp()
|
||||
{
|
||||
if (session_id())
|
||||
{
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'yes';
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
}
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'yes';
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
}
|
||||
|
||||
public function testFiles()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'files';
|
||||
public function testFiles()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'files';
|
||||
|
||||
new Session();
|
||||
new Session();
|
||||
|
||||
$_SESSION['test'] = 'files';
|
||||
$this->assertEquals('files', $_SESSION['test']);
|
||||
}
|
||||
$_SESSION['test'] = 'files';
|
||||
$this->assertEquals('files', $_SESSION['test']);
|
||||
}
|
||||
|
||||
public function testMemcache()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'memcache';
|
||||
$config->data['datasources']['memcache'] = [
|
||||
'type' => 'memcache',
|
||||
'hostname' => 'localhost',
|
||||
'port' => '11211',
|
||||
];
|
||||
public function testMemcache()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'memcache';
|
||||
$config->data['datasources']['memcache'] = [
|
||||
'type' => 'memcache',
|
||||
'hostname' => 'localhost',
|
||||
'port' => '11211',
|
||||
];
|
||||
|
||||
new Session();
|
||||
new Session();
|
||||
|
||||
$_SESSION['test'] = 'memcache';
|
||||
$this->assertEquals('memcache', $_SESSION['test']);
|
||||
}
|
||||
$_SESSION['test'] = 'memcache';
|
||||
$this->assertEquals('memcache', $_SESSION['test']);
|
||||
}
|
||||
|
||||
public function testMemcached()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'memcached';
|
||||
$config->data['datasources']['memcached'] = [
|
||||
'type' => 'memcached',
|
||||
'hostname' => 'localhost',
|
||||
'port' => '11211',
|
||||
];
|
||||
public function testMemcached()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'memcached';
|
||||
$config->data['datasources']['memcached'] = [
|
||||
'type' => 'memcached',
|
||||
'hostname' => 'localhost',
|
||||
'port' => '11211',
|
||||
];
|
||||
|
||||
new Session();
|
||||
new Session();
|
||||
|
||||
$_SESSION['test'] = 'memcached';
|
||||
$this->assertEquals('memcached', $_SESSION['test']);
|
||||
}
|
||||
$_SESSION['test'] = 'memcached';
|
||||
$this->assertEquals('memcached', $_SESSION['test']);
|
||||
}
|
||||
|
||||
public function testRedis()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'redis';
|
||||
$config->data['datasources']['redis'] = [
|
||||
'type' => 'redis',
|
||||
'hostname' => 'localhost',
|
||||
'port' => '6379',
|
||||
'database' => '1',
|
||||
'prefix' => 'p:',
|
||||
];
|
||||
public function testRedis()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'redis';
|
||||
$config->data['datasources']['redis'] = [
|
||||
'type' => 'redis',
|
||||
'hostname' => 'localhost',
|
||||
'port' => '6379',
|
||||
'database' => '1',
|
||||
'prefix' => 'p:',
|
||||
];
|
||||
|
||||
new Session();
|
||||
new Session();
|
||||
|
||||
$_SESSION['test'] = 'redis';
|
||||
$this->assertEquals('redis', $_SESSION['test']);
|
||||
}
|
||||
$_SESSION['test'] = 'redis';
|
||||
$this->assertEquals('redis', $_SESSION['test']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage You must provide both the hostname and port for the datasource.
|
||||
*/
|
||||
public function testMissingHostname()
|
||||
{
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage You must provide both the hostname and port for the datasource.
|
||||
*/
|
||||
public function testMissingHostname()
|
||||
{
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'redis';
|
||||
$config->data['datasources']['redis'] = [
|
||||
'type' => 'redis',
|
||||
'port' => '6379',
|
||||
];
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'redis';
|
||||
$config->data['datasources']['redis'] = [
|
||||
'type' => 'redis',
|
||||
'port' => '6379',
|
||||
];
|
||||
|
||||
new Session();
|
||||
new Session();
|
||||
|
||||
$_SESSION['test'] = 'redis';
|
||||
$this->assertEquals('redis', $_SESSION['test']);
|
||||
}
|
||||
$_SESSION['test'] = 'redis';
|
||||
$this->assertEquals('redis', $_SESSION['test']);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,61 +2,60 @@
|
|||
|
||||
class SortTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testByNameASC()
|
||||
{
|
||||
$shuffled = [
|
||||
['name' => 'epsilon'],
|
||||
['name' => 'gamma'],
|
||||
['name' => 'alpha'],
|
||||
['name' => 'delta'],
|
||||
['name' => 'beta'],
|
||||
];
|
||||
public function testByNameASC()
|
||||
{
|
||||
$shuffled = [
|
||||
['name' => 'epsilon'],
|
||||
['name' => 'gamma'],
|
||||
['name' => 'alpha'],
|
||||
['name' => 'delta'],
|
||||
['name' => 'beta'],
|
||||
];
|
||||
|
||||
$sorted = [
|
||||
['name' => 'alpha'],
|
||||
['name' => 'beta'],
|
||||
['name' => 'delta'],
|
||||
['name' => 'epsilon'],
|
||||
['name' => 'gamma'],
|
||||
];
|
||||
$sorted = [
|
||||
['name' => 'alpha'],
|
||||
['name' => 'beta'],
|
||||
['name' => 'delta'],
|
||||
['name' => 'epsilon'],
|
||||
['name' => 'gamma'],
|
||||
];
|
||||
|
||||
Sort::by('name', $shuffled);
|
||||
Sort::by('name', $shuffled);
|
||||
|
||||
$this->assertEquals($sorted, $shuffled);
|
||||
}
|
||||
$this->assertEquals($sorted, $shuffled);
|
||||
}
|
||||
|
||||
public function testByNameDESC()
|
||||
{
|
||||
$shuffled = [
|
||||
['name' => 'epsilon'],
|
||||
['name' => 'gamma'],
|
||||
['name' => 'alpha'],
|
||||
['name' => 'delta'],
|
||||
['name' => 'beta'],
|
||||
];
|
||||
public function testByNameDESC()
|
||||
{
|
||||
$shuffled = [
|
||||
['name' => 'epsilon'],
|
||||
['name' => 'gamma'],
|
||||
['name' => 'alpha'],
|
||||
['name' => 'delta'],
|
||||
['name' => 'beta'],
|
||||
];
|
||||
|
||||
$sorted = [
|
||||
['name' => 'gamma'],
|
||||
['name' => 'epsilon'],
|
||||
['name' => 'delta'],
|
||||
['name' => 'beta'],
|
||||
['name' => 'alpha'],
|
||||
];
|
||||
$sorted = [
|
||||
['name' => 'gamma'],
|
||||
['name' => 'epsilon'],
|
||||
['name' => 'delta'],
|
||||
['name' => 'beta'],
|
||||
['name' => 'alpha'],
|
||||
];
|
||||
|
||||
Sort::by('name', $shuffled, Sort::DESC);
|
||||
Sort::by('name', $shuffled, Sort::DESC);
|
||||
|
||||
$this->assertEquals($sorted, $shuffled);
|
||||
}
|
||||
$this->assertEquals($sorted, $shuffled);
|
||||
}
|
||||
|
||||
public function testMissingField()
|
||||
{
|
||||
$shuffled = [['foo' => 'bar', 'bar' => 'foo']];
|
||||
$sorted = [['foo' => 'bar', 'bar' => 'foo']];
|
||||
public function testMissingField()
|
||||
{
|
||||
$shuffled = [['foo' => 'bar', 'bar' => 'foo']];
|
||||
$sorted = [['foo' => 'bar', 'bar' => 'foo']];
|
||||
|
||||
Sort::by('name', $shuffled);
|
||||
Sort::by('name', $shuffled);
|
||||
|
||||
$this->assertEquals($sorted, $shuffled);
|
||||
}
|
||||
$this->assertEquals($sorted, $shuffled);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,141 +2,140 @@
|
|||
|
||||
class StringTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerFormatPhoneNumber
|
||||
*/
|
||||
public function testFormatPhoneNumber($a, $b)
|
||||
{
|
||||
$this->assertEquals(String::formatPhoneNumber($a), $b);
|
||||
}
|
||||
/**
|
||||
* @dataProvider providerFormatPhoneNumber
|
||||
*/
|
||||
public function testFormatPhoneNumber($a, $b)
|
||||
{
|
||||
$this->assertEquals(String::formatPhoneNumber($a), $b);
|
||||
}
|
||||
|
||||
public function providerFormatPhoneNumber()
|
||||
{
|
||||
return [
|
||||
['1234567890', '123-456-7890'],
|
||||
['123 456 7890', '123-456-7890'],
|
||||
['123.456.7890', '123-456-7890'],
|
||||
['123_456_7890', '123-456-7890'],
|
||||
['1234567890', '123-456-7890'],
|
||||
['1234-56-7890', '123-456-7890'],
|
||||
['(123) 456-7890', '123-456-7890'],
|
||||
['1234567890 x1000', '123-456-7890x1000'],
|
||||
['(123) 456-7890_x10.00', '123-456-7890x1000'],
|
||||
];
|
||||
}
|
||||
public function providerFormatPhoneNumber()
|
||||
{
|
||||
return [
|
||||
['1234567890', '123-456-7890'],
|
||||
['123 456 7890', '123-456-7890'],
|
||||
['123.456.7890', '123-456-7890'],
|
||||
['123_456_7890', '123-456-7890'],
|
||||
['1234567890', '123-456-7890'],
|
||||
['1234-56-7890', '123-456-7890'],
|
||||
['(123) 456-7890', '123-456-7890'],
|
||||
['1234567890 x1000', '123-456-7890x1000'],
|
||||
['(123) 456-7890_x10.00', '123-456-7890x1000'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerGenerateGravatarHash
|
||||
*/
|
||||
public function testGenerateGravatarHash($a, $b)
|
||||
{
|
||||
$this->assertEquals(String::generateGravatarHash($a), $b);
|
||||
}
|
||||
/**
|
||||
* @dataProvider providerGenerateGravatarHash
|
||||
*/
|
||||
public function testGenerateGravatarHash($a, $b)
|
||||
{
|
||||
$this->assertEquals(String::generateGravatarHash($a), $b);
|
||||
}
|
||||
|
||||
public function providerGenerateGravatarHash()
|
||||
{
|
||||
return [
|
||||
['foo@bar.com', 'f3ada405ce890b6f8204094deb12d8a8'],
|
||||
['FOO@BAR.COM', 'f3ada405ce890b6f8204094deb12d8a8'],
|
||||
];
|
||||
}
|
||||
public function providerGenerateGravatarHash()
|
||||
{
|
||||
return [
|
||||
['foo@bar.com', 'f3ada405ce890b6f8204094deb12d8a8'],
|
||||
['FOO@BAR.COM', 'f3ada405ce890b6f8204094deb12d8a8'],
|
||||
];
|
||||
}
|
||||
|
||||
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));
|
||||
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->assertFalse(String::isEmpty(0));
|
||||
$this->assertFalse(String::isEmpty('foo'));
|
||||
$this->assertFalse(String::isEmpty(' bar '));
|
||||
$this->assertFalse(String::isEmpty(true));
|
||||
}
|
||||
$this->assertFalse(String::isEmpty(0));
|
||||
$this->assertFalse(String::isEmpty('foo'));
|
||||
$this->assertFalse(String::isEmpty(' bar '));
|
||||
$this->assertFalse(String::isEmpty(true));
|
||||
}
|
||||
|
||||
public function testRandom()
|
||||
{
|
||||
$this->assertEquals(strlen(String::random()), 8);
|
||||
$this->assertEquals(strlen(String::random(16)), 16);
|
||||
public function testRandom()
|
||||
{
|
||||
$this->assertEquals(strlen(String::random()), 8);
|
||||
$this->assertEquals(strlen(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]/', 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('/[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]/', 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);
|
||||
}
|
||||
|
||||
public function testRandomSimilarFalse()
|
||||
{
|
||||
$this->assertRegExp('/[a-hj-np-z2-9]{8}/', String::random(8, true, true, false));
|
||||
}
|
||||
public function testRandomSimilarFalse()
|
||||
{
|
||||
$this->assertRegExp('/[a-hj-np-z2-9]{8}/', String::random(8, true, true, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTruncate
|
||||
*/
|
||||
public function testTruncate($a, $b, $c, $d)
|
||||
{
|
||||
$this->assertEquals(String::truncate($a, $b, $c), $d);
|
||||
}
|
||||
/**
|
||||
* @dataProvider providerTruncate
|
||||
*/
|
||||
public function testTruncate($a, $b, $c, $d)
|
||||
{
|
||||
$this->assertEquals(String::truncate($a, $b, $c), $d);
|
||||
}
|
||||
|
||||
public function providerTruncate()
|
||||
{
|
||||
return [
|
||||
['foo bar', 3, true, '<span title="foo bar">foo…</span>'],
|
||||
['foo bar', 3, false, 'foo…'],
|
||||
['foo bar', 7, true, 'foo bar'],
|
||||
['foo bar', 8, true, 'foo bar'],
|
||||
];
|
||||
}
|
||||
public function providerTruncate()
|
||||
{
|
||||
return [
|
||||
['foo bar', 3, true, '<span title="foo bar">foo…</span>'],
|
||||
['foo bar', 3, false, 'foo…'],
|
||||
['foo bar', 7, true, 'foo bar'],
|
||||
['foo bar', 8, true, 'foo bar'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerUpperWords
|
||||
*/
|
||||
public function testUpperWords($a, $b)
|
||||
{
|
||||
$this->assertEquals(String::upperWords($a), $b);
|
||||
}
|
||||
/**
|
||||
* @dataProvider providerUpperWords
|
||||
*/
|
||||
public function testUpperWords($a, $b)
|
||||
{
|
||||
$this->assertEquals(String::upperWords($a), $b);
|
||||
}
|
||||
|
||||
public function providerUpperWords()
|
||||
{
|
||||
return [
|
||||
['foo bar', 'Foo Bar'],
|
||||
['FOO BAR', 'Foo Bar'],
|
||||
['fOO bAR', 'Foo Bar'],
|
||||
['foo@bar.com', 'foo@bar.com'],
|
||||
['FOO@BAR.COM', 'FOO@BAR.COM'],
|
||||
];
|
||||
}
|
||||
public function providerUpperWords()
|
||||
{
|
||||
return [
|
||||
['foo bar', 'Foo Bar'],
|
||||
['FOO BAR', 'Foo Bar'],
|
||||
['fOO bAR', 'Foo Bar'],
|
||||
['foo@bar.com', 'foo@bar.com'],
|
||||
['FOO@BAR.COM', 'FOO@BAR.COM'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerGenerateSlug
|
||||
*/
|
||||
public function testGenerateSlug($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, String::generateSlug($a));
|
||||
}
|
||||
/**
|
||||
* @dataProvider providerGenerateSlug
|
||||
*/
|
||||
public function testGenerateSlug($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, String::generateSlug($a));
|
||||
}
|
||||
|
||||
public function providerGenerateSlug()
|
||||
{
|
||||
return [
|
||||
['TEST STRING', 'test-string'],
|
||||
['Test String', 'test-string'],
|
||||
['TEST STRING', 'test-string'],
|
||||
['#! Test String', 'test-string'],
|
||||
['-test--string-', 'test-string'],
|
||||
];
|
||||
}
|
||||
public function providerGenerateSlug()
|
||||
{
|
||||
return [
|
||||
['TEST STRING', 'test-string'],
|
||||
['Test String', 'test-string'],
|
||||
['TEST STRING', 'test-string'],
|
||||
['#! Test String', 'test-string'],
|
||||
['-test--string-', 'test-string'],
|
||||
];
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,160 +2,159 @@
|
|||
|
||||
class TimeTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
date_default_timezone_set('GMT');
|
||||
}
|
||||
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 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 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 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 testAgoJustNow()
|
||||
{
|
||||
$this->assertEquals('just now', Time::ago(Time::timestamp()));
|
||||
}
|
||||
|
||||
public function testAgoPastTimeSeconds()
|
||||
{
|
||||
$this->assertEquals('seconds ago', Time::ago(strtotime('-30 seconds')));
|
||||
}
|
||||
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 testRoundUpMonth()
|
||||
{
|
||||
$this->assertEquals('a month ago', Time::ago(strtotime('-29 days')));
|
||||
}
|
||||
|
||||
public function testRoundUpYear()
|
||||
{
|
||||
$this->assertEquals('a year ago', Time::ago(strtotime('-364 days')));
|
||||
}
|
||||
public function testRoundUpYear()
|
||||
{
|
||||
$this->assertEquals('a year ago', Time::ago(strtotime('-364 days')));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,200 +2,198 @@
|
|||
|
||||
class ValidateTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFilterBoolean()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid(true, ['filter:boolean' => 'error']));
|
||||
}
|
||||
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 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 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 testFilterEmailError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('invalid', ['filter:email' => 'error']));
|
||||
}
|
||||
|
||||
public function testFilterFloat()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid(2.231981, ['filter:float' => '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 testFilterFloatError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('invalid', ['filter:float' => 'error']));
|
||||
}
|
||||
|
||||
public function testFilterInt()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid(2231981, ['filter:int' => '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 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 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 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 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']));
|
||||
}
|
||||
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 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']);
|
||||
}
|
||||
/**
|
||||
* @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 testLengthLessThan()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('value', ['length:<:10' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthLessThanError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('value', ['length:<:1' => '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 testLengthLessThanOrEqual()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('value', ['length:<=:10' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthLessThanOrEqualError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('value', ['length:<=:1' => '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 testLengthEqual()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('value', ['length:==:5' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthEqualError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('value', ['length:==:1' => '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 testLengthNotEqual()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('value', ['length:!=:1' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthNotEqualError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('value', ['length:!=:5' => '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 testLengthGreaterThanOrEqual()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('value', ['length:>=:1' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthGreaterThanOrEqualError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('value', ['length:>=:10' => '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 testLengthGreaterThan()
|
||||
{
|
||||
$this->assertTrue(Validate::isValid('value', ['length:>:1' => 'error']));
|
||||
}
|
||||
|
||||
public function testLengthGreaterThanError()
|
||||
{
|
||||
$this->assertEquals(['error'], Validate::isValid('value', ['length:>:10' => '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 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 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']);
|
||||
}
|
||||
/**
|
||||
* @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 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 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 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']);
|
||||
}
|
||||
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