Cleaning up tests
This commit is contained in:
parent
bdb16009c1
commit
6097e29aef
8 changed files with 17 additions and 202 deletions
|
@ -12,10 +12,6 @@
|
|||
"homepage": "http://joshtronic.com"
|
||||
}
|
||||
],
|
||||
"repositories": [{
|
||||
"type": "vcs",
|
||||
"url": "https://github.com/joshtronic/php-ayah"
|
||||
}],
|
||||
"require-dev": {
|
||||
"mikey179/vfsStream": "1.3.0",
|
||||
"satooshi/php-coveralls": "dev-master"
|
||||
|
|
2
composer.lock
generated
2
composer.lock
generated
|
@ -3,7 +3,7 @@
|
|||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
|
||||
],
|
||||
"hash": "072c3455e32a8fe13eedc5d6ae22867b",
|
||||
"hash": "276692127a6b06339d4dcbc0bd8f0e34",
|
||||
"packages": [],
|
||||
"packages-dev": [
|
||||
{
|
||||
|
|
|
@ -23,132 +23,6 @@
|
|||
*/
|
||||
class Browser extends Object
|
||||
{
|
||||
/**
|
||||
* Attributes
|
||||
*
|
||||
* Variables passed on the query string as /var:value/
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
private $attributes = [];
|
||||
|
||||
/**
|
||||
* Get instance of the object
|
||||
*
|
||||
* Let's the parent class do all the work
|
||||
*
|
||||
* @static
|
||||
* @param string $class name of the class to instantiate
|
||||
* @return object self::$instance instance of the Config class
|
||||
*/
|
||||
public static function getInstance($class = 'Browser')
|
||||
{
|
||||
return parent::getInstance($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set browser variable
|
||||
*
|
||||
* Sets a variable in the attributes array for easier access later.
|
||||
*
|
||||
* @static
|
||||
* @param string $variable name of the variable to set
|
||||
* @param mixed $value the value to set to the variable
|
||||
* @return boolean true
|
||||
*/
|
||||
public static function set($variable, $value)
|
||||
{
|
||||
$browser = Browser::getInstance();
|
||||
$browser->attributes[$variable] = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get browser variable
|
||||
*
|
||||
* Gets a variable passed in from the browser. Currently only supports
|
||||
* the custom attribute URI format /$variable:$value/.
|
||||
*
|
||||
* @static
|
||||
* @param string $variable name of the variable to get
|
||||
* @return mixed the value of the variable or boolean false if not set
|
||||
*/
|
||||
public static function get($variable)
|
||||
{
|
||||
$browser = Browser::getInstance();
|
||||
|
||||
if (isset($browser->attributes[$variable]))
|
||||
{
|
||||
return $browser->attributes[$variable];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Go Home
|
||||
*
|
||||
* Alias for `Browser::redirect('/');`
|
||||
*
|
||||
* @static
|
||||
*/
|
||||
public static function goHome()
|
||||
{
|
||||
return Browser::redirect('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Mobile
|
||||
*
|
||||
* Detects if we're working with a mobile browser.
|
||||
*
|
||||
* @return boolean whether or not the browser is considered mobile
|
||||
*/
|
||||
public static function isMobile()
|
||||
{
|
||||
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
|
||||
|
||||
return preg_match('/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $user_agent) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i', substr($user_agent, 0, 4)) || strpos('iPhone', $user_agent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect
|
||||
*
|
||||
* Redirects the browser to another URL. Stops execution as to not run
|
||||
* code erroneously due to output buffering. HTTP/1.1 request an
|
||||
* absolute URI, hence the inclusion of the scheme, hostname and
|
||||
* absolute path if :// is not found. Don't hate the player, hate the
|
||||
* RFC.
|
||||
*
|
||||
* @static
|
||||
* @param string $destination URL to redirect to
|
||||
* @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30
|
||||
*/
|
||||
public static function redirect($destination)
|
||||
{
|
||||
if (strpos($destination, '://') === false)
|
||||
{
|
||||
$destination = 'http' . ((!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off' || $_SERVER['HTTPS'] == '') ? '' : 's') . '://' . $_SERVER['HTTP_HOST'] . $destination;
|
||||
}
|
||||
|
||||
header('Location: ' . $destination);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh
|
||||
*
|
||||
* Forces a browser refresh of the currently requested page.
|
||||
*
|
||||
* @static
|
||||
*/
|
||||
public static function refresh()
|
||||
{
|
||||
Browser::redirect($_SERVER['REQUEST_URI']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remote IP
|
||||
*
|
||||
|
|
|
@ -98,7 +98,10 @@ class Object
|
|||
$this->profiler = (isset($this->config->pickles['profiler']) && $this->config->pickles['profiler'] != '' ? $this->config->pickles['profiler'] : false);
|
||||
|
||||
// Optionally logs the constructor to the profiler
|
||||
if ($this->profiler === true || ((is_array($this->profiler) && in_array('objects', $this->profiler)) || stripos($this->profiler, 'objects') !== false))
|
||||
if ($this->profiler === true
|
||||
|| ((is_array($this->profiler)
|
||||
&& in_array('objects', $this->profiler))
|
||||
|| stripos($this->profiler, 'objects') !== false))
|
||||
{
|
||||
Profiler::log($this, '__construct');
|
||||
}
|
||||
|
@ -140,7 +143,10 @@ class Object
|
|||
public function __destruct()
|
||||
{
|
||||
// Optionally logs the destructor to the profiler
|
||||
if ($this->profiler === true || ((is_array($this->profiler) && in_array('objects', $this->profiler)) || stripos($this->profiler, 'objects') !== false))
|
||||
if ($this->profiler === true
|
||||
|| ((is_array($this->profiler)
|
||||
&& in_array('objects', $this->profiler))
|
||||
|| stripos($this->profiler, 'objects') !== false))
|
||||
{
|
||||
Profiler::log($this, '__destruct');
|
||||
}
|
||||
|
|
|
@ -34,9 +34,7 @@ if (!defined('SITE_CLASS_PATH'))
|
|||
{
|
||||
define('SITE_CLASS_PATH', SITE_PATH . 'classes/');
|
||||
define('SITE_MODEL_PATH', SITE_PATH . 'models/');
|
||||
// @todo The following 2 constants are being used in sites will need to update them before removing
|
||||
define('SITE_MODULE_PATH', SITE_PATH . 'modules/');
|
||||
define('SITE_TEMPLATE_PATH', SITE_PATH . 'templates/');
|
||||
|
||||
define('PRIVATE_PATH', SITE_PATH . 'private/');
|
||||
define('LOG_PATH', PRIVATE_PATH . 'logs/');
|
||||
|
@ -83,7 +81,7 @@ function __autoload($class)
|
|||
|
||||
$pickles_path = dirname(__FILE__) . '/';
|
||||
$pickles_paths = [
|
||||
'class' => $pickles_path . 'classes/',
|
||||
'class' => $pickles_path,
|
||||
];
|
||||
|
||||
// Path as the key, boolean value is whether ot not to convert back to hyphenated
|
||||
|
@ -133,12 +131,4 @@ if (is_array($config->php) && count($config->php))
|
|||
}
|
||||
|
||||
// }}}
|
||||
// {{{ Defaults some internals for ease of use
|
||||
|
||||
if (!isset($_REQUEST['request']))
|
||||
{
|
||||
$_REQUEST['request'] = 'home';
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
|
|
|
@ -23,16 +23,6 @@ if (!file_exists(SITE_MODULE_PATH))
|
|||
mkdir(SITE_MODULE_PATH, 0644);
|
||||
}
|
||||
|
||||
if (!file_exists(SITE_TEMPLATE_PATH))
|
||||
{
|
||||
mkdir(SITE_TEMPLATE_PATH, 0644);
|
||||
}
|
||||
|
||||
if (!file_exists(SITE_TEMPLATE_PATH . '__shared/'))
|
||||
{
|
||||
mkdir(SITE_TEMPLATE_PATH . '__shared/', 0644);
|
||||
}
|
||||
|
||||
$_SERVER['HTTP_HOST'] = 'testsite.com';
|
||||
$_SERVER['SERVER_NAME'] = 'Test Server';
|
||||
$_SERVER['SERVER_ADDR'] = '127.0.0.1';
|
||||
|
|
|
@ -2,42 +2,6 @@
|
|||
|
||||
class BrowserTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
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 testMissingVariable()
|
||||
{
|
||||
$this->assertFalse(Browser::get('missing'));
|
||||
}
|
||||
|
||||
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';
|
||||
|
||||
$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';
|
||||
|
||||
$this->assertFalse(Browser::isMobile());
|
||||
}
|
||||
|
||||
public function testRemoteIPNone()
|
||||
{
|
||||
$this->assertFalse(Browser::remoteIP());
|
||||
|
@ -64,6 +28,11 @@ class BrowserTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals('3.4.5.6', Browser::remoteIP());
|
||||
}
|
||||
|
||||
public function testRemoteIPWithComma()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testStatus1xx()
|
||||
{
|
||||
Browser::status(100);
|
||||
|
@ -93,13 +62,5 @@ class BrowserTest extends PHPUnit_Framework_TestCase
|
|||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@ class RouterTest extends PHPUnit_Framework_TestCase
|
|||
$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');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue