summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--index.php55
-rw-r--r--[-rwxr-xr-x]system/core/Benchmark.php0
-rw-r--r--[-rwxr-xr-x]system/core/CodeIgniter.php0
-rw-r--r--system/core/Common.php2
-rw-r--r--[-rwxr-xr-x]system/core/Config.php0
-rw-r--r--[-rwxr-xr-x]system/core/Exceptions.php0
-rw-r--r--[-rwxr-xr-x]system/core/Hooks.php0
-rw-r--r--[-rwxr-xr-x]system/core/Input.php20
-rw-r--r--[-rwxr-xr-x]system/core/Lang.php0
-rw-r--r--system/core/Loader.php2
-rw-r--r--[-rwxr-xr-x]system/core/Model.php0
-rw-r--r--[-rwxr-xr-x]system/core/Output.php0
-rw-r--r--[-rwxr-xr-x]system/core/Router.php0
-rw-r--r--[-rwxr-xr-x]system/core/Security.php0
-rw-r--r--[-rwxr-xr-x]system/core/URI.php20
-rw-r--r--[-rwxr-xr-x]system/database/DB.php0
-rw-r--r--system/database/DB_driver.php105
-rw-r--r--system/database/DB_forge.php54
-rw-r--r--system/database/DB_query_builder.php117
-rw-r--r--system/database/DB_utility.php13
-rw-r--r--system/database/drivers/cubrid/cubrid_utility.php6
-rw-r--r--system/database/drivers/interbase/interbase_forge.php8
-rw-r--r--system/database/drivers/mssql/mssql_driver.php25
-rw-r--r--system/database/drivers/mysqli/mysqli_utility.php119
-rw-r--r--system/database/drivers/postgre/postgre_driver.php9
-rw-r--r--system/database/drivers/sqlite/sqlite_forge.php8
-rw-r--r--system/database/drivers/sqlite3/sqlite3_forge.php8
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_driver.php27
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_forge.php2
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_result.php2
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_utility.php2
-rw-r--r--system/libraries/Cache/Cache.php5
-rw-r--r--system/libraries/Cache/drivers/Cache_file.php6
-rw-r--r--system/libraries/Cache/drivers/Cache_redis.php236
-rw-r--r--system/libraries/Email.php2
-rw-r--r--system/libraries/Encrypt.php1
-rw-r--r--system/libraries/Form_validation.php11
-rw-r--r--system/libraries/Pagination.php112
-rw-r--r--system/libraries/Upload.php14
-rw-r--r--tests/codeigniter/Setup_test.php6
-rw-r--r--tests/codeigniter/core/Benchmark_test.php11
-rw-r--r--tests/codeigniter/core/Common_test.php6
-rw-r--r--tests/codeigniter/core/Config_test.php38
-rw-r--r--tests/codeigniter/core/Input_test.php28
-rw-r--r--tests/codeigniter/core/Lang_test.php12
-rw-r--r--tests/codeigniter/core/Loader_test.php132
-rw-r--r--tests/codeigniter/core/Security_test.php23
-rw-r--r--tests/codeigniter/core/URI_test.php225
-rw-r--r--tests/codeigniter/database/query_builder/count_test.php12
-rw-r--r--tests/codeigniter/database/query_builder/delete_test.php16
-rw-r--r--tests/codeigniter/database/query_builder/distinct_test.php9
-rw-r--r--tests/codeigniter/database/query_builder/escape_test.php5
-rw-r--r--tests/codeigniter/database/query_builder/from_test.php18
-rw-r--r--tests/codeigniter/database/query_builder/get_test.php6
-rw-r--r--tests/codeigniter/database/query_builder/group_test.php26
-rw-r--r--tests/codeigniter/database/query_builder/join_test.php2
-rw-r--r--tests/codeigniter/database/query_builder/like_test.php2
-rw-r--r--tests/codeigniter/database/query_builder/limit_test.php7
-rw-r--r--tests/codeigniter/database/query_builder/order_test.php6
-rw-r--r--tests/codeigniter/database/query_builder/select_test.php12
-rw-r--r--tests/codeigniter/database/query_builder/truncate_test.php7
-rw-r--r--tests/codeigniter/database/query_builder/update_test.php26
-rw-r--r--tests/codeigniter/database/query_builder/where_test.php28
-rw-r--r--tests/codeigniter/helpers/array_helper_test.php22
-rw-r--r--tests/codeigniter/helpers/date_helper_test.php136
-rw-r--r--tests/codeigniter/helpers/directory_helper_test.php47
-rw-r--r--tests/codeigniter/helpers/email_helper_test.php2
-rw-r--r--tests/codeigniter/helpers/file_helper_test.php143
-rw-r--r--tests/codeigniter/helpers/form_helper_test.php112
-rw-r--r--tests/codeigniter/helpers/html_helper_test.php28
-rw-r--r--tests/codeigniter/helpers/inflector_helper_test.php31
-rw-r--r--tests/codeigniter/helpers/number_helper_test.php37
-rw-r--r--tests/codeigniter/helpers/path_helper_test.php5
-rw-r--r--tests/codeigniter/helpers/string_helper_test.php9
-rw-r--r--tests/codeigniter/helpers/text_helper_test.php70
-rw-r--r--tests/codeigniter/helpers/url_helper_test.php1
-rw-r--r--tests/codeigniter/helpers/xml_helper_test.php4
-rw-r--r--tests/codeigniter/libraries/Encrypt_test.php131
-rw-r--r--tests/codeigniter/libraries/Parser_test.php61
-rw-r--r--tests/codeigniter/libraries/Table_test.php153
-rw-r--r--tests/codeigniter/libraries/Typography_test.php40
-rw-r--r--tests/codeigniter/libraries/Useragent_test.php6
-rw-r--r--tests/mocks/autoloader.php4
-rw-r--r--tests/mocks/ci_testcase.php84
-rw-r--r--tests/mocks/core/common.php34
-rw-r--r--tests/mocks/core/input.php6
-rw-r--r--tests/mocks/core/loader.php7
-rw-r--r--tests/mocks/core/security.php2
-rw-r--r--tests/mocks/core/uri.php9
-rw-r--r--tests/mocks/core/utf8.php11
-rw-r--r--tests/mocks/database/config/mysql.php10
-rw-r--r--tests/mocks/database/config/pdo/mysql.php12
-rw-r--r--tests/mocks/database/config/pdo/pgsql.php12
-rw-r--r--tests/mocks/database/config/pdo/sqlite.php12
-rw-r--r--tests/mocks/database/config/pgsql.php10
-rw-r--r--tests/mocks/database/config/sqlite.php10
-rw-r--r--tests/mocks/database/db.php18
-rw-r--r--tests/mocks/database/db/driver.php7
-rw-r--r--tests/mocks/database/db/querybuilder.php9
-rw-r--r--tests/mocks/database/drivers/mysql.php9
-rw-r--r--tests/mocks/database/drivers/pdo.php8
-rw-r--r--tests/mocks/database/drivers/postgre.php9
-rw-r--r--tests/mocks/database/drivers/sqlite.php7
-rw-r--r--tests/mocks/database/schema/skeleton.php48
-rw-r--r--tests/mocks/libraries/encrypt.php21
-rw-r--r--tests/mocks/libraries/table.php3
-rw-r--r--user_guide_src/source/changelog.rst85
-rw-r--r--user_guide_src/source/general/requirements.rst5
-rw-r--r--user_guide_src/source/installation/upgrading.rst3
-rw-r--r--user_guide_src/source/libraries/file_uploading.rst4
-rw-r--r--user_guide_src/source/libraries/form_validation.rst7
-rw-r--r--user_guide_src/source/libraries/input.rst43
-rw-r--r--user_guide_src/source/libraries/pagination.rst24
-rw-r--r--user_guide_src/source/libraries/sessions.rst2
-rw-r--r--user_guide_src/source/libraries/uri.rst2
115 files changed, 1878 insertions, 1351 deletions
diff --git a/index.php b/index.php
index 3b00dd360..ad98013ca 100644
--- a/index.php
+++ b/index.php
@@ -174,17 +174,20 @@ if (defined('ENVIRONMENT'))
chdir(dirname(__FILE__));
}
- if (realpath($system_path) !== FALSE)
+ if (($_temp = realpath($system_path)) !== FALSE)
{
- $system_path = realpath($system_path).'/';
+ $system_path = $_temp.'/';
+ }
+ else
+ {
+ // Ensure there's a trailing slash
+ $system_path = rtrim($system_path, '/').'/';
}
-
- // ensure there's a trailing slash
- $system_path = rtrim($system_path, '/').'/';
// Is the system path correct?
if ( ! is_dir($system_path))
{
+ header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
exit('Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME));
}
@@ -196,10 +199,6 @@ if (defined('ENVIRONMENT'))
// The name of THIS file
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
- // The PHP file extension
- // this global constant is deprecated.
- define('EXT', '.php');
-
// Path to the system folder
define('BASEPATH', str_replace('\\', '/', $system_path));
@@ -212,13 +211,18 @@ if (defined('ENVIRONMENT'))
// The path to the "application" folder
if (is_dir($application_folder))
{
+ if (($_temp = realpath($application_folder)) !== FALSE)
+ {
+ $application_folder = $_temp;
+ }
+
define('APPPATH', $application_folder.'/');
}
else
{
if ( ! is_dir(BASEPATH.$application_folder.'/'))
{
- header('HTTP/1.1 503 Service Unavailable.', TRUE, '503');
+ header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
exit('Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF);
}
@@ -226,20 +230,33 @@ if (defined('ENVIRONMENT'))
}
// The path to the "views" folder
- if (is_dir($view_folder))
- {
- define ('VIEWPATH', $view_folder .'/');
- }
- else
+ if ( ! is_dir($view_folder))
{
- if ( ! is_dir(APPPATH.'views/'))
+ if ( ! empty($view_folder) && is_dir(APPPATH.$view_folder.'/'))
{
- header('HTTP/1.1 503 Service Unavailable.', TRUE, '503');
+ $view_folder = APPPATH.$view_folder;
+ }
+ elseif ( ! is_dir(APPPATH.'views/'))
+ {
+ header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
exit('Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF);
}
+ else
+ {
+ $view_folder = APPPATH.'views';
+ }
+ }
- define ('VIEWPATH', APPPATH.'views/' );
+ if (($_temp = realpath($view_folder)) !== FALSE)
+ {
+ $view_folder = realpath($view_folder).'/';
}
+ else
+ {
+ $view_folder = rtrim($view_folder, '/').'/';
+ }
+
+ define('VIEWPATH', $view_folder);
/*
* --------------------------------------------------------------------
@@ -251,4 +268,4 @@ if (defined('ENVIRONMENT'))
require_once BASEPATH.'core/CodeIgniter.php';
/* End of file index.php */
-/* Location: ./index.php */
+/* Location: ./index.php */ \ No newline at end of file
diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php
index 2fabdf46e..2fabdf46e 100755..100644
--- a/system/core/Benchmark.php
+++ b/system/core/Benchmark.php
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 8159b19f5..8159b19f5 100755..100644
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
diff --git a/system/core/Common.php b/system/core/Common.php
index c08755c91..1708653e7 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -240,7 +240,7 @@ if ( ! function_exists('get_config'))
}
// Is the config file in the environment folder?
- if (defined(ENVIRONMENT) && file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
+ if (defined('ENVIRONMENT') && file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
{
require($file_path);
}
diff --git a/system/core/Config.php b/system/core/Config.php
index 3de1bcb96..3de1bcb96 100755..100644
--- a/system/core/Config.php
+++ b/system/core/Config.php
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index 8c32085fe..8c32085fe 100755..100644
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
diff --git a/system/core/Hooks.php b/system/core/Hooks.php
index 29fd88201..29fd88201 100755..100644
--- a/system/core/Hooks.php
+++ b/system/core/Hooks.php
diff --git a/system/core/Input.php b/system/core/Input.php
index b986c4973..162e40c85 100755..100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -376,14 +376,26 @@ class CI_Input {
/**
* Validate IP Address
*
- * Updated version suggested by Geert De Deckere
- *
* @param string
+ * @param string 'ipv4' or 'ipv6'
* @return bool
*/
- public function valid_ip($ip)
+ public function valid_ip($ip, $which = '')
{
- return (bool) filter_var($ip, FILTER_VALIDATE_IP);
+ switch (strtolower($which))
+ {
+ case 'ipv4':
+ $which = FILTER_FLAG_IPV4;
+ break;
+ case 'ipv6':
+ $which = FILTER_FLAG_IPV6;
+ break;
+ default:
+ $which = NULL;
+ break;
+ }
+
+ return (bool) filter_var($ip, FILTER_VALIDATE_IP, $which);
}
// --------------------------------------------------------------------
diff --git a/system/core/Lang.php b/system/core/Lang.php
index 3001f1b13..3001f1b13 100755..100644
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 09e948714..94739c74a 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -668,7 +668,7 @@ class CI_Loader {
* @param bool
* @return void
*/
- public function add_package_path($path, $view_cascade=TRUE)
+ public function add_package_path($path, $view_cascade = TRUE)
{
$path = rtrim($path, '/').'/';
diff --git a/system/core/Model.php b/system/core/Model.php
index 9bc9f879f..9bc9f879f 100755..100644
--- a/system/core/Model.php
+++ b/system/core/Model.php
diff --git a/system/core/Output.php b/system/core/Output.php
index 5588ffe8e..5588ffe8e 100755..100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
diff --git a/system/core/Router.php b/system/core/Router.php
index 5bc053045..5bc053045 100755..100644
--- a/system/core/Router.php
+++ b/system/core/Router.php
diff --git a/system/core/Security.php b/system/core/Security.php
index 4593a1090..4593a1090 100755..100644
--- a/system/core/Security.php
+++ b/system/core/Security.php
diff --git a/system/core/URI.php b/system/core/URI.php
index a575bc36e..2e661ed4c 100755..100644
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -119,7 +119,7 @@ class CI_URI {
}
// No PATH_INFO?... What about QUERY_STRING?
- $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
+ $path = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
if (trim($path, '/') !== '')
{
$this->_set_uri_string($path);
@@ -163,7 +163,7 @@ class CI_URI {
* @param string
* @return void
*/
- public function _set_uri_string($str)
+ protected function _set_uri_string($str)
{
// Filter out control characters
$str = remove_invisible_characters($str, FALSE);
@@ -177,8 +177,8 @@ class CI_URI {
/**
* Detects the URI
*
- * This function will detect the URI automatically and fix the query string
- * if necessary.
+ * This function will detect the URI automatically
+ * and fix the query string if necessary.
*
* @return string
*/
@@ -189,7 +189,6 @@ class CI_URI {
return '';
}
- $uri = $_SERVER['REQUEST_URI'];
if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
{
$uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
@@ -198,14 +197,19 @@ class CI_URI {
{
$uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
}
+ else
+ {
+ $uri = $_SERVER['REQUEST_URI'];
+ }
// This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct
// URI is found, and also fixes the QUERY_STRING server var and $_GET array.
- if (strncmp($uri, '?/', 2) === 0)
+ if (strpos($uri, '?/') === 0)
{
$uri = substr($uri, 2);
}
- $parts = preg_split('#\?#i', $uri, 2);
+
+ $parts = explode('?', $uri, 2);
$uri = $parts[0];
if (isset($parts[1]))
{
@@ -223,7 +227,7 @@ class CI_URI {
return '/';
}
- $uri = parse_url($uri, PHP_URL_PATH);
+ $uri = parse_url('pseudo://hostname/'.$uri, PHP_URL_PATH);
// Do some final cleaning of the URI and return it
return str_replace(array('//', '../'), '/', trim($uri, '/'));
diff --git a/system/database/DB.php b/system/database/DB.php
index 00d14b43e..00d14b43e 100755..100644
--- a/system/database/DB.php
+++ b/system/database/DB.php
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 65f1f18d0..d056bdb90 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -596,35 +596,53 @@ abstract class CI_DB_driver {
*/
public function compile_binds($sql, $binds)
{
- if (strpos($sql, $this->bind_marker) === FALSE)
+ if (empty($binds) OR empty($this->bind_marker) OR strpos($sql, $this->bind_marker) === FALSE)
{
return $sql;
}
-
- if ( ! is_array($binds))
+ elseif ( ! is_array($binds))
{
$binds = array($binds);
+ $bind_count = 1;
+ }
+ else
+ {
+ // Make sure we're using numeric keys
+ $binds = array_values($binds);
+ $bind_count = count($binds);
}
- // Get the sql segments around the bind markers
- $segments = explode($this->bind_marker, $sql);
+ // We'll need the marker length later
+ $ml = strlen($this->bind_marker);
- // The count of bind should be 1 less then the count of segments
- // If there are more bind arguments trim it down
- if (count($binds) >= count($segments))
+ // Make sure not to replace a chunk inside a string that happens to match the bind marker
+ if ($c = preg_match_all("/'[^']*'/i", $sql, $matches))
{
- $binds = array_slice($binds, 0, count($segments)-1);
+ $c = preg_match_all('/'.preg_quote($this->bind_marker).'/i',
+ str_replace($matches[0],
+ str_replace($this->bind_marker, str_repeat(' ', $ml), $matches[0]),
+ $sql, $c),
+ $matches, PREG_OFFSET_CAPTURE);
+
+ // Bind values' count must match the count of markers in the query
+ if ($bind_count !== $c)
+ {
+ return $sql;
+ }
+ }
+ elseif (($c = preg_match_all('/'.preg_quote($this->bind_marker).'/i', $sql, $matches, PREG_OFFSET_CAPTURE)) !== $bind_count)
+ {
+ return $sql;
}
- // Construct the binded query
- $result = $segments[0];
- $i = 0;
- foreach ($binds as $bind)
+ do
{
- $result .= $this->escape($bind).$segments[++$i];
+ $c--;
+ $sql = substr_replace($sql, $this->escape($binds[$c]), $matches[0][$c][1], $ml);
}
+ while ($c !== 0);
- return $result;
+ return $sql;
}
// --------------------------------------------------------------------
@@ -1062,7 +1080,7 @@ abstract class CI_DB_driver {
*/
protected function _has_operator($str)
{
- return (bool) preg_match('/(\s|<|>|!|=|IS NULL|IS NOT NULL)/i', trim($str));
+ return (bool) preg_match('/(\s|<|>|!|=|IS NULL|IS NOT NULL|BETWEEN)/i', trim($str));
}
// --------------------------------------------------------------------
@@ -1300,36 +1318,63 @@ abstract class CI_DB_driver {
$escaped_array = array();
foreach ($item as $k => $v)
{
- $escaped_array[$this->protect_identifiers($k)] = $this->protect_identifiers($v);
+ $escaped_array[$this->protect_identifiers($k)] = $this->protect_identifiers($v, $prefix_single, $protect_identifiers, $field_exists);
}
return $escaped_array;
}
+ // This is basically a bug fix for queries that use MAX, MIN, etc.
+ // If a parenthesis is found we know that we do not need to
+ // escape the data or add a prefix. There's probably a more graceful
+ // way to deal with this, but I'm not thinking of it -- Rick
+ if (strpos($item, '(') !== FALSE)
+ {
+ return $item;
+ }
+
// Convert tabs or multiple spaces into single spaces
- $item = preg_replace('/[\t ]+/', ' ', $item);
+ $item = preg_replace('/\s+/', ' ', $item);
+
+ static $preg_ec = array();
+
+ if (empty($preg_ec))
+ {
+ if (is_array($this->_escape_char))
+ {
+ $preg_ec = array(preg_quote($this->_escape_char[0]), preg_quote($this->_escape_char[1]));
+ }
+ else
+ {
+ $preg_ec[0] = $preg_ec[1] = preg_quote($this->_escape_char);
+ }
+ }
// If the item has an alias declaration we remove it and set it aside.
// Basically we remove everything to the right of the first space
- if (strpos($item, ' ') !== FALSE)
+ preg_match('/^(('.$preg_ec[0].'[^'.$preg_ec[1].']+'.$preg_ec[1].')|([^'.$preg_ec[0].'][^\s]+))( AS)*(.+)*$/i', $item, $matches);
+
+ if (isset($matches[4]))
{
- $alias = strstr($item, ' ');
- $item = substr($item, 0, - strlen($alias));
+ $item = $matches[1];
+
+ // Escape the alias, if needed
+ if ($protect_identifiers === TRUE)
+ {
+ $alias = empty($matches[5])
+ ? ' '.$this->escape_identifiers(ltrim($matches[4]))
+ : $matches[4].' '.$this->escape_identifiers(ltrim($matches[5]));
+ }
+ else
+ {
+ $alias = $matches[4].$matches[5];
+ }
}
else
{
$alias = '';
}
- // This is basically a bug fix for queries that use MAX, MIN, etc.
- // If a parenthesis is found we know that we do not need to
- // escape the data or add a prefix. There's probably a more graceful
- // way to deal with this, but I'm not thinking of it -- Rick
- if (strpos($item, '(') !== FALSE)
- {
- return $item.$alias;
- }
-
// Break the string apart if it contains periods, then insert the table prefix
// in the correct location, assuming the period doesn't indicate that we're dealing
// with an alias. While we're at it, we will escape the components
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php
index ff5eb3fe6..9b7639289 100644
--- a/system/database/DB_forge.php
+++ b/system/database/DB_forge.php
@@ -72,6 +72,11 @@ abstract class CI_DB_forge {
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
}
+ if ( ! empty($this->db->data_cache['db_names']))
+ {
+ $this->db->data_cache['db_names'][] = $db_name;
+ }
+
return TRUE;
}
@@ -99,6 +104,15 @@ abstract class CI_DB_forge {
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
}
+ if ( ! empty($this->db->data_cache['db_names']))
+ {
+ $key = array_search(strtolower($db_name), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ unset($this->db->data_cache['db_names'][$key]);
+ }
+ }
+
return TRUE;
}
@@ -209,7 +223,18 @@ abstract class CI_DB_forge {
$sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists);
$this->_reset();
- return is_bool($sql) ? $sql : $this->db->query($sql);
+
+ if (is_bool($sql))
+ {
+ return $sql;
+ }
+
+ if (($result = $this->db->query($sql)) !== FALSE && ! empty($this->db->data_cache['table_names']))
+ {
+ $this->db->data_cache['table_names'][] = $$this->db->dbprefix.$table;
+ }
+
+ return $result;
}
// --------------------------------------------------------------------
@@ -231,7 +256,19 @@ abstract class CI_DB_forge {
return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
- return $this->db->query(sprintf($this->_drop_table, $this->db->escape_identifiers($this->db->dbprefix.$table_name)));
+ $result = $this->db->query(sprintf($this->_drop_table, $this->db->escape_identifiers($this->db->dbprefix.$table_name)));
+
+ // Update table list cache
+ if ($result && ! empty($this->db->data_cache['table_names']))
+ {
+ $key = array_search(strtolower($this->db->dbprefix.$table_name), array_map('strtolower', $this->db->data_cache['table_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ unset($this->db->data_cache['table_names'][$key]);
+ }
+ }
+
+ return $result;
}
// --------------------------------------------------------------------
@@ -255,10 +292,21 @@ abstract class CI_DB_forge {
return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
- return $this->db->query(sprintf($this->_rename_table,
+ $result = $this->db->query(sprintf($this->_rename_table,
$this->db->escape_identifiers($this->db->dbprefix.$table_name),
$this->db->escape_identifiers($this->db->dbprefix.$new_table_name))
);
+
+ if ($result && ! empty($this->db->data_cache['table_names']))
+ {
+ $key = array_search(strtolower($this->db->dbprefix.$table_name), array_map('strtolower', $this->db->data_cache['table_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ $this->db->data_cache['table_names'][$key] = $this->db->dbprefix.$new_table_name;
+ }
+ }
+
+ return $result;
}
// --------------------------------------------------------------------
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index 3ed556212..488b294e4 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -53,7 +53,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
protected $qb_keys = array();
protected $qb_limit = FALSE;
protected $qb_offset = FALSE;
- protected $qb_order = FALSE;
protected $qb_orderby = array();
protected $qb_set = array();
protected $qb_wherein = array();
@@ -84,6 +83,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* Generates the SELECT portion of the query
*
* @param string
+ * @param mixed
* @return object
*/
public function select($select = '*', $escape = NULL)
@@ -93,6 +93,9 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$select = explode(',', $select);
}
+ // If the escape value was not set will will base it on the global setting
+ is_bool($escape) OR $escape = $this->_protect_identifiers;
+
foreach ($select as $val)
{
$val = trim($val);
@@ -321,15 +324,16 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param string
* @param string the join condition
* @param string the type of join
+ * @param string wether not to try to escape identifiers
* @return object
*/
- public function join($table, $cond, $type = '')
+ public function join($table, $cond, $type = '', $escape = TRUE)
{
if ($type !== '')
{
$type = strtoupper(trim($type));
- if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER')))
+ if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE))
{
$type = '';
}
@@ -343,12 +347,39 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// in the protect_identifiers to know whether to add a table prefix
$this->_track_aliases($table);
- // Strip apart the condition and protect the identifiers
- if (preg_match('/([\[\w\.]+)([\W\s]+)(.+)/', $cond, $match))
+ // Split multiple conditions
+ if ($escape === TRUE && preg_match_all('/\sAND\s|\sOR\s/i', $cond, $m, PREG_SET_ORDER | PREG_OFFSET_CAPTURE))
+ {
+ $newcond = '';
+ $m[0][] = array('', strlen($cond));
+
+ for ($i = 0, $c = count($m[0]), $s = 0;
+ $i < $c;
+ $s += $m[0][$i][1] + strlen($m[0][$i][0]), $i++)
+ {
+ $temp = substr($cond, $s, $m[0][$i][1]);
+
+ $newcond .= preg_match('/([\[\w\.-]+)([\W\s]+)(.+)/i', $temp, $match)
+ ? $this->protect_identifiers($match[1]).$match[2].$this->protect_identifiers($match[3])
+ : $temp;
+
+ $newcond .= $m[0][$i][0];
+ }
+
+ $cond = $newcond;
+ }
+ // Split apart the condition and protect the identifiers
+ elseif ($escape === TRUE && preg_match('/([\[\w\.-]+)([\W\s]+)(.+)/i', $cond, $match))
{
$cond = $this->protect_identifiers($match[1]).$match[2].$this->protect_identifiers($match[3]);
}
+ // Do we want to escape the table name?
+ if ($escape === TRUE)
+ {
+ $table = $this->protect_identifiers($table, TRUE, NULL, FALSE);
+ }
+
// Assemble the JOIN statement
$this->qb_join[] = $join = $type.'JOIN '.$this->protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
@@ -371,6 +402,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* @param mixed
* @param mixed
+ * @param bool
* @return object
*/
public function where($key, $value = NULL, $escape = TRUE)
@@ -388,6 +420,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* @param mixed
* @param mixed
+ * @param bool
* @return object
*/
public function or_where($key, $value = NULL, $escape = TRUE)
@@ -405,6 +438,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param mixed
* @param mixed
* @param string
+ * @param mixed
* @return object
*/
protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
@@ -417,15 +451,16 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
}
// If the escape value was not set will will base it on the global setting
- if ( ! is_bool($escape))
- {
- $escape = $this->_protect_identifiers;
- }
+ $escape = $this->_protect_identifiers;
foreach ($key as $k => $v)
{
$prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type;
+ $k = $this->_has_operator($k)
+ ? $this->protect_identifiers(substr($k, 0, strpos(rtrim($k), ' ')), FALSE, $escape).strchr(rtrim($k), ' ')
+ : $this->protect_identifiers($k, FALSE, $escape);
+
if (is_null($v) && ! $this->_has_operator($k))
{
// value appears not to have been set, assign the test to IS NULL
@@ -436,7 +471,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
{
if ($escape === TRUE)
{
- $k = $this->protect_identifiers($k, FALSE, $escape);
$v = ' '.$this->escape($v);
}
@@ -445,10 +479,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$k .= ' = ';
}
}
- else
- {
- $k = $this->protect_identifiers($k, FALSE, $escape);
- }
$this->qb_where[] = $prefix.$k.$v;
if ($this->qb_caching === TRUE)
@@ -547,7 +577,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
{
if ($key === NULL OR $values === NULL)
{
- return;
+ return $this;
}
$type = $this->_group_get_type($type);
@@ -853,6 +883,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* @param string
* @param string
+ * @param bool
* @return object
*/
public function having($key, $value = '', $escape = TRUE)
@@ -869,6 +900,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* @param string
* @param string
+ * @param bool
* @return object
*/
public function or_having($key, $value = '', $escape = TRUE)
@@ -885,6 +917,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* @param string
* @param string
+ * @param string
+ * @param bool
* @return object
*/
protected function _having($key, $value = '', $type = 'AND ', $escape = TRUE)
@@ -943,7 +977,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
}
elseif (trim($direction) !== '')
{
- $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC';
+ $direction = in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE) ? ' '.$direction : ' ASC';
}
@@ -955,7 +989,9 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$part = trim($part);
if ( ! in_array($part, $this->qb_aliased_tables))
{
- $part = $this->protect_identifiers(trim($part));
+ $part = preg_match('/^(.+)\s+(ASC|DESC)$/i', $part, $matches)
+ ? $this->protect_identifiers(rtrim($matches[1])).' '.$matches[2]
+ : $this->protect_identifiers($part);
}
$temp[] = $part;
@@ -963,12 +999,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$orderby = implode(', ', $temp);
}
- elseif ($direction !== $this->_random_keyword)
+ elseif ($direction !== $this->_random_keyword && $escape === TRUE)
{
- if ($escape === TRUE)
- {
- $orderby = $this->protect_identifiers($orderby);
- }
+ $orderby = preg_match('/^(.+)\s+(ASC|DESC)$/i', $orderby, $matches)
+ ? $this->protect_identifiers(rtrim($matches[1])).' '.$matches[2]
+ : $this->protect_identifiers($orderby);
}
$this->qb_orderby[] = $orderby_statement = $orderby.$direction;
@@ -995,7 +1030,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
{
$this->qb_limit = (int) $value;
- if ( ! is_null($offset))
+ if ( ! empty($offset))
{
$this->qb_offset = (int) $offset;
}
@@ -1070,7 +1105,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$this->from($table);
}
- $select = $this->_compile_select();
+ $select = $this->_compile_select();
if ($reset === TRUE)
{
@@ -1093,7 +1128,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param string the offset clause
* @return object
*/
- public function get($table = '', $limit = null, $offset = null)
+ public function get($table = '', $limit = NULL, $offset = NULL)
{
if ($table !== '')
{
@@ -1101,7 +1136,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$this->from($table);
}
- if ( ! is_null($limit))
+ if ( ! empty($limit))
{
$this->limit($limit, $offset);
}
@@ -1166,7 +1201,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$this->where($where);
}
- if ( ! is_null($limit))
+ if ( ! empty($limit))
{
$this->limit($limit, $offset);
}
@@ -1275,11 +1310,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
ksort($row); // puts $row in the same order as our keys
- if ($escape === FALSE)
- {
- $this->qb_set[] = '('.implode(',', $row).')';
- }
- else
+ if ($escape !== FALSE)
{
$clean = array();
foreach ($row as $value)
@@ -1287,8 +1318,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$clean[] = $this->escape($value);
}
- $this->qb_set[] = '('.implode(',', $clean).')';
+ $row = $clean;
}
+
+ $this->qb_set[] = '('.implode(',', $row).')';
}
foreach ($keys as $k)
@@ -1553,7 +1586,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$this->where($where);
}
- if ($limit != NULL)
+ if ( ! empty($limit))
{
$this->limit($limit);
}
@@ -1874,7 +1907,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$this->where($where);
}
- if ($limit != NULL)
+ if ( ! empty($limit))
{
$this->limit($limit);
}
@@ -1915,7 +1948,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
return 'DELETE FROM '.$table
.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : '')
- .($limit ? ' LIMIT '.$limit : '');
+ .($limit ? ' LIMIT '.(int) $limit : '');
}
// --------------------------------------------------------------------
@@ -1985,7 +2018,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
if (strpos($table, ' ') !== FALSE)
{
// if the alias is written with the AS keyword, remove it
- $table = preg_replace('/ AS /i', ' ', $table);
+ $table = preg_replace('/\s+AS\s+/i', ' ', $table);
// Grab the alias
$table = trim(strrchr($table, ' '));
@@ -2088,10 +2121,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
if (count($this->qb_orderby) > 0)
{
$sql .= "\nORDER BY ".implode(', ', $this->qb_orderby);
- if ($this->qb_order !== FALSE)
- {
- $sql .= ($this->qb_order === 'desc') ? ' DESC' : ' ASC';
- }
}
// Write the "LIMIT" portion of the query
@@ -2321,8 +2350,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
'qb_no_escape' => array(),
'qb_distinct' => FALSE,
'qb_limit' => FALSE,
- 'qb_offset' => FALSE,
- 'qb_order' => FALSE
+ 'qb_offset' => FALSE
)
);
}
@@ -2345,8 +2373,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
'qb_like' => array(),
'qb_orderby' => array(),
'qb_keys' => array(),
- 'qb_limit' => FALSE,
- 'qb_order' => FALSE
+ 'qb_limit' => FALSE
)
);
}
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index 02c921834..6a3b40779 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -35,7 +35,6 @@
abstract class CI_DB_utility extends CI_DB_forge {
public $db;
- public $data_cache = array();
// Platform specific SQL strings
// Just setting those defaults to FALSE as they are mostly MySQL-specific
@@ -60,29 +59,29 @@ abstract class CI_DB_utility extends CI_DB_forge {
public function list_databases()
{
// Is there a cached result?
- if (isset($this->data_cache['db_names']))
+ if (isset($this->db->data_cache['db_names']))
{
- return $this->data_cache['db_names'];
+ return $this->db->data_cache['db_names'];
}
elseif ($this->_list_databases === FALSE)
{
return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
- $this->data_cache['db_names'] = array();
+ $this->db->data_cache['db_names'] = array();
$query = $this->db->query($this->_list_databases);
if ($query === FALSE)
{
- return $this->data_cache['db_names'];
+ return $this->db->data_cache['db_names'];
}
for ($i = 0, $c = count($query); $i < $c; $i++)
{
- $this->data_cache['db_names'] = current($query[$i]);
+ $this->db->data_cache['db_names'] = current($query[$i]);
}
- return $this->data_cache['db_names'];
+ return $this->db->data_cache['db_names'];
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php
index c8cee99b6..ea8feb4e2 100644
--- a/system/database/drivers/cubrid/cubrid_utility.php
+++ b/system/database/drivers/cubrid/cubrid_utility.php
@@ -41,12 +41,12 @@ class CI_DB_cubrid_utility extends CI_DB_utility {
*/
public function list_databases()
{
- if (isset($this->data_cache['db_names']))
+ if (isset($this->db->data_cache['db_names']))
{
- return $this->data_cache['db_names'];
+ return $this->db->data_cache['db_names'];
}
- return $this->data_cache['db_names'] = cubrid_list_dbs($this->db->conn_id);
+ return $this->db->data_cache['db_names'] = cubrid_list_dbs($this->db->conn_id);
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/interbase/interbase_forge.php b/system/database/drivers/interbase/interbase_forge.php
index 3f9967f1f..d1b006e80 100644
--- a/system/database/drivers/interbase/interbase_forge.php
+++ b/system/database/drivers/interbase/interbase_forge.php
@@ -67,6 +67,14 @@ class CI_DB_interbase_forge extends CI_DB_forge {
{
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
}
+ elseif ( ! empty($this->db->data_cache['db_names']))
+ {
+ $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ unset($this->db->data_cache['db_names'][$key]);
+ }
+ }
return TRUE;
}
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 87094e76e..47dc55844 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -504,7 +504,30 @@ class CI_DB_mssql_driver extends CI_DB {
*/
protected function _limit($sql, $limit, $offset)
{
- return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.($limit + $offset).' ', $sql);
+ // As of SQL Server 2012 (11.0.*) OFFSET is supported
+ if (version_compare($this->version(), '11', '>='))
+ {
+ return $sql.' OFFSET '.(int) $offset.' ROWS FETCH NEXT '.(int) $limit.' ROWS ONLY';
+ }
+
+ $limit = $offset + $limit;
+
+ // As of SQL Server 2005 (9.0.*) ROW_NUMBER() is supported,
+ // however an ORDER BY clause is required for it to work
+ if (version_compare($this->version(), '9', '>=') && $offset && ! empty($this->qb_orderby))
+ {
+ $orderby = 'ORDER BY '.implode(', ', $this->qb_orderby);
+
+ // We have to strip the ORDER BY clause
+ $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby)));
+
+ return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n"
+ .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql)
+ ."\n) ".$this->escape_identifiers('CI_subquery')
+ ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.((int) $offset + 1).' AND '.$limit;
+ }
+
+ return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php
index 27d4ef817..5d2bdbce0 100644
--- a/system/database/drivers/mysqli/mysqli_utility.php
+++ b/system/database/drivers/mysqli/mysqli_utility.php
@@ -46,9 +46,124 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
*/
protected function _backup($params = array())
{
- // Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ if (count($params) === 0)
+ {
+ return FALSE;
+ }
+
+ // Extract the prefs for simplicity
+ extract($params);
+
+ // Build the output
+ $output = '';
+ foreach ( (array) $tables as $table)
+ {
+ // Is the table in the "ignore" list?
+ if (in_array($table, (array) $ignore, TRUE))
+ {
+ continue;
+ }
+
+ // Get the table schema
+ $query = $this->db->query('SHOW CREATE TABLE '.$this->db->escape_identifiers($this->db->database.'.'.$table));
+
+ // No result means the table name was invalid
+ if ($query === FALSE)
+ {
+ continue;
+ }
+
+ // Write out the table schema
+ $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline;
+
+ if ($add_drop === TRUE)
+ {
+ $output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline;
+ }
+
+ $i = 0;
+ $result = $query->result_array();
+ foreach ($result[0] as $val)
+ {
+ if ($i++ % 2)
+ {
+ $output .= $val.';'.$newline.$newline;
+ }
+ }
+
+ // If inserts are not needed we're done...
+ if ($add_insert === FALSE)
+ {
+ continue;
+ }
+
+ // Grab all the data from the current table
+ $query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table));
+
+ if ($query->num_rows() === 0)
+ {
+ continue;
+ }
+
+ // Fetch the field names and determine if the field is an
+ // integer type. We use this info to decide whether to
+ // surround the data with quotes or not
+
+ $i = 0;
+ $field_str = '';
+ $is_int = array();
+ while ($field = $query->result_id->fetch_field())
+ {
+ // Most versions of MySQL store timestamp as a string
+ $is_int[$i] = in_array(strtolower($field->type),
+ array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
+ TRUE);
+
+ // Create a string of field names
+ $field_str .= $this->db->escape_identifiers($field->name).', ';
+ $i++;
+ }
+
+ // Trim off the end comma
+ $field_str = preg_replace('/, $/' , '', $field_str);
+
+ // Build the insert string
+ foreach ($query->result_array() as $row)
+ {
+ $val_str = '';
+
+ $i = 0;
+ foreach ($row as $v)
+ {
+ // Is the value NULL?
+ if ($v === NULL)
+ {
+ $val_str .= 'NULL';
+ }
+ else
+ {
+ // Escape the data if it's not an integer
+ $val_str .= ($is_int[$i] === FALSE) ? $this->db->escape($v) : $v;
+ }
+
+ // Append a comma
+ $val_str .= ', ';
+ $i++;
+ }
+
+ // Remove the comma at the end of the string
+ $val_str = preg_replace('/, $/' , '', $val_str);
+
+ // Build the INSERT string
+ $output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
+ }
+
+ $output .= $newline.$newline;
+ }
+
+ return $output;
}
+
}
/* End of file mysqli_utility.php */
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 7375fbf71..ad9ac9000 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -615,6 +615,10 @@ class CI_DB_postgre_driver extends CI_DB {
{
$prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type;
+ $k = $this->_has_operator($k)
+ ? $this->protect_identifiers(substr($k, 0, strpos(rtrim($k), ' ')), FALSE, $escape).strchr(rtrim($k), ' ')
+ : $this->protect_identifiers($k, FALSE, $escape);
+
if (is_null($v) && ! $this->_has_operator($k))
{
// value appears not to have been set, assign the test to IS NULL
@@ -625,7 +629,6 @@ class CI_DB_postgre_driver extends CI_DB {
{
if ($escape === TRUE)
{
- $k = $this->protect_identifiers($k, FALSE, $escape);
$v = ' '.$this->escape($v);
}
elseif (is_bool($v))
@@ -638,10 +641,6 @@ class CI_DB_postgre_driver extends CI_DB {
$k .= ' = ';
}
}
- else
- {
- $k = $this->protect_identifiers($k, FALSE, $escape);
- }
$this->qb_where[] = $prefix.$k.$v;
if ($this->qb_caching === TRUE)
diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php
index 71eed7df4..e02e327f3 100644
--- a/system/database/drivers/sqlite/sqlite_forge.php
+++ b/system/database/drivers/sqlite/sqlite_forge.php
@@ -61,6 +61,14 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
{
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
}
+ elseif ( ! empty($this->db->data_cache['db_names']))
+ {
+ $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ unset($this->db->data_cache['db_names'][$key]);
+ }
+ }
return TRUE;
}
diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php
index f8bd11656..6a76ba929 100644
--- a/system/database/drivers/sqlite3/sqlite3_forge.php
+++ b/system/database/drivers/sqlite3/sqlite3_forge.php
@@ -66,6 +66,14 @@ class CI_DB_sqlite3_forge extends CI_DB_forge {
{
return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE;
}
+ elseif ( ! empty($this->db->data_cache['db_names']))
+ {
+ $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ unset($this->db->data_cache['db_names'][$key]);
+ }
+ }
return TRUE;
}
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index 655a9e90b..825c02452 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -21,7 +21,7 @@
* @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
- * @since Version 1.0
+ * @since Version 2.0.3
* @filesource
*/
@@ -463,9 +463,28 @@ class CI_DB_sqlsrv_driver extends CI_DB {
protected function _limit($sql, $limit, $offset)
{
// As of SQL Server 2012 (11.0.*) OFFSET is supported
- return version_compare($this->version(), '11', '>=')
- ? $sql.' OFFSET '.(int) $offset.' ROWS FETCH NEXT '.(int) $limit.' ROWS ONLY'
- : preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.($limit + $offset).' ', $sql);
+ if (version_compare($this->version(), '11', '>='))
+ {
+ return $sql.' OFFSET '.(int) $offset.' ROWS FETCH NEXT '.(int) $limit.' ROWS ONLY';
+ }
+
+ $limit = $offset + $limit;
+
+ // An ORDER BY clause is required for ROW_NUMBER() to work
+ if ($offset && ! empty($this->qb_orderby))
+ {
+ $orderby = 'ORDER BY '.implode(', ', $this->qb_orderby);
+
+ // We have to strip the ORDER BY clause
+ $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby)));
+
+ return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n"
+ .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql)
+ ."\n) ".$this->escape_identifiers('CI_subquery')
+ ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.((int) $offset + 1).' AND '.$limit;
+ }
+
+ return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php
index e6f7e1ac1..ccdb36929 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_forge.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php
@@ -21,7 +21,7 @@
* @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
- * @since Version 1.0
+ * @since Version 2.0.3
* @filesource
*/
diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php
index f802383d2..f9d5a0d29 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_result.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_result.php
@@ -21,7 +21,7 @@
* @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
- * @since Version 1.0
+ * @since Version 2.0.3
* @filesource
*/
diff --git a/system/database/drivers/sqlsrv/sqlsrv_utility.php b/system/database/drivers/sqlsrv/sqlsrv_utility.php
index 5a71b1628..d518cc15a 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_utility.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_utility.php
@@ -21,7 +21,7 @@
* @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
- * @since Version 1.0
+ * @since Version 2.0.3
* @filesource
*/
diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php
index 53f9f81a7..4395cf411 100644
--- a/system/libraries/Cache/Cache.php
+++ b/system/libraries/Cache/Cache.php
@@ -41,11 +41,12 @@ class CI_Cache extends CI_Driver_Library {
*
* @var array
*/
- protected $valid_drivers = array(
+ protected $valid_drivers = array(
'cache_apc',
+ 'cache_dummy',
'cache_file',
'cache_memcached',
- 'cache_dummy',
+ 'cache_redis',
'cache_wincache'
);
diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php
index 5170de821..08231963e 100644
--- a/system/libraries/Cache/drivers/Cache_file.php
+++ b/system/libraries/Cache/drivers/Cache_file.php
@@ -26,7 +26,7 @@
*/
/**
- * CodeIgniter Memcached Caching Class
+ * CodeIgniter File Caching Class
*
* @package CodeIgniter
* @subpackage Libraries
@@ -171,13 +171,13 @@ class CI_Cache_file extends CI_Driver {
{
$mtime = filemtime($this->_cache_path.$id);
- if ( ! isset($data['data']['ttl']))
+ if ( ! isset($data['ttl']))
{
return FALSE;
}
return array(
- 'expire' => $mtime + $data['data']['ttl'],
+ 'expire' => $mtime + $data['ttl'],
'mtime' => $mtime
);
}
diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php
new file mode 100644
index 000000000..e4a26b5f0
--- /dev/null
+++ b/system/libraries/Cache/drivers/Cache_redis.php
@@ -0,0 +1,236 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 3.0
+ * @filesource
+ */
+
+/**
+ * CodeIgniter Redis Caching Class
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Core
+ * @author Anton Lindqvist <anton@qvister.se>
+ * @link
+ */
+class CI_Cache_redis extends CI_Driver
+{
+ /**
+ * Default config
+ *
+ * @static
+ * @var array
+ */
+ protected static $_default_config = array(
+ 'host' => '127.0.0.1',
+ 'password' => NULL,
+ 'port' => 6379,
+ 'timeout' => 0
+ );
+
+ /**
+ * Redis connection
+ *
+ * @var Redis
+ */
+ protected $_redis;
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get cache
+ *
+ * @param string Cache key identifier
+ * @return mixed
+ */
+ public function get($key)
+ {
+ return $this->_redis->get($key);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Save cache
+ *
+ * @param string Cache key identifier
+ * @param mixed Data to save
+ * @param int Time to live
+ * @return bool
+ */
+ public function save($key, $value, $ttl = NULL)
+ {
+ return ($ttl)
+ ? $this->_redis->setex($key, $ttl, $value)
+ : $this->_redis->set($key, $value);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Delete from cache
+ *
+ * @param string Cache key
+ * @return bool
+ */
+ public function delete($key)
+ {
+ return ($this->_redis->delete($key) === 1);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Clean cache
+ *
+ * @return bool
+ * @see Redis::flushDB()
+ */
+ public function clean()
+ {
+ return $this->_redis->flushDB();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get cache driver info
+ *
+ * @param string Not supported in Redis.
+ * Only included in order to offer a
+ * consistent cache API.
+ * @return array
+ * @see Redis::info()
+ */
+ public function cache_info($type = NULL)
+ {
+ return $this->_redis->info();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get cache metadata
+ *
+ * @param string Cache key
+ * @return array
+ */
+ public function get_metadata($key)
+ {
+ $value = $this->get($key);
+
+ if ($value)
+ {
+ return array(
+ 'expire' => time() + $this->_redis->ttl($key),
+ 'data' => $value
+ );
+ }
+
+ return FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Check if Redis driver is supported
+ *
+ * @return bool
+ */
+ public function is_supported()
+ {
+ if (extension_loaded('redis'))
+ {
+ $this->_setup_redis();
+ return TRUE;
+ }
+ else
+ {
+ log_message('error', 'The Redis extension must be loaded to use Redis cache.');
+ return FALSE;
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Setup Redis config and connection
+ *
+ * Loads Redis config file if present. Will halt execution
+ * if a Redis connection can't be established.
+ *
+ * @return bool
+ * @see Redis::connect()
+ */
+ protected function _setup_redis()
+ {
+ $config = array();
+ $CI =& get_instance();
+
+ if ($CI->config->load('redis', TRUE, TRUE))
+ {
+ $config += $CI->config->item('redis');
+ }
+
+ $config = array_merge(self::$_default_config, $config);
+
+ $this->_redis = new Redis();
+
+ try
+ {
+ $this->_redis->connect($config['host'], $config['port'], $config['timeout']);
+ }
+ catch (RedisException $e)
+ {
+ show_error('Redis connection refused. ' . $e->getMessage());
+ }
+
+ if (isset($config['password']))
+ {
+ $this->_redis->auth($config['password']);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+
+ * Class destructor
+ *
+ * Closes the connection to Redis if present.
+ *
+ * @return void
+ */
+ public function __destruct()
+ {
+ if ($this->_redis)
+ {
+ $this->_redis->close();
+ }
+ }
+
+}
+
+/* End of file Cache_redis.php */
+/* Location: ./system/libraries/Cache/drivers/Cache_redis.php */ \ No newline at end of file
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index c70144f7c..09f217530 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -1599,7 +1599,7 @@ class CI_Email {
$this->_debug_msg[] = '<pre>'.$cmd.': '.$reply.'</pre>';
- if (substr($reply, 0, 3) !== $resp)
+ if ( (int) substr($reply, 0, 3) !== $resp)
{
$this->_set_error_message('lang:email_smtp_error', $reply);
return FALSE;
diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php
index ce5e030b0..8ffd93aea 100644
--- a/system/libraries/Encrypt.php
+++ b/system/libraries/Encrypt.php
@@ -213,6 +213,7 @@ class CI_Encrypt {
$dec = base64_decode($string);
if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE)
{
+ $this->set_mode($current_mode);
return FALSE;
}
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 225325d6f..6cbe032c7 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -187,6 +187,12 @@ class CI_Form_validation {
return $this;
}
+ // Convert an array of rules to a string
+ if (is_array($rules))
+ {
+ $rules = implode('|', $rules);
+ }
+
// No fields? Nothing to do...
if ( ! is_string($field) OR ! is_string($rules) OR $field === '')
{
@@ -1089,11 +1095,12 @@ class CI_Form_validation {
* Validate IP Address
*
* @param string
+ * @param string 'ipv4' or 'ipv6' to validate a specific IP format
* @return bool
*/
- public function valid_ip($ip)
+ public function valid_ip($ip, $which = '')
{
- return $this->CI->input->valid_ip($ip);
+ return $this->CI->input->valid_ip($ip, $which);
}
// --------------------------------------------------------------------
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index a91159c98..cdec736ff 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.php
@@ -36,38 +36,39 @@
*/
class CI_Pagination {
- protected $base_url = ''; // The page we are linking to
- protected $prefix = ''; // A custom prefix added to the path.
- protected $suffix = ''; // A custom suffix added to the path.
- protected $total_rows = 0; // Total number of items (database results)
- protected $per_page = 10; // Max number of items you want shown per page
- protected $num_links = 2; // Number of "digit" links to show before/after the currently viewed page
- protected $cur_page = 0; // The current page being viewed
- protected $use_page_numbers = FALSE; // Use page number for segment instead of offset
- protected $first_link = '&lsaquo; First';
- protected $next_link = '&gt;';
- protected $prev_link = '&lt;';
- protected $last_link = 'Last &rsaquo;';
- protected $uri_segment = 3;
- protected $full_tag_open = '';
- protected $full_tag_close = '';
- protected $first_tag_open = '';
- protected $first_tag_close = '&nbsp;';
- protected $last_tag_open = '&nbsp;';
- protected $last_tag_close = '';
- protected $first_url = ''; // Alternative URL for the First Page.
- protected $cur_tag_open = '&nbsp;<strong>';
- protected $cur_tag_close = '</strong>';
- protected $next_tag_open = '&nbsp;';
- protected $next_tag_close = '&nbsp;';
- protected $prev_tag_open = '&nbsp;';
- protected $prev_tag_close = '';
- protected $num_tag_open = '&nbsp;';
- protected $num_tag_close = '';
- protected $page_query_string = FALSE;
- protected $query_string_segment = 'per_page';
- protected $display_pages = TRUE;
- protected $anchor_class = '';
+ public $base_url = ''; // The page we are linking to
+ public $prefix = ''; // A custom prefix added to the path.
+ public $suffix = ''; // A custom suffix added to the path.
+ public $total_rows = 0; // Total number of items (database results)
+ public $per_page = 10; // Max number of items you want shown per page
+ public $num_links = 2; // Number of "digit" links to show before/after the currently viewed page
+ public $cur_page = 0; // The current page being viewed
+ public $use_page_numbers = FALSE; // Use page number for segment instead of offset
+ public $first_link = '&lsaquo; First';
+ public $next_link = '&gt;';
+ public $prev_link = '&lt;';
+ public $last_link = 'Last &rsaquo;';
+ public $uri_segment = 3;
+ public $full_tag_open = '';
+ public $full_tag_close = '';
+ public $first_tag_open = '';
+ public $first_tag_close = '&nbsp;';
+ public $last_tag_open = '&nbsp;';
+ public $last_tag_close = '';
+ public $first_url = ''; // Alternative URL for the First Page.
+ public $cur_tag_open = '&nbsp;<strong>';
+ public $cur_tag_close = '</strong>';
+ public $next_tag_open = '&nbsp;';
+ public $next_tag_close = '&nbsp;';
+ public $prev_tag_open = '&nbsp;';
+ public $prev_tag_close = '';
+ public $num_tag_open = '&nbsp;';
+ public $num_tag_close = '';
+ public $page_query_string = FALSE;
+ public $query_string_segment = 'per_page';
+ public $display_pages = TRUE;
+ public $anchor_class = '';
+ public $attr_rel = TRUE;
/**
* Constructor
@@ -97,7 +98,7 @@ class CI_Pagination {
{
if ($key === 'anchor_class')
{
- $this->anchor_class = ($val !== '') ? 'class="'.$val.'" ' : '';
+ $this->anchor_class = ($val) ? 'class="'.$val.'" ' : '';
}
elseif (isset($this->$key))
{
@@ -145,7 +146,7 @@ class CI_Pagination {
if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
{
- if ($CI->input->get($this->query_string_segment) !== $base_page)
+ if ($CI->input->get($this->query_string_segment) != $base_page)
{
$this->cur_page = (int) $CI->input->get($this->query_string_segment);
}
@@ -212,7 +213,8 @@ class CI_Pagination {
if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1))
{
$first_url = ($this->first_url === '') ? $this->base_url : $this->first_url;
- $output .= $this->first_tag_open.'<a '.$this->anchor_class.'href="'.$first_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;
+ $output .= $this->first_tag_open.'<a '.$this->anchor_class.'href="'.$first_url.'"'.$this->_attr_rel('start').'>'
+ .$this->first_link.'</a>'.$this->first_tag_close;
}
// Render the "previous" link
@@ -222,12 +224,14 @@ class CI_Pagination {
if ($i === $base_page && $this->first_url !== '')
{
- $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
+ $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'"'.$this->_attr_rel('prev').'>'
+ .$this->prev_link.'</a>'.$this->prev_tag_close;
}
else
{
$i = ($i === $base_page) ? '' : $this->prefix.$i.$this->suffix;
- $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
+ $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$i.'"'.$this->_attr_rel('prev').'>'
+ .$this->prev_link.'</a>'.$this->prev_tag_close;
}
}
@@ -252,13 +256,15 @@ class CI_Pagination {
if ($n === '' && $this->first_url !== '')
{
- $output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$loop.'</a>'.$this->num_tag_close;
+ $output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'"'.$this->_attr_rel('start').'>'
+ .$loop.'</a>'.$this->num_tag_close;
}
else
{
$n = ($n === '') ? '' : $this->prefix.$n.$this->suffix;
- $output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$n.'">'.$loop.'</a>'.$this->num_tag_close;
+ $output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$n.'"'.$this->_attr_rel().'>'
+ .$loop.'</a>'.$this->num_tag_close;
}
}
}
@@ -270,7 +276,8 @@ class CI_Pagination {
{
$i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page;
- $output .= $this->next_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->next_link.'</a>'.$this->next_tag_close;
+ $output .= $this->next_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$this->_attr_rel('next').'>'
+ .$this->next_link.'</a>'.$this->next_tag_close;
}
// Render the "Last" link
@@ -278,7 +285,8 @@ class CI_Pagination {
{
$i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page;
- $output .= $this->last_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.'</a>'.$this->last_tag_close;
+ $output .= $this->last_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'"'.$this->_attr_rel().'>'
+ .$this->last_link.'</a>'.$this->last_tag_close;
}
// Kill double slashes. Note: Sometimes we can end up with a double slash
@@ -289,6 +297,28 @@ class CI_Pagination {
return $this->full_tag_open.$output.$this->full_tag_close;
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Add "rel" attribute
+ *
+ * @param string
+ * @return string
+ */
+ protected function _attr_rel($value = '')
+ {
+ if (empty($this->attr_rel) OR ($this->attr_rel === TRUE && empty($value)))
+ {
+ return '';
+ }
+ elseif ( ! is_bool($this->attr_rel))
+ {
+ $value = $this->attr_rel;
+ }
+
+ return ' rel="'.$value.'"';
+ }
+
}
/* End of file Pagination.php */
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 1f6aeeb6b..c96daaf15 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -347,11 +347,12 @@ class CI_Upload {
* Returns an associative array containing all of the information
* related to the upload, allowing the developer easy access in one array.
*
- * @return array
+ * @param string
+ * @return mixed
*/
- public function data()
+ public function data($index = NULL)
{
- return array(
+ $data = array(
'file_name' => $this->file_name,
'file_type' => $this->file_type,
'file_path' => $this->upload_path,
@@ -367,6 +368,13 @@ class CI_Upload {
'image_type' => $this->image_type,
'image_size_str' => $this->image_size_str,
);
+
+ if ( ! empty($index))
+ {
+ return isset($data[$index]) ? $data[$index] : NULL;
+ }
+
+ return $data;
}
// --------------------------------------------------------------------
diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php
index b48e32bfb..5317c56c7 100644
--- a/tests/codeigniter/Setup_test.php
+++ b/tests/codeigniter/Setup_test.php
@@ -1,13 +1,13 @@
<?php
class Setup_test extends PHPUnit_Framework_TestCase {
-
- function test_bootstrap_constants()
+
+ public function test_bootstrap_constants()
{
$this->assertTrue(defined('PROJECT_BASE'));
$this->assertTrue(defined('BASEPATH'));
$this->assertTrue(defined('APPPATH'));
$this->assertTrue(defined('VIEWPATH'));
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php
index 109b38821..a239ba51d 100644
--- a/tests/codeigniter/core/Benchmark_test.php
+++ b/tests/codeigniter/core/Benchmark_test.php
@@ -1,14 +1,14 @@
<?php
class Benchmark_test extends CI_TestCase {
-
+
public function set_up()
{
$this->benchmark = new Mock_Core_Benchmark();
}
-
+
// --------------------------------------------------------------------
-
+
public function test_mark()
{
$this->assertEmpty($this->benchmark->marker);
@@ -18,7 +18,7 @@ class Benchmark_test extends CI_TestCase {
$this->assertEquals(1, count($this->benchmark->marker));
$this->assertArrayHasKey('code_start', $this->benchmark->marker);
}
-
+
// --------------------------------------------------------------------
public function test_elapsed_time()
@@ -29,7 +29,7 @@ class Benchmark_test extends CI_TestCase {
$this->benchmark->mark('code_start');
sleep(1);
$this->benchmark->mark('code_end');
-
+
$this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1));
}
@@ -39,4 +39,5 @@ class Benchmark_test extends CI_TestCase {
{
$this->assertEquals('{memory_usage}', $this->benchmark->memory_usage());
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php
index dded2e824..f9bf6c27f 100644
--- a/tests/codeigniter/core/Common_test.php
+++ b/tests/codeigniter/core/Common_test.php
@@ -1,13 +1,13 @@
<?php
class Common_test extends CI_TestCase {
-
+
// ------------------------------------------------------------------------
-
+
public function test_is_php()
{
$this->assertEquals(TRUE, is_php('1.2.0'));
$this->assertEquals(FALSE, is_php('9999.9.9'));
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php
index 30f0cc61d..30cb90a28 100644
--- a/tests/codeigniter/core/Config_test.php
+++ b/tests/codeigniter/core/Config_test.php
@@ -5,7 +5,7 @@ class Config_test extends CI_TestCase {
public function set_up()
{
$cls =& $this->ci_core_class('cfg');
-
+
// set predictable config values
$this->ci_set_config(array(
'index_page' => 'index.php',
@@ -13,9 +13,9 @@ class Config_test extends CI_TestCase {
'subclass_prefix' => 'MY_'
));
- $this->config = new $cls;
+ $this->config = new $cls;
}
-
+
// --------------------------------------------------------------------
public function test_item()
@@ -24,30 +24,30 @@ class Config_test extends CI_TestCase {
// Bad Config value
$this->assertFalse($this->config->item('no_good_item'));
-
+
// Index
$this->assertFalse($this->config->item('no_good_item', 'bad_index'));
$this->assertFalse($this->config->item('no_good_item', 'default'));
}
-
+
// --------------------------------------------------------------------
-
+
public function test_set_item()
{
$this->assertFalse($this->config->item('not_yet_set'));
-
+
$this->config->set_item('not_yet_set', 'is set');
-
+
$this->assertEquals('is set', $this->config->item('not_yet_set'));
}
// --------------------------------------------------------------------
-
+
public function test_slash_item()
{
// Bad Config value
$this->assertFalse($this->config->slash_item('no_good_item'));
-
+
$this->assertEquals('http://example.com/', $this->config->slash_item('base_url'));
$this->assertEquals('MY_/', $this->config->slash_item('subclass_prefix'));
@@ -58,33 +58,33 @@ class Config_test extends CI_TestCase {
public function test_site_url()
{
$this->assertEquals('http://example.com/index.php', $this->config->site_url());
-
+
$base_url = $this->config->item('base_url');
-
+
$this->config->set_item('base_url', '');
-
+
$q_string = $this->config->item('enable_query_strings');
-
+
$this->config->set_item('enable_query_strings', FALSE);
$this->assertEquals('index.php/test', $this->config->site_url('test'));
$this->assertEquals('index.php/test/1', $this->config->site_url(array('test', '1')));
-
+
$this->config->set_item('enable_query_strings', TRUE);
$this->assertEquals('index.php?test', $this->config->site_url('test'));
$this->assertEquals('index.php?0=test&1=1', $this->config->site_url(array('test', '1')));
-
+
$this->config->set_item('base_url', $base_url);
$this->assertEquals('http://example.com/index.php?test', $this->config->site_url('test'));
-
+
// back to home base
- $this->config->set_item('enable_query_strings', $q_string);
+ $this->config->set_item('enable_query_strings', $q_string);
}
// --------------------------------------------------------------------
-
+
public function test_system_url()
{
$this->assertEquals('http://example.com/system/', $this->config->system_url());
diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php
index c9322c027..fe8738832 100644
--- a/tests/codeigniter/core/Input_test.php
+++ b/tests/codeigniter/core/Input_test.php
@@ -1,7 +1,7 @@
<?php
class Input_test extends CI_TestCase {
-
+
public function set_up()
{
// Set server variable to GET as default, since this will leave unset in STDIN env
@@ -17,9 +17,9 @@ class Input_test extends CI_TestCase {
$this->input = new Mock_Core_Input($security, $utf8);
}
-
+
// --------------------------------------------------------------------
-
+
public function test_get_not_exists()
{
$this->assertEmpty($this->input->get());
@@ -38,7 +38,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_get_exist()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
@@ -49,7 +49,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_get_exist_with_xss_clean()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
@@ -61,7 +61,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_post_not_exists()
{
$this->assertEmpty($this->input->post());
@@ -78,7 +78,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_post_exist()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
@@ -89,7 +89,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_post_exist_with_xss_clean()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
@@ -101,7 +101,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_get_post()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
@@ -111,7 +111,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_cookie()
{
$_COOKIE['foo'] = 'bar';
@@ -120,14 +120,14 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_server()
{
$this->assertEquals('GET', $this->input->server('REQUEST_METHOD'));
}
// --------------------------------------------------------------------
-
+
public function test_fetch_from_array()
{
$data = array(
@@ -145,14 +145,14 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_valid_ip()
{
$ip_v4 = '192.18.0.1';
$this->assertTrue($this->input->valid_ip($ip_v4));
$ip_v6 = array('2001:0db8:0000:85a3:0000:0000:ac1f:8001', '2001:db8:0:85a3:0:0:ac1f:8001', '2001:db8:0:85a3::ac1f:8001');
- foreach($ip_v6 as $ip)
+ foreach ($ip_v6 as $ip)
{
$this->assertTrue($this->input->valid_ip($ip));
}
diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php
index 874230feb..a410dabfa 100644
--- a/tests/codeigniter/core/Lang_test.php
+++ b/tests/codeigniter/core/Lang_test.php
@@ -1,9 +1,9 @@
<?php
class Lang_test extends CI_TestCase {
-
+
protected $lang;
-
+
public function set_up()
{
$loader_cls = $this->ci_core_class('load');
@@ -12,9 +12,9 @@ class Lang_test extends CI_TestCase {
$cls = $this->ci_core_class('lang');
$this->lang = new $cls;
}
-
+
// --------------------------------------------------------------------
-
+
public function test_load()
{
$this->assertTrue($this->lang->load('profiler', 'english'));
@@ -22,11 +22,11 @@ class Lang_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_load_with_unspecified_language()
{
$this->assertTrue($this->lang->load('profiler'));
$this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string'));
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php
index 43008651e..fdea962b7 100644
--- a/tests/codeigniter/core/Loader_test.php
+++ b/tests/codeigniter/core/Loader_test.php
@@ -1,35 +1,35 @@
<?php
class Loader_test extends CI_TestCase {
-
+
private $ci_obj;
-
+
public function set_up()
{
// Instantiate a new loader
$this->load = new Mock_Core_Loader();
-
+
// mock up a ci instance
- $this->ci_obj = new StdClass;
-
+ $this->ci_obj = new stdClass;
+
// Fix get_instance()
$this->ci_instance($this->ci_obj);
}
// --------------------------------------------------------------------
-
+
public function test_library()
{
$this->_setup_config_mock();
-
+
// Test loading as an array.
$this->assertNull($this->load->library(array('table')));
$this->assertTrue(class_exists('CI_Table'), 'Table class exists');
$this->assertAttributeInstanceOf('CI_Table', 'table', $this->ci_obj);
-
+
// Test no lib given
$this->assertEquals(FALSE, $this->load->library());
-
+
// Test a string given to params
$this->assertEquals(NULL, $this->load->library('table', ' '));
}
@@ -39,20 +39,18 @@ class Loader_test extends CI_TestCase {
public function test_load_library_in_application_dir()
{
$this->_setup_config_mock();
-
+
$content = '<?php class Super_test_library {} ';
-
- $model = vfsStream::newFile('Super_test_library.php')->withContent($content)
- ->at($this->load->libs_dir);
-
+
+ $model = vfsStream::newFile('Super_test_library.php')->withContent($content)->at($this->load->libs_dir);
$this->assertNull($this->load->library('super_test_library'));
-
+
// Was the model class instantiated.
- $this->assertTrue(class_exists('Super_test_library'));
+ $this->assertTrue(class_exists('Super_test_library'));
}
-
+
// --------------------------------------------------------------------
-
+
private function _setup_config_mock()
{
// Mock up a config object until we
@@ -61,7 +59,7 @@ class Loader_test extends CI_TestCase {
$config->expects($this->any())
->method('load')
->will($this->returnValue(TRUE));
-
+
// Add the mock to our stdClass
$this->ci_instance_var('config', $config);
}
@@ -73,64 +71,62 @@ class Loader_test extends CI_TestCase {
$this->setExpectedException(
'RuntimeException',
'CI Error: Unable to locate the model you have specified: ci_test_nonexistent_model.php'
- );
-
+ );
+
$this->load->model('ci_test_nonexistent_model.php');
}
// --------------------------------------------------------------------
-
+
/**
* @coverts CI_Loader::model
*/
public function test_models()
{
$this->ci_set_core_class('model', 'CI_Model');
-
+
$content = '<?php class Unit_test_model extends CI_Model {} ';
-
- $model = vfsStream::newFile('unit_test_model.php')->withContent($content)
- ->at($this->load->models_dir);
-
+
+ $model = vfsStream::newFile('unit_test_model.php')->withContent($content)->at($this->load->models_dir);
+
$this->assertNull($this->load->model('unit_test_model'));
-
+
// Was the model class instantiated.
$this->assertTrue(class_exists('Unit_test_model'));
-
+
// Test no model given
- $this->assertNull($this->load->model(''));
+ $this->assertNull($this->load->model(''));
}
// --------------------------------------------------------------------
-
+
// public function testDatabase()
// {
// $this->assertEquals(NULL, $this->load->database());
- // $this->assertEquals(NULL, $this->load->dbutil());
+ // $this->assertEquals(NULL, $this->load->dbutil());
// }
// --------------------------------------------------------------------
-
+
/**
* @coverts CI_Loader::view
*/
public function test_load_view()
{
$this->ci_set_core_class('output', 'CI_Output');
-
+
$content = 'This is my test page. <?php echo $hello; ?>';
- $view = vfsStream::newFile('unit_test_view.php')->withContent($content)
- ->at($this->load->views_dir);
-
+ $view = vfsStream::newFile('unit_test_view.php')->withContent($content)->at($this->load->views_dir);
+
// Use the optional return parameter in this test, so the view is not
// run through the output class.
$this->assertEquals('This is my test page. World!',
$this->load->view('unit_test_view', array('hello' => "World!"), TRUE));
-
+
}
// --------------------------------------------------------------------
-
+
/**
* @coverts CI_Loader::view
*/
@@ -139,8 +135,8 @@ class Loader_test extends CI_TestCase {
$this->setExpectedException(
'RuntimeException',
'CI Error: Unable to load the requested file: ci_test_nonexistent_view.php'
- );
-
+ );
+
$this->load->view('ci_test_nonexistent_view', array('foo' => 'bar'));
}
@@ -149,87 +145,77 @@ class Loader_test extends CI_TestCase {
public function test_file()
{
$content = 'Here is a test file, which we will load now.';
- $file = vfsStream::newFile('ci_test_mock_file.php')->withContent($content)
- ->at($this->load->views_dir);
-
+ $file = vfsStream::newFile('ci_test_mock_file.php')->withContent($content)->at($this->load->views_dir);
+
// Just like load->view(), take the output class out of the mix here.
- $load = $this->load->file(vfsStream::url('application').'/views/ci_test_mock_file.php',
- TRUE);
-
+ $load = $this->load->file(vfsStream::url('application').'/views/ci_test_mock_file.php', TRUE);
+
$this->assertEquals($content, $load);
-
+
$this->setExpectedException(
'RuntimeException',
'CI Error: Unable to load the requested file: ci_test_file_not_exists'
- );
-
+ );
+
$this->load->file('ci_test_file_not_exists', TRUE);
-
}
// --------------------------------------------------------------------
-
+
public function test_vars()
{
- $vars = array(
- 'foo' => 'bar'
- );
-
- $this->assertNull($this->load->vars($vars));
+ $this->assertNull($this->load->vars(array('foo' => 'bar')));
$this->assertNull($this->load->vars('foo', 'bar'));
}
// --------------------------------------------------------------------
-
+
public function test_helper()
{
$this->assertEquals(NULL, $this->load->helper('array'));
-
+
$this->setExpectedException(
'RuntimeException',
'CI Error: Unable to load the requested file: helpers/bad_helper.php'
- );
-
+ );
+
$this->load->helper('bad');
}
-
+
// --------------------------------------------------------------------
public function test_loading_multiple_helpers()
{
$this->assertEquals(NULL, $this->load->helpers(array('file', 'array', 'string')));
}
-
+
// --------------------------------------------------------------------
-
+
// public function testLanguage()
// {
// $this->assertEquals(NULL, $this->load->language('test'));
- // }
+ // }
// --------------------------------------------------------------------
public function test_load_config()
{
$this->_setup_config_mock();
-
$this->assertNull($this->load->config('config', FALSE));
}
-
+
// --------------------------------------------------------------------
public function test_load_bad_config()
{
$this->_setup_config_mock();
-
+
$this->setExpectedException(
'RuntimeException',
'CI Error: The configuration file foobar.php does not exist.'
- );
-
+ );
+
$this->load->config('foobar', FALSE);
}
- // --------------------------------------------------------------------
-
-}
+} \ No newline at end of file
diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php
index b2f8c69d2..3f6e3b07a 100644
--- a/tests/codeigniter/core/Security_test.php
+++ b/tests/codeigniter/core/Security_test.php
@@ -1,7 +1,7 @@
<?php
class Security_test extends CI_TestCase {
-
+
public function set_up()
{
// Set cookie for security test
@@ -14,9 +14,9 @@ class Security_test extends CI_TestCase {
$this->security = new Mock_Core_Security();
}
-
+
// --------------------------------------------------------------------
-
+
public function test_csrf_verify()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
@@ -25,7 +25,7 @@ class Security_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_csrf_verify_invalid()
{
// Without issuing $_POST[csrf_token_name], this request will triggering CSRF error
@@ -37,7 +37,7 @@ class Security_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_csrf_verify_valid()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
@@ -47,21 +47,21 @@ class Security_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_get_csrf_hash()
{
$this->assertEquals($this->security->csrf_hash, $this->security->get_csrf_hash());
}
// --------------------------------------------------------------------
-
+
public function test_get_csrf_token_name()
{
$this->assertEquals('ci_csrf_token', $this->security->get_csrf_token_name());
}
// --------------------------------------------------------------------
-
+
public function test_xss_clean()
{
$harm_string = "Hello, i try to <script>alert('Hack');</script> your site";
@@ -72,7 +72,7 @@ class Security_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_xss_hash()
{
$this->assertEmpty($this->security->xss_hash);
@@ -84,7 +84,7 @@ class Security_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_entity_decode()
{
$encoded = '&lt;div&gt;Hello &lt;b&gt;Booya&lt;/b&gt;&lt;/div&gt;';
@@ -94,7 +94,7 @@ class Security_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_sanitize_filename()
{
$filename = './<!--foo-->';
@@ -102,4 +102,5 @@ class Security_test extends CI_TestCase {
$this->assertEquals('foo', $safe_filename);
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php
index e340ddf73..0ba694b46 100644
--- a/tests/codeigniter/core/URI_test.php
+++ b/tests/codeigniter/core/URI_test.php
@@ -1,7 +1,7 @@
<?php
class URI_test extends CI_TestCase {
-
+
public function set_up()
{
$this->uri = new Mock_Core_URI();
@@ -13,19 +13,12 @@ class URI_test extends CI_TestCase {
{
// Slashes get killed
$this->uri->_set_uri_string('/');
-
- $a = '';
- $b =& $this->uri->uri_string;
-
- $this->assertEquals($a, $b);
-
+ $this->assertEquals('', $this->uri->uri_string);
+
$this->uri->_set_uri_string('nice/uri');
-
- $a = 'nice/uri';
-
- $this->assertEquals($a, $b);
+ $this->assertEquals('nice/uri', $this->uri->uri_string);
}
-
+
// --------------------------------------------------------------------
public function test_fetch_uri_string()
@@ -34,75 +27,61 @@ class URI_test extends CI_TestCase {
// uri_protocol: AUTO
$this->uri->config->set_item('uri_protocol', 'AUTO');
-
+
// Test a variety of request uris
$requests = array(
'/index.php/controller/method' => 'controller/method',
'/index.php?/controller/method' => 'controller/method',
'/index.php?/controller/method/?var=foo' => 'controller/method'
);
-
+
foreach($requests as $request => $expected)
{
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['REQUEST_URI'] = $request;
-
+
$this->uri->_fetch_uri_string();
$this->assertEquals($expected, $this->uri->uri_string );
}
-
+
// Test a subfolder
$_SERVER['SCRIPT_NAME'] = '/subfolder/index.php';
$_SERVER['REQUEST_URI'] = '/subfolder/index.php/controller/method';
-
+
$this->uri->_fetch_uri_string();
-
- $a = 'controller/method';
- $b = $this->uri->uri_string;
-
- $this->assertEquals($a, $b);
-
+ $this->assertEquals('controller/method', $this->uri->uri_string);
+
// death to request uri
unset($_SERVER['REQUEST_URI']);
-
+
// life to path info
- $_SERVER['PATH_INFO'] = '/controller/method/';
-
+ $_SERVER['PATH_INFO'] = $a = '/controller/method/';
+
$this->uri->_fetch_uri_string();
-
- $a = '/controller/method/';
- $b =& $this->uri->uri_string;
+ $this->assertEquals($a, $this->uri->uri_string);
- $this->assertEquals($a, $b);
-
// death to path info
// At this point your server must be seriously drunk
unset($_SERVER['PATH_INFO']);
-
+
$_SERVER['QUERY_STRING'] = '/controller/method/';
-
+
$this->uri->_fetch_uri_string();
+ $this->assertEquals($a, $this->uri->uri_string);
- $a = '/controller/method/';
- $b = $this->uri->uri_string;
-
- $this->assertEquals($a, $b);
-
// At this point your server is a labotomy victim
-
unset($_SERVER['QUERY_STRING']);
-
+
$_GET['/controller/method/'] = '';
-
+
$this->uri->_fetch_uri_string();
- $this->assertEquals($a, $b);
+ $this->assertEquals($a, $this->uri->uri_string);
// Test coverage implies that these will work
// uri_protocol: REQUEST_URI
// uri_protocol: CLI
-
}
-
+
// --------------------------------------------------------------------
public function test_explode_segments()
@@ -113,18 +92,15 @@ class URI_test extends CI_TestCase {
'/test2/uri2' => array('test2', 'uri2'),
'//test3/test3///' => array('test3', 'test3')
);
-
- foreach($uris as $uri => $a)
+
+ foreach ($uris as $uri => $a)
{
$this->uri->segments = array();
$this->uri->uri_string = $uri;
$this->uri->_explode_segments();
-
- $b = $this->uri->segments;
-
- $this->assertEquals($a, $b);
+
+ $this->assertEquals($a, $this->uri->segments);
}
-
}
// --------------------------------------------------------------------
@@ -133,7 +109,7 @@ class URI_test extends CI_TestCase {
{
$this->uri->config->set_item('enable_query_strings', FALSE);
$this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-');
-
+
$str_in = 'abc01239~%.:_-';
$str = $this->uri->_filter_uri($str_in);
@@ -145,52 +121,52 @@ class URI_test extends CI_TestCase {
public function test_filter_uri_escaping()
{
// ensure escaping even if dodgey characters are permitted
-
+
$this->uri->config->set_item('enable_query_strings', FALSE);
$this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-()$');
$str = $this->uri->_filter_uri('$destroy_app(foo)');
-
+
$this->assertEquals($str, '&#36;destroy_app&#40;foo&#41;');
}
// --------------------------------------------------------------------
- public function test_filter_uri_throws_error()
- {
+ public function test_filter_uri_throws_error()
+ {
$this->setExpectedException('RuntimeException');
-
+
$this->uri->config->set_item('enable_query_strings', FALSE);
$this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-');
$this->uri->_filter_uri('$this()');
- }
+ }
// --------------------------------------------------------------------
public function test_remove_url_suffix()
{
$this->uri->config->set_item('url_suffix', '.html');
-
+
$this->uri->uri_string = 'controller/method/index.html';
$this->uri->_remove_url_suffix();
-
+
$this->assertEquals($this->uri->uri_string, 'controller/method/index');
-
+
$this->uri->uri_string = 'controller/method/index.htmlify.html';
$this->uri->_remove_url_suffix();
-
+
$this->assertEquals($this->uri->uri_string, 'controller/method/index.htmlify');
}
// --------------------------------------------------------------------
-
+
public function test_segment()
{
$this->uri->segments = array(1 => 'controller');
$this->assertEquals($this->uri->segment(1), 'controller');
$this->assertEquals($this->uri->segment(2, 'default'), 'default');
}
-
+
// --------------------------------------------------------------------
public function test_rsegment()
@@ -205,32 +181,33 @@ class URI_test extends CI_TestCase {
public function test_uri_to_assoc()
{
$this->uri->segments = array('a', '1', 'b', '2', 'c', '3');
-
- $a = array('a' => '1', 'b' => '2', 'c' => '3');
- $b = $this->uri->uri_to_assoc(1);
- $this->assertEquals($a, $b);
-
- $a = array('b' => '2', 'c' => '3');
- $b = $this->uri->uri_to_assoc(3);
- $this->assertEquals($a, $b);
-
-
+
+ $this->assertEquals(
+ array('a' => '1', 'b' => '2', 'c' => '3'),
+ $this->uri->uri_to_assoc(1)
+ );
+
+ $this->assertEquals(
+ array('b' => '2', 'c' => '3'),
+ $this->uri->uri_to_assoc(3)
+ );
+
$this->uri->keyval = array(); // reset cache
-
$this->uri->segments = array('a', '1', 'b', '2', 'c');
-
- $a = array('a' => '1', 'b' => '2', 'c' => FALSE);
- $b = $this->uri->uri_to_assoc(1);
- $this->assertEquals($a, $b);
-
+
+ $this->assertEquals(
+ array('a' => '1', 'b' => '2', 'c' => FALSE),
+ $this->uri->uri_to_assoc(1)
+ );
+
$this->uri->keyval = array(); // reset cache
-
$this->uri->segments = array('a', '1');
-
+
// test default
- $a = array('a' => '1', 'b' => FALSE);
- $b = $this->uri->uri_to_assoc(1, array('a', 'b'));
- $this->assertEquals($a, $b);
+ $this->assertEquals(
+ array('a' => '1', 'b' => FALSE),
+ $this->uri->uri_to_assoc(1, array('a', 'b'))
+ );
}
// --------------------------------------------------------------------
@@ -238,33 +215,33 @@ class URI_test extends CI_TestCase {
public function test_ruri_to_assoc()
{
$this->uri->rsegments = array('x', '1', 'y', '2', 'z', '3');
-
- $a = array('x' => '1', 'y' => '2', 'z' => '3');
- $b = $this->uri->ruri_to_assoc(1);
- $this->assertEquals($a, $b);
-
- $a = array('y' => '2', 'z' => '3');
- $b = $this->uri->ruri_to_assoc(3);
- $this->assertEquals($a, $b);
-
-
+
+ $this->assertEquals(
+ array('x' => '1', 'y' => '2', 'z' => '3'),
+ $this->uri->ruri_to_assoc(1)
+ );
+
+ $this->assertEquals(
+ array('y' => '2', 'z' => '3'),
+ $this->uri->ruri_to_assoc(3)
+ );
+
$this->uri->keyval = array(); // reset cache
-
$this->uri->rsegments = array('x', '1', 'y', '2', 'z');
-
- $a = array('x' => '1', 'y' => '2', 'z' => FALSE);
- $b = $this->uri->ruri_to_assoc(1);
- $this->assertEquals($a, $b);
-
+
+ $this->assertEquals(
+ array('x' => '1', 'y' => '2', 'z' => FALSE),
+ $this->uri->ruri_to_assoc(1)
+ );
+
$this->uri->keyval = array(); // reset cache
-
$this->uri->rsegments = array('x', '1');
-
- // test default
- $a = array('x' => '1', 'y' => FALSE);
- $b = $this->uri->ruri_to_assoc(1, array('x', 'y'));
- $this->assertEquals($a, $b);
+ // test default
+ $this->assertEquals(
+ array('x' => '1', 'y' => FALSE),
+ $this->uri->ruri_to_assoc(1, array('x', 'y'))
+ );
}
// --------------------------------------------------------------------
@@ -272,11 +249,7 @@ class URI_test extends CI_TestCase {
public function test_assoc_to_uri()
{
$this->uri->config->set_item('uri_string_slashes', 'none');
-
- $arr = array('a' => 1, 'b' => 2);
- $a = 'a/1/b/2';
- $b = $this->uri->assoc_to_uri($arr);
- $this->assertEquals($a, $b);
+ $this->assertEquals('a/1/b/2', $this->uri->assoc_to_uri(array('a' => '1', 'b' => '2')));
}
// --------------------------------------------------------------------
@@ -286,28 +259,18 @@ class URI_test extends CI_TestCase {
$this->uri->segments[1] = 'segment';
$this->uri->rsegments[1] = 'segment';
- $a = '/segment/';
- $b = $this->uri->slash_segment(1, 'both');
- $this->assertEquals($a, $b);
- $b = $this->uri->slash_rsegment(1, 'both');
- $this->assertEquals($a, $b);
-
+ $this->assertEquals('/segment/', $this->uri->slash_segment(1, 'both'));
+ $this->assertEquals('/segment/', $this->uri->slash_rsegment(1, 'both'));
+
$a = '/segment';
- $b = $this->uri->slash_segment(1, 'leading');
- $this->assertEquals($a, $b);
- $b = $this->uri->slash_rsegment(1, 'leading');
- $this->assertEquals($a, $b);
-
- $a = 'segment/';
- $b = $this->uri->slash_segment(1, 'trailing');
- $this->assertEquals($a, $b);
- $b = $this->uri->slash_rsegment(1, 'trailing');
- $this->assertEquals($a, $b);
- }
+ $this->assertEquals('/segment', $this->uri->slash_segment(1, 'leading'));
+ $this->assertEquals('/segment', $this->uri->slash_rsegment(1, 'leading'));
+ $this->assertEquals('segment/', $this->uri->slash_segment(1, 'trailing'));
+ $this->assertEquals('segment/', $this->uri->slash_rsegment(1, 'trailing'));
+ }
}
-// END URI_test Class
/* End of file URI_test.php */
-/* Location: ./tests/core/URI_test.php */
+/* Location: ./tests/core/URI_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/count_test.php b/tests/codeigniter/database/query_builder/count_test.php
index 5e691692d..90ac5283e 100644
--- a/tests/codeigniter/database/query_builder/count_test.php
+++ b/tests/codeigniter/database/query_builder/count_test.php
@@ -22,10 +22,7 @@ class Count_test extends CI_TestCase {
*/
public function test_count_all()
{
- $job_count = $this->db->count_all('job');
-
- // Check the result
- $this->assertEquals(4, $job_count);
+ $this->assertEquals(4, $this->db->count_all('job'));
}
// ------------------------------------------------------------------------
@@ -35,10 +32,7 @@ class Count_test extends CI_TestCase {
*/
public function test_count_all_results()
{
- $job_count = $this->db->like('name', 'ian')
- ->count_all_results('job');
-
- // Check the result
- $this->assertEquals(2, $job_count);
+ $this->assertEquals(2, $this->db->like('name', 'ian')->count_all_results('job'));
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/delete_test.php b/tests/codeigniter/database/query_builder/delete_test.php
index 84ea7616f..ab9d97f56 100644
--- a/tests/codeigniter/database/query_builder/delete_test.php
+++ b/tests/codeigniter/database/query_builder/delete_test.php
@@ -23,9 +23,7 @@ class Delete_test extends CI_TestCase {
public function test_delete()
{
// Check initial record
- $job1 = $this->db->where('id', 1)
- ->get('job')
- ->row();
+ $job1 = $this->db->where('id', 1)->get('job')->row();
$this->assertEquals('Developer', $job1->name);
@@ -33,8 +31,7 @@ class Delete_test extends CI_TestCase {
$this->db->delete('job', array('id' => 1));
// Check the record
- $job1 = $this->db->where('id', 1)
- ->get('job');
+ $job1 = $this->db->where('id', 1)->get('job');
$this->assertEmpty($job1->result_array());
}
@@ -47,13 +44,8 @@ class Delete_test extends CI_TestCase {
public function test_delete_several_tables()
{
// Check initial record
- $user4 = $this->db->where('id', 4)
- ->get('user')
- ->row();
-
- $job4 = $this->db->where('id', 4)
- ->get('job')
- ->row();
+ $user4 = $this->db->where('id', 4)->get('user')->row();
+ $job4 = $this->db->where('id', 4)->get('job')->row();
$this->assertEquals('Musician', $job4->name);
$this->assertEquals('Chris Martin', $user4->name);
diff --git a/tests/codeigniter/database/query_builder/distinct_test.php b/tests/codeigniter/database/query_builder/distinct_test.php
index 925eadb19..cc98009ce 100644
--- a/tests/codeigniter/database/query_builder/distinct_test.php
+++ b/tests/codeigniter/database/query_builder/distinct_test.php
@@ -23,11 +23,10 @@ class Distinct_test extends CI_TestCase {
public function test_distinct()
{
$users = $this->db->select('country')
- ->distinct()
- ->get('user')
- ->result_array();
-
- // Check the result
+ ->distinct()
+ ->get('user')
+ ->result_array();
+
$this->assertEquals(3, count($users));
}
diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php
index 5d575a37b..c6380ddf1 100644
--- a/tests/codeigniter/database/query_builder/escape_test.php
+++ b/tests/codeigniter/database/query_builder/escape_test.php
@@ -35,7 +35,7 @@ class Escape_test extends CI_TestCase {
}
$res = $this->db->query($sql)->result_array();
-
+
// Check the result
$this->assertEquals(1, count($res));
}
@@ -60,8 +60,9 @@ class Escape_test extends CI_TestCase {
}
$res = $this->db->query($sql)->result_array();
-
+
// Check the result
$this->assertEquals(2, count($res));
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/from_test.php b/tests/codeigniter/database/query_builder/from_test.php
index 95ae4dfdb..7aaae348d 100644
--- a/tests/codeigniter/database/query_builder/from_test.php
+++ b/tests/codeigniter/database/query_builder/from_test.php
@@ -23,10 +23,9 @@ class From_test extends CI_TestCase {
public function test_from_simple()
{
$jobs = $this->db->from('job')
- ->get()
- ->result_array();
-
- // Check items
+ ->get()
+ ->result_array();
+
$this->assertEquals(4, count($jobs));
}
@@ -38,14 +37,13 @@ class From_test extends CI_TestCase {
public function test_from_with_where()
{
$job1 = $this->db->from('job')
- ->where('id', 1)
- ->get()
- ->row();
-
- // Check the result
+ ->where('id', 1)
+ ->get()
+ ->row();
+
$this->assertEquals('1', $job1->id);
$this->assertEquals('Developer', $job1->name);
$this->assertEquals('Awesome job, but sometimes makes you bored', $job1->description);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php
index 0751c9332..699d2906a 100644
--- a/tests/codeigniter/database/query_builder/get_test.php
+++ b/tests/codeigniter/database/query_builder/get_test.php
@@ -23,7 +23,7 @@ class Get_test extends CI_TestCase {
public function test_get_simple()
{
$jobs = $this->db->get('job')->result_array();
-
+
// Dummy jobs contain 4 rows
$this->assertCount(4, $jobs);
@@ -42,12 +42,12 @@ class Get_test extends CI_TestCase {
public function test_get_where()
{
$job1 = $this->db->get('job', array('id' => 1))->result_array();
-
+
// Dummy jobs contain 1 rows
$this->assertCount(1, $job1);
// Check rows item
$this->assertEquals('Developer', $job1[0]['name']);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php
index 7d8abc33f..5249f7c87 100644
--- a/tests/codeigniter/database/query_builder/group_test.php
+++ b/tests/codeigniter/database/query_builder/group_test.php
@@ -23,12 +23,11 @@ class Group_test extends CI_TestCase {
public function test_group_by()
{
$jobs = $this->db->select('name')
- ->from('job')
- ->group_by('name')
- ->get()
- ->result_array();
-
- // Check the result
+ ->from('job')
+ ->group_by('name')
+ ->get()
+ ->result_array();
+
$this->assertEquals(4, count($jobs));
}
@@ -40,14 +39,13 @@ class Group_test extends CI_TestCase {
public function test_having_by()
{
$jobs = $this->db->select('name')
- ->from('job')
- ->group_by('name')
- ->having('SUM(id) > 2')
- ->get()
- ->result_array();
-
- // Check the result
+ ->from('job')
+ ->group_by('name')
+ ->having('SUM(id) > 2')
+ ->get()
+ ->result_array();
+
$this->assertEquals(2, count($jobs));
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php
index e05329d67..b8cf2a822 100644
--- a/tests/codeigniter/database/query_builder/join_test.php
+++ b/tests/codeigniter/database/query_builder/join_test.php
@@ -34,5 +34,5 @@ class Join_test extends CI_TestCase {
$this->assertEquals('Derek Jones', $job_user[0]['user_name']);
$this->assertEquals('Developer', $job_user[0]['job_name']);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php
index df98c713f..5f3e52228 100644
--- a/tests/codeigniter/database/query_builder/like_test.php
+++ b/tests/codeigniter/database/query_builder/like_test.php
@@ -86,5 +86,5 @@ class Like_test extends CI_TestCase {
$this->assertEquals('Accountant', $jobs[1]['name']);
$this->assertEquals('Musician', $jobs[2]['name']);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/limit_test.php b/tests/codeigniter/database/query_builder/limit_test.php
index 704f3b651..a0954c7ab 100644
--- a/tests/codeigniter/database/query_builder/limit_test.php
+++ b/tests/codeigniter/database/query_builder/limit_test.php
@@ -25,8 +25,7 @@ class Limit_test extends CI_TestCase {
$jobs = $this->db->limit(2)
->get('job')
->result_array();
-
- // Check the result
+
$this->assertEquals(2, count($jobs));
}
@@ -40,10 +39,10 @@ class Limit_test extends CI_TestCase {
$jobs = $this->db->limit(2, 2)
->get('job')
->result_array();
-
- // Check the result
+
$this->assertEquals(2, count($jobs));
$this->assertEquals('Accountant', $jobs[0]['name']);
$this->assertEquals('Musician', $jobs[1]['name']);
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/order_test.php b/tests/codeigniter/database/query_builder/order_test.php
index 01aa1c2b4..46f452bae 100644
--- a/tests/codeigniter/database/query_builder/order_test.php
+++ b/tests/codeigniter/database/query_builder/order_test.php
@@ -25,7 +25,7 @@ class Order_test extends CI_TestCase {
$jobs = $this->db->order_by('name', 'asc')
->get('job')
->result_array();
-
+
// Check the result
$this->assertEquals(4, count($jobs));
$this->assertEquals('Accountant', $jobs[0]['name']);
@@ -44,12 +44,12 @@ class Order_test extends CI_TestCase {
$jobs = $this->db->order_by('name', 'desc')
->get('job')
->result_array();
-
- // Check the result
+
$this->assertEquals(4, count($jobs));
$this->assertEquals('Politician', $jobs[0]['name']);
$this->assertEquals('Musician', $jobs[1]['name']);
$this->assertEquals('Developer', $jobs[2]['name']);
$this->assertEquals('Accountant', $jobs[3]['name']);
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php
index 0d299ed16..877b5d8c0 100644
--- a/tests/codeigniter/database/query_builder/select_test.php
+++ b/tests/codeigniter/database/query_builder/select_test.php
@@ -25,7 +25,7 @@ class Select_test extends CI_TestCase {
$jobs_name = $this->db->select('name')
->get('job')
->result_array();
-
+
// Check rows item
$this->assertArrayHasKey('name',$jobs_name[0]);
$this->assertFalse(array_key_exists('id', $jobs_name[0]));
@@ -42,7 +42,7 @@ class Select_test extends CI_TestCase {
$job_min = $this->db->select_min('id')
->get('job')
->row();
-
+
// Minimum id was 1
$this->assertEquals('1', $job_min->id);
}
@@ -57,7 +57,7 @@ class Select_test extends CI_TestCase {
$job_max = $this->db->select_max('id')
->get('job')
->row();
-
+
// Maximum id was 4
$this->assertEquals('4', $job_max->id);
}
@@ -72,7 +72,7 @@ class Select_test extends CI_TestCase {
$job_avg = $this->db->select_avg('id')
->get('job')
->row();
-
+
// Average should be 2.5
$this->assertEquals('2.5', $job_avg->id);
}
@@ -87,9 +87,9 @@ class Select_test extends CI_TestCase {
$job_sum = $this->db->select_sum('id')
->get('job')
->row();
-
+
// Sum of ids should be 10
$this->assertEquals('10', $job_sum->id);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/truncate_test.php b/tests/codeigniter/database/query_builder/truncate_test.php
index 2a9c8a91e..09923c7f1 100644
--- a/tests/codeigniter/database/query_builder/truncate_test.php
+++ b/tests/codeigniter/database/query_builder/truncate_test.php
@@ -24,7 +24,6 @@ class Truncate_test extends CI_TestCase {
{
// Check initial record
$jobs = $this->db->get('job')->result_array();
-
$this->assertEquals(4, count($jobs));
// Do the empty
@@ -32,7 +31,6 @@ class Truncate_test extends CI_TestCase {
// Check the record
$jobs = $this->db->get('job');
-
$this->assertEmpty($jobs->result_array());
}
@@ -45,16 +43,13 @@ class Truncate_test extends CI_TestCase {
{
// Check initial record
$users = $this->db->get('user')->result_array();
-
$this->assertEquals(4, count($users));
// Do the empty
- $this->db->from('user')
- ->truncate();
+ $this->db->from('user')->truncate();
// Check the record
$users = $this->db->get('user');
-
$this->assertEmpty($users->result_array());
}
diff --git a/tests/codeigniter/database/query_builder/update_test.php b/tests/codeigniter/database/query_builder/update_test.php
index f5bbffd4f..27a647c45 100644
--- a/tests/codeigniter/database/query_builder/update_test.php
+++ b/tests/codeigniter/database/query_builder/update_test.php
@@ -23,23 +23,14 @@ class Update_test extends CI_TestCase {
public function test_update()
{
// Check initial record
- $job1 = $this->db->where('id', 1)
- ->get('job')
- ->row();
-
+ $job1 = $this->db->where('id', 1)->get('job')->row();
$this->assertEquals('Developer', $job1->name);
// Do the update
- $job_data = array('name' => 'Programmer');
-
- $this->db->where('id', 1)
- ->update('job', $job_data);
+ $this->db->where('id', 1)->update('job', array('name' => 'Programmer'));
// Check updated record
- $job1 = $this->db->where('id', 1)
- ->get('job')
- ->row();
-
+ $job1 = $this->db->where('id', 1)->get('job')->row();
$this->assertEquals('Programmer', $job1->name);
}
@@ -51,10 +42,7 @@ class Update_test extends CI_TestCase {
public function test_update_with_set()
{
// Check initial record
- $job1 = $this->db->where('id', 4)
- ->get('job')
- ->row();
-
+ $job1 = $this->db->where('id', 4)->get('job')->row();
$this->assertEquals('Musician', $job1->name);
// Do the update
@@ -62,10 +50,8 @@ class Update_test extends CI_TestCase {
$this->db->update('job', NULL, 'id = 4');
// Check updated record
- $job1 = $this->db->where('id', 4)
- ->get('job')
- ->row();
-
+ $job1 = $this->db->where('id', 4)->get('job')->row();
$this->assertEquals('Vocalist', $job1->name);
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php
index 607eaa076..20b7a567c 100644
--- a/tests/codeigniter/database/query_builder/where_test.php
+++ b/tests/codeigniter/database/query_builder/where_test.php
@@ -22,11 +22,8 @@ class Where_test extends CI_TestCase {
*/
public function test_where_simple_key_value()
{
- $job1 = $this->db->where('id', 1)
- ->get('job')
- ->row();
+ $job1 = $this->db->where('id', 1)->get('job')->row();
- // Check the result
$this->assertEquals('1', $job1->id);
$this->assertEquals('Developer', $job1->name);
}
@@ -38,11 +35,7 @@ class Where_test extends CI_TestCase {
*/
public function test_where_custom_key_value()
{
- $jobs = $this->db->where('id !=', 1)
- ->get('job')
- ->result_array();
-
- // Check the result
+ $jobs = $this->db->where('id !=', 1)->get('job')->result_array();
$this->assertEquals(3, count($jobs));
}
@@ -54,16 +47,12 @@ class Where_test extends CI_TestCase {
public function test_where_associative_array()
{
$where = array('id >' => 2, 'name !=' => 'Accountant');
- $jobs = $this->db->where($where)
- ->get('job')
- ->result_array();
+ $jobs = $this->db->where($where)->get('job')->result_array();
- // Check the result
$this->assertEquals(1, count($jobs));
// Should be Musician
$job = current($jobs);
-
$this->assertEquals('Musician', $job['name']);
}
@@ -75,16 +64,12 @@ class Where_test extends CI_TestCase {
public function test_where_custom_string()
{
$where = "id > 2 AND name != 'Accountant'";
- $jobs = $this->db->where($where)
- ->get('job')
- ->result_array();
+ $jobs = $this->db->where($where)->get('job')->result_array();
- // Check the result
$this->assertEquals(1, count($jobs));
// Should be Musician
$job = current($jobs);
-
$this->assertEquals('Musician', $job['name']);
}
@@ -100,7 +85,6 @@ class Where_test extends CI_TestCase {
->get('job')
->result_array();
- // Check the result
$this->assertEquals(3, count($jobs));
$this->assertEquals('Developer', $jobs[0]['name']);
$this->assertEquals('Politician', $jobs[1]['name']);
@@ -118,7 +102,6 @@ class Where_test extends CI_TestCase {
->get('job')
->result_array();
- // Check the result
$this->assertEquals(2, count($jobs));
$this->assertEquals('Politician', $jobs[0]['name']);
$this->assertEquals('Accountant', $jobs[1]['name']);
@@ -135,10 +118,9 @@ class Where_test extends CI_TestCase {
->get('job')
->result_array();
- // Check the result
$this->assertEquals(2, count($jobs));
$this->assertEquals('Developer', $jobs[0]['name']);
$this->assertEquals('Musician', $jobs[1]['name']);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php
index 9cd15960f..ba46e86f9 100644
--- a/tests/codeigniter/helpers/array_helper_test.php
+++ b/tests/codeigniter/helpers/array_helper_test.php
@@ -1,7 +1,7 @@
<?php
class Array_helper_test extends CI_TestCase {
-
+
public function set_up()
{
$this->helper('array');
@@ -13,31 +13,31 @@ class Array_helper_test extends CI_TestCase {
'herb' => 'cook'
);
}
-
+
// ------------------------------------------------------------------------
-
+
public function test_element_with_existing_item()
- {
+ {
$this->assertEquals(FALSE, element('testing', $this->my_array));
-
+
$this->assertEquals('not set', element('testing', $this->my_array, 'not set'));
-
+
$this->assertEquals('bar', element('foo', $this->my_array));
}
-
- // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
public function test_random_element()
{
// Send a string, not an array to random_element
$this->assertEquals('my string', random_element('my string'));
-
+
// Test sending an array
$this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array));
}
- // ------------------------------------------------------------------------
-
+ // ------------------------------------------------------------------------
+
public function test_elements()
{
$this->assertEquals(TRUE, is_array(elements('test', $this->my_array)));
diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php
index 17d1ef21e..4b747b864 100644
--- a/tests/codeigniter/helpers/date_helper_test.php
+++ b/tests/codeigniter/helpers/date_helper_test.php
@@ -5,6 +5,8 @@ class Date_helper_test extends CI_TestCase {
public function set_up()
{
$this->helper('date');
+
+ $this->time = time();
}
// ------------------------------------------------------------------------
@@ -16,13 +18,11 @@ class Date_helper_test extends CI_TestCase {
$config->expects($this->any())
->method('item')
->will($this->returnValue('local'));
-
+
// Add the stub to our test instance
$this->ci_instance_var('config', $config);
- $expected = time();
- $test = now();
- $this->assertEquals($expected, $test);
+ $this->assertEquals(time(), now());
}
// ------------------------------------------------------------------------
@@ -34,124 +34,125 @@ class Date_helper_test extends CI_TestCase {
$config->expects($this->any())
->method('item')
->will($this->returnValue('gmt'));
-
+
// Add the stub to our stdClass
$this->ci_instance_var('config', $config);
$t = time();
- $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t));
- $test = now();
- $this->assertEquals($expected, $test);
+ $this->assertEquals(
+ mktime(gmdate('H', $t), gmdate('i', $t), gmdate('s', $t), gmdate('m', $t), gmdate('d', $t), gmdate('Y', $t)),
+ now()
+ );
}
// ------------------------------------------------------------------------
public function test_mdate()
{
- $time = time();
- $expected = date("Y-m-d - h:i a", $time);
- $test = mdate("%Y-%m-%d - %h:%i %a", $time);
- $this->assertEquals($expected, $test);
+ $this->assertEquals(
+ date('Y-m-d - h:i a', $this->time),
+ mdate('%Y-%m-%d - %h:%i %a', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_rfc822()
{
- $time = time();
- $format = 'DATE_RFC822';
- $expected = date("D, d M y H:i:s O", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date('D, d M y H:i:s O', $this->time),
+ standard_date('DATE_RFC822', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_atom()
{
- $time = time();
- $format = 'DATE_ATOM';
- $expected = date("Y-m-d\TH:i:sO", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date("Y-m-d\TH:i:sO", $this->time),
+ standard_date('DATE_ATOM', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_cookie()
{
- $time = time();
- $format = 'DATE_COOKIE';
- $expected = date("l, d-M-y H:i:s \U\T\C", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date("l, d-M-y H:i:s \U\T\C", $this->time),
+ standard_date('DATE_COOKIE', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_iso8601()
{
- $time = time();
- $format = 'DATE_ISO8601';
- $expected = date("Y-m-d\TH:i:sO", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date("Y-m-d\TH:i:sO", $this->time),
+ standard_date('DATE_ISO8601', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_rfc850()
{
- $time = time();
- $format = 'DATE_RFC850';
- $expected = date("l, d-M-y H:i:s \U\T\C", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date("l, d-M-y H:i:s \U\T\C", $this->time),
+ standard_date('DATE_RFC850', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_rfc1036()
{
- $time = time();
- $format = 'DATE_RFC1036';
- $expected = date("D, d M y H:i:s O", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date('D, d M y H:i:s O', $this->time),
+ standard_date('DATE_RFC1036', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_rfc1123()
{
- $time = time();
- $format = 'DATE_RFC1123';
- $expected = date("D, d M Y H:i:s O", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date('D, d M Y H:i:s O', $this->time),
+ standard_date('DATE_RFC1123', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_rfc2822()
{
- $time = time();
- $format = 'DATE_RFC2822';
- $expected = date("D, d M Y H:i:s O", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date('D, d M Y H:i:s O', $this->time),
+ standard_date('DATE_RFC2822', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_rss()
{
- $time = time();
- $format = 'DATE_RSS';
- $expected = date("D, d M Y H:i:s O", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date('D, d M Y H:i:s O', $this->time),
+ standard_date('DATE_RSS', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_w3c()
{
- $time = time();
- $format = 'DATE_W3C';
- $expected = date("Y-m-d\TH:i:sO", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date("Y-m-d\TH:i:sO", $this->time),
+ standard_date('DATE_W3C', $this->time)
+ );
}
// ------------------------------------------------------------------------
@@ -183,39 +184,36 @@ class Date_helper_test extends CI_TestCase {
public function test_local_to_gmt()
{
- $t = time();
- $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t));
- $this->assertEquals($expected, local_to_gmt($t));
+ $this->assertEquals(
+ mktime(
+ gmdate('H', $this->time), gmdate('i', $this->time), gmdate('s', $this->time),
+ gmdate('m', $this->time), gmdate('d', $this->time), gmdate('Y', $this->time)
+ ),
+ local_to_gmt($this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_gmt_to_local()
{
- $timestamp = '1140153693';
- $timezone = 'UM8';
- $daylight_saving = TRUE;
-
- $this->assertEquals(1140128493, gmt_to_local($timestamp, $timezone, $daylight_saving));
+ $this->assertEquals(1140128493, gmt_to_local('1140153693', 'UM8', TRUE));
}
// ------------------------------------------------------------------------
public function test_mysql_to_unix()
{
- $time = time();
- $this->assertEquals($time,
- mysql_to_unix(date("Y-m-d H:i:s", $time)));
+ $this->assertEquals($this->time, mysql_to_unix(date('Y-m-d H:i:s', $this->time)));
}
// ------------------------------------------------------------------------
public function test_unix_to_human()
{
- $time = time();
- $this->assertEquals(date("Y-m-d h:i A", $time), unix_to_human($time));
- $this->assertEquals(date("Y-m-d h:i:s A", $time), unix_to_human($time, TRUE, 'us'));
- $this->assertEquals(date("Y-m-d H:i:s", $time), unix_to_human($time, TRUE, 'eu'));
+ $this->assertEquals(date('Y-m-d h:i A', $this->time), unix_to_human($this->time));
+ $this->assertEquals(date('Y-m-d h:i:s A', $this->time), unix_to_human($this->time, TRUE, 'us'));
+ $this->assertEquals(date('Y-m-d H:i:s', $this->time), unix_to_human($this->time, TRUE, 'eu'));
}
// ------------------------------------------------------------------------
@@ -223,8 +221,7 @@ class Date_helper_test extends CI_TestCase {
public function test_human_to_unix()
{
$date = '2000-12-31 10:00:00 PM';
- $expected = strtotime($date);
- $this->assertEquals($expected, human_to_unix($date));
+ $this->assertEquals(strtotime($date), human_to_unix($date));
$this->assertFalse(human_to_unix());
}
@@ -283,6 +280,7 @@ class Date_helper_test extends CI_TestCase {
$this->assertArrayHasKey('UP3', timezones());
$this->assertEquals(0, timezones('non_existant'));
}
+
}
/* End of file date_helper_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php
index 3937d2913..176ff1d78 100644
--- a/tests/codeigniter/helpers/directory_helper_test.php
+++ b/tests/codeigniter/helpers/directory_helper_test.php
@@ -1,41 +1,50 @@
<?php
class Directory_helper_test extends CI_TestCase {
-
+
public function set_up()
{
$this->helper('directory');
vfsStreamWrapper::register();
vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir'));
-
+
$this->_test_dir = vfsStreamWrapper::getRoot();
- }
-
+ }
+
public function test_directory_map()
{
- $structure = array('libraries' => array('benchmark.html' => '', 'database' =>
- array('active_record.html' => '', 'binds.html' => ''), 'email.html' => '', '.hiddenfile.txt' => ''));
-
+ $structure = array(
+ 'libraries' => array(
+ 'benchmark.html' => '',
+ 'database' => array('active_record.html' => '', 'binds.html' => ''),
+ 'email.html' => '',
+ '.hiddenfile.txt' => ''
+ )
+ );
+
vfsStream::create($structure, $this->_test_dir);
// test default recursive behavior
- $expected = array('libraries' => array('benchmark.html', 'database' =>
- array('active_record.html', 'binds.html'), 'email.html'));
-
- $this->assertEquals($expected, directory_map(vfsStream::url('testDir')));
+ $expected = array(
+ 'libraries' => array(
+ 'benchmark.html',
+ 'database' => array('active_record.html', 'binds.html'),
+ 'email.html'
+ )
+ );
- // test recursion depth behavior
- $expected = array('libraries');
-
- $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), 1));
+ $this->assertEquals($expected, directory_map(vfsStream::url('testDir')));
// test detection of hidden files
- $expected = array('libraries' => array('benchmark.html', 'database' =>
- array('active_record.html', 'binds.html'), 'email.html', '.hiddenfile.txt'));
-
+ $expected['libraries'][] = '.hiddenfile.txt';
+
$this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE));
- }
+
+ // test recursion depth behavior
+ $this->assertEquals(array('libraries'), directory_map(vfsStream::url('testDir'), 1));
+ }
+
}
/* End of file directory_helper_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php
index a01f3d5af..fea452f5f 100644
--- a/tests/codeigniter/helpers/email_helper_test.php
+++ b/tests/codeigniter/helpers/email_helper_test.php
@@ -14,5 +14,5 @@ class Email_helper_test extends CI_TestCase {
$this->assertEquals(TRUE, valid_email('test@test.com'));
$this->assertEquals(TRUE, valid_email('my.test@test.com'));
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php
index 4b9c29485..9b03da9d7 100644
--- a/tests/codeigniter/helpers/file_helper_test.php
+++ b/tests/codeigniter/helpers/file_helper_test.php
@@ -5,24 +5,23 @@ class File_helper_Test extends CI_TestCase {
public function set_up()
{
$this->helper('file');
-
+
vfsStreamWrapper::register();
vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir'));
-
+
$this->_test_dir = vfsStreamWrapper::getRoot();
}
-
+
// --------------------------------------------------------------------
-
+
public function test_read_file()
{
$this->assertFalse(read_file('does_not_exist'));
-
+
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
-
- $file = vfsStream::newFile('my_file.txt')->withContent($content)
- ->at($this->_test_dir);
-
+
+ $file = vfsStream::newFile('my_file.txt')->withContent($content)->at($this->_test_dir);
+
$this->assertEquals($content, read_file(vfsStream::url('my_file.txt')));
}
@@ -31,126 +30,124 @@ class File_helper_Test extends CI_TestCase {
public function test_octal_permissions()
{
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
-
+
$file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
- ->lastModified(time() - 86400)
- ->at($this->_test_dir);
-
- $this->assertEquals('777', octal_permissions($file->getPermissions()));
+ ->lastModified(time() - 86400)
+ ->at($this->_test_dir);
+
+ $this->assertEquals('777', octal_permissions($file->getPermissions()));
}
- // --------------------------------------------------------------------
-
+ // --------------------------------------------------------------------
+
/**
* More tests should happen here, since I'm not hitting the whole function.
*/
public function test_symbolic_permissions()
{
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
-
+
$file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
- ->lastModified(time() - 86400)
- ->at($this->_test_dir);
-
- $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions()));
+ ->lastModified(time() - 86400)
+ ->at($this->_test_dir);
+
+ $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions()));
}
- // --------------------------------------------------------------------
-
+ // --------------------------------------------------------------------
+
public function test_get_mime_by_extension()
{
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
-
+
$file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
- ->lastModified(time() - 86400)
- ->at($this->_test_dir);
-
- $this->assertEquals('text/plain',
- get_mime_by_extension(vfsStream::url('my_file.txt')));
-
- // Test a mime with an array, such as png
+ ->lastModified(time() - 86400)
+ ->at($this->_test_dir);
+
+ $this->assertEquals('text/plain', get_mime_by_extension(vfsStream::url('my_file.txt')));
+
+ // Test a mime with an array, such as png
$file = vfsStream::newFile('foo.png')->at($this->_test_dir);
-
- $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png')));
-
+
+ $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png')));
+
// Test a file not in the mimes array
$file = vfsStream::newFile('foo.blarfengar')->at($this->_test_dir);
-
+
$this->assertFalse(get_mime_by_extension(vfsStream::url('foo.blarfengar')));
}
- // --------------------------------------------------------------------
+ // --------------------------------------------------------------------
public function test_get_file_info()
{
// Test Bad File
$this->assertFalse(get_file_info('i_am_bad_boo'));
-
+
// Test the rest
-
+
// First pass in an array
$vals = array(
'name', 'server_path', 'size', 'date',
- 'readable', 'writable', 'executable', 'fileperms'
+ 'readable', 'writable', 'executable', 'fileperms'
);
-
+
$this->_test_get_file_info($vals);
// Test passing in vals as a string.
- $vals = 'name, server_path, size, date, readable, writable, executable, fileperms';
- $this->_test_get_file_info($vals);
+ $this->_test_get_file_info(implode(', ', $vals));
}
-
+
private function _test_get_file_info($vals)
{
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
$last_modified = time() - 86400;
-
+
$file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
- ->lastModified($last_modified)
- ->at($this->_test_dir);
-
+ ->lastModified($last_modified)
+ ->at($this->_test_dir);
+
$ret_values = array(
- 'name' => 'my_file.txt',
- 'server_path' => 'vfs://my_file.txt',
- 'size' => 57,
- 'date' => $last_modified,
+ 'name' => 'my_file.txt',
+ 'server_path' => 'vfs://my_file.txt',
+ 'size' => 57,
+ 'date' => $last_modified,
'readable' => TRUE,
- 'writable' => TRUE,
- 'executable' => TRUE,
+ 'writable' => TRUE,
+ 'executable' => TRUE,
'fileperms' => 33279
);
-
+
$info = get_file_info(vfsStream::url('my_file.txt'), $vals);
-
+
foreach ($info as $k => $v)
{
$this->assertEquals($ret_values[$k], $v);
}
}
-
- // --------------------------------------------------------------------
+
+ // --------------------------------------------------------------------
// Skipping for now, as it's not implemented in vfsStreamWrapper
// flock(): vfsStreamWrapper::stream_lock is not implemented!
-
+
// public function test_write_file()
// {
- // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE'))
- // {
- // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb');
- // }
- //
- // $content = 'Jack and Jill went up the mountain to fight a billy goat.';
- //
- // $file = vfsStream::newFile('write.txt', 0777)->withContent('')
- // ->lastModified(time() - 86400)
- // ->at($this->_test_dir);
- //
- // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content));
- //
+ // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE'))
+ // {
+ // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb');
+ // }
+ //
+ // $content = 'Jack and Jill went up the mountain to fight a billy goat.';
+ //
+ // $file = vfsStream::newFile('write.txt', 0777)->withContent('')
+ // ->lastModified(time() - 86400)
+ // ->at($this->_test_dir);
+ //
+ // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content));
+ //
// }
- // --------------------------------------------------------------------
-
+ // --------------------------------------------------------------------
+
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php
index 80bace9d1..1a30ed993 100644
--- a/tests/codeigniter/helpers/form_helper_test.php
+++ b/tests/codeigniter/helpers/form_helper_test.php
@@ -3,26 +3,26 @@
require BASEPATH . 'core/Common.php';
require BASEPATH . 'helpers/form_helper.php';
-class Form_helper_test extends CI_TestCase
+class Form_helper_test extends CI_TestCase
{
public function test_form_hidden()
- {
+ {
$expected = <<<EOH
<input type="hidden" name="username" value="johndoe" />
EOH;
-
+
$this->assertEquals($expected, form_hidden('username', 'johndoe'));
}
-
+
public function test_form_input()
{
$expected = <<<EOH
<input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%" />
EOH;
-
+
$data = array(
'name' => 'username',
'id' => 'username',
@@ -34,37 +34,37 @@ EOH;
$this->assertEquals($expected, form_input($data));
}
-
+
public function test_form_password()
- {
+ {
$expected = <<<EOH
<input type="password" name="password" value="" />
EOH;
-
+
$this->assertEquals($expected, form_password('password'));
}
-
+
public function test_form_upload()
- {
+ {
$expected = <<<EOH
<input type="file" name="attachment" value="" />
EOH;
-
+
$this->assertEquals($expected, form_upload('attachment'));
}
-
+
public function test_form_textarea()
- {
+ {
$expected = <<<EOH
<textarea name="notes" cols="40" rows="10" >Notes</textarea>
EOH;
-
+
$this->assertEquals($expected, form_textarea('notes', 'Notes'));
}
-
+
public function test_form_dropdown()
{
$expected = <<<EOH
@@ -76,16 +76,16 @@ EOH;
</select>
EOH;
-
+
$options = array(
- 'small' => 'Small Shirt',
- 'med' => 'Medium Shirt',
- 'large' => 'Large Shirt',
- 'xlarge' => 'Extra Large Shirt',
+ 'small' => 'Small Shirt',
+ 'med' => 'Medium Shirt',
+ 'large' => 'Large Shirt',
+ 'xlarge' => 'Extra Large Shirt',
);
-
+
$this->assertEquals($expected, form_dropdown('shirts', $options, 'large'));
-
+
$expected = <<<EOH
<select name="shirts" multiple="multiple">
<option value="small" selected="selected">Small Shirt</option>
@@ -95,22 +95,22 @@ EOH;
</select>
EOH;
-
+
$shirts_on_sale = array('small', 'large');
-
+
$this->assertEquals($expected, form_dropdown('shirts', $options, $shirts_on_sale));
-
+
$options = array(
'Swedish Cars' => array(
- 'volvo' => 'Volvo',
- 'saab' => 'Saab'
+ 'volvo' => 'Volvo',
+ 'saab' => 'Saab'
),
'German Cars' => array(
- 'mercedes' => 'Mercedes',
- 'audi' => 'Audi'
+ 'mercedes' => 'Mercedes',
+ 'audi' => 'Audi'
)
);
-
+
$expected = <<<EOH
<select name="cars" multiple="multiple">
<optgroup label="Swedish Cars">
@@ -124,13 +124,10 @@ EOH;
</select>
EOH;
-
- $cars_on_sale = array('volvo', 'audi');
-
- $this->assertEquals($expected, form_dropdown('cars', $options, $cars_on_sale));
-
+
+ $this->assertEquals($expected, form_dropdown('cars', $options, array('volvo', 'audi')));
}
-
+
public function test_form_multiselect()
{
$expected = <<<EOH
@@ -142,17 +139,17 @@ EOH;
</select>
EOH;
-
+
$options = array(
- 'small' => 'Small Shirt',
- 'med' => 'Medium Shirt',
- 'large' => 'Large Shirt',
- 'xlarge' => 'Extra Large Shirt',
- );
-
+ 'small' => 'Small Shirt',
+ 'med' => 'Medium Shirt',
+ 'large' => 'Large Shirt',
+ 'xlarge' => 'Extra Large Shirt',
+ );
+
$this->assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large')));
}
-
+
public function test_form_fieldset()
{
$expected = <<<EOH
@@ -160,7 +157,7 @@ EOH;
<legend>Address Information</legend>
EOH;
-
+
$this->assertEquals($expected, form_fieldset('Address Information'));
}
@@ -169,10 +166,10 @@ EOH;
$expected = <<<EOH
</fieldset></div></div>
EOH;
-
+
$this->assertEquals($expected, form_fieldset_close('</div></div>'));
}
-
+
public function test_form_checkbox()
{
$expected = <<<EOH
@@ -182,7 +179,7 @@ EOH;
$this->assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE));
}
-
+
public function test_form_radio()
{
$expected = <<<EOH
@@ -192,7 +189,7 @@ EOH;
$this->assertEquals($expected, form_radio('newsletter', 'accept', TRUE));
}
-
+
public function test_form_submit()
{
$expected = <<<EOH
@@ -202,7 +199,7 @@ EOH;
$this->assertEquals($expected, form_submit('mysubmit', 'Submit Post!'));
}
-
+
public function test_form_label()
{
$expected = <<<EOH
@@ -211,7 +208,7 @@ EOH;
$this->assertEquals($expected, form_label('What is your Name', 'username'));
}
-
+
public function test_form_reset()
{
$expected = <<<EOH
@@ -221,7 +218,7 @@ EOH;
$this->assertEquals($expected, form_reset('myreset', 'Reset'));
}
-
+
public function test_form_button()
{
$expected = <<<EOH
@@ -229,9 +226,9 @@ EOH;
EOH;
- $this->assertEquals($expected, form_button('name','content'));
+ $this->assertEquals($expected, form_button('name', 'content'));
}
-
+
public function test_form_close()
{
$expected = <<<EOH
@@ -240,13 +237,14 @@ EOH;
$this->assertEquals($expected, form_close('</div></div>'));
}
-
+
public function test_form_prep()
{
- $expected = "Here is a string containing &quot;quoted&quot; text.";
-
+ $expected = 'Here is a string containing &quot;quoted&quot; text.';
+
$this->assertEquals($expected, form_prep('Here is a string containing "quoted" text.'));
}
+
}
/* End of file form_helper_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php
index 28974b0f8..9a7bb48bf 100644
--- a/tests/codeigniter/helpers/html_helper_test.php
+++ b/tests/codeigniter/helpers/html_helper_test.php
@@ -6,16 +6,16 @@ class Html_helper_test extends CI_TestCase {
{
$this->helper('html');
}
-
+
// ------------------------------------------------------------------------
-
+
public function test_br()
{
$this->assertEquals('<br /><br />', br(2));
}
-
+
// ------------------------------------------------------------------------
-
+
public function test_heading()
{
$this->assertEquals('<h1>foobar</h1>', heading('foobar'));
@@ -23,7 +23,7 @@ class Html_helper_test extends CI_TestCase {
}
// ------------------------------------------------------------------------
-
+
public function test_Ul()
{
$expect = <<<EOH
@@ -35,11 +35,9 @@ class Html_helper_test extends CI_TestCase {
EOH;
$expect = ltrim($expect);
-
$list = array('foo', 'bar');
-
- $this->assertEquals($expect, ul($list));
+ $this->assertEquals(ltrim($expect), ul($list));
$expect = <<<EOH
<ul class="test">
@@ -51,13 +49,11 @@ EOH;
$expect = ltrim($expect);
- $list = array('foo', 'bar');
-
$this->assertEquals($expect, ul($list, 'class="test"'));
$this->assertEquals($expect, ul($list, array('class' => 'test')));
}
-
+
// ------------------------------------------------------------------------
public function test_NBS()
@@ -66,15 +62,15 @@ EOH;
}
// ------------------------------------------------------------------------
-
+
public function test_meta()
{
$this->assertEquals("<meta name=\"test\" content=\"foo\" />\n", meta('test', 'foo'));
-
+
$expect = "<meta name=\"foo\" content=\"\" />\n";
-
+
$this->assertEquals($expect, meta(array('name' => 'foo')));
-
+
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php
index 9e9478711..f3b0ebbe8 100644
--- a/tests/codeigniter/helpers/inflector_helper_test.php
+++ b/tests/codeigniter/helpers/inflector_helper_test.php
@@ -1,12 +1,12 @@
<?php
class Inflector_helper_test extends CI_TestCase {
-
+
public function set_up()
{
$this->helper('inflector');
}
-
+
public function test_singular()
{
$strs = array(
@@ -16,15 +16,15 @@ class Inflector_helper_test extends CI_TestCase {
'smells' => 'smell',
'equipment' => 'equipment'
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, singular($str));
}
}
-
+
// --------------------------------------------------------------------
-
+
public function test_plural()
{
$strs = array(
@@ -35,15 +35,15 @@ class Inflector_helper_test extends CI_TestCase {
'witch' => 'witches',
'equipment' => 'equipment'
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, plural($str));
- }
- }
+ }
+ }
// --------------------------------------------------------------------
-
+
public function test_camelize()
{
$strs = array(
@@ -52,15 +52,15 @@ class Inflector_helper_test extends CI_TestCase {
'i-am-playing-a-trick' => 'i-am-playing-a-trick',
'what_do_you_think-yo?' => 'whatDoYouThink-yo?',
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, camelize($str));
}
- }
+ }
// --------------------------------------------------------------------
-
+
public function test_underscore()
{
$strs = array(
@@ -69,7 +69,7 @@ class Inflector_helper_test extends CI_TestCase {
'i-am-playing-a-trick' => 'i-am-playing-a-trick',
'what_do_you_think-yo?' => 'what_do_you_think-yo?',
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, underscore($str));
@@ -77,7 +77,7 @@ class Inflector_helper_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_humanize()
{
$strs = array(
@@ -86,10 +86,11 @@ class Inflector_helper_test extends CI_TestCase {
'i-am-playing-a-trick' => 'I-am-playing-a-trick',
'what_do_you_think-yo?' => 'What Do You Think-yo?',
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, humanize($str));
}
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php
index 4bb9a918a..ef6aae138 100644
--- a/tests/codeigniter/helpers/number_helper_test.php
+++ b/tests/codeigniter/helpers/number_helper_test.php
@@ -1,35 +1,35 @@
<?php
class Number_helper_test extends CI_TestCase {
-
+
public function set_up()
{
$this->helper('number');
-
+
// Grab the core lang class
$lang_cls = $this->ci_core_class('lang');
-
+
// Mock away load, too much going on in there,
// we'll just check for the expected parameter
-
+
$lang = $this->getMock($lang_cls, array('load'));
$lang->expects($this->once())
->method('load')
->with($this->equalTo('number'));
-
+
// Assign the proper language array
-
+
$lang->language = $this->_get_lang('number');
-
+
// We don't have a controller, so just create
// a cheap class to act as our super object.
// Make sure it has a lang attribute.
-
- $obj = new StdClass;
+
+ $obj = new stdClass;
$obj->lang = $lang;
$this->ci_instance($obj);
}
-
+
// Quick helper to actually grab the language
// file. Consider moving this to ci_testcase?
public function _get_lang($name)
@@ -37,41 +37,40 @@ class Number_helper_test extends CI_TestCase {
require BASEPATH.'language/english/'.$name.'_lang.php';
return $lang;
}
-
+
public function test_byte_format()
{
$this->assertEquals('456 Bytes', byte_format(456));
}
-
+
public function test_kb_format()
{
$this->assertEquals('4.5 KB', byte_format(4567));
}
-
+
public function test_kb_format_medium()
{
$this->assertEquals('44.6 KB', byte_format(45678));
}
-
+
public function test_kb_format_large()
{
$this->assertEquals('446.1 KB', byte_format(456789));
}
-
+
public function test_mb_format()
{
$this->assertEquals('3.3 MB', byte_format(3456789));
}
-
+
public function test_gb_format()
{
$this->assertEquals('1.8 GB', byte_format(1932735283.2));
}
-
+
public function test_tb_format()
{
$this->assertEquals('112,283.3 TB', byte_format(123456789123456789));
}
-}
-// EOF \ No newline at end of file
+} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php
index 632f57501..0faf6f383 100644
--- a/tests/codeigniter/helpers/path_helper_test.php
+++ b/tests/codeigniter/helpers/path_helper_test.php
@@ -8,9 +8,8 @@ class Path_helper_test extends CI_TestCase {
}
public function test_set_realpath()
- {
- $expected = getcwd() . DIRECTORY_SEPARATOR;
- $this->assertEquals($expected, set_realpath(getcwd()));
+ {
+ $this->assertEquals(getcwd().DIRECTORY_SEPARATOR, set_realpath(getcwd()));
}
public function test_set_realpath_nonexistent_directory()
diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php
index 29c3d6594..75701ec13 100644
--- a/tests/codeigniter/helpers/string_helper_test.php
+++ b/tests/codeigniter/helpers/string_helper_test.php
@@ -10,18 +10,18 @@ class String_helper_test extends CI_TestCase {
public function test_strip_slashes()
{
$expected = array(
- "Is your name O'reilly?",
+ "Is your name O'reilly?",
"No, my name is O'connor."
);
-
+
$str = array(
"Is your name O\'reilly?",
"No, my name is O\'connor."
);
-
+
$this->assertEquals($expected, strip_slashes($str));
}
-
+
public function test_trim_slashes()
{
$strs = array(
@@ -144,4 +144,5 @@ class String_helper_test extends CI_TestCase {
$this->assertEquals('file-1', increment_string('file', '-', '1'));
$this->assertEquals(124, increment_string('123', ''));
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php
index 73e2b9429..f131469cb 100644
--- a/tests/codeigniter/helpers/text_helper_test.php
+++ b/tests/codeigniter/helpers/text_helper_test.php
@@ -3,16 +3,16 @@
class Text_helper_test extends CI_TestCase {
private $_long_string;
-
+
public function set_up()
{
$this->helper('text');
-
+
$this->_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.';
}
-
+
// ------------------------------------------------------------------------
-
+
public function test_word_limiter()
{
$this->assertEquals('Once upon a time,&#8230;', word_limiter($this->_long_string, 4));
@@ -20,8 +20,8 @@ class Text_helper_test extends CI_TestCase {
$this->assertEquals('', word_limiter('', 4));
}
- // ------------------------------------------------------------------------
-
+ // ------------------------------------------------------------------------
+
public function test_character_limiter()
{
$this->assertEquals('Once upon a time, a&#8230;', character_limiter($this->_long_string, 20));
@@ -30,22 +30,22 @@ class Text_helper_test extends CI_TestCase {
$this->assertEquals('Short', character_limiter('Short', 5));
}
- // ------------------------------------------------------------------------
-
+ // ------------------------------------------------------------------------
+
public function test_ascii_to_entities()
{
$strs = array(
'“‘ “test”' => '&#8220;&#8216; &#8220;test&#8221;',
'†¥¨ˆøåß∂ƒ©˙∆˚¬' => '&#8224;&#165;&#168;&#710;&#248;&#229;&#223;&#8706;&#402;&#169;&#729;&#8710;&#730;&#172;'
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, ascii_to_entities($str));
}
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
public function test_entities_to_ascii()
{
@@ -53,27 +53,27 @@ class Text_helper_test extends CI_TestCase {
'&#8220;&#8216; &#8220;test&#8221;' => '“‘ “test”',
'&#8224;&#165;&#168;&#710;&#248;&#229;&#223;&#8706;&#402;&#169;&#729;&#8710;&#730;&#172;' => '†¥¨ˆøåß∂ƒ©˙∆˚¬'
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, entities_to_ascii($str));
- }
+ }
}
-
- // ------------------------------------------------------------------------
-
- function test_convert_accented_characters()
+
+ // ------------------------------------------------------------------------
+
+ public function test_convert_accented_characters()
{
$this->assertEquals('AAAeEEEIIOOEUUUeY', convert_accented_characters('ÀÂÄÈÊËÎÏÔŒÙÛÜŸ'));
$this->assertEquals('a e i o u n ue', convert_accented_characters('á é í ó ú ñ ü'));
}
- // ------------------------------------------------------------------------
-
+ // ------------------------------------------------------------------------
+
public function test_censored_words()
{
$censored = array('boob', 'nerd', 'ass', 'fart');
-
+
$strs = array(
'Ted bobbled the ball' => 'Ted bobbled the ball',
'Jake is a nerdo' => 'Jake is a nerdo',
@@ -81,28 +81,26 @@ class Text_helper_test extends CI_TestCase {
'Did Mary Fart?' => 'Did Mary $*#?',
'Jake is really a boob' => 'Jake is really a $*#'
);
-
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, word_censor($str, $censored, '$*#'));
}
-
+
// test censored words being sent as a string
$this->assertEquals('test', word_censor('test', 'test'));
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
public function test_highlight_code()
{
- $code = '<?php var_dump($this); ?>';
$expect = "<code><span style=\"color: #000000\">\n<span style=\"color: #0000BB\">&lt;?php&nbsp;var_dump</span><span style=\"color: #007700\">(</span><span style=\"color: #0000BB\">\$this</span><span style=\"color: #007700\">);&nbsp;</span><span style=\"color: #0000BB\">?&gt;&nbsp;</span>\n</span>\n</code>";
- $this->assertEquals($expect, highlight_code($code));
+ $this->assertEquals($expect, highlight_code('<?php var_dump($this); ?>'));
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
public function test_highlight_phrase()
{
@@ -113,14 +111,14 @@ class Text_helper_test extends CI_TestCase {
'Or tell me what this is' => 'Or tell me what <strong>this is</strong>',
'' => ''
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, highlight_phrase($str, 'this is'));
}
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
public function test_ellipsize()
{
@@ -144,32 +142,30 @@ class Text_helper_test extends CI_TestCase {
'short' => 'short'
),
);
-
+
foreach ($strs as $pos => $s)
{
foreach ($s as $str => $expect)
{
- $this->assertEquals($expect, ellipsize($str, 10, $pos));
+ $this->assertEquals($expect, ellipsize($str, 10, $pos));
}
}
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
public function test_word_wrap()
{
- $string = "Here is a simple string of text that will help us demonstrate this function.";
- $word_wrapped = word_wrap($string, 25);
- $this->assertEquals(substr_count($word_wrapped, "\n"), 4);
+ $string = 'Here is a simple string of text that will help us demonstrate this function.';
+ $this->assertEquals(substr_count(word_wrap($string, 25), "\n"), 4);
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
public function test_default_word_wrap_charlim()
{
$string = "Here is a longer string of text that will help us demonstrate the default charlim of this function.";
- $word_wrapped = word_wrap($string);
- $this->assertEquals(strpos($word_wrapped, "\n"), 73);
+ $this->assertEquals(strpos(word_wrap($string), "\n"), 73);
}
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php
index c561809ce..c81c5f1b8 100644
--- a/tests/codeigniter/helpers/url_helper_test.php
+++ b/tests/codeigniter/helpers/url_helper_test.php
@@ -72,4 +72,5 @@ class Url_helper_test extends CI_TestCase {
$this->assertEquals($out, auto_link($in, 'url'));
}
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/xml_helper_test.php b/tests/codeigniter/helpers/xml_helper_test.php
index a83fef91e..e8cf411da 100644
--- a/tests/codeigniter/helpers/xml_helper_test.php
+++ b/tests/codeigniter/helpers/xml_helper_test.php
@@ -6,10 +6,10 @@ class Xml_helper_test extends CI_TestCase {
{
$this->helper('xml');
}
-
+
public function test_xml_convert()
{
$this->assertEquals('&lt;tag&gt;my &amp; test &#45; &lt;/tag&gt;', xml_convert('<tag>my & test - </tag>'));
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php
index 066990186..153a25e1d 100644
--- a/tests/codeigniter/libraries/Encrypt_test.php
+++ b/tests/codeigniter/libraries/Encrypt_test.php
@@ -2,70 +2,71 @@
class Encrypt_test extends CI_TestCase {
- public function set_up()
- {
- $obj = new StdClass;
- $obj->encrypt = new Mock_Libraries_Encrypt();
-
- $this->ci_instance($obj);
- $this->encrypt = $obj->encrypt;
-
- $this->ci_set_config('encryption_key', "Encryptin'glike@boss!");
- $this->msg = 'My secret message';
- }
-
- // --------------------------------------------------------------------
-
- public function test_encode()
- {
- $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg));
- }
-
- // --------------------------------------------------------------------
-
- public function test_decode()
- {
- $encoded_msg = $this->encrypt->encode($this->msg);
- $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg));
- }
-
- // --------------------------------------------------------------------
-
- public function test_optional_key()
- {
- $key = 'Ohai!ù0129°03182%HD1892P0';
- $encoded_msg = $this->encrypt->encode($this->msg, $key);
- $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key));
- }
-
- // --------------------------------------------------------------------
-
- public function test_default_cipher()
- {
- $this->assertEquals('rijndael-256', $this->encrypt->get_cipher());
- }
-
- // --------------------------------------------------------------------
-
- public function test_set_cipher()
- {
- $this->encrypt->set_cipher(MCRYPT_BLOWFISH);
- $this->assertEquals('blowfish', $this->encrypt->get_cipher());
- }
-
- // --------------------------------------------------------------------
-
- public function test_default_mode()
- {
- $this->assertEquals('cbc', $this->encrypt->get_mode());
- }
-
- // --------------------------------------------------------------------
-
- public function test_set_mode()
- {
- $this->encrypt->set_mode(MCRYPT_MODE_CFB);
- $this->assertEquals('cfb', $this->encrypt->get_mode());
- }
+ public function set_up()
+ {
+ $obj = new stdClass;
+ $obj->encrypt = new Mock_Libraries_Encrypt();
+
+ $this->ci_instance($obj);
+ $this->encrypt = $obj->encrypt;
+
+ $this->ci_set_config('encryption_key', "Encryptin'glike@boss!");
+ $this->msg = 'My secret message';
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_encode()
+ {
+ $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_decode()
+ {
+ $encoded_msg = $this->encrypt->encode($this->msg);
+ $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_optional_key()
+ {
+ $key = 'Ohai!ù0129°03182%HD1892P0';
+ $encoded_msg = $this->encrypt->encode($this->msg, $key);
+ $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_default_cipher()
+ {
+ $this->assertEquals('rijndael-256', $this->encrypt->get_cipher());
+ }
+
+ // --------------------------------------------------------------------
+
+
+ public function test_set_cipher()
+ {
+ $this->encrypt->set_cipher(MCRYPT_BLOWFISH);
+ $this->assertEquals('blowfish', $this->encrypt->get_cipher());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_default_mode()
+ {
+ $this->assertEquals('cbc', $this->encrypt->get_mode());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_set_mode()
+ {
+ $this->encrypt->set_mode(MCRYPT_MODE_CFB);
+ $this->assertEquals('cfb', $this->encrypt->get_mode());
+ }
} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php
index c3d88fa85..b68f44a33 100644
--- a/tests/codeigniter/libraries/Parser_test.php
+++ b/tests/codeigniter/libraries/Parser_test.php
@@ -1,73 +1,74 @@
<?php
class Parser_test extends CI_TestCase {
-
+
public function set_up()
{
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->parser = new Mock_Libraries_Parser();
-
+
$this->ci_instance($obj);
-
+
$this->parser = $obj->parser;
}
+
// --------------------------------------------------------------------
-
+
public function test_set_delimiters()
{
// Make sure default delimiters are there
$this->assertEquals('{', $this->parser->l_delim);
$this->assertEquals('}', $this->parser->r_delim);
-
+
// Change them to square brackets
$this->parser->set_delimiters('[', ']');
-
+
// Make sure they changed
$this->assertEquals('[', $this->parser->l_delim);
$this->assertEquals(']', $this->parser->r_delim);
-
+
// Reset them
$this->parser->set_delimiters();
-
+
// Make sure default delimiters are there
$this->assertEquals('{', $this->parser->l_delim);
$this->assertEquals('}', $this->parser->r_delim);
}
-
+
// --------------------------------------------------------------------
-
+
public function test_parse_simple_string()
{
$data = array(
'title' => 'Page Title',
'body' => 'Lorem ipsum dolor sit amet.'
);
-
+
$template = "{title}\n{body}";
-
+
$result = implode("\n", $data);
-
+
$this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
}
-
+
// --------------------------------------------------------------------
-
+
public function test_parse()
{
$this->_parse_no_template();
$this->_parse_var_pair();
$this->_mismatched_var_pair();
}
-
+
// --------------------------------------------------------------------
-
+
private function _parse_no_template()
{
$this->assertFalse($this->parser->parse_string('', '', TRUE));
}
-
+
// --------------------------------------------------------------------
-
+
private function _parse_var_pair()
{
$data = array(
@@ -78,16 +79,14 @@ class Parser_test extends CI_TestCase {
'flying' => 'no'),
)
);
-
+
$template = "{title}\n{powers}{invisibility}\n{flying}{/powers}";
-
- $result = "Super Heroes\nyes\nno";
-
- $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
+
+ $this->assertEquals("Super Heroes\nyes\nno", $this->parser->parse_string($template, $data, TRUE));
}
-
+
// --------------------------------------------------------------------
-
+
private function _mismatched_var_pair()
{
$data = array(
@@ -98,13 +97,11 @@ class Parser_test extends CI_TestCase {
'flying' => 'no'),
)
);
-
+
$template = "{title}\n{powers}{invisibility}\n{flying}";
-
$result = "Super Heroes\n{powers}{invisibility}\n{flying}";
-
- $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
+
+ $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
}
- // --------------------------------------------------------------------
} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php
index f5133de1e..edfc83dd0 100644
--- a/tests/codeigniter/libraries/Table_test.php
+++ b/tests/codeigniter/libraries/Table_test.php
@@ -4,43 +4,39 @@ class Table_test extends CI_TestCase {
public function set_up()
{
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->table = new Mock_Libraries_Table();
-
+
$this->ci_instance($obj);
-
+
$this->table = $obj->table;
}
-
// Setter Methods
// --------------------------------------------------------------------
-
+
public function test_set_template()
{
$this->assertFalse($this->table->set_template('not an array'));
-
- $template = array(
- 'a' => 'b'
- );
-
+
+ $template = array('a' => 'b');
+
$this->table->set_template($template);
$this->assertEquals($template, $this->table->template);
}
-
+
public function test_set_empty()
{
$this->table->set_empty('nada');
$this->assertEquals('nada', $this->table->empty_cells);
}
-
+
public function test_set_caption()
{
$this->table->set_caption('awesome cap');
$this->assertEquals('awesome cap', $this->table->caption);
}
-
-
+
/*
* @depends testPrepArgs
*/
@@ -49,9 +45,9 @@ class Table_test extends CI_TestCase {
// uses _prep_args internally, so we'll just do a quick
// check to verify that func_get_args and prep_args are
// being called.
-
+
$this->table->set_heading('name', 'color', 'size');
-
+
$this->assertEquals(
array(
array('data' => 'name'),
@@ -61,8 +57,7 @@ class Table_test extends CI_TestCase {
$this->table->heading
);
}
-
-
+
/*
* @depends testPrepArgs
*/
@@ -71,13 +66,13 @@ class Table_test extends CI_TestCase {
// uses _prep_args internally, so we'll just do a quick
// check to verify that func_get_args and prep_args are
// being called.
-
+
$this->table->add_row('my', 'pony', 'sings');
$this->table->add_row('your', 'pony', 'stinks');
$this->table->add_row('my pony', '>', 'your pony');
-
+
$this->assertEquals(count($this->table->rows), 3);
-
+
$this->assertEquals(
array(
array('data' => 'your'),
@@ -87,11 +82,10 @@ class Table_test extends CI_TestCase {
$this->table->rows[1]
);
}
-
-
+
// Uility Methods
// --------------------------------------------------------------------
-
+
public function test_prep_args()
{
$expected = array(
@@ -99,7 +93,7 @@ class Table_test extends CI_TestCase {
array('data' => 'color'),
array('data' => 'size')
);
-
+
$this->assertEquals(
$expected,
$this->table->prep_args(array('name', 'color', 'size'))
@@ -114,7 +108,7 @@ class Table_test extends CI_TestCase {
$this->table->prep_args(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome')))
);
}
-
+
public function test_default_template_keys()
{
$keys = array(
@@ -126,132 +120,124 @@ class Table_test extends CI_TestCase {
'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end',
'table_close'
);
-
+
foreach ($keys as $key)
{
$this->assertArrayHasKey($key, $this->table->default_template());
}
}
-
+
public function test_compile_template()
{
$this->assertFalse($this->table->set_template('invalid_junk'));
-
+
// non default key
$this->table->set_template(array('nonsense' => 'foo'));
$this->table->compile_template();
-
+
$this->assertArrayHasKey('nonsense', $this->table->template);
$this->assertEquals('foo', $this->table->template['nonsense']);
-
+
// override default
$this->table->set_template(array('table_close' => '</table junk>'));
$this->table->compile_template();
-
+
$this->assertArrayHasKey('table_close', $this->table->template);
$this->assertEquals('</table junk>', $this->table->template['table_close']);
}
-
+
public function test_make_columns()
{
// Test bogus parameters
$this->assertFalse($this->table->make_columns('invalid_junk'));
$this->assertFalse($this->table->make_columns(array()));
$this->assertFalse($this->table->make_columns(array('one', 'two'), '2.5'));
-
-
+
// Now on to the actual column creation
-
+
$five_values = array(
'Laura', 'Red', '15',
'Katie', 'Blue'
);
-
+
// No column count - no changes to the array
$this->assertEquals(
$five_values,
$this->table->make_columns($five_values)
);
-
+
// Column count of 3 leaves us with one &nbsp;
$this->assertEquals(
array(
array('Laura', 'Red', '15'),
- array('Katie', 'Blue', '&nbsp;')
+ array('Katie', 'Blue', '&nbsp;')
),
$this->table->make_columns($five_values, 3)
);
}
-
+
public function test_clear()
{
$this->table->set_heading('Name', 'Color', 'Size');
-
+
// Make columns changes auto_heading
$rows = $this->table->make_columns(array(
'Laura', 'Red', '15',
'Katie', 'Blue'
), 3);
-
+
foreach ($rows as $row)
{
$this->table->add_row($row);
}
-
+
$this->assertFalse($this->table->auto_heading);
$this->assertEquals(count($this->table->heading), 3);
$this->assertEquals(count($this->table->rows), 2);
-
+
$this->table->clear();
-
+
$this->assertTrue($this->table->auto_heading);
$this->assertEmpty($this->table->heading);
$this->assertEmpty($this->table->rows);
}
-
-
+
public function test_set_from_array()
{
$this->assertFalse($this->table->set_from_array('bogus'));
$this->assertFalse($this->table->set_from_array(NULL));
-
+
$data = array(
array('name', 'color', 'number'),
array('Laura', 'Red', '22'),
- array('Katie', 'Blue')
+ array('Katie', 'Blue')
);
-
+
$this->table->set_from_array($data, FALSE);
$this->assertEmpty($this->table->heading);
-
+
$this->table->clear();
-
- $expected_heading = array(
+
+ $this->table->set_from_array($data);
+ $this->assertEquals(count($this->table->rows), 2);
+
+ $expected = array(
array('data' => 'name'),
array('data' => 'color'),
array('data' => 'number')
);
-
- $expected_second = array(
+
+ $this->assertEquals($expected, $this->table->heading);
+
+ $expected = array(
array('data' => 'Katie'),
array('data' => 'Blue'),
);
-
- $this->table->set_from_array($data);
- $this->assertEquals(count($this->table->rows), 2);
-
- $this->assertEquals(
- $expected_heading,
- $this->table->heading
- );
-
- $this->assertEquals(
- $expected_second,
- $this->table->rows[1]
- );
+
+ $this->assertEquals($expected, $this->table->rows[1]);
}
-
- function test_set_from_object()
+
+ public function test_set_from_object()
{
// Make a stub of query instance
$query = new CI_TestCase();
@@ -268,37 +254,31 @@ class Table_test extends CI_TestCase {
return 2;
};
- $expected_heading = array(
+ $this->table->set_from_object($query);
+
+ $expected = array(
array('data' => 'name'),
array('data' => 'email')
);
- $expected_second = array(
+ $this->assertEquals($expected, $this->table->heading);
+
+ $expected = array(
'name' => array('data' => 'Foo Bar'),
'email' => array('data' => 'foo@bar.com'),
);
- $this->table->set_from_object($query);
-
- $this->assertEquals(
- $expected_heading,
- $this->table->heading
- );
-
- $this->assertEquals(
- $expected_second,
- $this->table->rows[1]
- );
+ $this->assertEquals($expected, $this->table->rows[1]);
}
-
- function test_generate()
+
+ public function test_generate()
{
// Prepare the data
$data = array(
array('Name', 'Color', 'Size'),
array('Fred', 'Blue', 'Small'),
array('Mary', 'Red', 'Large'),
- array('John', 'Green', 'Medium')
+ array('John', 'Green', 'Medium')
);
$table = $this->table->generate($data);
@@ -313,4 +293,5 @@ class Table_test extends CI_TestCase {
$this->assertTrue(strpos($table, '<td>Blue</td>') !== FALSE);
$this->assertTrue(strpos($table, '<td>Small</td>') !== FALSE);
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php
index 250aefb24..eb6dacb73 100644
--- a/tests/codeigniter/libraries/Typography_test.php
+++ b/tests/codeigniter/libraries/Typography_test.php
@@ -4,11 +4,11 @@ class Typography_test extends CI_TestCase {
public function set_up()
{
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->type = new Mock_Libraries_Typography();
-
+
$this->ci_instance($obj);
-
+
$this->type = $obj->type;
}
@@ -33,18 +33,18 @@ class Typography_test extends CI_TestCase {
'foo..' => 'foo..',
'foo...bar.' => 'foo&#8230;bar.',
'test. new' => 'test.&nbsp; new',
- );
-
+ );
+
foreach ($strs as $str => $expected)
{
- $this->assertEquals($expected, $this->type->format_characters($str));
+ $this->assertEquals($expected, $this->type->format_characters($str));
}
}
// --------------------------------------------------------------------
public function test_nl2br_except_pre()
- {
+ {
$str = <<<EOH
Hello, I'm a happy string with some new lines.
@@ -85,12 +85,11 @@ That's my story and I'm sticking to it.<br />
The End.
EOH;
- $this->assertEquals($expected,
- $this->type->nl2br_except_pre($str));
+ $this->assertEquals($expected, $this->type->nl2br_except_pre($str));
}
// --------------------------------------------------------------------
-
+
public function test_auto_typography()
{
$this->_blank_string();
@@ -103,7 +102,7 @@ EOH;
}
// --------------------------------------------------------------------
-
+
private function _blank_string()
{
// Test blank string
@@ -131,7 +130,7 @@ EOH;
{
$str = "This has way too many linebreaks.\n\n\n\nSee?";
$expect = "<p>This has way too many linebreaks.</p>\n\n<p>See?</p>";
-
+
$this->assertEquals($expect, $this->type->auto_typography($str, TRUE));
}
@@ -141,7 +140,7 @@ EOH;
{
$str = '<!-- I can haz comments? --> But no!';
$expect = '<p><!-- I can haz comments? -->&nbsp; But no!</p>';
-
+
$this->assertEquals($expect, $this->type->auto_typography($str));
}
@@ -151,7 +150,7 @@ EOH;
{
$str = '<p>My Sentence</p><pre>var_dump($this);</pre>';
$expect = '<p>My Sentence</p><pre>var_dump($this);</pre>';
-
+
$this->assertEquals($expect, $this->type->auto_typography($str));
}
@@ -161,7 +160,7 @@ EOH;
{
$str = 'My Sentence<pre>var_dump($this);</pre>';
$expect = '<p>My Sentence</p><pre>var_dump($this);</pre>';
-
+
$this->assertEquals($expect, $this->type->auto_typography($str));
}
@@ -170,19 +169,18 @@ EOH;
public function _protect_braced_quotes()
{
$this->type->protect_braced_quotes = TRUE;
-
+
$str = 'Test {parse="foobar"}';
$expect = '<p>Test {parse="foobar"}</p>';
-
+
$this->assertEquals($expect, $this->type->auto_typography($str));
$this->type->protect_braced_quotes = FALSE;
-
+
$str = 'Test {parse="foobar"}';
$expect = '<p>Test {parse=&#8220;foobar&#8221;}</p>';
-
- $this->assertEquals($expect, $this->type->auto_typography($str));
-
+ $this->assertEquals($expect, $this->type->auto_typography($str));
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Useragent_test.php b/tests/codeigniter/libraries/Useragent_test.php
index 7dad7ac54..89383f807 100644
--- a/tests/codeigniter/libraries/Useragent_test.php
+++ b/tests/codeigniter/libraries/Useragent_test.php
@@ -1,7 +1,7 @@
<?php
class UserAgent_test extends CI_TestCase {
-
+
protected $_user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27';
protected $_mobile_ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7';
@@ -10,7 +10,7 @@ class UserAgent_test extends CI_TestCase {
// set a baseline user agent
$_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->agent = new Mock_Libraries_UserAgent();
$this->ci_instance($obj);
@@ -82,6 +82,4 @@ class UserAgent_test extends CI_TestCase {
$this->assertFalse($this->agent->accept_charset());
}
- // --------------------------------------------------------------------
-
} \ No newline at end of file
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
index 90aabcbe6..e3ff7a8bd 100644
--- a/tests/mocks/autoloader.php
+++ b/tests/mocks/autoloader.php
@@ -69,7 +69,7 @@ function autoload($class)
}
}
- $file = (isset($file)) ? $file : $dir.$class.'.php';
+ $file = isset($file) ? $file : $dir.$class.'.php';
if ( ! file_exists($file))
{
@@ -82,7 +82,7 @@ function autoload($class)
return FALSE;
}
- throw new InvalidArgumentException("Unable to load $class.");
+ throw new InvalidArgumentException("Unable to load {$class}.");
}
include_once($file);
diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php
index f327e6b07..eda9e1b60 100644
--- a/tests/mocks/ci_testcase.php
+++ b/tests/mocks/ci_testcase.php
@@ -1,11 +1,11 @@
<?php
class CI_TestCase extends PHPUnit_Framework_TestCase {
-
+
protected $ci_config;
protected $ci_instance;
protected static $ci_test_instance;
-
+
private $global_map = array(
'benchmark' => 'bm',
'config' => 'cfg',
@@ -19,18 +19,17 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
'loader' => 'load',
'model' => 'model'
);
-
+
// --------------------------------------------------------------------
-
+
public function __construct()
{
parent::__construct();
-
$this->ci_config = array();
}
-
+
// --------------------------------------------------------------------
-
+
public function setUp()
{
if (method_exists($this, 'set_up'))
@@ -38,10 +37,10 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
$this->set_up();
}
}
-
+
// --------------------------------------------------------------------
-
- public function tearDown()
+
+ public function tearDown()
{
if (method_exists($this, 'tear_down'))
{
@@ -50,15 +49,15 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
}
// --------------------------------------------------------------------
-
+
public static function instance()
{
return self::$ci_test_instance;
}
-
+
// --------------------------------------------------------------------
-
- function ci_set_config($key, $val = '')
+
+ public function ci_set_config($key, $val = '')
{
if (is_array($key))
{
@@ -71,36 +70,36 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
}
// --------------------------------------------------------------------
-
- function ci_get_config()
+
+ public function ci_get_config()
{
return $this->ci_config;
}
-
+
// --------------------------------------------------------------------
-
- function ci_instance($obj = FALSE)
+
+ public function ci_instance($obj = FALSE)
{
if ( ! is_object($obj))
{
return $this->ci_instance;
}
-
+
$this->ci_instance = $obj;
}
-
+
// --------------------------------------------------------------------
-
- function ci_instance_var($name, $obj = FALSE)
+
+ public function ci_instance_var($name, $obj = FALSE)
{
if ( ! is_object($obj))
{
return $this->ci_instance->$name;
}
-
+
$this->ci_instance->$name =& $obj;
}
-
+
// --------------------------------------------------------------------
/**
@@ -112,10 +111,10 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
* test can modify the variable it assigns to and
* still maintain the global.
*/
- function &ci_core_class($name)
+ public function &ci_core_class($name)
{
$name = strtolower($name);
-
+
if (isset($this->global_map[$name]))
{
$class_name = ucfirst($name);
@@ -130,29 +129,29 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
{
throw new Exception('Not a valid core class.');
}
-
+
if ( ! class_exists('CI_'.$class_name))
{
require_once BASEPATH.'core/'.$class_name.'.php';
}
-
+
$GLOBALS[strtoupper($global_name)] = 'CI_'.$class_name;
return $GLOBALS[strtoupper($global_name)];
}
-
+
// --------------------------------------------------------------------
-
+
// convenience function for global mocks
- function ci_set_core_class($name, $obj)
+ public function ci_set_core_class($name, $obj)
{
$orig =& $this->ci_core_class($name);
$orig = $obj;
}
-
+
// --------------------------------------------------------------------
// Internals
// --------------------------------------------------------------------
-
+
/**
* Overwrite runBare
*
@@ -169,28 +168,27 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
}
// --------------------------------------------------------------------
-
- function helper($name)
+
+ public function helper($name)
{
require_once(BASEPATH.'helpers/'.$name.'_helper.php');
}
// --------------------------------------------------------------------
-
+
/**
* This overload is useful to create a stub, that need to have a specific method.
*/
- function __call($method, $args)
+ public function __call($method, $args)
{
- if ($this->{$method} instanceof Closure)
+ if ($this->{$method} instanceof Closure)
{
return call_user_func_array($this->{$method},$args);
- }
- else
+ }
+ else
{
return parent::__call($method, $args);
}
}
-}
-// EOF \ No newline at end of file
+} \ No newline at end of file
diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php
index e1c493aa0..a655ee1db 100644
--- a/tests/mocks/core/common.php
+++ b/tests/mocks/core/common.php
@@ -4,11 +4,11 @@
if ( ! function_exists('get_instance'))
{
- function &get_instance()
+ function &get_instance()
{
$test = CI_TestCase::instance();
- $instance = $test->ci_instance();
- return $instance;
+ $test = $test->ci_instance();
+ return $test;
}
}
@@ -16,10 +16,10 @@ if ( ! function_exists('get_instance'))
if ( ! function_exists('get_config'))
{
- function &get_config() {
+ function &get_config()
+ {
$test = CI_TestCase::instance();
$config = $test->ci_get_config();
-
return $config;
}
}
@@ -29,12 +29,12 @@ if ( ! function_exists('config_item'))
function config_item($item)
{
$config =& get_config();
-
+
if ( ! isset($config[$item]))
{
return FALSE;
}
-
+
return $config[$item];
}
}
@@ -49,16 +49,16 @@ if ( ! function_exists('load_class'))
{
throw new Exception('Not Implemented: Non-core load_class()');
}
-
+
$test = CI_TestCase::instance();
-
+
$obj =& $test->ci_core_class($class);
-
+
if (is_string($obj))
{
- throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class.'');
+ throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class);
}
-
+
return $obj;
}
}
@@ -74,16 +74,16 @@ if ( ! function_exists('remove_invisible_characters'))
function remove_invisible_characters($str, $url_encoded = TRUE)
{
$non_displayables = array();
-
+
// every control character except newline (dec 10)
// carriage return (dec 13), and horizontal tab (dec 09)
-
+
if ($url_encoded)
{
$non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15
$non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31
}
-
+
$non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
do
@@ -166,6 +166,4 @@ if ( ! function_exists('set_status_header'))
{
return TRUE;
}
-}
-
-// EOF \ No newline at end of file
+} \ No newline at end of file
diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php
index 8a337d2ef..2a4aa4997 100644
--- a/tests/mocks/core/input.php
+++ b/tests/mocks/core/input.php
@@ -1,10 +1,10 @@
<?php
class Mock_Core_Input extends CI_Input {
-
+
/**
- * Since we use GLOBAL to fetch Security and Utf8 classes,
- * we need to use inversion of control to mock up
+ * Since we use GLOBAL to fetch Security and Utf8 classes,
+ * we need to use inversion of control to mock up
* the same process within CI_Input class constructor.
*
* @covers CI_Input::__construct()
diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php
index d4b29bb3d..53d88d55b 100644
--- a/tests/mocks/core/loader.php
+++ b/tests/mocks/core/loader.php
@@ -1,7 +1,7 @@
<?php
class Mock_Core_Loader extends CI_Loader {
-
+
/**
* Since we use paths to load up models, views, etc, we need the ability to
* mock up the file system so when core tests are run, we aren't mucking
@@ -15,16 +15,17 @@ class Mock_Core_Loader extends CI_Loader {
{
vfsStreamWrapper::register();
vfsStreamWrapper::setRoot(new vfsStreamDirectory('application'));
-
+
$this->models_dir = vfsStream::newDirectory('models')->at(vfsStreamWrapper::getRoot());
$this->libs_dir = vfsStream::newDirectory('libraries')->at(vfsStreamWrapper::getRoot());
$this->helpers_dir = vfsStream::newDirectory('helpers')->at(vfsStreamWrapper::getRoot());
$this->views_dir = vfsStream::newDirectory('views')->at(vfsStreamWrapper::getRoot());
-
+
$this->_ci_ob_level = ob_get_level();
$this->_ci_library_paths = array(vfsStream::url('application').'/', BASEPATH);
$this->_ci_helper_paths = array(vfsStream::url('application').'/', BASEPATH);
$this->_ci_model_paths = array(vfsStream::url('application').'/');
$this->_ci_view_paths = array(vfsStream::url('application').'/views/' => TRUE);
}
+
} \ No newline at end of file
diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php
index d7ea0e6bd..e19a8b20b 100644
--- a/tests/mocks/core/security.php
+++ b/tests/mocks/core/security.php
@@ -1,7 +1,7 @@
<?php
class Mock_Core_Security extends CI_Security {
-
+
public function csrf_set_cookie()
{
// We cannot set cookie in CLI mode, so for csrf test, who rely on $_COOKIE,
diff --git a/tests/mocks/core/uri.php b/tests/mocks/core/uri.php
index b6946091e..94f75df64 100644
--- a/tests/mocks/core/uri.php
+++ b/tests/mocks/core/uri.php
@@ -1,12 +1,12 @@
<?php
class Mock_Core_URI extends CI_URI {
-
+
public function __construct()
{
$test = CI_TestCase::instance();
$cls =& $test->ci_core_class('cfg');
-
+
// set predictable config values
$test->ci_set_config(array(
'index_page' => 'index.php',
@@ -14,12 +14,13 @@ class Mock_Core_URI extends CI_URI {
'subclass_prefix' => 'MY_'
));
- $this->config = new $cls;
+ $this->config = new $cls;
}
-
+
protected function _is_cli_request()
{
return FALSE;
}
+
} \ No newline at end of file
diff --git a/tests/mocks/core/utf8.php b/tests/mocks/core/utf8.php
index b77d717e7..068e74ac1 100644
--- a/tests/mocks/core/utf8.php
+++ b/tests/mocks/core/utf8.php
@@ -1,27 +1,26 @@
<?php
class Mock_Core_Utf8 extends CI_Utf8 {
-
+
/**
- * We need to define several constants as
+ * We need to define several constants as
* the same process within CI_Utf8 class constructor.
*
* @covers CI_Utf8::__construct()
*/
public function __construct()
{
- defined('UTF8_ENABLED') or define('UTF8_ENABLED', TRUE);
+ defined('UTF8_ENABLED') OR define('UTF8_ENABLED', TRUE);
if (extension_loaded('mbstring'))
{
- defined('MB_ENABLED') or define('MB_ENABLED', TRUE);
+ defined('MB_ENABLED') OR define('MB_ENABLED', TRUE);
mb_internal_encoding('UTF-8');
}
else
{
- defined('MB_ENABLED') or define('MB_ENABLED', FALSE);
+ defined('MB_ENABLED') OR define('MB_ENABLED', FALSE);
}
-
}
} \ No newline at end of file
diff --git a/tests/mocks/database/config/mysql.php b/tests/mocks/database/config/mysql.php
index ace0a31b1..a590b9f53 100644
--- a/tests/mocks/database/config/mysql.php
+++ b/tests/mocks/database/config/mysql.php
@@ -1,7 +1,7 @@
<?php
return array(
-
+
// Typical Database configuration
'mysql' => array(
'dsn' => '',
@@ -9,7 +9,7 @@ return array(
'username' => 'travis',
'password' => '',
'database' => 'ci_test',
- 'dbdriver' => 'mysql',
+ 'dbdriver' => 'mysql'
),
// Database configuration with failover
@@ -28,7 +28,7 @@ return array(
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'mysql',
- ),
- ),
- ),
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/mysql.php b/tests/mocks/database/config/pdo/mysql.php
index cefb6b008..fefe0d624 100644
--- a/tests/mocks/database/config/pdo/mysql.php
+++ b/tests/mocks/database/config/pdo/mysql.php
@@ -1,7 +1,7 @@
<?php
return array(
-
+
// Typical Database configuration
'pdo/mysql' => array(
'dsn' => '',
@@ -10,7 +10,7 @@ return array(
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'mysql',
+ 'pdodriver' => 'mysql'
),
// Database configuration with failover
@@ -30,8 +30,8 @@ return array(
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'mysql',
- ),
- ),
- ),
+ 'pdodriver' => 'mysql'
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/pgsql.php b/tests/mocks/database/config/pdo/pgsql.php
index 5196e9ad9..ddd638c8a 100644
--- a/tests/mocks/database/config/pdo/pgsql.php
+++ b/tests/mocks/database/config/pdo/pgsql.php
@@ -1,7 +1,7 @@
<?php
return array(
-
+
// Typical Database configuration
'pdo/pgsql' => array(
'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;',
@@ -10,7 +10,7 @@ return array(
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'pgsql',
+ 'pdodriver' => 'pgsql'
),
// Database configuration with failover
@@ -30,8 +30,8 @@ return array(
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'pgsql',
- ),
- ),
- ),
+ 'pdodriver' => 'pgsql'
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php
index c68b4b213..36461843d 100644
--- a/tests/mocks/database/config/pdo/sqlite.php
+++ b/tests/mocks/database/config/pdo/sqlite.php
@@ -10,7 +10,7 @@ return array(
'password' => 'sqlite',
'database' => 'sqlite',
'dbdriver' => 'pdo',
- 'pdodriver' => 'sqlite',
+ 'pdodriver' => 'sqlite'
),
// Database configuration with failover
@@ -29,9 +29,9 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => 'sqlite',
- 'dbdriver' => 'pdo',
- 'pdodriver' => 'sqlite',
- ),
- ),
- ),
+ 'dbdriver' => 'pdo',
+ 'pdodriver' => 'sqlite'
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/config/pgsql.php b/tests/mocks/database/config/pgsql.php
index c06af8ce0..1444b0066 100644
--- a/tests/mocks/database/config/pgsql.php
+++ b/tests/mocks/database/config/pgsql.php
@@ -1,7 +1,7 @@
<?php
return array(
-
+
// Typical Database configuration
'pgsql' => array(
'dsn' => '',
@@ -9,7 +9,7 @@ return array(
'username' => 'postgres',
'password' => '',
'database' => 'ci_test',
- 'dbdriver' => 'postgre',
+ 'dbdriver' => 'postgre'
),
// Database configuration with failover
@@ -28,7 +28,7 @@ return array(
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'postgre',
- ),
- ),
- ),
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php
index 755ce2a3a..d37ee4871 100644
--- a/tests/mocks/database/config/sqlite.php
+++ b/tests/mocks/database/config/sqlite.php
@@ -9,7 +9,7 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
- 'dbdriver' => 'sqlite3',
+ 'dbdriver' => 'sqlite3'
),
// Database configuration with failover
@@ -27,8 +27,8 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
- 'dbdriver' => 'sqlite3',
- ),
- ),
- ),
+ 'dbdriver' => 'sqlite3'
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php
index 59028ed9c..30504bba6 100644
--- a/tests/mocks/database/db.php
+++ b/tests/mocks/database/db.php
@@ -6,7 +6,7 @@ class Mock_Database_DB {
* @var array DB configuration
*/
private $config = array();
-
+
/**
* Prepare database configuration skeleton
*
@@ -21,7 +21,7 @@ class Mock_Database_DB {
/**
* Build DSN connection string for DB driver instantiate process
*
- * @param string Group name
+ * @param string Group name
* @return string DSN Connection string
*/
public function set_dsn($group = 'default')
@@ -65,28 +65,27 @@ class Mock_Database_DB {
* Return a database config array
*
* @see ./config
- * @param string Driver based configuration
- * @return array
+ * @param string Driver based configuration
+ * @return array
*/
public static function config($driver)
{
$dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR;
-
return include($dir.'config'.DIRECTORY_SEPARATOR.$driver.'.php');
}
/**
* Main DB method wrapper
*
- * @param string Group or DSN string
- * @param bool
- * @return object
+ * @param string Group or DSN string
+ * @param bool
+ * @return object
*/
public static function DB($group, $query_builder = FALSE)
{
include_once(BASEPATH.'database/DB.php');
- try
+ try
{
$db = DB($group, $query_builder);
}
@@ -97,4 +96,5 @@ class Mock_Database_DB {
return $db;
}
+
} \ No newline at end of file
diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php
index cb1820277..65ac2c4cc 100644
--- a/tests/mocks/database/db/driver.php
+++ b/tests/mocks/database/db/driver.php
@@ -1,7 +1,7 @@
<?php
class Mock_Database_DB_Driver extends CI_DB_driver {
-
+
/**
* @var object The actual Driver
*/
@@ -16,7 +16,10 @@ class Mock_Database_DB_Driver extends CI_DB_driver {
*/
public function __construct($driver_class, $config = array())
{
- if (is_string($driver_class)) $this->ci_db_driver = new $driver_class($config);
+ if (is_string($driver_class))
+ {
+ $this->ci_db_driver = new $driver_class($config);
+ }
}
/**
diff --git a/tests/mocks/database/db/querybuilder.php b/tests/mocks/database/db/querybuilder.php
index 1b95c92af..3f2252622 100644
--- a/tests/mocks/database/db/querybuilder.php
+++ b/tests/mocks/database/db/querybuilder.php
@@ -1,10 +1,3 @@
<?php
-if ( ! class_exists('CI_DB_query_builder'))
-{
- class Mock_Database_DB_QueryBuilder extends CI_DB_active_record {}
-}
-else
-{
- class Mock_Database_DB_QueryBuilder extends CI_DB_query_builder {}
-}
+class Mock_Database_DB_QueryBuilder extends CI_DB_query_builder {} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/mysql.php b/tests/mocks/database/drivers/mysql.php
index 34a74e2bf..e0c1fb06c 100644
--- a/tests/mocks/database/drivers/mysql.php
+++ b/tests/mocks/database/drivers/mysql.php
@@ -1,16 +1,17 @@
<?php
class Mock_Database_Drivers_Mysql extends Mock_Database_DB_Driver {
-
+
/**
* Instantiate the database driver
*
- * @param string DB Driver class name
- * @param array DB configuration to set
- * @return void
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
*/
public function __construct($config = array())
{
parent::__construct('CI_DB_mysql_driver', $config);
}
+
} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/pdo.php b/tests/mocks/database/drivers/pdo.php
index 590e19552..17768eed7 100644
--- a/tests/mocks/database/drivers/pdo.php
+++ b/tests/mocks/database/drivers/pdo.php
@@ -1,13 +1,13 @@
<?php
class Mock_Database_Drivers_PDO extends Mock_Database_DB_Driver {
-
+
/**
* Instantiate the database driver
*
- * @param string DB Driver class name
- * @param array DB configuration to set
- * @return void
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
*/
public function __construct($config = array())
{
diff --git a/tests/mocks/database/drivers/postgre.php b/tests/mocks/database/drivers/postgre.php
index 0df905963..5a45115fa 100644
--- a/tests/mocks/database/drivers/postgre.php
+++ b/tests/mocks/database/drivers/postgre.php
@@ -1,16 +1,17 @@
<?php
class Mock_Database_Drivers_Postgre extends Mock_Database_DB_Driver {
-
+
/**
* Instantiate the database driver
*
- * @param string DB Driver class name
- * @param array DB configuration to set
- * @return void
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
*/
public function __construct($config = array())
{
parent::__construct('CI_DB_postgre_driver', $config);
}
+
} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/sqlite.php b/tests/mocks/database/drivers/sqlite.php
index 15cefbf53..512467520 100644
--- a/tests/mocks/database/drivers/sqlite.php
+++ b/tests/mocks/database/drivers/sqlite.php
@@ -5,12 +5,13 @@ class Mock_Database_Drivers_Sqlite extends Mock_Database_DB_Driver {
/**
* Instantiate the database driver
*
- * @param string DB Driver class name
- * @param array DB configuration to set
- * @return void
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
*/
public function __construct($config = array())
{
parent::__construct('CI_DB_sqlite3_driver', $config);
}
+
} \ No newline at end of file
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index 05499f82f..18e1ddd4d 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -41,8 +41,7 @@ class Mock_Database_Schema_Skeleton {
return static::$db;
}
-
-
+
/**
* Create the dummy tables
*
@@ -54,20 +53,20 @@ class Mock_Database_Schema_Skeleton {
static::$forge->add_field(array(
'id' => array(
'type' => 'INTEGER',
- 'constraint' => 3,
+ 'constraint' => 3
),
'name' => array(
'type' => 'VARCHAR',
- 'constraint' => 40,
+ 'constraint' => 40
),
'email' => array(
'type' => 'VARCHAR',
- 'constraint' => 100,
+ 'constraint' => 100
),
'country' => array(
'type' => 'VARCHAR',
- 'constraint' => 40,
- ),
+ 'constraint' => 40
+ )
));
static::$forge->add_key('id', TRUE);
static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE));
@@ -76,15 +75,15 @@ class Mock_Database_Schema_Skeleton {
static::$forge->add_field(array(
'id' => array(
'type' => 'INTEGER',
- 'constraint' => 3,
+ 'constraint' => 3
),
'name' => array(
'type' => 'VARCHAR',
- 'constraint' => 40,
+ 'constraint' => 40
),
'description' => array(
- 'type' => 'TEXT',
- ),
+ 'type' => 'TEXT'
+ )
));
static::$forge->add_key('id', TRUE);
static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE));
@@ -93,15 +92,15 @@ class Mock_Database_Schema_Skeleton {
static::$forge->add_field(array(
'id' => array(
'type' => 'INTEGER',
- 'constraint' => 3,
+ 'constraint' => 3
),
'key' => array(
'type' => 'VARCHAR',
- 'constraint' => 40,
+ 'constraint' => 40
),
'value' => array(
- 'type' => 'TEXT',
- ),
+ 'type' => 'TEXT'
+ )
));
static::$forge->add_key('id', TRUE);
static::$forge->create_table('misc', (strpos(static::$driver, 'pgsql') === FALSE));
@@ -120,28 +119,29 @@ class Mock_Database_Schema_Skeleton {
array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com', 'country' => 'US'),
array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com', 'country' => 'Iran'),
array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com', 'country' => 'US'),
- array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com', 'country' => 'UK'),
+ array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com', 'country' => 'UK')
),
'job' => array(
- array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'),
+ array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'),
array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'),
- array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'),
- array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician'),
+ array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'),
+ array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician')
),
'misc' => array(
- array('id' => 1, 'key' => '\\xxxfoo456', 'value' => 'Entry with \\xxx'),
- array('id' => 2, 'key' => '\\%foo456', 'value' => 'Entry with \\%'),
- ),
+ array('id' => 1, 'key' => '\\xxxfoo456', 'value' => 'Entry with \\xxx'),
+ array('id' => 2, 'key' => '\\%foo456', 'value' => 'Entry with \\%')
+ )
);
- foreach ($data as $table => $dummy_data)
+ foreach ($data as $table => $dummy_data)
{
static::$db->truncate($table);
foreach ($dummy_data as $single_dummy_data)
{
- static::$db->insert($table, $single_dummy_data);
+ static::$db->insert($table, $single_dummy_data);
}
}
}
+
} \ No newline at end of file
diff --git a/tests/mocks/libraries/encrypt.php b/tests/mocks/libraries/encrypt.php
index a9bbaafdc..f1859398f 100644
--- a/tests/mocks/libraries/encrypt.php
+++ b/tests/mocks/libraries/encrypt.php
@@ -2,14 +2,15 @@
class Mock_Libraries_Encrypt extends CI_Encrypt {
- // Overide inaccesible protected method
- public function __call($method, $params)
- {
- if (is_callable(array($this, '_'.$method)))
- {
- return call_user_func_array(array($this, '_'.$method), $params);
- }
-
- throw new BadMethodCallException('Method '.$method.' was not found');
- }
+ // Overide inaccesible protected method
+ public function __call($method, $params)
+ {
+ if (is_callable(array($this, '_'.$method)))
+ {
+ return call_user_func_array(array($this, '_'.$method), $params);
+ }
+
+ throw new BadMethodCallException('Method '.$method.' was not found');
+ }
+
} \ No newline at end of file
diff --git a/tests/mocks/libraries/table.php b/tests/mocks/libraries/table.php
index 97fbb30bd..87c278bce 100644
--- a/tests/mocks/libraries/table.php
+++ b/tests/mocks/libraries/table.php
@@ -1,7 +1,7 @@
<?php
class Mock_Libraries_Table extends CI_Table {
-
+
// Overide inaccesible protected method
public function __call($method, $params)
{
@@ -12,4 +12,5 @@ class Mock_Libraries_Table extends CI_Table {
throw new BadMethodCallException('Method '.$method.' was not found');
}
+
} \ No newline at end of file
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 80507b284..1f5bcb648 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -33,15 +33,18 @@ Release Date: Not Released
- Added support for ics Calendar files to mimes.php
- Updated support for xml ('application/xml') and xsl ('application/xml', 'text/xsl') files in mimes.php.
- Updated support for doc files in mimes.php.
+ - Added some more doctypes.
- Added Romanian and Greek characters in foreign_characters.php.
- Changed logger to only chmod when file is first created.
- Removed previously deprecated SHA1 Library.
- Removed previously deprecated use of ``$autoload['core']`` in application/config/autoload.php.
Only entries in ``$autoload['libraries']`` are auto-loaded now.
- - Added some more doctypes.
+ - Removed previously deprecated EXT constant.
- Updated all classes to be written in PHP 5 style, with visibility declarations and no ``var`` usage for properties.
- Moved error templates to "application/views/errors"
- - Global config files are loaded first, then environment ones. Environment config keys overwrite base ones, allowing to only set the keys we want changed per Env.
+ - Global config files are loaded first, then environment ones. Environment config keys overwrite base ones, allowing to only set the keys we want changed per environment.
+ - Changed detection of ``$view_folder`` so that if it's not found in the current path, it will now also be searched for under the application folder.
+ - Path constants BASEPATH, APPPATH and VIEWPATH are now (internally) defined as absolute paths.
- Helpers
@@ -64,14 +67,18 @@ Release Date: Not Released
- Database
- - Renamed the Active Record class to Query Builder to remove confusion with the Active Record design pattern.
- - Added the ability to insert objects with insert_batch() in :doc:`Query Builder <database/query_builder>`.
- - Added new :doc:`Query Builder <database/query_builder>` methods that return the SQL string of queries without executing them: get_compiled_select(), get_compiled_insert(), get_compiled_update(), get_compiled_delete().
- - Adding $escape parameter to the order_by() method, this enables ordering by custom fields.
+ - :doc:`Query Builder <database/query_builder>` changes include:
+ - Renamed the Active Record class to Query Builder to remove confusion with the Active Record design pattern.
+ - Added the ability to insert objects with insert_batch().
+ - Added new methods that return the SQL string of queries without executing them: get_compiled_select(), get_compiled_insert(), get_compiled_update(), get_compiled_delete().
+ - Added an optional order_by() parameter that allows to disable escaping (useful for custom fields).
+ - Added an optional join() parameter that allows to disable escaping.
+ - Added support for join() with multiple conditions.
- Improved support for the MySQLi driver, including:
- - OOP style of the PHP extension is now used, instead of the procedural aliases.
- - Server version checking is now done via ``mysqli::$server_info`` instead of running an SQL query.
- - Added persistent connections support for PHP >= 5.3.
+ - OOP style of the PHP extension is now used, instead of the procedural aliases.
+ - Server version checking is now done via ``mysqli::$server_info`` instead of running an SQL query.
+ - Added persistent connections support for PHP >= 5.3.
+ - Added support for backup() in :doc:`Database Utilities <database/utilities>`.
- Added 'dsn' configuration setting for drivers that support DSN strings (PDO, PostgreSQL, Oracle, ODBC, CUBRID).
- Improved PDO database support.
- Added Interbase/Firebird database support via the "interbase" driver.
@@ -79,14 +86,16 @@ Release Date: Not Released
- Replaced the _error_message() and _error_number() methods with error(), that returns an array containing the last database error code and message.
- Improved version() implementation so that drivers that have a native function to get the version number don't have to be defined in the core DB_driver class.
- Improved support of the PostgreSQL driver, including:
- - pg_version() is now used to get the database version number, when possible.
- - Added db_set_charset() support.
- - Added _optimize_table() support for the :doc:`Database Utility Class <database/utilities>` (rebuilds table indexes).
- - Added boolean data type support in escape().
- - Added update_batch() support.
- - Removed limit() and order_by() support for UPDATE and DELETE queries in as PostgreSQL does not support those features.
+ - pg_version() is now used to get the database version number, when possible.
+ - Added db_set_charset() support.
+ - Added support for optimize_table() in :doc:`Database Utilities <database/utilities>` (rebuilds table indexes).
+ - Added boolean data type support in escape().
+ - Added update_batch() support.
+ - Removed limit() and order_by() support for UPDATE and DELETE queries in as PostgreSQL does not support those features.
- Added a constructor to the DB_result class and moved all driver-specific properties and logic out of the base DB_driver class to allow better abstraction.
- Removed protect_identifiers() and renamed internal method _protect_identifiers() to it instead - it was just an alias.
+ - Renamed internal method _escape_identifiers() to escape_identifiers().
+ - Updated escape_identifiers() to accept an array of fields as well as strings.
- MySQL and MySQLi drivers now require at least MySQL version 5.1.
- db_set_charset() now only requires one parameter (collation was only needed due to legacy support for MySQL versions prior to 5.1).
- Added support for SQLite3 database driver.
@@ -99,18 +108,17 @@ Release Date: Not Released
- Added support for optimize_table() in :doc:`Database Utility <database/utilities>`.
- Added escaping with QUOTE_IDENTIFIER setting detection.
- Added port handling support for UNIX-based systems (MSSQL driver).
- - Added OFFSET support for SQL Server 2012 and above.
+ - Added OFFSET support for SQL Server 2005 and above.
- Improved support of the Oracle (OCI8) driver, including:
- - Added DSN string support (Easy Connect and TNS).
- - Added support for dropping tables to :doc:`Database Forge <database/forge>`.
- - Added support for listing database schemas to :doc:`Database Utilities <database/utilities>`.
- - Generally improved for speed and cleaned up all of its components.
- - *Row* result methods now really only fetch only the needed number of rows, instead of depending entirely on result().
- - num_rows() is now only called explicitly by the developer and no longer re-executes statements.
- - Added replace() support for SQLite.
- - Renamed internal method _escape_identifiers() to escape_identifiers().
- - Updated escape_identifiers() to accept an array of fields as well as strings.
- - Added SQLite support for drop_table() in :doc:`Database Forge <database/forge>`.
+ - Added DSN string support (Easy Connect and TNS).
+ - Added support for drop_table() in :doc:`Database Forge <database/forge>`.
+ - Added support for list_databases() in :doc:`Database Utilities <database/utilities>`.
+ - Generally improved for speed and cleaned up all of its components.
+ - *Row* result methods now really only fetch only the needed number of rows, instead of depending entirely on result().
+ - num_rows() is now only called explicitly by the developer and no longer re-executes statements.
+ - Improved support of the SQLite driver, including:
+ - Added support for replace() in :doc:`Query Builder <database/query_builder>`.
+ - Added support for drop_table() in :doc:`Database Forge <database/forge>`.
- Added ODBC support for create_database(), drop_database() and drop_table() in :doc:`Database Forge <database/forge>`.
- Added PDO support for create_database(), drop_database and drop_table() in :doc:`Database Forge <database/forge>`.
- Added unbuffered_row() method for getting a row without prefetching whole result (consume less memory).
@@ -140,13 +148,16 @@ Release Date: Not Released
- _execute() now considers input data to be invalid if a specified rule is not found.
- Removed method is_numeric() as it exists as a native PHP function and _execute() will find and use that (the 'is_numeric' rule itself is deprecated since 1.6.1).
- Native PHP functions used as rules can now accept an additional parameter, other than the data itself.
+ - Updated set_rules() to accept an array of rules as well as a string.
- Changed the :doc:`Session Library <libraries/sessions>` to select only one row when using database sessions.
- Added all_flashdata() method to session class. Returns an associative array of only flashdata.
- Allowed for setting table class defaults in a config file.
- Added a Wincache driver to the :doc:`Caching Library <libraries/caching>`.
+ - Added a Redis driver to the :doc:`Caching Library <libraries/caching>`.
- Added dsn (delivery status notification) option to the :doc:`Email Library <libraries/email>`.
- - Input library now supports IPv6.
- Renamed method _set_header() to set_header() and made it public to enable adding custom headers in the :doc:`Email Library <libraries/email>`.
+ - Added an "index" parameter to the data() method in the :doc:`Upload Library <libraries/file_uploading>`.
+ - Added support for the anchor "rel" attribute in the :doc:`Pagination Library <libraries/pagination>`.
- Core
@@ -169,7 +180,7 @@ Bug fixes for 3.0
- Fixed a bug where ``unlink()`` raised an error if cache file did not exist when you try to delete it.
- Fixed a bug (#181) where a mis-spelling was in the form validation language file.
- Fixed a bug (#159, #163) that mishandled Query Builder nested transactions because _trans_depth was not getting incremented.
-- Fixed a bug (#737, #75) where pagination anchor class was not set properly when using initialize method.
+- Fixed a bug (#737, #75) - :doc:`Pagination <libraries/pagination>` anchor class was not set properly when using initialize method.
- Fixed a bug (#419) - auto_link() now recognizes URLs that come after a word boundary.
- Fixed a bug (#724) - is_unique in form validation now checks that you are connected to a database.
- Fixed a bug (#647) - _get_mod_time() in Zip library no longer generates stat failed errors.
@@ -245,17 +256,31 @@ Bug fixes for 3.0
- Fixed a bug (#666) - :doc:`Output library <libraries/output>`'s set_content_type() method didn't set the document charset.
- Fixed a bug (#784, #861) - :doc:`Database Forge <database/forge>` method ``create_table()`` used to accept constraints for MSSQL/SQLSRV integer-type columns.
- Fixed a bug (#706) - SQLSRV/MSSSQL didn't escape field names.
+- Fixed a bug (#1452) - protect_identifiers() didn't properly detect identifiers with spaces in their names.
+- Fixed a bug where protect_identifiers() ignored it's extra arguments when the value passed to it is an array.
+- Fixed a bug where _has_operator() didn't detect BETWEEN.
+- Fixed a bug in :doc:`Query Builder <database/query_builder>`'s join() method where it failed with identifiers containing dashes.
+- Fixed a bug (#1264) - :doc:`Database Forge <database/forge>` and :doc:`Database Utilities <database/utilities>` didn't update/reset the databases and tables list cache when a table or a database is created, dropped or renamed.
+- Fixed a bug (#7) - :doc:`Query Builder <database/query_builder>`'s join() method only escaped one set of conditions.
+- Fixed a bug (#1321) - Core Exceptions class couldn't find the errors/ folder in some cases.
+- Fixed a bug in the File-based :doc:`Cache Library <libraries/caching>` driver's get_metadata() method where a non-existent array key was accessed for the TTL value.
+- Fixed a bug (#1202) - :doc:`Encryption Library <libraries/encryption>` encode_from_legacy() didn't set back the encrypt mode on failure.
+- Fixed a bug (#145) - compile_binds() failed when the bind marker was present in a literal string within the query.
+- Fixed a bug in protect_identifiers() where if passed along with the field names, operators got escaped as well.
+- Fixed a bug (#10) - :doc:`URI Library <libraries/uri>` internal method _detect_uri() failed with paths containing a colon.
Version 2.1.1
=============
-Release Date: Not Released
+Release Date: June 13, 2012
- General Changes
- Fixed support for docx, xlsx files in mimes.php.
- Libraries
- Further improved MIME type detection in the :doc:`File Uploading Library <libraries/file_uploading>`.
+ - Added support for IPv6 to the :doc:`Input Library <libraries/input>`.
+ - Added support for the IP format parameter to the :doc:`Form Validation Library <libraries/form_validation>`.
- Helpers
- url_title() performance and output improved. You can now use any string as the word delimiter, but 'dash' and 'underscore' are still supported.
@@ -270,6 +295,8 @@ Bug fixes for 2.1.1
- Fixed a bug - When database caching was enabled, $this->db->query() checked the cache before binding variables which resulted in cached queries never being found.
- Fixed a bug - CSRF cookie value was allowed to be any (non-empty) string before being written to the output, making code injection a risk.
- Fixed a bug (#726) - PDO put a 'dbname' argument in it's connection string regardless of the database platform in use, which made it impossible to use SQLite.
+- Fixed a bug - CI_DB_pdo_driver::num_rows() was not returning properly value with SELECT queries, cause it was relying on PDOStatement::rowCount().
+- Fixed a bug (#1059) - CI_Image_lib::clear() was not correctly clearing all necessary object properties, namely width and height.
Version 2.1.0
=============
diff --git a/user_guide_src/source/general/requirements.rst b/user_guide_src/source/general/requirements.rst
index d97b7b4b2..d9edfba6d 100644
--- a/user_guide_src/source/general/requirements.rst
+++ b/user_guide_src/source/general/requirements.rst
@@ -4,5 +4,6 @@ Server Requirements
- `PHP <http://www.php.net/>`_ version 5.2.4 or newer.
- A Database is required for most web application programming. Current
- supported databases are MySQL (5.1+), MySQLi, MS SQL, SQLSRV, Oracle,
- PostgreSQL, SQLite, SQLite3, CUBRID, Interbase, ODBC and PDO.
+ supported databases are MySQL (5.1+), MySQLi, Oracle, PostgreSQL,
+ MS SQL, SQLSRV (SQL Server 2005+), SQLite, SQLite3, CUBRID, Interbase,
+ ODBC and PDO.
diff --git a/user_guide_src/source/installation/upgrading.rst b/user_guide_src/source/installation/upgrading.rst
index 2badffc93..255c6a557 100644
--- a/user_guide_src/source/installation/upgrading.rst
+++ b/user_guide_src/source/installation/upgrading.rst
@@ -5,7 +5,8 @@ Upgrading From a Previous Version
Please read the upgrade notes corresponding to the version you are
upgrading from.
-- :doc:`Upgrading from 2.0.3 to 2.1.0 <upgrade_210>`
+- :doc:`Upgrading from 2.1.1 to 3.0.0 <upgrade_300>`
+- :doc:`Upgrading from 2.1.0 to 2.1.1 <upgrade_211>`
- :doc:`Upgrading from 2.0.2 to 2.0.3 <upgrade_203>`
- :doc:`Upgrading from 2.0.1 to 2.0.2 <upgrade_202>`
- :doc:`Upgrading from 2.0 to 2.0.1 <upgrade_201>`
diff --git a/user_guide_src/source/libraries/file_uploading.rst b/user_guide_src/source/libraries/file_uploading.rst
index d573fc770..414d84f0b 100644
--- a/user_guide_src/source/libraries/file_uploading.rst
+++ b/user_guide_src/source/libraries/file_uploading.rst
@@ -287,6 +287,10 @@ data related to the file you uploaded. Here is the array prototype::
[image_size_str] => width="800" height="200"
)
+To return one element from the array::
+
+ $this->upload->data('file_name'); // Returns: mypic.jpg
+
Explanation
***********
diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst
index 028b61c4c..3bcad7ba6 100644
--- a/user_guide_src/source/libraries/form_validation.rst
+++ b/user_guide_src/source/libraries/form_validation.rst
@@ -304,6 +304,10 @@ Give it a try! Submit your form without the proper data and you'll see
new error messages that correspond to your new rules. There are numerous
rules available which you can read about in the validation reference.
+.. note:: You can also pass an array of rules to set_rules(), instead of a string. Example::
+
+ $this->form_validation->set_rules('username', 'Username', array('required', 'min_length[5]'));
+
Prepping Data
=============
@@ -884,6 +888,7 @@ Rule Parameter Description
**valid_email** No Returns FALSE if the form element does not contain a valid email address.
**valid_emails** No Returns FALSE if any value provided in a comma separated list is not a valid email.
**valid_ip** No Returns FALSE if the supplied IP is not valid.
+ Accepts an optional parameter of 'ipv4' or 'ipv6' to specify an IP format.
**valid_base64** No Returns FALSE if the supplied string contains anything other than valid Base64 characters.
========================= ========== ============================================================================================= =======================
@@ -934,7 +939,7 @@ $this->form_validation->set_rules();
:param string $field: The field name
:param string $label: The field label
- :param string $rules: The rules, seperated by a pipe "|"
+ :param mixed $rules: The rules, as a string with rules separated by a pipe "|", or an array or rules.
:rtype: Object
Permits you to set validation rules, as described in the tutorial
diff --git a/user_guide_src/source/libraries/input.rst b/user_guide_src/source/libraries/input.rst
index 432bac3c7..c0b9c6589 100644
--- a/user_guide_src/source/libraries/input.rst
+++ b/user_guide_src/source/libraries/input.rst
@@ -42,14 +42,14 @@ this::
Please refer to the :doc:`Security class <security>` documentation for
information on using XSS Filtering in your application.
-Using POST, COOKIE, or SERVER Data
-==================================
+Using POST, GET, COOKIE, or SERVER Data
+=======================================
-CodeIgniter comes with three helper functions that let you fetch POST,
+CodeIgniter comes with four helper methods that let you fetch POST, GET,
COOKIE or SERVER items. The main advantage of using the provided
functions rather than fetching an item directly ($_POST['something'])
-is that the functions will check to see if the item is set and return
-false (boolean) if not. This lets you conveniently use data without
+is that the methods will check to see if the item is set and return
+NULL if not. This lets you conveniently use data without
having to test whether an item exists first. In other words, normally
you might do something like this::
@@ -59,9 +59,10 @@ With CodeIgniter's built in functions you can simply do this::
$something = $this->input->post('something');
-The three functions are:
+The four methods are:
- $this->input->post()
+- $this->input->get()
- $this->input->cookie()
- $this->input->server()
@@ -73,8 +74,8 @@ looking for::
$this->input->post('some_data');
-The function returns FALSE (boolean) if the item you are attempting to
-retrieve does not exist.
+The function returns NULL if the item you are attempting to retrieve
+does not exist.
The second optional parameter lets you run the data through the XSS
filter. It's enabled by setting the second parameter to boolean TRUE;
@@ -130,7 +131,9 @@ $this->input->cookie()
This function is identical to the post function, only it fetches cookie
data::
- $this->input->cookie('some_data', TRUE);
+ $this->input->cookie('some_cookie');
+ $this->input->cookie('some_cookie, TRUE); // with XSS filter
+
$this->input->server()
======================
@@ -195,25 +198,6 @@ parameters::
$this->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure);
-$this->input->cookie()
-======================
-
-Lets you fetch a cookie. The first parameter will contain the name of
-the cookie you are looking for (including any prefixes)::
-
- cookie('some_cookie');
-
-The function returns NULL if the item you are attempting to
-retrieve does not exist.
-
-The second optional parameter lets you run the data through the XSS
-filter. It's enabled by setting the second parameter to boolean TRUE;
-
-::
-
- cookie('some_cookie', TRUE);
-
-
$this->input->ip_address()
===========================
@@ -242,6 +226,9 @@ validates the IP automatically.
echo 'Valid';
}
+Accepts an optional second string parameter of 'ipv4' or 'ipv6' to specify
+an IP format. The default checks for both formats.
+
$this->input->user_agent()
===========================
diff --git a/user_guide_src/source/libraries/pagination.rst b/user_guide_src/source/libraries/pagination.rst
index f1653c913..560755fb6 100644
--- a/user_guide_src/source/libraries/pagination.rst
+++ b/user_guide_src/source/libraries/pagination.rst
@@ -254,3 +254,27 @@ Adding a class to every anchor
If you want to add a class attribute to every link rendered by the
pagination class, you can set the config "anchor_class" equal to the
classname you want.
+
+::
+
+ $config['anchor_class'] = 'myclass'; // class="myclass"
+
+**********************************
+Changing the "rel" attribute value
+**********************************
+
+By default, the rel attribute will be automatically put under the
+following conditions:
+
+- rel="start" for the "first" link
+- rel="prev" for the "previous" link
+- rel="next" for the "next" link
+
+If you want to disable the rel attribute, or change its value, you
+can set the 'attr_rel' config option::
+
+ // Disable
+ $config['attr_rel'] = FALSE;
+
+ // Use a custom value on all anchors
+ $config['attr_rel'] = 'custom_value'; // produces: rel="custom_value" \ No newline at end of file
diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst
index e8332ee97..5400524a9 100644
--- a/user_guide_src/source/libraries/sessions.rst
+++ b/user_guide_src/source/libraries/sessions.rst
@@ -245,7 +245,7 @@ session class::
CREATE TABLE IF NOT EXISTS `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
- ip_address varchar(16) DEFAULT '0' NOT NULL,
+ ip_address varchar(45) DEFAULT '0' NOT NULL,
user_agent varchar(120) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
diff --git a/user_guide_src/source/libraries/uri.rst b/user_guide_src/source/libraries/uri.rst
index cdd76e322..bb959b002 100644
--- a/user_guide_src/source/libraries/uri.rst
+++ b/user_guide_src/source/libraries/uri.rst
@@ -146,7 +146,7 @@ full URL::
The function would return this::
- /news/local/345
+ news/local/345
$this->uri->ruri_string()
==========================