From 6a96bf7ece4da23e2a802f48c408fa240da776f0 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 4 Apr 2012 19:13:03 +0700 Subject: Include PDO code coverage, remove unnecessary line on phpunit xml --- tests/travis/mysql.phpunit.xml | 5 ----- tests/travis/pdo/mysql.phpunit.xml | 32 ++++++++++++++++++++++++++++++++ tests/travis/pdo/pgsql.phpunit.xml | 32 ++++++++++++++++++++++++++++++++ tests/travis/pdo/sqlite.phpunit.xml | 32 ++++++++++++++++++++++++++++++++ tests/travis/pgsql.phpunit.xml | 5 ----- tests/travis/sqlite.phpunit.xml | 5 ----- 6 files changed, 96 insertions(+), 15 deletions(-) create mode 100644 tests/travis/pdo/mysql.phpunit.xml create mode 100644 tests/travis/pdo/pgsql.phpunit.xml create mode 100644 tests/travis/pdo/sqlite.phpunit.xml (limited to 'tests') diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml index 44d6d6ed9..e9556f758 100644 --- a/tests/travis/mysql.phpunit.xml +++ b/tests/travis/mysql.phpunit.xml @@ -28,10 +28,5 @@ PROJECT_BASE.'tests' '../../system/core/CodeIgniter.php' - - - \ No newline at end of file diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml new file mode 100644 index 000000000..eb650fa1e --- /dev/null +++ b/tests/travis/pdo/mysql.phpunit.xml @@ -0,0 +1,32 @@ + + + + + + + + + ../../codeigniter/Setup_test.php + ../../codeigniter/core + ../../codeigniter/helpers + ../../codeigniter/libraries + ../../codeigniter/database + + + + + PEAR_INSTALL_DIR + PHP_LIBDIR + PROJECT_BASE.'tests' + '../../../system/core/CodeIgniter.php' + + + \ No newline at end of file diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml new file mode 100644 index 000000000..351f690d5 --- /dev/null +++ b/tests/travis/pdo/pgsql.phpunit.xml @@ -0,0 +1,32 @@ + + + + + + + + + ../../codeigniter/Setup_test.php + ../../codeigniter/core + ../../codeigniter/helpers + ../../codeigniter/libraries + ../../codeigniter/database + + + + + PEAR_INSTALL_DIR + PHP_LIBDIR + PROJECT_BASE.'tests' + '../../../system/core/CodeIgniter.php' + + + \ No newline at end of file diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml new file mode 100644 index 000000000..ae139b7a9 --- /dev/null +++ b/tests/travis/pdo/sqlite.phpunit.xml @@ -0,0 +1,32 @@ + + + + + + + + + ../../codeigniter/Setup_test.php + ../../codeigniter/core + ../../codeigniter/helpers + ../../codeigniter/libraries + ../../codeigniter/database + + + + + PEAR_INSTALL_DIR + PHP_LIBDIR + PROJECT_BASE.'tests' + '../../../system/core/CodeIgniter.php' + + + \ No newline at end of file diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml index 9f52b40ae..ad8aeded2 100644 --- a/tests/travis/pgsql.phpunit.xml +++ b/tests/travis/pgsql.phpunit.xml @@ -28,10 +28,5 @@ PROJECT_BASE.'tests' '../../system/core/CodeIgniter.php' - - - \ No newline at end of file diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml index 74ebb482b..628370e93 100644 --- a/tests/travis/sqlite.phpunit.xml +++ b/tests/travis/sqlite.phpunit.xml @@ -28,10 +28,5 @@ PROJECT_BASE.'tests' '../../system/core/CodeIgniter.php' - - - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 44015c8d91ecea78ee4a10de579c36a859c2fcb6 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 4 Apr 2012 19:38:16 +0700 Subject: Set up PDO constant and configuration --- tests/mocks/database/config/pdo/mysql.php | 37 ++++++++++++++++++++++++++++++ tests/mocks/database/config/pdo/pgsql.php | 37 ++++++++++++++++++++++++++++++ tests/mocks/database/config/pdo/sqlite.php | 22 ++++++++++++++++++ tests/mocks/database/config/sqlite.php | 7 +++--- tests/travis/pdo/mysql.phpunit.xml | 2 +- tests/travis/pdo/pgsql.phpunit.xml | 2 +- tests/travis/pdo/sqlite.phpunit.xml | 2 +- 7 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 tests/mocks/database/config/pdo/mysql.php create mode 100644 tests/mocks/database/config/pdo/pgsql.php create mode 100644 tests/mocks/database/config/pdo/sqlite.php (limited to 'tests') diff --git a/tests/mocks/database/config/pdo/mysql.php b/tests/mocks/database/config/pdo/mysql.php new file mode 100644 index 000000000..cefb6b008 --- /dev/null +++ b/tests/mocks/database/config/pdo/mysql.php @@ -0,0 +1,37 @@ + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'travis', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'pdo', + 'pdodriver' => 'mysql', + ), + + // Database configuration with failover + 'pdo/mysql_failover' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'not_travis', + 'password' => 'wrong password', + 'database' => 'not_ci_test', + 'dbdriver' => 'pdo', + 'pdodriver' => 'mysql', + 'failover' => array( + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'travis', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'pdo', + '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 new file mode 100644 index 000000000..b2f409d8d --- /dev/null +++ b/tests/mocks/database/config/pdo/pgsql.php @@ -0,0 +1,37 @@ + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'postgres', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'pdo', + 'pdodriver' => 'pgsql', + ), + + // Database configuration with failover + 'pdo/pgsql_failover' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'not_travis', + 'password' => 'wrong password', + 'database' => 'not_ci_test', + 'dbdriver' => 'pdo', + 'pdodriver' => 'pgsql', + 'failover' => array( + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'postgres', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'pdo', + '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 new file mode 100644 index 000000000..c6827b41c --- /dev/null +++ b/tests/mocks/database/config/pdo/sqlite.php @@ -0,0 +1,22 @@ + array( + 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite', + 'dbdriver' => 'pdo', + ), + + // Database configuration with failover + 'pdo/sqlite_failover' => array( + 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/not_exists.sqlite', + 'dbdriver' => 'pdo', + 'failover' => array( + array( + 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite', + 'dbdriver' => 'pdo', + ), + ), + ), +); \ No newline at end of file diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php index 8665e208d..c70986e7c 100644 --- a/tests/mocks/database/config/sqlite.php +++ b/tests/mocks/database/config/sqlite.php @@ -1,5 +1,4 @@ 'sqlite', 'password' => 'sqlite', 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite', - 'dbdriver' => $dbdriver, + 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite', ), // Database configuration with failover @@ -20,7 +19,7 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => '../not_exists.sqlite', - 'dbdriver' => $dbdriver, + 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite', 'failover' => array( array( 'dsn' => '', @@ -28,7 +27,7 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite', - 'dbdriver' => $dbdriver, + 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite', ), ), ), diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml index eb650fa1e..69eece24f 100644 --- a/tests/travis/pdo/mysql.phpunit.xml +++ b/tests/travis/pdo/mysql.phpunit.xml @@ -10,7 +10,7 @@ stopOnIncomplete="false" stopOnSkipped="false"> - + diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml index 351f690d5..e68c3e028 100644 --- a/tests/travis/pdo/pgsql.phpunit.xml +++ b/tests/travis/pdo/pgsql.phpunit.xml @@ -10,7 +10,7 @@ stopOnIncomplete="false" stopOnSkipped="false"> - + diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml index ae139b7a9..1871f6221 100644 --- a/tests/travis/pdo/sqlite.phpunit.xml +++ b/tests/travis/pdo/sqlite.phpunit.xml @@ -10,7 +10,7 @@ stopOnIncomplete="false" stopOnSkipped="false"> - + -- cgit v1.2.3-24-g4f1b From f4c6c9b3061b464c959b6409f962228959f35287 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 4 Apr 2012 23:24:09 +0700 Subject: DB Drivers test --- tests/codeigniter/database/DB_driver_test.php | 36 +++++++++++++++++++++++++++ tests/mocks/autoloader.php | 15 +++++++++-- tests/mocks/database/config/ci_test.sqlite | 0 tests/mocks/database/config/pdo/sqlite.php | 3 +++ tests/mocks/database/db.php | 6 +++++ tests/mocks/database/db/driver.php | 36 +++++++++++++++++++++++++++ tests/mocks/database/drivers/mysql.php | 16 ++++++++++++ tests/mocks/database/drivers/pdo.php | 16 ++++++++++++ tests/mocks/database/drivers/postgre.php | 16 ++++++++++++ tests/mocks/database/drivers/sqlite.php | 16 ++++++++++++ 10 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 tests/codeigniter/database/DB_driver_test.php create mode 100644 tests/mocks/database/config/ci_test.sqlite create mode 100644 tests/mocks/database/db/driver.php create mode 100644 tests/mocks/database/drivers/mysql.php create mode 100644 tests/mocks/database/drivers/pdo.php create mode 100644 tests/mocks/database/drivers/postgre.php create mode 100644 tests/mocks/database/drivers/sqlite.php (limited to 'tests') diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php new file mode 100644 index 000000000..fb40f0608 --- /dev/null +++ b/tests/codeigniter/database/DB_driver_test.php @@ -0,0 +1,36 @@ +$driver_name($config[DB_DRIVER]); + + $this->assertTrue($driver->initialize()); + } + + protected function pdo($config) + { + return new Mock_Database_Drivers_PDO($config); + } + + protected function mysql($config) + { + return new Mock_Database_Drivers_Mysql($config); + } + + protected function sqlite($config) + { + return new Mock_Database_Drivers_Sqlite($config); + } + + protected function pgsql($config) + { + return new Mock_Database_Drivers_Postgre($config); + } + +} \ No newline at end of file diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index dd5929206..22448139e 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -53,13 +53,24 @@ function autoload($class) $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR; $class = $subclass; } + elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) == 3) + { + $driver_path = BASEPATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; + $dir = $driver_path.$m[1].DIRECTORY_SEPARATOR; + $file = $dir.$m[1].'_'.$m[2].'.php'; + } + elseif (strpos($class, 'CI_DB') === 0) + { + $dir = BASEPATH.'database'.DIRECTORY_SEPARATOR; + $file = $dir.str_replace('CI_DB', 'DB', $subclass).'.php'; + } else { $class = strtolower($class); } } - $file = $dir.$class.'.php'; + $file = (isset($file)) ? $file : $dir.$class.'.php'; if ( ! file_exists($file)) { @@ -71,7 +82,7 @@ function autoload($class) { return FALSE; } - + var_dump($file); throw new InvalidArgumentException("Unable to load $class."); } diff --git a/tests/mocks/database/config/ci_test.sqlite b/tests/mocks/database/config/ci_test.sqlite new file mode 100644 index 000000000..e69de29bb diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php index c6827b41c..1e5043b00 100644 --- a/tests/mocks/database/config/pdo/sqlite.php +++ b/tests/mocks/database/config/pdo/sqlite.php @@ -6,16 +6,19 @@ return array( 'pdo/sqlite' => array( 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite', 'dbdriver' => 'pdo', + 'pdodriver' => 'sqlite', ), // Database configuration with failover 'pdo/sqlite_failover' => array( 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/not_exists.sqlite', 'dbdriver' => 'pdo', + 'pdodriver' => 'sqlite', 'failover' => array( array( 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite', 'dbdriver' => 'pdo', + 'pdodriver' => 'sqlite', ), ), ), diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php index 43a0d391f..c30e6d2e6 100644 --- a/tests/mocks/database/db.php +++ b/tests/mocks/database/db.php @@ -45,6 +45,8 @@ class Mock_Database_DB { ); $config = array_merge($this->config[$group], $params); + $pdodriver = ( ! empty($config['pdodriver'])) ? $config['pdodriver'] : FALSE; + $failover = ( ! empty($config['failover'])) ? $config['failover'] : FALSE; if ( ! empty($config['dsn'])) { @@ -57,7 +59,11 @@ class Mock_Database_DB { } + // Build the parameter $other_params = array_slice($config, 6); + $other_params['dsn'] = $dsn; + if ($pdodriver) $other_params['pdodriver'] = $pdodriver; + if ($failover) $other_params['failover'] = $failover; return $dsn.'?'.http_build_query($other_params); } diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php new file mode 100644 index 000000000..9bf5231e3 --- /dev/null +++ b/tests/mocks/database/db/driver.php @@ -0,0 +1,36 @@ +ci_db_driver = new $driver_class($config); + } + + /** + * Overloading method, emulate the actual driver method (multiple inheritance workaround) + */ + public function __call($method, $arguments) + { + if ( ! is_callable(array($this->ci_db_driver, $method))) + { + throw new BadMethodCallException($method. ' not exists or not implemented'); + } + + return call_user_func_array(array($this->ci_db_driver, $method), $arguments); + } +} + +class CI_DB extends CI_DB_Driver {} \ No newline at end of file diff --git a/tests/mocks/database/drivers/mysql.php b/tests/mocks/database/drivers/mysql.php new file mode 100644 index 000000000..34a74e2bf --- /dev/null +++ b/tests/mocks/database/drivers/mysql.php @@ -0,0 +1,16 @@ + Date: Wed, 4 Apr 2012 23:46:23 +0700 Subject: Fix sqlite issue on PHP 5.4 both for native and PDO driver --- tests/mocks/database/config/ci_test.sqlite | 0 tests/mocks/database/config/pdo/sqlite.php | 20 ++++++++++++++++---- tests/mocks/database/db.php | 13 +++---------- 3 files changed, 19 insertions(+), 14 deletions(-) delete mode 100644 tests/mocks/database/config/ci_test.sqlite (limited to 'tests') diff --git a/tests/mocks/database/config/ci_test.sqlite b/tests/mocks/database/config/ci_test.sqlite deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php index 1e5043b00..c68b4b213 100644 --- a/tests/mocks/database/config/pdo/sqlite.php +++ b/tests/mocks/database/config/pdo/sqlite.php @@ -4,20 +4,32 @@ return array( // Typical Database configuration 'pdo/sqlite' => array( - 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite', + 'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite', + 'hostname' => 'localhost', + 'username' => 'sqlite', + 'password' => 'sqlite', + 'database' => 'sqlite', 'dbdriver' => 'pdo', 'pdodriver' => 'sqlite', ), // Database configuration with failover 'pdo/sqlite_failover' => array( - 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/not_exists.sqlite', + 'dsn' => 'sqlite:not_exists.sqlite', + 'hostname' => 'localhost', + 'username' => 'sqlite', + 'password' => 'sqlite', + 'database' => 'sqlite', 'dbdriver' => 'pdo', 'pdodriver' => 'sqlite', 'failover' => array( array( - 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite', - 'dbdriver' => 'pdo', + 'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite', + 'hostname' => 'localhost', + 'username' => 'sqlite', + 'password' => 'sqlite', + 'database' => 'sqlite', + 'dbdriver' => 'pdo', 'pdodriver' => 'sqlite', ), ), diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php index c30e6d2e6..59028ed9c 100644 --- a/tests/mocks/database/db.php +++ b/tests/mocks/database/db.php @@ -45,23 +45,16 @@ class Mock_Database_DB { ); $config = array_merge($this->config[$group], $params); + $dsnstring = ( ! empty($config['dsn'])) ? $config['dsn'] : FALSE; $pdodriver = ( ! empty($config['pdodriver'])) ? $config['pdodriver'] : FALSE; $failover = ( ! empty($config['failover'])) ? $config['failover'] : FALSE; - if ( ! empty($config['dsn'])) - { - $dsn = $config['dsn']; - } - else - { - $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password'] + $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password'] .'@'.$config['hostname'].'/'.$config['database']; - } - // Build the parameter $other_params = array_slice($config, 6); - $other_params['dsn'] = $dsn; + if ($dsnstring) $other_params['dsn'] = $dsnstring; if ($pdodriver) $other_params['pdodriver'] = $pdodriver; if ($failover) $other_params['failover'] = $failover; -- cgit v1.2.3-24-g4f1b From 26490e37f4bdb267b71431abd79782549cbbadda Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 4 Apr 2012 23:50:00 +0700 Subject: Add branch to travis list --- tests/mocks/database/drivers/sqlite.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mocks/database/drivers/sqlite.php b/tests/mocks/database/drivers/sqlite.php index 49c68c50f..76a182cbf 100644 --- a/tests/mocks/database/drivers/sqlite.php +++ b/tests/mocks/database/drivers/sqlite.php @@ -11,6 +11,6 @@ class Mock_Database_Drivers_Sqlite extends Mock_Database_DB_Driver { */ public function __construct($config = array()) { - parent::__construct('CI_DB_sqlite_driver', $config); + parent::__construct('CI_DB_sqlite3_driver', $config); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 61ff054fb905f0514b942bf3e70a6c882bd64f7a Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 01:23:56 +0700 Subject: Adding schema and initial Query Builder code coverage --- tests/codeigniter/database/query_builder/.gitkeep | 0 tests/mocks/autoloader.php | 4 ++-- tests/mocks/database/ci_test.sqlite | Bin 17408 -> 17408 bytes tests/mocks/database/config/sqlite.php | 6 +++--- tests/mocks/database/db/driver.php | 2 +- tests/mocks/database/schema/.gitkeep | 0 6 files changed, 6 insertions(+), 6 deletions(-) delete mode 100644 tests/codeigniter/database/query_builder/.gitkeep delete mode 100644 tests/mocks/database/schema/.gitkeep (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/.gitkeep b/tests/codeigniter/database/query_builder/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 22448139e..f1bdb5d6f 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -62,7 +62,7 @@ function autoload($class) elseif (strpos($class, 'CI_DB') === 0) { $dir = BASEPATH.'database'.DIRECTORY_SEPARATOR; - $file = $dir.str_replace('CI_DB', 'DB', $subclass).'.php'; + $file = $dir.str_replace(array('CI_DB','active_record'), array('DB', 'active_rec'), $subclass).'.php'; } else { @@ -82,7 +82,7 @@ function autoload($class) { return FALSE; } - var_dump($file); + throw new InvalidArgumentException("Unable to load $class."); } diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite index 37ce4f870..86d868af2 100755 Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php index c70986e7c..75fdacd96 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' => is_php('5.4') ? 'sqlite3' : 'sqlite', + 'dbdriver' => 'sqlite3', ), // Database configuration with failover @@ -19,7 +19,7 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => '../not_exists.sqlite', - 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite', + 'dbdriver' => 'sqlite3', 'failover' => array( array( 'dsn' => '', @@ -27,7 +27,7 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite', - 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite', + 'dbdriver' => 'sqlite3', ), ), ), diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php index 9bf5231e3..cb1820277 100644 --- a/tests/mocks/database/db/driver.php +++ b/tests/mocks/database/db/driver.php @@ -33,4 +33,4 @@ class Mock_Database_DB_Driver extends CI_DB_driver { } } -class CI_DB extends CI_DB_Driver {} \ No newline at end of file +class CI_DB extends Mock_Database_DB_QueryBuilder {} \ No newline at end of file diff --git a/tests/mocks/database/schema/.gitkeep b/tests/mocks/database/schema/.gitkeep deleted file mode 100644 index e69de29bb..000000000 -- cgit v1.2.3-24-g4f1b From 5b421665bac7609192917f7b0f34838534be099e Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 01:24:50 +0700 Subject: Simple query builder tests --- .../database/query_builder/get_test.php | 48 ++++++++++++++++ tests/mocks/database/db/querybuilder.php | 10 ++++ tests/mocks/database/schema/skeleton.php | 65 ++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/get_test.php create mode 100644 tests/mocks/database/db/querybuilder.php create mode 100644 tests/mocks/database/schema/skeleton.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php new file mode 100644 index 000000000..6f98ded4f --- /dev/null +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -0,0 +1,48 @@ +set_dsn(DB_DRIVER), TRUE); + + $this->ci_instance_var('db', $db); + + $loader = new Mock_Core_Loader(); + $loader->dbforge(); + + $forge = $this->ci_instance->dbforge; + + Mock_Database_Schema_Skeleton::create_tables($forge); + Mock_Database_Schema_Skeleton::create_data($db); + + $this->query_builder = $db; + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_get_simple() + { + $jobs = $this->query_builder->get('job')->result_array(); + + // Dummy jobs contain 4 rows + $this->assertCount(4, $jobs); + + // Check rows item + $this->assertEquals('Developer', $jobs[0]['name']); + $this->assertEquals('Politician', $jobs[1]['name']); + $this->assertEquals('Accountant', $jobs[2]['name']); + $this->assertEquals('Musician', $jobs[3]['name']); + } + +} \ No newline at end of file diff --git a/tests/mocks/database/db/querybuilder.php b/tests/mocks/database/db/querybuilder.php new file mode 100644 index 000000000..1b95c92af --- /dev/null +++ b/tests/mocks/database/db/querybuilder.php @@ -0,0 +1,10 @@ +add_field(array( + 'id' => array( + 'type' => 'INT', + 'constraint' => 3, + ), + 'name' => array( + 'type' => 'VARCHAR', + 'constraint' => 40, + ), + 'description' => array( + 'type' => 'TEXT', + 'constraint' => 0, + ), + )); + $forge->add_key('id', TRUE); + $forge->create_table('job', TRUE); + } + + /** + * Create the dummy datas + * + * @return void + */ + public static function create_data($db) + { + // Job Data + $data = array( + 'job' => array( + 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'), + ), + ); + + foreach ($data as $table => $dummy_data) + { + $db->truncate($table); + + if (strpos(DB_DRIVER, 'sqlite') === FALSE) + { + $db->insert_batch($table, $dummy_data); + } + else + { + foreach ($dummy_data as $single_dummy_data) + { + $db->insert($table, $single_dummy_data); + } + } + } + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 55f804239cb0141fdac748607d8cdfa143efac92 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 01:48:52 +0700 Subject: Add dsn to pgsql --- tests/mocks/database/config/pdo/pgsql.php | 4 ++-- tests/mocks/database/config/sqlite.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/mocks/database/config/pdo/pgsql.php b/tests/mocks/database/config/pdo/pgsql.php index b2f409d8d..5196e9ad9 100644 --- a/tests/mocks/database/config/pdo/pgsql.php +++ b/tests/mocks/database/config/pdo/pgsql.php @@ -4,7 +4,7 @@ return array( // Typical Database configuration 'pdo/pgsql' => array( - 'dsn' => '', + 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;', 'hostname' => 'localhost', 'username' => 'postgres', 'password' => '', @@ -24,7 +24,7 @@ return array( 'pdodriver' => 'pgsql', 'failover' => array( array( - 'dsn' => '', + 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;', 'hostname' => 'localhost', 'username' => 'postgres', 'password' => '', diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php index 75fdacd96..755ce2a3a 100644 --- a/tests/mocks/database/config/sqlite.php +++ b/tests/mocks/database/config/sqlite.php @@ -26,7 +26,7 @@ return array( 'hostname' => 'localhost', 'username' => 'sqlite', 'password' => 'sqlite', - 'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite', + 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite', 'dbdriver' => 'sqlite3', ), ), -- cgit v1.2.3-24-g4f1b From 024098d05d00383bf82165e1f8bbadb53cbcaa9b Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 01:51:57 +0700 Subject: Use more user-friendly method for dummy create data --- tests/mocks/database/schema/skeleton.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index bf9e75b45..53df73bdd 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -48,17 +48,10 @@ class Mock_Database_Schema_Skeleton { foreach ($data as $table => $dummy_data) { $db->truncate($table); - - if (strpos(DB_DRIVER, 'sqlite') === FALSE) - { - $db->insert_batch($table, $dummy_data); - } - else + + foreach ($dummy_data as $single_dummy_data) { - foreach ($dummy_data as $single_dummy_data) - { - $db->insert($table, $single_dummy_data); - } + $db->insert($table, $single_dummy_data); } } } -- cgit v1.2.3-24-g4f1b From 1bfc0d9a2b47be1a2a0b8efda60ebdd9d7a303dd Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 02:25:25 +0700 Subject: Fix postgre table datatype --- tests/mocks/database/schema/skeleton.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index 53df73bdd..47e8bfd35 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -12,7 +12,7 @@ class Mock_Database_Schema_Skeleton { // Job Table $forge->add_field(array( 'id' => array( - 'type' => 'INT', + 'type' => 'INTEGER', 'constraint' => 3, ), 'name' => array( @@ -21,11 +21,11 @@ class Mock_Database_Schema_Skeleton { ), 'description' => array( 'type' => 'TEXT', - 'constraint' => 0, ), )); $forge->add_key('id', TRUE); - $forge->create_table('job', TRUE); + $res = $forge->create_table('job'); + var_dump($res); } /** -- cgit v1.2.3-24-g4f1b From b0703b0bee89ab0eae83bae78daad5c5a3504043 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 02:31:52 +0700 Subject: Resolve postgres issue on create table --- tests/mocks/database/schema/skeleton.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index 47e8bfd35..6610d6b59 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -7,7 +7,7 @@ class Mock_Database_Schema_Skeleton { * * @return void */ - public static function create_tables($forge) + public static function create_tables($forge, $driver) { // Job Table $forge->add_field(array( @@ -24,8 +24,7 @@ class Mock_Database_Schema_Skeleton { ), )); $forge->add_key('id', TRUE); - $res = $forge->create_table('job'); - var_dump($res); + $forge->create_table('job', (strpos($driver, 'pgsql') === FALSE)); } /** -- cgit v1.2.3-24-g4f1b From 333ce0db32865d1e6d6a96207e5c9306bd40c676 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 02:34:06 +0700 Subject: Fixed schema --- tests/codeigniter/database/query_builder/get_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php index 6f98ded4f..e6fe319c5 100644 --- a/tests/codeigniter/database/query_builder/get_test.php +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -20,7 +20,7 @@ class Get_test extends CI_TestCase { $forge = $this->ci_instance->dbforge; - Mock_Database_Schema_Skeleton::create_tables($forge); + Mock_Database_Schema_Skeleton::create_tables($forge, DB_DRIVER); Mock_Database_Schema_Skeleton::create_data($db); $this->query_builder = $db; -- cgit v1.2.3-24-g4f1b From 55f622f76371949ae615ccdff76ed1e4bab55170 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 19:01:34 +0700 Subject: Add select clause test --- .../database/query_builder/get_test.php | 31 +++++++----- .../database/query_builder/select_test.php | 37 +++++++++++++++ tests/mocks/database/schema/skeleton.php | 55 +++++++++++++++++++--- 3 files changed, 104 insertions(+), 19 deletions(-) create mode 100644 tests/codeigniter/database/query_builder/select_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php index e6fe319c5..dd946a40c 100644 --- a/tests/codeigniter/database/query_builder/get_test.php +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -9,19 +9,10 @@ class Get_test extends CI_TestCase { public function set_up() { - $config = Mock_Database_DB::config(DB_DRIVER); - $connection = new Mock_Database_DB($config); - $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER), TRUE); + $db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - $this->ci_instance_var('db', $db); - - $loader = new Mock_Core_Loader(); - $loader->dbforge(); - - $forge = $this->ci_instance->dbforge; - - Mock_Database_Schema_Skeleton::create_tables($forge, DB_DRIVER); - Mock_Database_Schema_Skeleton::create_data($db); + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); $this->query_builder = $db; } @@ -44,5 +35,21 @@ class Get_test extends CI_TestCase { $this->assertEquals('Accountant', $jobs[2]['name']); $this->assertEquals('Musician', $jobs[3]['name']); } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_get_where() + { + $job1 = $this->query_builder->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/select_test.php b/tests/codeigniter/database/query_builder/select_test.php new file mode 100644 index 000000000..ba2f21b64 --- /dev/null +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -0,0 +1,37 @@ +query_builder = $db; + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_select_only_one_collumn() + { + $jobs_name = $this->query_builder->select('name') + ->get('job') + ->result_array(); + + // Check rows item + $this->assertArrayHasKey('name',$jobs_name[0]); + $this->assertFalse(array_key_exists('id', $jobs_name[0])); + $this->assertFalse(array_key_exists('description', $jobs_name[0])); + } + +} \ No newline at end of file diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index 6610d6b59..a3d5bac65 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -1,16 +1,57 @@ set_dsn($driver), TRUE); + + CI_TestCase::instance()->ci_instance_var('db', $db); + + $loader = new Mock_Core_Loader(); + $loader->dbforge(); + $forge = CI_TestCase::instance()->ci_instance_var('dbforge'); + + static::$db = $db; + static::$forge = $forge; + static::$driver = $driver; + } + + return static::$db; + } + /** * Create the dummy tables * * @return void */ - public static function create_tables($forge, $driver) + public static function create_tables() { // Job Table - $forge->add_field(array( + static::$forge->add_field(array( 'id' => array( 'type' => 'INTEGER', 'constraint' => 3, @@ -23,8 +64,8 @@ class Mock_Database_Schema_Skeleton { 'type' => 'TEXT', ), )); - $forge->add_key('id', TRUE); - $forge->create_table('job', (strpos($driver, 'pgsql') === FALSE)); + static::$forge->add_key('id', TRUE); + static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE)); } /** @@ -32,7 +73,7 @@ class Mock_Database_Schema_Skeleton { * * @return void */ - public static function create_data($db) + public static function create_data() { // Job Data $data = array( @@ -46,11 +87,11 @@ class Mock_Database_Schema_Skeleton { foreach ($data as $table => $dummy_data) { - $db->truncate($table); + static::$db->truncate($table); foreach ($dummy_data as $single_dummy_data) { - $db->insert($table, $single_dummy_data); + static::$db->insert($table, $single_dummy_data); } } } -- cgit v1.2.3-24-g4f1b From fdc0ea8802c48a5f74df97c013f683d4b264218a Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 19:08:00 +0700 Subject: Min, Max, Avg and Sum --- .../database/query_builder/select_test.php | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php index ba2f21b64..50a062c9f 100644 --- a/tests/codeigniter/database/query_builder/select_test.php +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -33,5 +33,65 @@ class Select_test extends CI_TestCase { $this->assertFalse(array_key_exists('id', $jobs_name[0])); $this->assertFalse(array_key_exists('description', $jobs_name[0])); } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_select_min() + { + $job_min = $this->query_builder->select_min('id') + ->get('job') + ->result_array(); + + // Minimum id was 1 + $this->assertEquals('1', $job_min[0]['id']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_select_max() + { + $job_max = $this->query_builder->select_max('id') + ->get('job') + ->result_array(); + + // Maximum id was 4 + $this->assertEquals('4', $job_max[0]['id']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_select_avg() + { + $job_avg = $this->query_builder->select_avg('id') + ->get('job') + ->result_array(); + + // Average should be 2.5 + $this->assertEquals('2.5', $job_avg[0]['id']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_select_sum() + { + $job_sum = $this->query_builder->select_sum('id') + ->get('job') + ->result_array(); + + // Sum of ids should be 10 + $this->assertEquals('10', $job_sum[0]['id']); + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0793b1c918a0146920b1a03323f055521c4a9c66 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 21:47:53 +0700 Subject: Rename to db, for more familiar naming convention --- .../database/query_builder/get_test.php | 10 +++--- .../database/query_builder/select_test.php | 36 ++++++++++------------ 2 files changed, 21 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php index dd946a40c..0751c9332 100644 --- a/tests/codeigniter/database/query_builder/get_test.php +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -5,16 +5,14 @@ class Get_test extends CI_TestCase { /** * @var object Database/Query Builder holder */ - protected $query_builder; + protected $db; public function set_up() { - $db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); Mock_Database_Schema_Skeleton::create_tables(); Mock_Database_Schema_Skeleton::create_data(); - - $this->query_builder = $db; } // ------------------------------------------------------------------------ @@ -24,7 +22,7 @@ class Get_test extends CI_TestCase { */ public function test_get_simple() { - $jobs = $this->query_builder->get('job')->result_array(); + $jobs = $this->db->get('job')->result_array(); // Dummy jobs contain 4 rows $this->assertCount(4, $jobs); @@ -43,7 +41,7 @@ class Get_test extends CI_TestCase { */ public function test_get_where() { - $job1 = $this->query_builder->get('job', array('id' => 1))->result_array(); + $job1 = $this->db->get('job', array('id' => 1))->result_array(); // Dummy jobs contain 1 rows $this->assertCount(1, $job1); diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php index 50a062c9f..dbf432a7c 100644 --- a/tests/codeigniter/database/query_builder/select_test.php +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -5,16 +5,14 @@ class Select_test extends CI_TestCase { /** * @var object Database/Query Builder holder */ - protected $query_builder; + protected $db; public function set_up() { - $db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); Mock_Database_Schema_Skeleton::create_tables(); Mock_Database_Schema_Skeleton::create_data(); - - $this->query_builder = $db; } // ------------------------------------------------------------------------ @@ -24,9 +22,9 @@ class Select_test extends CI_TestCase { */ public function test_select_only_one_collumn() { - $jobs_name = $this->query_builder->select('name') - ->get('job') - ->result_array(); + $jobs_name = $this->db->select('name') + ->get('job') + ->result_array(); // Check rows item $this->assertArrayHasKey('name',$jobs_name[0]); @@ -41,9 +39,9 @@ class Select_test extends CI_TestCase { */ public function test_select_min() { - $job_min = $this->query_builder->select_min('id') - ->get('job') - ->result_array(); + $job_min = $this->db->select_min('id') + ->get('job') + ->result_array(); // Minimum id was 1 $this->assertEquals('1', $job_min[0]['id']); @@ -56,9 +54,9 @@ class Select_test extends CI_TestCase { */ public function test_select_max() { - $job_max = $this->query_builder->select_max('id') - ->get('job') - ->result_array(); + $job_max = $this->db->select_max('id') + ->get('job') + ->result_array(); // Maximum id was 4 $this->assertEquals('4', $job_max[0]['id']); @@ -71,9 +69,9 @@ class Select_test extends CI_TestCase { */ public function test_select_avg() { - $job_avg = $this->query_builder->select_avg('id') - ->get('job') - ->result_array(); + $job_avg = $this->db->select_avg('id') + ->get('job') + ->result_array(); // Average should be 2.5 $this->assertEquals('2.5', $job_avg[0]['id']); @@ -86,9 +84,9 @@ class Select_test extends CI_TestCase { */ public function test_select_sum() { - $job_sum = $this->query_builder->select_sum('id') - ->get('job') - ->result_array(); + $job_sum = $this->db->select_sum('id') + ->get('job') + ->result_array(); // Sum of ids should be 10 $this->assertEquals('10', $job_sum[0]['id']); -- cgit v1.2.3-24-g4f1b From c0df5a231a28c6038f0a8ab702e090ce0e12b5a5 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 6 Apr 2012 17:35:12 +0700 Subject: Include insert test --- .../database/query_builder/insert_test.php | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/insert_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php new file mode 100644 index 000000000..5607e8ce1 --- /dev/null +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -0,0 +1,47 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_insert() + { + $job_data = array('name' => 'Grocery Sales', 'description' => 'Discount!'); + + // Do normal insert + $this->assertTrue($this->db->insert('job', $job_data)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_insert_batch() + { + $job_datas = array( + array('name' => 'Commedian', 'description' => 'Theres something in your teeth'), + array('name' => 'Cab Driver', 'description' => 'Iam yellow'), + ); + + // Do insert batch + $this->assertTrue($this->db->insert_batch('job', $job_datas)); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 81b6b5d4ea2e63159c443bae19880a78f6ac2f9f Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 6 Apr 2012 17:58:22 +0700 Subject: Insert test --- tests/codeigniter/database/query_builder/insert_test.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 5607e8ce1..80073b9ba 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -12,7 +12,6 @@ class Insert_test extends CI_TestCase { $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); } // ------------------------------------------------------------------------ @@ -22,7 +21,7 @@ class Insert_test extends CI_TestCase { */ public function test_insert() { - $job_data = array('name' => 'Grocery Sales', 'description' => 'Discount!'); + $job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!'); // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); @@ -36,8 +35,8 @@ class Insert_test extends CI_TestCase { public function test_insert_batch() { $job_datas = array( - array('name' => 'Commedian', 'description' => 'Theres something in your teeth'), - array('name' => 'Cab Driver', 'description' => 'Iam yellow'), + array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'), + array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'), ); // Do insert batch -- cgit v1.2.3-24-g4f1b From fc92fc2e4f262a3607898ca7cd8b361d95f09136 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 6 Apr 2012 18:00:55 +0700 Subject: Add truncate --- tests/codeigniter/database/query_builder/insert_test.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 80073b9ba..78587d2e9 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -4,6 +4,7 @@ class Insert_test extends CI_TestCase { /** * @var object Database/Query Builder holder + * @see ./mocks/schema/skeleton.php */ protected $db; @@ -12,6 +13,9 @@ class Insert_test extends CI_TestCase { $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); Mock_Database_Schema_Skeleton::create_tables(); + + // Truncate the current datas + $this->db->truncate('job'); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 80c0e3df5998a2a4b2376a6361f4690b783446df Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 7 Apr 2012 01:15:53 +0700 Subject: Check the insert result --- tests/codeigniter/database/query_builder/insert_test.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 78587d2e9..5dfccce82 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -29,6 +29,12 @@ class Insert_test extends CI_TestCase { // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); + + $job_1 = $this->db->get('job')->row(); + + // Check the result + $this->assertEquals('Grocery Sales', $job_1->name); + } // ------------------------------------------------------------------------ @@ -45,6 +51,11 @@ class Insert_test extends CI_TestCase { // Do insert batch $this->assertTrue($this->db->insert_batch('job', $job_datas)); + + $job_2 = $this->db->get_where('job', array('id' => 2))->row(); + + // Check the result + $this->assertEquals('Commedian', $job_2->name); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d489747059db6a91d5532f35437a812a81f2b98b Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 7 Apr 2012 03:16:25 +0700 Subject: Remove batch test from sqlite --- .../database/query_builder/insert_test.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 5dfccce82..b86feeb74 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -30,10 +30,11 @@ class Insert_test extends CI_TestCase { // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); - $job_1 = $this->db->get('job')->row(); + $jobs = $this->db->get('job')->result_array(); + $job1 = $jobs[0]; // Check the result - $this->assertEquals('Grocery Sales', $job_1->name); + $this->assertEquals('Grocery Sales', $job1['name']); } @@ -49,13 +50,18 @@ class Insert_test extends CI_TestCase { array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'), ); - // Do insert batch - $this->assertTrue($this->db->insert_batch('job', $job_datas)); + // Do insert batch except for sqlite driver + if (strpos(DB_DRIVER, 'sqlite') === FALSE) + { + $this->assertTrue($this->db->insert('job', $job_datas[0])); - $job_2 = $this->db->get_where('job', array('id' => 2))->row(); + $job_2 = $this->db->where('id', 2)->get('job')->row(); + $job_3 = $this->db->where('id', 3)->get('job')->row(); - // Check the result - $this->assertEquals('Commedian', $job_2->name); + // Check the result + $this->assertEquals('Commedian', $job_2->name); + $this->assertEquals('Cab Driver', $job_3->name); + } } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5ce26c912f11fb859e661a43a6667fba5a5a3ca2 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 7 Apr 2012 03:19:35 +0700 Subject: Typo --- tests/codeigniter/database/query_builder/insert_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index b86feeb74..53ce23c19 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -53,7 +53,7 @@ class Insert_test extends CI_TestCase { // Do insert batch except for sqlite driver if (strpos(DB_DRIVER, 'sqlite') === FALSE) { - $this->assertTrue($this->db->insert('job', $job_datas[0])); + $this->assertTrue($this->db->insert_batch('job', $job_datas)); $job_2 = $this->db->where('id', 2)->get('job')->row(); $job_3 = $this->db->where('id', 3)->get('job')->row(); -- cgit v1.2.3-24-g4f1b From 190c6bb125447f83793d9437f1bea28feada910a Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 3 May 2012 12:13:39 +0700 Subject: Cleaning up --- tests/codeigniter/database/query_builder/insert_test.php | 5 ++--- tests/codeigniter/database/query_builder/select_test.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 53ce23c19..8ba60e242 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -30,11 +30,10 @@ class Insert_test extends CI_TestCase { // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); - $jobs = $this->db->get('job')->result_array(); - $job1 = $jobs[0]; + $job1 = $this->db->get('job')->row(); // Check the result - $this->assertEquals('Grocery Sales', $job1['name']); + $this->assertEquals('Grocery Sales', $job1->name); } diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php index dbf432a7c..0d299ed16 100644 --- a/tests/codeigniter/database/query_builder/select_test.php +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -41,10 +41,10 @@ class Select_test extends CI_TestCase { { $job_min = $this->db->select_min('id') ->get('job') - ->result_array(); + ->row(); // Minimum id was 1 - $this->assertEquals('1', $job_min[0]['id']); + $this->assertEquals('1', $job_min->id); } // ------------------------------------------------------------------------ @@ -56,10 +56,10 @@ class Select_test extends CI_TestCase { { $job_max = $this->db->select_max('id') ->get('job') - ->result_array(); + ->row(); // Maximum id was 4 - $this->assertEquals('4', $job_max[0]['id']); + $this->assertEquals('4', $job_max->id); } // ------------------------------------------------------------------------ @@ -71,10 +71,10 @@ class Select_test extends CI_TestCase { { $job_avg = $this->db->select_avg('id') ->get('job') - ->result_array(); + ->row(); // Average should be 2.5 - $this->assertEquals('2.5', $job_avg[0]['id']); + $this->assertEquals('2.5', $job_avg->id); } // ------------------------------------------------------------------------ @@ -86,10 +86,10 @@ class Select_test extends CI_TestCase { { $job_sum = $this->db->select_sum('id') ->get('job') - ->result_array(); + ->row(); // Sum of ids should be 10 - $this->assertEquals('10', $job_sum[0]['id']); + $this->assertEquals('10', $job_sum->id); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6e131cbd0a5243f29a5ad9f56c80715e534e4267 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 3 May 2012 12:14:19 +0700 Subject: FROM clause API code-coverage --- .../database/query_builder/from_test.php | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/from_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/from_test.php b/tests/codeigniter/database/query_builder/from_test.php new file mode 100644 index 000000000..95ae4dfdb --- /dev/null +++ b/tests/codeigniter/database/query_builder/from_test.php @@ -0,0 +1,51 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_from_simple() + { + $jobs = $this->db->from('job') + ->get() + ->result_array(); + + // Check items + $this->assertEquals(4, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_from_with_where() + { + $job1 = $this->db->from('job') + ->where('id', 1) + ->get() + ->row(); + + // Check the result + $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 -- cgit v1.2.3-24-g4f1b From 17f799e1017d1688a2890a1ba78e4f53d80af77e Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 3 May 2012 15:15:40 +0700 Subject: Add user entity into schema skeleton --- tests/mocks/database/schema/skeleton.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index a3d5bac65..fbd533bfb 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -50,6 +50,24 @@ class Mock_Database_Schema_Skeleton { */ public static function create_tables() { + // User Table + static::$forge->add_field(array( + 'id' => array( + 'type' => 'INTEGER', + 'constraint' => 3, + ), + 'name' => array( + 'type' => 'VARCHAR', + 'constraint' => 40, + ), + 'email' => array( + 'type' => 'VARCHAR', + 'constraint' => 100, + ), + )); + static::$forge->add_key('id', TRUE); + static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE)); + // Job Table static::$forge->add_field(array( 'id' => array( @@ -77,6 +95,12 @@ class Mock_Database_Schema_Skeleton { { // Job Data $data = array( + 'user' => array( + array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com'), + array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com'), + array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com'), + array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com'), + ) 'job' => array( 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'), -- cgit v1.2.3-24-g4f1b From d6b41bb2659f959da01aee0ddb38bb4bce6cd4b6 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 15:05:22 +0700 Subject: JOIN clause API code-coverage --- .../database/query_builder/join_test.php | 38 ++++++++++++++++++++++ tests/mocks/database/schema/skeleton.php | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/codeigniter/database/query_builder/join_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php new file mode 100644 index 000000000..e05329d67 --- /dev/null +++ b/tests/codeigniter/database/query_builder/join_test.php @@ -0,0 +1,38 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_join_simple() + { + $job_user = $this->db->select('job.id as job_id, job.name as job_name, user.id as user_id, user.name as user_name') + ->from('job') + ->join('user', 'user.id = job.id') + ->get() + ->result_array(); + + // Check the result + $this->assertEquals('1', $job_user[0]['job_id']); + $this->assertEquals('1', $job_user[0]['user_id']); + $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/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index fbd533bfb..9ebd6e85f 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -100,7 +100,7 @@ class Mock_Database_Schema_Skeleton { array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com'), array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com'), array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com'), - ) + ), 'job' => array( 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'), -- cgit v1.2.3-24-g4f1b From 12f5475e2b279d1c2361ad5fc85bc2ba0d0f9033 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 15:46:39 +0700 Subject: WHERE clause API code-coverage --- .../database/query_builder/where_test.php | 144 +++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/where_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php new file mode 100644 index 000000000..607eaa076 --- /dev/null +++ b/tests/codeigniter/database/query_builder/where_test.php @@ -0,0 +1,144 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_simple_key_value() + { + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + // Check the result + $this->assertEquals('1', $job1->id); + $this->assertEquals('Developer', $job1->name); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_custom_key_value() + { + $jobs = $this->db->where('id !=', 1) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_associative_array() + { + $where = array('id >' => 2, 'name !=' => 'Accountant'); + $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']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_custom_string() + { + $where = "id > 2 AND name != 'Accountant'"; + $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']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_or() + { + $jobs = $this->db->where('name !=', 'Accountant') + ->or_where('id >', 3) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Developer', $jobs[0]['name']); + $this->assertEquals('Politician', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_in() + { + $jobs = $this->db->where_in('name', array('Politician', 'Accountant')) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Accountant', $jobs[1]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_not_in() + { + $jobs = $this->db->where_not_in('name', array('Politician', 'Accountant')) + ->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 -- cgit v1.2.3-24-g4f1b From f78018ec6b081518e4be24934448862a31bda9f8 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 15:53:55 +0700 Subject: LIKE clause API code-coverage --- .../database/query_builder/like_test.php | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/like_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php new file mode 100644 index 000000000..df98c713f --- /dev/null +++ b/tests/codeigniter/database/query_builder/like_test.php @@ -0,0 +1,90 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_like() + { + $job1 = $this->db->like('name', 'veloper') + ->get('job') + ->row(); + + // Check the result + $this->assertEquals('1', $job1->id); + $this->assertEquals('Developer', $job1->name); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_or_like() + { + $jobs = $this->db->like('name', 'ian') + ->or_like('name', 'veloper') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Developer', $jobs[0]['name']); + $this->assertEquals('Politician', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_not_like() + { + $jobs = $this->db->not_like('name', 'veloper') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Accountant', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_or_not_like() + { + $jobs = $this->db->like('name', 'an') + ->or_not_like('name', 'veloper') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Accountant', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4e607b00b2c56b7fdcc5f1d1a290be2363c74a46 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 19:22:48 +0700 Subject: GROUP BY clause API code-coverage --- .../database/query_builder/group_test.php | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/group_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php new file mode 100644 index 000000000..ddb2d0d6a --- /dev/null +++ b/tests/codeigniter/database/query_builder/group_test.php @@ -0,0 +1,37 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_group_by() + { + $jobs = $this->db->select('name') + ->from('job') + ->group_by('name HAVING SUM(id) > 2') + ->get() + ->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 -- cgit v1.2.3-24-g4f1b From f7377abee2ef1e165a362edc9a1c650373a002ca Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 19:42:24 +0700 Subject: Trace error --- .../database/query_builder/group_test.php | 8 ++++---- tests/mocks/database/ci_test.sqlite | Bin 17408 -> 19456 bytes 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php index ddb2d0d6a..dd248ae9a 100644 --- a/tests/codeigniter/database/query_builder/group_test.php +++ b/tests/codeigniter/database/query_builder/group_test.php @@ -22,16 +22,16 @@ class Group_test extends CI_TestCase { */ public function test_group_by() { - $jobs = $this->db->select('name') + $jobs = $this->db->select('job.name as job_name, job.id as job_id') ->from('job') - ->group_by('name HAVING SUM(id) > 2') + ->group_by('job_name HAVING SUM(job_id) > 2') ->get() ->result_array(); // Check the result $this->assertEquals(2, count($jobs)); - $this->assertEquals('Accountant', $jobs[0]['name']); - $this->assertEquals('Musician', $jobs[1]['name']); + $this->assertEquals('Accountant', $jobs[0]['job_name']); + $this->assertEquals('Musician', $jobs[1]['job_name']); } } \ No newline at end of file diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite index 86d868af2..e4128b23f 100755 Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ -- cgit v1.2.3-24-g4f1b From 1afd479059c3d6f7c46aa0c36aa56cfba7f94226 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 20:34:30 +0700 Subject: HAVING clause API code-coverage --- .../database/query_builder/group_test.php | 24 +++++++++++++++++---- tests/mocks/database/ci_test.sqlite | Bin 19456 -> 19456 bytes tests/mocks/database/schema/skeleton.php | 12 +++++++---- 3 files changed, 28 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php index dd248ae9a..7d8abc33f 100644 --- a/tests/codeigniter/database/query_builder/group_test.php +++ b/tests/codeigniter/database/query_builder/group_test.php @@ -22,16 +22,32 @@ class Group_test extends CI_TestCase { */ public function test_group_by() { - $jobs = $this->db->select('job.name as job_name, job.id as job_id') + $jobs = $this->db->select('name') ->from('job') - ->group_by('job_name HAVING SUM(job_id) > 2') + ->group_by('name') + ->get() + ->result_array(); + + // Check the result + $this->assertEquals(4, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + 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 $this->assertEquals(2, count($jobs)); - $this->assertEquals('Accountant', $jobs[0]['job_name']); - $this->assertEquals('Musician', $jobs[1]['job_name']); } } \ No newline at end of file diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite index e4128b23f..d48e3317f 100755 Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index 9ebd6e85f..671336cc4 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -64,6 +64,10 @@ class Mock_Database_Schema_Skeleton { 'type' => 'VARCHAR', 'constraint' => 100, ), + 'country' => array( + 'type' => 'VARCHAR', + 'constraint' => 40, + ), )); static::$forge->add_key('id', TRUE); static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE)); @@ -96,10 +100,10 @@ class Mock_Database_Schema_Skeleton { // Job Data $data = array( 'user' => array( - array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com'), - array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com'), - array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com'), - array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com'), + 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'), ), 'job' => array( array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'), -- cgit v1.2.3-24-g4f1b From 44d8d881b401238661d81fc9db10482604b4cf43 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 20:43:45 +0700 Subject: DISTINCT clause API code-coverage --- .../database/query_builder/distinct_test.php | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/distinct_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/distinct_test.php b/tests/codeigniter/database/query_builder/distinct_test.php new file mode 100644 index 000000000..925eadb19 --- /dev/null +++ b/tests/codeigniter/database/query_builder/distinct_test.php @@ -0,0 +1,34 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_distinct() + { + $users = $this->db->select('country') + ->distinct() + ->get('user') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($users)); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 8ca31f34c855c783689198f0d352e6efec352b4d Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 23:57:46 +0700 Subject: PDO SQLite bug fixed, for result_object --- tests/mocks/database/ci_test.sqlite | Bin 19456 -> 19456 bytes 1 file changed, 0 insertions(+), 0 deletions(-) (limited to 'tests') diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite index d48e3317f..23a3de2a4 100755 Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ -- cgit v1.2.3-24-g4f1b From d2d329a99f60bebc36eebc1c7b3c1a94b9789b49 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:33:04 +0700 Subject: ORDER BY clause API code-coverage --- .../database/query_builder/order_test.php | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/order_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/order_test.php b/tests/codeigniter/database/query_builder/order_test.php new file mode 100644 index 000000000..01aa1c2b4 --- /dev/null +++ b/tests/codeigniter/database/query_builder/order_test.php @@ -0,0 +1,55 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_order_ascending() + { + $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']); + $this->assertEquals('Developer', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + $this->assertEquals('Politician', $jobs[3]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_order_descending() + { + $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 -- cgit v1.2.3-24-g4f1b From be6fb4271ce723376930507dbe534f91344f26c7 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:35:41 +0700 Subject: LIMIT clause API code-coverage --- .../database/query_builder/limit_test.php | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/limit_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/limit_test.php b/tests/codeigniter/database/query_builder/limit_test.php new file mode 100644 index 000000000..704f3b651 --- /dev/null +++ b/tests/codeigniter/database/query_builder/limit_test.php @@ -0,0 +1,49 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_limit() + { + $jobs = $this->db->limit(2) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_limit_and_offset() + { + $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 -- cgit v1.2.3-24-g4f1b From c386b2a363c289afcfa07eea081050e35c1e86d8 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:42:02 +0700 Subject: count code-coverage --- .../database/query_builder/count_test.php | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/count_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/count_test.php b/tests/codeigniter/database/query_builder/count_test.php new file mode 100644 index 000000000..5e691692d --- /dev/null +++ b/tests/codeigniter/database/query_builder/count_test.php @@ -0,0 +1,44 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_count_all() + { + $job_count = $this->db->count_all('job'); + + // Check the result + $this->assertEquals(4, $job_count); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + 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); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9ec507badf60952750e76b5d83da54874dd19119 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:55:39 +0700 Subject: UPDATE and SET clause code-coverage --- .../database/query_builder/update_test.php | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/update_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/update_test.php b/tests/codeigniter/database/query_builder/update_test.php new file mode 100644 index 000000000..f5bbffd4f --- /dev/null +++ b/tests/codeigniter/database/query_builder/update_test.php @@ -0,0 +1,71 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_update() + { + // Check initial record + $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); + + // Check updated record + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + $this->assertEquals('Programmer', $job1->name); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_update_with_set() + { + // Check initial record + $job1 = $this->db->where('id', 4) + ->get('job') + ->row(); + + $this->assertEquals('Musician', $job1->name); + + // Do the update + $this->db->set('name', 'Vocalist'); + $this->db->update('job', NULL, 'id = 4'); + + // Check updated record + $job1 = $this->db->where('id', 4) + ->get('job') + ->row(); + + $this->assertEquals('Vocalist', $job1->name); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6657cc1672f3f466655b1e476028b9d46a16bd1c Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:06:41 +0700 Subject: DELETE code-coverage --- .../database/query_builder/delete_test.php | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/delete_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/delete_test.php b/tests/codeigniter/database/query_builder/delete_test.php new file mode 100644 index 000000000..84ea7616f --- /dev/null +++ b/tests/codeigniter/database/query_builder/delete_test.php @@ -0,0 +1,72 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_delete() + { + // Check initial record + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + $this->assertEquals('Developer', $job1->name); + + // Do the delete + $this->db->delete('job', array('id' => 1)); + + // Check the record + $job1 = $this->db->where('id', 1) + ->get('job'); + + $this->assertEmpty($job1->result_array()); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + 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(); + + $this->assertEquals('Musician', $job4->name); + $this->assertEquals('Chris Martin', $user4->name); + + // Do the delete + $this->db->delete(array('job', 'user'), array('id' => 4)); + + // Check the record + $job4 = $this->db->where('id', 4)->get('job'); + $user4 = $this->db->where('id', 4)->get('user'); + + $this->assertEmpty($job4->result_array()); + $this->assertEmpty($user4->result_array()); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 85859b212e480e2e1a59aae50c759367d6794ecd Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:26:51 +0700 Subject: empty table API code-coverage --- .../database/query_builder/empty_test.php | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/empty_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/empty_test.php b/tests/codeigniter/database/query_builder/empty_test.php new file mode 100644 index 000000000..d1f56285f --- /dev/null +++ b/tests/codeigniter/database/query_builder/empty_test.php @@ -0,0 +1,39 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_empty_table() + { + // Check initial record + $jobs = $this->db->get('job')->result_array(); + + $this->assertEquals(4, count($jobs)); + + // Do the empty + $this->db->empty_table('job'); + + // Check the record + $jobs = $this->db->get('job'); + + $this->assertEmpty($jobs->result_array()); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 39f35fde6d023433e98904105f55f305483b6b5e Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:29:13 +0700 Subject: TRUNCATE code-coverage --- .../database/query_builder/truncate_test.php | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/truncate_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/truncate_test.php b/tests/codeigniter/database/query_builder/truncate_test.php new file mode 100644 index 000000000..2a9c8a91e --- /dev/null +++ b/tests/codeigniter/database/query_builder/truncate_test.php @@ -0,0 +1,61 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_truncate() + { + // Check initial record + $jobs = $this->db->get('job')->result_array(); + + $this->assertEquals(4, count($jobs)); + + // Do the empty + $this->db->truncate('job'); + + // Check the record + $jobs = $this->db->get('job'); + + $this->assertEmpty($jobs->result_array()); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_truncate_with_from() + { + // Check initial record + $users = $this->db->get('user')->result_array(); + + $this->assertEquals(4, count($users)); + + // Do the empty + $this->db->from('user') + ->truncate(); + + // Check the record + $users = $this->db->get('user'); + + $this->assertEmpty($users->result_array()); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 51a7c0b98df29205d39bb404c2bcd12bfb4ed4cb Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:43:08 +0700 Subject: Clean up --- tests/README.md | 6 ------ tests/codeigniter/Setup_test.php | 10 +++++----- tests/travis/mysql.phpunit.xml | 6 +----- tests/travis/pdo/mysql.phpunit.xml | 4 ---- tests/travis/pdo/pgsql.phpunit.xml | 6 +----- tests/travis/pdo/sqlite.phpunit.xml | 6 +----- tests/travis/pgsql.phpunit.xml | 6 +----- tests/travis/sqlite.phpunit.xml | 6 +----- 8 files changed, 10 insertions(+), 40 deletions(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index 6d83c34d8..b46f344cb 100644 --- a/tests/README.md +++ b/tests/README.md @@ -2,12 +2,6 @@ Status : [![Build Status](https://secure.travis-ci.org/EllisLab/CodeIgniter.png?branch=feature/unit-tests)](http://travis-ci.org/EllisLab/CodeIgniter) -*Do not merge to default until these issues have been addressed* - -- Clean up naming conventions -- Figure out config stuff -- Figure out database testing - ### Introduction: This is the preliminary CodeIgniter testing documentation. It diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php index 550245f2f..b48e32bfb 100644 --- a/tests/codeigniter/Setup_test.php +++ b/tests/codeigniter/Setup_test.php @@ -2,12 +2,12 @@ class Setup_test extends PHPUnit_Framework_TestCase { - function test_nonsense() + function test_bootstrap_constants() { - $this->markTestIncomplete('not implemented'); - // ensure that our bootstrapped test environment - // is a good representation of an isolated CI install - //die('here'); + $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/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml index e9556f758..c5fcf1335 100644 --- a/tests/travis/mysql.phpunit.xml +++ b/tests/travis/mysql.phpunit.xml @@ -14,11 +14,7 @@ - ../codeigniter/Setup_test.php - ../codeigniter/core - ../codeigniter/helpers - ../codeigniter/libraries - ../codeigniter/database + ../codeigniter diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml index 69eece24f..f6fcc1c39 100644 --- a/tests/travis/pdo/mysql.phpunit.xml +++ b/tests/travis/pdo/mysql.phpunit.xml @@ -14,10 +14,6 @@ - ../../codeigniter/Setup_test.php - ../../codeigniter/core - ../../codeigniter/helpers - ../../codeigniter/libraries ../../codeigniter/database diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml index e68c3e028..6a23227db 100644 --- a/tests/travis/pdo/pgsql.phpunit.xml +++ b/tests/travis/pdo/pgsql.phpunit.xml @@ -14,11 +14,7 @@ - ../../codeigniter/Setup_test.php - ../../codeigniter/core - ../../codeigniter/helpers - ../../codeigniter/libraries - ../../codeigniter/database + ../../codeigniter diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml index 1871f6221..b85b7308a 100644 --- a/tests/travis/pdo/sqlite.phpunit.xml +++ b/tests/travis/pdo/sqlite.phpunit.xml @@ -14,11 +14,7 @@ - ../../codeigniter/Setup_test.php - ../../codeigniter/core - ../../codeigniter/helpers - ../../codeigniter/libraries - ../../codeigniter/database + ../../codeigniter diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml index ad8aeded2..78b6046cf 100644 --- a/tests/travis/pgsql.phpunit.xml +++ b/tests/travis/pgsql.phpunit.xml @@ -14,11 +14,7 @@ - ../codeigniter/Setup_test.php - ../codeigniter/core - ../codeigniter/helpers - ../codeigniter/libraries - ../codeigniter/database + ../codeigniter diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml index 628370e93..46e3d5073 100644 --- a/tests/travis/sqlite.phpunit.xml +++ b/tests/travis/sqlite.phpunit.xml @@ -14,11 +14,7 @@ - ../codeigniter/Setup_test.php - ../codeigniter/core - ../codeigniter/helpers - ../codeigniter/libraries - ../codeigniter/database + ../codeigniter -- cgit v1.2.3-24-g4f1b From 570e77cd78e0c704b032c3e7702372ca63d5ddaa Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Tue, 15 May 2012 18:47:24 +0700 Subject: Benchmark code-coverage --- tests/codeigniter/core/Benchmark_test.php | 42 +++++++++++++++++++++++++++++++ tests/mocks/core/benchmark.php | 3 +++ 2 files changed, 45 insertions(+) create mode 100644 tests/codeigniter/core/Benchmark_test.php create mode 100644 tests/mocks/core/benchmark.php (limited to 'tests') diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php new file mode 100644 index 000000000..2790b582e --- /dev/null +++ b/tests/codeigniter/core/Benchmark_test.php @@ -0,0 +1,42 @@ +benchmark = new Mock_Core_Benchmark(); + } + + // -------------------------------------------------------------------- + + public function test_mark() + { + $this->assertEmpty($this->benchmark->marker); + + $this->benchmark->mark('code_start'); + + $this->assertEquals(1, count($this->benchmark->marker)); + $this->assertArrayHasKey('code_start', $this->benchmark->marker); + } + + // -------------------------------------------------------------------- + + public function test_elapsed_time() + { + $this->assertEquals('{elapsed_time}', $this->benchmark->elapsed_time()); + $this->assertEmpty($this->benchmark->elapsed_time('undefined_point')); + + $this->benchmark->mark('code_start'); + sleep(1); + $this->benchmark->mark('code_end'); + + $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 3)); + } + + // -------------------------------------------------------------------- + + public function test_memory_usage() + { + $this->assertEquals('{memory_usage}', $this->benchmark->memory_usage()); + } +} \ No newline at end of file diff --git a/tests/mocks/core/benchmark.php b/tests/mocks/core/benchmark.php new file mode 100644 index 000000000..d92be21db --- /dev/null +++ b/tests/mocks/core/benchmark.php @@ -0,0 +1,3 @@ + Date: Tue, 15 May 2012 18:48:45 +0700 Subject: Clean up autoloader annotation --- tests/mocks/autoloader.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index f1bdb5d6f..92c9bea59 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -6,7 +6,6 @@ // // Prototype : // -// include_once('Mock_Core_Loader') // Will load ./mocks/core/loader.php // $mock_table = new Mock_Libraries_Table(); // Will load ./mocks/libraries/table.php // $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php // and so on... -- cgit v1.2.3-24-g4f1b From 8af88f3f729b7bcfd2a106f858b5445deafe5ed0 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Tue, 15 May 2012 21:52:53 +0700 Subject: Security Code coverage --- tests/Bootstrap.php | 3 ++ tests/codeigniter/core/Security_test.php | 79 ++++++++++++++++++++++++++++++++ tests/mocks/core/security.php | 27 +++++++++++ tests/mocks/libraries/table.php | 2 +- 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 tests/codeigniter/core/Security_test.php create mode 100644 tests/mocks/core/security.php (limited to 'tests') diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 9f89d1be8..2bec364ef 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -12,6 +12,9 @@ define('BASEPATH', PROJECT_BASE.'system/'); define('APPPATH', PROJECT_BASE.'application/'); define('VIEWPATH', PROJECT_BASE.''); +// Set cookie for security test +$_COOKIE['ci_csrf_cookie'] = md5(uniqid(rand(), TRUE)); + // Prep our test environment require_once 'vfsStream/vfsStream.php'; include_once $dir.'/mocks/core/common.php'; diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php new file mode 100644 index 000000000..c3b526965 --- /dev/null +++ b/tests/codeigniter/core/Security_test.php @@ -0,0 +1,79 @@ +ci_set_config('csrf_protection', TRUE); + $this->ci_set_config('csrf_token_name', 'ci_csrf_token'); + // @see : ./Bootstrap.php Line 16 + $this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie'); + $this->ci_set_config('csrf_expire', 7200); + $this->ci_set_config('csrf_regenerate', TRUE); + $this->ci_set_config('csrf_exclude_uris', array()); + + $this->ci_set_config('cookie_prefix', ""); + $this->ci_set_config('cookie_domain', ""); + $this->ci_set_config('cookie_path', "/"); + $this->ci_set_config('cookie_secure', FALSE); + $this->ci_set_config('cookie_httponly', FALSE); + + $this->security = new Mock_Core_Security(); + } + + // -------------------------------------------------------------------- + + public function test_csrf_verify() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + + $this->assertInstanceOf('CI_Security', $this->security->csrf_verify()); + } + + // -------------------------------------------------------------------- + + public function test_csrf_verify_invalid() + { + // Without issuing $_POST[csrf_token_name], this request will triggering CSRF error + $_SERVER['REQUEST_METHOD'] = 'POST'; + + $this->setExpectedException('RuntimeException', 'CI Error: The action you have requested is not allowed'); + + $this->security->csrf_verify(); + } + + // -------------------------------------------------------------------- + + public function test_csrf_verify_valid() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST[$this->security->csrf_token_name] = $this->security->csrf_hash; + + $this->assertInstanceOf('CI_Security', $this->security->csrf_verify()); + } + + // -------------------------------------------------------------------- + + 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 your site"; + + $harmless_string = $this->security->xss_clean($harm_string); + + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless_string); + } +} \ No newline at end of file diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php new file mode 100644 index 000000000..de8e44710 --- /dev/null +++ b/tests/mocks/core/security.php @@ -0,0 +1,27 @@ +{'_'.$property}) ? $this->{'_'.$property} : NULL; + } + + // 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 1a6ff8d35..97fbb30bd 100644 --- a/tests/mocks/libraries/table.php +++ b/tests/mocks/libraries/table.php @@ -2,7 +2,7 @@ class Mock_Libraries_Table extends CI_Table { - // Overide inaccesible private or protected method + // Overide inaccesible protected method public function __call($method, $params) { if (is_callable(array($this, '_'.$method))) -- cgit v1.2.3-24-g4f1b From d40a545e9e7e4dc222d58fe46fe23f3691f043ee Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Tue, 15 May 2012 22:00:14 +0700 Subject: Comment block for explanation --- tests/mocks/core/security.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php index de8e44710..c5269fbc5 100644 --- a/tests/mocks/core/security.php +++ b/tests/mocks/core/security.php @@ -4,6 +4,9 @@ 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, + // we superseded set_cookie with directly set the cookie variable, + // @see : ./Bootstrap.php, line 16 return $this; } -- cgit v1.2.3-24-g4f1b From 7756af5df0a53930019e9fd7b828504f0c2c5427 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Tue, 15 May 2012 23:57:05 +0700 Subject: Input class code-coverage --- tests/Bootstrap.php | 3 - tests/codeigniter/core/Input_test.php | 144 +++++++++++++++++++++++++++++++ tests/codeigniter/core/Security_test.php | 14 +-- tests/mocks/core/input.php | 31 +++++++ tests/mocks/core/security.php | 2 +- tests/mocks/core/utf8.php | 27 ++++++ 6 files changed, 207 insertions(+), 14 deletions(-) create mode 100644 tests/codeigniter/core/Input_test.php create mode 100644 tests/mocks/core/input.php create mode 100644 tests/mocks/core/utf8.php (limited to 'tests') diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 2bec364ef..9f89d1be8 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -12,9 +12,6 @@ define('BASEPATH', PROJECT_BASE.'system/'); define('APPPATH', PROJECT_BASE.'application/'); define('VIEWPATH', PROJECT_BASE.''); -// Set cookie for security test -$_COOKIE['ci_csrf_cookie'] = md5(uniqid(rand(), TRUE)); - // Prep our test environment require_once 'vfsStream/vfsStream.php'; include_once $dir.'/mocks/core/common.php'; diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php new file mode 100644 index 000000000..fd0576e38 --- /dev/null +++ b/tests/codeigniter/core/Input_test.php @@ -0,0 +1,144 @@ +ci_set_config('allow_get_array', TRUE); + $this->ci_set_config('global_xss_filtering', FALSE); + $this->ci_set_config('csrf_protection', FALSE); + + $security = new Mock_Core_Security(); + $utf8 = new Mock_Core_Utf8(); + + $this->input = new Mock_Core_Input($security, $utf8); + } + + // -------------------------------------------------------------------- + + public function test_get_not_exists() + { + $this->assertEmpty($this->input->get()); + $this->assertEmpty($this->input->get('foo')); + + $this->assertTrue( ! $this->input->get()); + $this->assertTrue( ! $this->input->get('foo')); + + $this->assertTrue($this->input->get() == FALSE); + $this->assertTrue($this->input->get('foo') == FALSE); + + $this->assertTrue($this->input->get() === FALSE); + $this->assertTrue($this->input->get('foo') === FALSE); + } + + // -------------------------------------------------------------------- + + public function test_get_exist() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_GET['foo'] = 'bar'; + + $this->assertArrayHasKey('foo', $this->input->get()); + $this->assertEquals('bar', $this->input->get('foo')); + } + + // -------------------------------------------------------------------- + + public function test_get_exist_with_xss_clean() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_GET['harm'] = "Hello, i try to your site"; + + $this->assertArrayHasKey('harm', $this->input->get()); + $this->assertEquals("Hello, i try to your site", $this->input->get('harm')); + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $this->input->get('harm', TRUE)); + } + + // -------------------------------------------------------------------- + + public function test_post_not_exists() + { + $this->assertEmpty($this->input->post()); + $this->assertEmpty($this->input->post('foo')); + + $this->assertTrue( ! $this->input->post()); + $this->assertTrue( ! $this->input->post('foo')); + + $this->assertTrue($this->input->post() == FALSE); + $this->assertTrue($this->input->post('foo') == FALSE); + + $this->assertTrue($this->input->post() === FALSE); + $this->assertTrue($this->input->post('foo') === FALSE); + } + + // -------------------------------------------------------------------- + + public function test_post_exist() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['foo'] = 'bar'; + + $this->assertArrayHasKey('foo', $this->input->post()); + $this->assertEquals('bar', $this->input->post('foo')); + } + + // -------------------------------------------------------------------- + + public function test_post_exist_with_xss_clean() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['harm'] = "Hello, i try to your site"; + + $this->assertArrayHasKey('harm', $this->input->post()); + $this->assertEquals("Hello, i try to your site", $this->input->post('harm')); + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $this->input->post('harm', TRUE)); + } + + // -------------------------------------------------------------------- + + public function test_get_post() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['foo'] = 'bar'; + + $this->assertEquals('bar', $this->input->get_post('foo')); + } + + // -------------------------------------------------------------------- + + public function test_cookie() + { + $_COOKIE['foo'] = 'bar'; + + $this->assertEquals('bar', $this->input->cookie('foo')); + } + + // -------------------------------------------------------------------- + + public function test_server() + { + $this->assertEquals('GET', $this->input->server('REQUEST_METHOD')); + } + + // -------------------------------------------------------------------- + + public function test_fetch_from_array() + { + $data = array( + 'foo' => 'bar', + 'harm' => 'Hello, i try to your site', + ); + + $foo = $this->input->fetch_from_array($data, 'foo'); + $harm = $this->input->fetch_from_array($data, 'harm'); + $harmless = $this->input->fetch_from_array($data, 'harm', TRUE); + + $this->assertEquals('bar', $foo); + $this->assertEquals("Hello, i try to your site", $harm); + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless); + } +} \ No newline at end of file diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index c3b526965..1796ba74d 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -4,19 +4,13 @@ class Security_test extends CI_TestCase { public function set_up() { + // Set cookie for security test + $_COOKIE['ci_csrf_cookie'] = md5(uniqid(rand(), TRUE)); + + // Set config for Security class $this->ci_set_config('csrf_protection', TRUE); $this->ci_set_config('csrf_token_name', 'ci_csrf_token'); - // @see : ./Bootstrap.php Line 16 $this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie'); - $this->ci_set_config('csrf_expire', 7200); - $this->ci_set_config('csrf_regenerate', TRUE); - $this->ci_set_config('csrf_exclude_uris', array()); - - $this->ci_set_config('cookie_prefix', ""); - $this->ci_set_config('cookie_domain', ""); - $this->ci_set_config('cookie_path', "/"); - $this->ci_set_config('cookie_secure', FALSE); - $this->ci_set_config('cookie_httponly', FALSE); $this->security = new Mock_Core_Security(); } diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php new file mode 100644 index 000000000..8a337d2ef --- /dev/null +++ b/tests/mocks/core/input.php @@ -0,0 +1,31 @@ +_allow_get_array = (config_item('allow_get_array') === TRUE); + $this->_enable_xss = (config_item('global_xss_filtering') === TRUE); + $this->_enable_csrf = (config_item('csrf_protection') === TRUE); + + // Assign Security and Utf8 classes + $this->security = $security; + $this->uni = $utf8; + + // Sanitize global arrays + $this->_sanitize_globals(); + } + + public function fetch_from_array($array, $index = '', $xss_clean = FALSE) + { + return parent::_fetch_from_array($array, $index, $xss_clean); + } + +} \ No newline at end of file diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php index c5269fbc5..d7ea0e6bd 100644 --- a/tests/mocks/core/security.php +++ b/tests/mocks/core/security.php @@ -6,7 +6,7 @@ class Mock_Core_Security extends CI_Security { { // We cannot set cookie in CLI mode, so for csrf test, who rely on $_COOKIE, // we superseded set_cookie with directly set the cookie variable, - // @see : ./Bootstrap.php, line 16 + // @see : ./tests/codeigniter/core/Security_test.php, line 8 return $this; } diff --git a/tests/mocks/core/utf8.php b/tests/mocks/core/utf8.php new file mode 100644 index 000000000..b77d717e7 --- /dev/null +++ b/tests/mocks/core/utf8.php @@ -0,0 +1,27 @@ + Date: Wed, 16 May 2012 00:08:05 +0700 Subject: Remove unused hardcoded reference from *phpunit.xml files --- tests/travis/mysql.phpunit.xml | 2 -- tests/travis/pdo/mysql.phpunit.xml | 4 +--- tests/travis/pdo/pgsql.phpunit.xml | 2 -- tests/travis/pdo/sqlite.phpunit.xml | 2 -- tests/travis/pgsql.phpunit.xml | 2 -- tests/travis/sqlite.phpunit.xml | 2 -- 6 files changed, 1 insertion(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml index c5fcf1335..1792ae38d 100644 --- a/tests/travis/mysql.phpunit.xml +++ b/tests/travis/mysql.phpunit.xml @@ -21,8 +21,6 @@ PEAR_INSTALL_DIR PHP_LIBDIR - PROJECT_BASE.'tests' - '../../system/core/CodeIgniter.php' \ No newline at end of file diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml index f6fcc1c39..602030d4e 100644 --- a/tests/travis/pdo/mysql.phpunit.xml +++ b/tests/travis/pdo/mysql.phpunit.xml @@ -14,15 +14,13 @@ - ../../codeigniter/database + ../../codeigniter PEAR_INSTALL_DIR PHP_LIBDIR - PROJECT_BASE.'tests' - '../../../system/core/CodeIgniter.php' \ No newline at end of file diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml index 6a23227db..77e1493c6 100644 --- a/tests/travis/pdo/pgsql.phpunit.xml +++ b/tests/travis/pdo/pgsql.phpunit.xml @@ -21,8 +21,6 @@ PEAR_INSTALL_DIR PHP_LIBDIR - PROJECT_BASE.'tests' - '../../../system/core/CodeIgniter.php' \ No newline at end of file diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml index b85b7308a..cdccef017 100644 --- a/tests/travis/pdo/sqlite.phpunit.xml +++ b/tests/travis/pdo/sqlite.phpunit.xml @@ -21,8 +21,6 @@ PEAR_INSTALL_DIR PHP_LIBDIR - PROJECT_BASE.'tests' - '../../../system/core/CodeIgniter.php' \ No newline at end of file diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml index 78b6046cf..dfc1bff1c 100644 --- a/tests/travis/pgsql.phpunit.xml +++ b/tests/travis/pgsql.phpunit.xml @@ -21,8 +21,6 @@ PEAR_INSTALL_DIR PHP_LIBDIR - PROJECT_BASE.'tests' - '../../system/core/CodeIgniter.php' \ No newline at end of file diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml index 46e3d5073..3223da5e7 100644 --- a/tests/travis/sqlite.phpunit.xml +++ b/tests/travis/sqlite.phpunit.xml @@ -21,8 +21,6 @@ PEAR_INSTALL_DIR PHP_LIBDIR - PROJECT_BASE.'tests' - '../../system/core/CodeIgniter.php' \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 09a1b5e7fb3c930aa9a50e246236227a499b5d28 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 16 May 2012 22:18:00 +0700 Subject: Reduce decimal points, since there is a micro differencess on runtime and update travis status --- tests/README.md | 2 +- tests/codeigniter/core/Benchmark_test.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index b46f344cb..c8fc608e8 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,6 +1,6 @@ # CodeIgniter Unit Tests # -Status : [![Build Status](https://secure.travis-ci.org/EllisLab/CodeIgniter.png?branch=feature/unit-tests)](http://travis-ci.org/EllisLab/CodeIgniter) +Status : [![Build Status](https://secure.travis-ci.org/EllisLab/CodeIgniter.png?branch=develop)](http://travis-ci.org/EllisLab/CodeIgniter) ### Introduction: diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php index 2790b582e..109b38821 100644 --- a/tests/codeigniter/core/Benchmark_test.php +++ b/tests/codeigniter/core/Benchmark_test.php @@ -29,8 +29,8 @@ class Benchmark_test extends CI_TestCase { $this->benchmark->mark('code_start'); sleep(1); $this->benchmark->mark('code_end'); - - $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 3)); + + $this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1)); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 55a6ddb0c7bab1149bb1ddfa3a1aff46612c91d4 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 23 May 2012 18:37:24 +0100 Subject: Input, Session and Cookie get's will return NULL. Read more about this change here: http://codeigniter.com/forums/viewthread/215833 --- tests/codeigniter/core/Input_test.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index fd0576e38..a066d9960 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -28,11 +28,13 @@ class Input_test extends CI_TestCase { $this->assertTrue( ! $this->input->get()); $this->assertTrue( ! $this->input->get('foo')); - $this->assertTrue($this->input->get() == FALSE); - $this->assertTrue($this->input->get('foo') == FALSE); + // Test we're getting empty results + $this->assertTrue($this->input->get() == NULL); + $this->assertTrue($this->input->get('foo') == NULL); - $this->assertTrue($this->input->get() === FALSE); - $this->assertTrue($this->input->get('foo') === FALSE); + // Test new 3.0 behaviour for non existant results (used to be FALSE) + $this->assertTrue($this->input->get() === NULL); + $this->assertTrue($this->input->get('foo') === NULL); } // -------------------------------------------------------------------- @@ -68,11 +70,11 @@ class Input_test extends CI_TestCase { $this->assertTrue( ! $this->input->post()); $this->assertTrue( ! $this->input->post('foo')); - $this->assertTrue($this->input->post() == FALSE); - $this->assertTrue($this->input->post('foo') == FALSE); + $this->assertTrue($this->input->post() == NULL); + $this->assertTrue($this->input->post('foo') == NULL); - $this->assertTrue($this->input->post() === FALSE); - $this->assertTrue($this->input->post('foo') === FALSE); + $this->assertTrue($this->input->post() === NULL); + $this->assertTrue($this->input->post('foo') === NULL); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 6bca9f836836f4bea2112cd6635a384e862b4db2 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 25 May 2012 01:55:36 +0700 Subject: get vfsStream via composer if its PEAR package not exists --- tests/Bootstrap.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 9f89d1be8..c14a4dee2 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -12,8 +12,17 @@ define('BASEPATH', PROJECT_BASE.'system/'); define('APPPATH', PROJECT_BASE.'application/'); define('VIEWPATH', PROJECT_BASE.''); +// Get vfsStream either via pear or composer +if (file_exists('vfsStream/vfsStream.php')) +{ + require_once 'vfsStream/vfsStream.php'; +} +else +{ + include_once '../vendor/autoload.php'; +} + // Prep our test environment -require_once 'vfsStream/vfsStream.php'; include_once $dir.'/mocks/core/common.php'; include_once $dir.'/mocks/autoloader.php'; spl_autoload_register('autoload'); -- cgit v1.2.3-24-g4f1b From e13511a1368adb9914a4252d98cb2d0165138e0d Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 25 May 2012 02:15:42 +0700 Subject: Global class aliasing, at least until namespace introduced into further release --- tests/Bootstrap.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index c14a4dee2..71394720a 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -12,14 +12,17 @@ define('BASEPATH', PROJECT_BASE.'system/'); define('APPPATH', PROJECT_BASE.'application/'); define('VIEWPATH', PROJECT_BASE.''); -// Get vfsStream either via pear or composer +// Get vfsStream either via PEAR or composer if (file_exists('vfsStream/vfsStream.php')) { require_once 'vfsStream/vfsStream.php'; } else { - include_once '../vendor/autoload.php'; + include_once PROJECT_BASE.'vendor/autoload.php'; + class_alias('org\bovigo\vfs\vfsStream', 'vfsStream'); + class_alias('org\bovigo\vfs\vfsStreamDirectory', 'vfsStreamDirectory'); + class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper'); } // Prep our test environment -- cgit v1.2.3-24-g4f1b From eeca6d265c4e104e3a6b34b8581180d2926b3dba Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 25 May 2012 03:15:19 +0700 Subject: Backward compatibility, in case someone already has vfsStream in their PEAR or other include_path --- tests/Bootstrap.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 71394720a..1dbd178ca 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -13,11 +13,16 @@ define('APPPATH', PROJECT_BASE.'application/'); define('VIEWPATH', PROJECT_BASE.''); // Get vfsStream either via PEAR or composer -if (file_exists('vfsStream/vfsStream.php')) +foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) { - require_once 'vfsStream/vfsStream.php'; + if (file_exists($path.DIRECTORY_SEPARATOR.'vfsStream/vfsStream.phps')) + { + require_once 'vfsStream/vfsStream.php'; + break; + } } -else + +if ( ! class_exists('vfsStream') && file_exists(PROJECT_BASE.'vendor/autoload.php')) { include_once PROJECT_BASE.'vendor/autoload.php'; class_alias('org\bovigo\vfs\vfsStream', 'vfsStream'); -- cgit v1.2.3-24-g4f1b From 2d57445ba66f8b6e5fef526b932d691b0e5690db Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 25 May 2012 04:03:56 +0700 Subject: Escape like tests, #136 verification --- tests/Bootstrap.php | 2 +- .../database/query_builder/escape_test.php | 47 ++++++++++++++++++++++ tests/mocks/database/schema/skeleton.php | 21 ++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/codeigniter/database/query_builder/escape_test.php (limited to 'tests') diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 1dbd178ca..38615dd89 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -15,7 +15,7 @@ define('VIEWPATH', PROJECT_BASE.''); // Get vfsStream either via PEAR or composer foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) { - if (file_exists($path.DIRECTORY_SEPARATOR.'vfsStream/vfsStream.phps')) + if (file_exists($path.DIRECTORY_SEPARATOR.'vfsStream/vfsStream.php')) { require_once 'vfsStream/vfsStream.php'; break; diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php new file mode 100644 index 000000000..6d220d65d --- /dev/null +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -0,0 +1,47 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_escape_like_percent_sign() + { + $string = $this->db->escape_like_str('\%foo'); + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; + $res = $this->db->query($sql)->result_array(); + + // Check the result + $this->assertEquals(1, count($res)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_escape_like_backslash_sign() + { + $string = $this->db->escape_like_str('\\'); + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; + $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/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index 671336cc4..05499f82f 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -88,6 +88,23 @@ class Mock_Database_Schema_Skeleton { )); static::$forge->add_key('id', TRUE); static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE)); + + // Misc Table + static::$forge->add_field(array( + 'id' => array( + 'type' => 'INTEGER', + 'constraint' => 3, + ), + 'key' => array( + 'type' => 'VARCHAR', + 'constraint' => 40, + ), + 'value' => array( + 'type' => 'TEXT', + ), + )); + static::$forge->add_key('id', TRUE); + static::$forge->create_table('misc', (strpos(static::$driver, 'pgsql') === FALSE)); } /** @@ -111,6 +128,10 @@ class Mock_Database_Schema_Skeleton { 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 \\%'), + ), ); foreach ($data as $table => $dummy_data) -- cgit v1.2.3-24-g4f1b From 6a43244e1d739db17db266456221099232d120d6 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 25 May 2012 04:09:38 +0700 Subject: replace space with tab --- tests/codeigniter/database/query_builder/escape_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 6d220d65d..f2d1b84ca 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -23,8 +23,8 @@ class Escape_test extends CI_TestCase { public function test_escape_like_percent_sign() { $string = $this->db->escape_like_str('\%foo'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; - $res = $this->db->query($sql)->result_array(); + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; + $res = $this->db->query($sql)->result_array(); // Check the result $this->assertEquals(1, count($res)); @@ -38,8 +38,8 @@ class Escape_test extends CI_TestCase { public function test_escape_like_backslash_sign() { $string = $this->db->escape_like_str('\\'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; - $res = $this->db->query($sql)->result_array(); + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; + $res = $this->db->query($sql)->result_array(); // Check the result $this->assertEquals(2, count($res)); -- cgit v1.2.3-24-g4f1b From 98dcac7ea5f82cc1d5cecedd030c5f242f1dc652 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 25 May 2012 05:07:51 +0700 Subject: Alter the escape like test, since it use raw SQL via query(), the sql statement would need to add ESCAPE clause for database(s) other than mysql --- .../database/query_builder/escape_test.php | 7 +++++-- tests/mocks/database/ci_test.sqlite | Bin 19456 -> 19456 bytes 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index f2d1b84ca..5dd2da058 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -23,7 +23,9 @@ class Escape_test extends CI_TestCase { public function test_escape_like_percent_sign() { $string = $this->db->escape_like_str('\%foo'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%'"; + $sql .= (strpos(DB_DRIVER, 'mysql') !== FALSE) ? ";" : "ESCAPE '!';"; + $res = $this->db->query($sql)->result_array(); // Check the result @@ -38,7 +40,8 @@ class Escape_test extends CI_TestCase { public function test_escape_like_backslash_sign() { $string = $this->db->escape_like_str('\\'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%'"; + $sql .= (strpos(DB_DRIVER, 'mysql') !== FALSE) ? ";" : "ESCAPE '!';"; $res = $this->db->query($sql)->result_array(); // Check the result diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite index 23a3de2a4..44dcef9ec 100755 Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ -- cgit v1.2.3-24-g4f1b From 59d6b4fc4f4d7d5265b59cfd8c0f68f885083f69 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 25 May 2012 02:08:00 +0300 Subject: Alter LIKE escaping tests again --- tests/codeigniter/database/DB_driver_test.php | 4 +--- tests/codeigniter/database/DB_test.php | 4 +--- tests/codeigniter/database/query_builder/escape_test.php | 16 ++++++---------- 3 files changed, 8 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php index fb40f0608..9e16e29b4 100644 --- a/tests/codeigniter/database/DB_driver_test.php +++ b/tests/codeigniter/database/DB_driver_test.php @@ -2,8 +2,6 @@ class DB_driver_test extends CI_TestCase { - // ------------------------------------------------------------------------ - public function test_initialize() { $config = Mock_Database_DB::config(DB_DRIVER); @@ -32,5 +30,5 @@ class DB_driver_test extends CI_TestCase { { return new Mock_Database_Drivers_Postgre($config); } - + } \ No newline at end of file diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php index 9b93e223d..d5c0dea08 100644 --- a/tests/codeigniter/database/DB_test.php +++ b/tests/codeigniter/database/DB_test.php @@ -2,8 +2,6 @@ class DB_test extends CI_TestCase { - // ------------------------------------------------------------------------ - public function test_db_invalid() { $connection = new Mock_Database_DB(array( @@ -45,5 +43,5 @@ class DB_test extends CI_TestCase { $this->assertTrue($db instanceof CI_DB); $this->assertTrue($db instanceof CI_DB_Driver); } - + } \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 5dd2da058..96fbd078b 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -23,13 +23,10 @@ class Escape_test extends CI_TestCase { public function test_escape_like_percent_sign() { $string = $this->db->escape_like_str('\%foo'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%'"; - $sql .= (strpos(DB_DRIVER, 'mysql') !== FALSE) ? ";" : "ESCAPE '!';"; + $res = $this->db->select('value')->from('misc')->like('key', $string, 'after')->get(); - $res = $this->db->query($sql)->result_array(); - // Check the result - $this->assertEquals(1, count($res)); + $this->assertEquals(1, count($res->result_array())); } // ------------------------------------------------------------------------ @@ -40,11 +37,10 @@ class Escape_test extends CI_TestCase { public function test_escape_like_backslash_sign() { $string = $this->db->escape_like_str('\\'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%'"; - $sql .= (strpos(DB_DRIVER, 'mysql') !== FALSE) ? ";" : "ESCAPE '!';"; - $res = $this->db->query($sql)->result_array(); - + $res = $this->db->select('value')->from('misc')->like('key', $string, 'after')->get(); + // Check the result - $this->assertEquals(2, count($res)); + $this->assertEquals(2, count($res->result_array())); } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0174d84401b5c5996115a4a6193161f1dab96de2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 25 May 2012 02:17:49 +0300 Subject: Alter LIKE escaping tests again --- tests/codeigniter/database/query_builder/escape_test.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 96fbd078b..9df82c2d0 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -23,7 +23,10 @@ class Escape_test extends CI_TestCase { public function test_escape_like_percent_sign() { $string = $this->db->escape_like_str('\%foo'); - $res = $this->db->select('value')->from('misc')->like('key', $string, 'after')->get(); + $this->db->select('value'); + $this->db->from('misc'); + $this->db->like('key', $string, 'after'); + $res = $this->db->get(); // Check the result $this->assertEquals(1, count($res->result_array())); @@ -38,6 +41,10 @@ class Escape_test extends CI_TestCase { { $string = $this->db->escape_like_str('\\'); $res = $this->db->select('value')->from('misc')->like('key', $string, 'after')->get(); + $this->db->select('value'); + $this->db->from('misc'); + $this->db->like('key', $string, 'after'); + $res = $this->db->get(); // Check the result $this->assertEquals(2, count($res->result_array())); -- cgit v1.2.3-24-g4f1b From f33e2ff30b0a9c54d6e8adbe88662838b9bd525e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 25 May 2012 02:24:17 +0300 Subject: Again ... escape_like_str() tests --- tests/codeigniter/database/query_builder/escape_test.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 9df82c2d0..50685922a 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -22,7 +22,8 @@ class Escape_test extends CI_TestCase { */ public function test_escape_like_percent_sign() { - $string = $this->db->escape_like_str('\%foo'); + $string = '\%foo' +; $this->db->select('value'); $this->db->from('misc'); $this->db->like('key', $string, 'after'); @@ -39,8 +40,8 @@ class Escape_test extends CI_TestCase { */ public function test_escape_like_backslash_sign() { - $string = $this->db->escape_like_str('\\'); - $res = $this->db->select('value')->from('misc')->like('key', $string, 'after')->get(); + $string = '\\'; + $this->db->select('value'); $this->db->from('misc'); $this->db->like('key', $string, 'after'); -- cgit v1.2.3-24-g4f1b From 502942bd94fef292970df331b15652ef6e1385e7 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 25 May 2012 07:00:41 +0700 Subject: Explicitely testing escape_like_str API --- tests/codeigniter/database/query_builder/escape_test.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 5dd2da058..ac1c8f659 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -13,6 +13,9 @@ class Escape_test extends CI_TestCase { Mock_Database_Schema_Skeleton::create_tables(); Mock_Database_Schema_Skeleton::create_data(); + + $this->pre = (strpos(DB_DRIVER, 'pgsql') === FALSE) ? '`' : '"'; + $this->esc = (strpos(DB_DRIVER, 'mysql') === FALSE) ? '!' : ''; } // ------------------------------------------------------------------------ @@ -23,8 +26,8 @@ class Escape_test extends CI_TestCase { public function test_escape_like_percent_sign() { $string = $this->db->escape_like_str('\%foo'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%'"; - $sql .= (strpos(DB_DRIVER, 'mysql') !== FALSE) ? ";" : "ESCAPE '!';"; + + $sql = "SELECT {$this->pre}value{$this->pre} FROM {$this->pre}misc{$this->pre} WHERE {$this->pre}key{$this->pre} LIKE '$string%' ESCAPE '$this->esc';"; $res = $this->db->query($sql)->result_array(); @@ -40,8 +43,9 @@ class Escape_test extends CI_TestCase { public function test_escape_like_backslash_sign() { $string = $this->db->escape_like_str('\\'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%'"; - $sql .= (strpos(DB_DRIVER, 'mysql') !== FALSE) ? ";" : "ESCAPE '!';"; + + $sql = "SELECT {$this->pre}value{$this->pre} FROM {$this->pre}misc{$this->pre} WHERE {$this->pre}key{$this->pre} LIKE '$string%' ESCAPE '$this->esc';"; + $res = $this->db->query($sql)->result_array(); // Check the result -- cgit v1.2.3-24-g4f1b From 3c5abf93d3031064c8181069cfee83ebfb54dcf0 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 25 May 2012 07:17:26 +0700 Subject: Clean up --- tests/codeigniter/database/query_builder/escape_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index fe225436a..5df812ca6 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -32,7 +32,7 @@ class Escape_test extends CI_TestCase { $res = $this->db->query($sql)->result_array(); // Check the result - $this->assertEquals(1, count($res->result_array())); + $this->assertEquals(1, count($res)); } // ------------------------------------------------------------------------ @@ -49,7 +49,7 @@ class Escape_test extends CI_TestCase { $res = $this->db->query($sql)->result_array(); // Check the result - $this->assertEquals(2, count($res->result_array())); + $this->assertEquals(2, count($res)); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1af5b47ad6f95f805d9f411ce020f2e2fa88b302 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 26 May 2012 16:04:39 +0700 Subject: Remove ternary --- .../database/query_builder/escape_test.php | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 5df812ca6..5d575a37b 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -13,9 +13,6 @@ class Escape_test extends CI_TestCase { Mock_Database_Schema_Skeleton::create_tables(); Mock_Database_Schema_Skeleton::create_data(); - - $this->pre = (strpos(DB_DRIVER, 'pgsql') === FALSE) ? '`' : '"'; - $this->esc = (strpos(DB_DRIVER, 'mysql') === FALSE) ? '!' : ''; } // ------------------------------------------------------------------------ @@ -25,9 +22,17 @@ class Escape_test extends CI_TestCase { */ public function test_escape_like_percent_sign() { + // Escape the like string $string = $this->db->escape_like_str('\%foo'); - $sql = "SELECT {$this->pre}value{$this->pre} FROM {$this->pre}misc{$this->pre} WHERE {$this->pre}key{$this->pre} LIKE '$string%' ESCAPE '$this->esc';"; + if (strpos(DB_DRIVER, 'mysql') !== FALSE) + { + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '';"; + } + else + { + $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';'; + } $res = $this->db->query($sql)->result_array(); @@ -42,14 +47,21 @@ class Escape_test extends CI_TestCase { */ public function test_escape_like_backslash_sign() { + // Escape the like string $string = $this->db->escape_like_str('\\'); - $sql = "SELECT {$this->pre}value{$this->pre} FROM {$this->pre}misc{$this->pre} WHERE {$this->pre}key{$this->pre} LIKE '$string%' ESCAPE '$this->esc';"; + if (strpos(DB_DRIVER, 'mysql') !== FALSE) + { + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '';"; + } + else + { + $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';'; + } $res = $this->db->query($sql)->result_array(); // Check the result $this->assertEquals(2, count($res)); } - } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4912f8b25cd8fa1b88b4babd1bad2b6bf29dd235 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 26 May 2012 22:09:58 +0700 Subject: Allowing main constants defined via phpunit config or other bootstraper --- tests/Bootstrap.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 38615dd89..5216038c6 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -7,10 +7,10 @@ error_reporting(E_ALL | E_STRICT); $dir = realpath(dirname(__FILE__)); // Path constants -define('PROJECT_BASE', realpath($dir.'/../').'/'); -define('BASEPATH', PROJECT_BASE.'system/'); -define('APPPATH', PROJECT_BASE.'application/'); -define('VIEWPATH', PROJECT_BASE.''); +defined('PROJECT_BASE') OR define('PROJECT_BASE', realpath($dir.'/../').'/'); +defined('BASEPATH') OR define('BASEPATH', PROJECT_BASE.'system/'); +defined('APPPATH') OR define('APPPATH', PROJECT_BASE.'application/'); +defined('VIEWPATH') OR define('VIEWPATH', PROJECT_BASE.''); // Get vfsStream either via PEAR or composer foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) -- cgit v1.2.3-24-g4f1b From 6c7526c95b3fbd502dc8105a67fd38da793caa4e Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sun, 27 May 2012 13:51:27 +0700 Subject: Continuation for Security and Table code-coverage, add coverage report to travis --- tests/codeigniter/core/Security_test.php | 32 ++++++++++++++++++++++++++++++ tests/codeigniter/libraries/Table_test.php | 24 ++++++++++++++++++++-- tests/mocks/autoloader.php | 4 ++-- tests/travis/mysql.phpunit.xml | 11 +++++----- tests/travis/pdo/mysql.phpunit.xml | 11 +++++----- tests/travis/pdo/pgsql.phpunit.xml | 11 +++++----- tests/travis/pdo/sqlite.phpunit.xml | 11 +++++----- tests/travis/pgsql.phpunit.xml | 11 +++++----- tests/travis/sqlite.phpunit.xml | 11 +++++----- 9 files changed, 86 insertions(+), 40 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 1796ba74d..b2f8c69d2 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -70,4 +70,36 @@ class Security_test extends CI_TestCase { $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless_string); } + + // -------------------------------------------------------------------- + + public function test_xss_hash() + { + $this->assertEmpty($this->security->xss_hash); + + // Perform hash + $this->security->xss_hash(); + + $this->assertTrue(preg_match('#^[0-9a-f]{32}$#iS', $this->security->xss_hash) === 1); + } + + // -------------------------------------------------------------------- + + public function test_entity_decode() + { + $encoded = '<div>Hello <b>Booya</b></div>'; + $decoded = $this->security->entity_decode($encoded); + + $this->assertEquals('
Hello Booya
', $decoded); + } + + // -------------------------------------------------------------------- + + public function test_sanitize_filename() + { + $filename = './'; + $safe_filename = $this->security->sanitize_filename($filename); + + $this->assertEquals('foo', $safe_filename); + } } \ No newline at end of file diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index 13f338c6b..f5133de1e 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -291,6 +291,26 @@ class Table_test extends CI_TestCase { ); } - // Test main generate method - // -------------------------------------------------------------------- + function test_generate() + { + // Prepare the data + $data = array( + array('Name', 'Color', 'Size'), + array('Fred', 'Blue', 'Small'), + array('Mary', 'Red', 'Large'), + array('John', 'Green', 'Medium') + ); + + $table = $this->table->generate($data); + + // Test the table header + $this->assertTrue(strpos($table, 'Name') !== FALSE); + $this->assertTrue(strpos($table, 'Color') !== FALSE); + $this->assertTrue(strpos($table, 'Size') !== FALSE); + + // Test the first entry + $this->assertTrue(strpos($table, 'Fred') !== FALSE); + $this->assertTrue(strpos($table, 'Blue') !== FALSE); + $this->assertTrue(strpos($table, 'Small') !== FALSE); + } } \ No newline at end of file diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 92c9bea59..441c88944 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -22,7 +22,7 @@ function autoload($class) ); $ci_libraries = array( - 'Calendar', 'Cart', 'Driver', + 'Calendar', 'Cart', 'Driver_Library', 'Email', 'Encrypt', 'Form_validation', 'Ftp', 'Image_lib', 'Javascript', 'Log', 'Migration', 'Pagination', @@ -50,7 +50,7 @@ function autoload($class) elseif (in_array($subclass, $ci_libraries)) { $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR; - $class = $subclass; + $class = ($subclass == 'Driver_Library') ? 'Driver' : $subclass; } elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) == 3) { diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml index 1792ae38d..38c8eba48 100644 --- a/tests/travis/mysql.phpunit.xml +++ b/tests/travis/mysql.phpunit.xml @@ -17,10 +17,9 @@ ../codeigniter
- - - PEAR_INSTALL_DIR - PHP_LIBDIR - - + + + ../../system + + \ No newline at end of file diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml index 602030d4e..c3113a66f 100644 --- a/tests/travis/pdo/mysql.phpunit.xml +++ b/tests/travis/pdo/mysql.phpunit.xml @@ -17,10 +17,9 @@ ../../codeigniter
- - - PEAR_INSTALL_DIR - PHP_LIBDIR - - + + + ../../../system + + \ No newline at end of file diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml index 77e1493c6..232025523 100644 --- a/tests/travis/pdo/pgsql.phpunit.xml +++ b/tests/travis/pdo/pgsql.phpunit.xml @@ -17,10 +17,9 @@ ../../codeigniter
- - - PEAR_INSTALL_DIR - PHP_LIBDIR - - + + + ../../../system + + \ No newline at end of file diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml index cdccef017..3d1256721 100644 --- a/tests/travis/pdo/sqlite.phpunit.xml +++ b/tests/travis/pdo/sqlite.phpunit.xml @@ -17,10 +17,9 @@ ../../codeigniter - - - PEAR_INSTALL_DIR - PHP_LIBDIR - - + + + ../../../system + + \ No newline at end of file diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml index dfc1bff1c..51e433d76 100644 --- a/tests/travis/pgsql.phpunit.xml +++ b/tests/travis/pgsql.phpunit.xml @@ -17,10 +17,9 @@ ../codeigniter - - - PEAR_INSTALL_DIR - PHP_LIBDIR - - + + + ../../system + + \ No newline at end of file diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml index 3223da5e7..701165734 100644 --- a/tests/travis/sqlite.phpunit.xml +++ b/tests/travis/sqlite.phpunit.xml @@ -17,10 +17,9 @@ ../codeigniter - - - PEAR_INSTALL_DIR - PHP_LIBDIR - - + + + ../../system + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b2e10b7de0d8979ce19fed5859e696904e2923dd Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sun, 27 May 2012 15:31:53 +0700 Subject: Adding more flexibilities to mock-common --- tests/mocks/core/common.php | 167 +++++++++++++++++++++++++++----------------- 1 file changed, 103 insertions(+), 64 deletions(-) (limited to 'tests') diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php index fc94d7fff..e74576626 100644 --- a/tests/mocks/core/common.php +++ b/tests/mocks/core/common.php @@ -2,53 +2,65 @@ // Set up the global CI functions in their most minimal core representation -function &get_instance() +if ( ! function_exists('get_instance')) { - $test = CI_TestCase::instance(); - $instance = $test->ci_instance(); - return $instance; + function &get_instance() + { + $test = CI_TestCase::instance(); + $instance = $test->ci_instance(); + return $instance; + } } // -------------------------------------------------------------------- -function &get_config() { - $test = CI_TestCase::instance(); - $config = $test->ci_get_config(); - - return $config; +if ( ! function_exists('get_config')) +{ + function &get_config() { + $test = CI_TestCase::instance(); + $config = $test->ci_get_config(); + + return $config; + } } -function config_item($item) +if ( ! function_exists('config_item')) { - $config =& get_config(); - - if ( ! isset($config[$item])) + function config_item($item) { - return FALSE; + $config =& get_config(); + + if ( ! isset($config[$item])) + { + return FALSE; + } + + return $config[$item]; } - - return $config[$item]; } // -------------------------------------------------------------------- -function load_class($class, $directory = 'libraries', $prefix = 'CI_') +if ( ! function_exists('load_class')) { - if ($directory != 'core' OR $prefix != 'CI_') - { - throw new Exception('Not Implemented: Non-core load_class()'); - } - - $test = CI_TestCase::instance(); - - $obj =& $test->ci_core_class($class); - - if (is_string($obj)) + function load_class($class, $directory = 'libraries', $prefix = 'CI_') { - throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class.''); + if ($directory != 'core' OR $prefix != 'CI_') + { + 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.''); + } + + return $obj; } - - return $obj; } // This is sort of meh. Should probably be mocked up with @@ -57,76 +69,103 @@ function load_class($class, $directory = 'libraries', $prefix = 'CI_') // bootstrap testsuite. // -------------------------------------------------------------------- -function remove_invisible_characters($str, $url_encoded = TRUE) +if ( ! function_exists('remove_invisible_characters')) { - $non_displayables = array(); - - // every control character except newline (dec 10) - // carriage return (dec 13), and horizontal tab (dec 09) - - if ($url_encoded) + function remove_invisible_characters($str, $url_encoded = TRUE) { - $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 + $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 - { - $str = preg_replace($non_displayables, '', $str, -1, $count); - } - while ($count); + do + { + $str = preg_replace($non_displayables, '', $str, -1, $count); + } + while ($count); - return $str; + return $str; + } } // Clean up error messages // -------------------------------------------------------------------- -function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered') +if ( ! function_exists('show_error')) { - throw new RuntimeException('CI Error: '.$message); + function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered') + { + throw new RuntimeException('CI Error: '.$message); + } } -function show_404($page = '', $log_error = TRUE) +if ( ! function_exists('show_404')) { - throw new RuntimeException('CI Error: 404'); + function show_404($page = '', $log_error = TRUE) + { + throw new RuntimeException('CI Error: 404'); + } } -function _exception_handler($severity, $message, $filepath, $line) +if ( ! function_exists('_exception_handler')) { - throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line); + function _exception_handler($severity, $message, $filepath, $line) + { + throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line); + } } // We assume a few things about our environment ... // -------------------------------------------------------------------- -function is_php($version = '5.0.0') +if ( ! function_exists('is_php')) { - return ! (version_compare(PHP_VERSION, $version) < 0); + function is_php($version = '5.0.0') + { + return ! (version_compare(PHP_VERSION, $version) < 0); + } } -function is_really_writable($file) +if ( ! function_exists('is_really_writable')) { - return is_writable($file); + function is_really_writable($file) + { + return is_writable($file); + } } -function is_loaded() +if ( ! function_exists('is_loaded')) { - throw new Exception('Bad Isolation: mock up environment'); + function is_loaded() + { + throw new Exception('Bad Isolation: mock up environment'); + } } -function log_message($level = 'error', $message, $php_error = FALSE) +if ( ! function_exists('log_message')) { - return TRUE; + function log_message($level = 'error', $message, $php_error = FALSE) + { + return TRUE; + } } -function set_status_header($code = 200, $text = '') +if ( ! function_exists('set_status_header')) { - return TRUE; + function set_status_header($code = 200, $text = '') + { + return TRUE; + } } // EOF \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d6d1150959c95e43d310d0bc45f8bd674ff6460c Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:12:55 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /tests --- tests/codeigniter/core/Input_test.php | 8 ++++---- tests/codeigniter/database/query_builder/where_test.php | 2 +- tests/mocks/autoloader.php | 6 +++--- tests/mocks/core/common.php | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index a066d9960..cfc80c950 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -29,8 +29,8 @@ class Input_test extends CI_TestCase { $this->assertTrue( ! $this->input->get('foo')); // Test we're getting empty results - $this->assertTrue($this->input->get() == NULL); - $this->assertTrue($this->input->get('foo') == NULL); + $this->assertTrue($this->input->get() === NULL); + $this->assertTrue($this->input->get('foo') === NULL); // Test new 3.0 behaviour for non existant results (used to be FALSE) $this->assertTrue($this->input->get() === NULL); @@ -70,8 +70,8 @@ class Input_test extends CI_TestCase { $this->assertTrue( ! $this->input->post()); $this->assertTrue( ! $this->input->post('foo')); - $this->assertTrue($this->input->post() == NULL); - $this->assertTrue($this->input->post('foo') == NULL); + $this->assertTrue($this->input->post() === NULL); + $this->assertTrue($this->input->post('foo') === NULL); $this->assertTrue($this->input->post() === NULL); $this->assertTrue($this->input->post('foo') === NULL); diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php index 607eaa076..6a92c6fce 100644 --- a/tests/codeigniter/database/query_builder/where_test.php +++ b/tests/codeigniter/database/query_builder/where_test.php @@ -74,7 +74,7 @@ class Where_test extends CI_TestCase { */ public function test_where_custom_string() { - $where = "id > 2 AND name != 'Accountant'"; + $where = "id > 2 AND name !== 'Accountant'"; $jobs = $this->db->where($where) ->get('job') ->result_array(); diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 441c88944..ff2196d4e 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -50,9 +50,9 @@ function autoload($class) elseif (in_array($subclass, $ci_libraries)) { $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR; - $class = ($subclass == 'Driver_Library') ? 'Driver' : $subclass; + $class = ($subclass === 'Driver_Library') ? 'Driver' : $subclass; } - elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) == 3) + elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 3) { $driver_path = BASEPATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; $dir = $driver_path.$m[1].DIRECTORY_SEPARATOR; @@ -77,7 +77,7 @@ function autoload($class) // If the autoload call came from `class_exists` or `file_exists`, // we skipped and return FALSE - if ($trace[2]['function'] == 'class_exists' OR $trace[2]['function'] == 'file_exists') + if ($trace[2]['function'] === 'class_exists' OR $trace[2]['function'] === 'file_exists') { return FALSE; } diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php index e74576626..e1c493aa0 100644 --- a/tests/mocks/core/common.php +++ b/tests/mocks/core/common.php @@ -45,7 +45,7 @@ if ( ! function_exists('load_class')) { function load_class($class, $directory = 'libraries', $prefix = 'CI_') { - if ($directory != 'core' OR $prefix != 'CI_') + if ($directory !== 'core' OR $prefix !== 'CI_') { throw new Exception('Not Implemented: Non-core load_class()'); } -- cgit v1.2.3-24-g4f1b From 2be12da6a443e74fb3f5f64d12c4e0a7164503da Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 15:39:04 +0100 Subject: Fixed bug created in `test_where_custom_string()` in /tests/codeigniter/database/query_builder/where_test.php by d6d1150959c95e43d310d0bc45f8bd674ff6460c --- tests/codeigniter/database/query_builder/where_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php index 6a92c6fce..607eaa076 100644 --- a/tests/codeigniter/database/query_builder/where_test.php +++ b/tests/codeigniter/database/query_builder/where_test.php @@ -74,7 +74,7 @@ class Where_test extends CI_TestCase { */ public function test_where_custom_string() { - $where = "id > 2 AND name !== 'Accountant'"; + $where = "id > 2 AND name != 'Accountant'"; $jobs = $this->db->where($where) ->get('job') ->result_array(); -- cgit v1.2.3-24-g4f1b From 9d533aef135dff9dd3465f993283d6e49a9983a5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 4 Jun 2012 15:56:56 +0300 Subject: Fix an SQLite3 pconnect() bug + other minor changes --- tests/codeigniter/database/query_builder/insert_test.php | 8 ++++---- tests/mocks/database/drivers/sqlite.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 8ba60e242..a9aafb66e 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -26,7 +26,7 @@ class Insert_test extends CI_TestCase { public function test_insert() { $job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!'); - + // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); @@ -45,10 +45,10 @@ class Insert_test extends CI_TestCase { public function test_insert_batch() { $job_datas = array( - array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'), + array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'), array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'), ); - + // Do insert batch except for sqlite driver if (strpos(DB_DRIVER, 'sqlite') === FALSE) { @@ -62,5 +62,5 @@ class Insert_test extends CI_TestCase { $this->assertEquals('Cab Driver', $job_3->name); } } - + } \ No newline at end of file diff --git a/tests/mocks/database/drivers/sqlite.php b/tests/mocks/database/drivers/sqlite.php index 76a182cbf..15cefbf53 100644 --- a/tests/mocks/database/drivers/sqlite.php +++ b/tests/mocks/database/drivers/sqlite.php @@ -1,7 +1,7 @@ Date: Mon, 4 Jun 2012 16:39:19 +0300 Subject: Alter SQLite3's version() method and clear some spaces --- tests/mocks/autoloader.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index ff2196d4e..90aabcbe6 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -7,9 +7,9 @@ // Prototype : // // $mock_table = new Mock_Libraries_Table(); // Will load ./mocks/libraries/table.php -// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php +// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php // and so on... -function autoload($class) +function autoload($class) { $dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR; @@ -75,13 +75,13 @@ function autoload($class) { $trace = debug_backtrace(); - // If the autoload call came from `class_exists` or `file_exists`, + // If the autoload call came from `class_exists` or `file_exists`, // we skipped and return FALSE if ($trace[2]['function'] === 'class_exists' OR $trace[2]['function'] === 'file_exists') { return FALSE; } - + throw new InvalidArgumentException("Unable to load $class."); } -- cgit v1.2.3-24-g4f1b From 407fcc9878f795d18b827cbdfa9a3f8d5c0fa822 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Mon, 4 Jun 2012 11:14:49 -0500 Subject: Added a "non-DB" phpunit.xml for local testing Any developer can use this without having to set up DB's and have PostgreSQL installed by running: phpunit --configuration=tests/phpunit.xml This just skips DB stuff, so code coverage will look lower than it is. --- tests/phpunit.xml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/phpunit.xml (limited to 'tests') diff --git a/tests/phpunit.xml b/tests/phpunit.xml new file mode 100644 index 000000000..56cb8841c --- /dev/null +++ b/tests/phpunit.xml @@ -0,0 +1,25 @@ + + + + + + ./codeigniter/core + ./codeigniter/helpers + ./codeigniter/libraries + + + + + PEAR_INSTALL_DIR + PHP_LIBDIR + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 06c22871943bee956522b893e8acbf206524a229 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Tue, 5 Jun 2012 13:36:13 +0200 Subject: Add test when loading language file and not using the second parameter (language) --- tests/codeigniter/core/Lang_test.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php index a414f0ace..92c71322e 100644 --- a/tests/codeigniter/core/Lang_test.php +++ b/tests/codeigniter/core/Lang_test.php @@ -18,13 +18,21 @@ class Lang_test extends CI_TestCase { public function test_load() { $this->assertTrue($this->lang->load('profiler', 'english')); + $this->_test_line(); + } + + // -------------------------------------------------------------------- + + public function test_load_with_unspecified_language() + { + $this->assertTrue($this->lang->load('profiler')); + $this->_test_line(); } // -------------------------------------------------------------------- - public function test_line() + private function _test_line() { - $this->assertTrue($this->lang->load('profiler', 'english')); $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); } -- cgit v1.2.3-24-g4f1b From d348cb0fd6f255074bc410f169072e2f613074fe Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Tue, 5 Jun 2012 15:32:55 +0200 Subject: remove _test_line() --- tests/codeigniter/core/Lang_test.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php index 92c71322e..874230feb 100644 --- a/tests/codeigniter/core/Lang_test.php +++ b/tests/codeigniter/core/Lang_test.php @@ -18,7 +18,7 @@ class Lang_test extends CI_TestCase { public function test_load() { $this->assertTrue($this->lang->load('profiler', 'english')); - $this->_test_line(); + $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); } // -------------------------------------------------------------------- @@ -26,13 +26,6 @@ class Lang_test extends CI_TestCase { public function test_load_with_unspecified_language() { $this->assertTrue($this->lang->load('profiler')); - $this->_test_line(); - } - - // -------------------------------------------------------------------- - - private function _test_line() - { $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); } -- cgit v1.2.3-24-g4f1b From 83c62ccf881847c5f4eef83822de0f7b09f98491 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 14:26:31 +0200 Subject: add tests for ipv6 and new method ip_version() --- tests/codeigniter/core/Input_test.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index cfc80c950..27e152d6a 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -143,4 +143,31 @@ class Input_test extends CI_TestCase { $this->assertEquals("Hello, i try to your site", $harm); $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless); } + + // -------------------------------------------------------------------- + + public function test_valid_ip() + { + $ip_v4 = '175.123.74.43'; + $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) { + $this->assertTrue($this->input->valid_ip($ip)); + } + } + + // -------------------------------------------------------------------- + + public function test_ip_version() + { + $ip_v4 = '175.123.74.43'; + $this->assertEquals('4', $this->input->ip_version($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) { + $this->assertEquals('6', $this->input->ip_version($ip)); + } + } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0723617703dda3660597d9cdef59e7cdded1c497 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 14:39:02 +0200 Subject: follow styling guide --- tests/codeigniter/core/Input_test.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 27e152d6a..2aa3a6246 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -152,7 +152,8 @@ class Input_test extends CI_TestCase { $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)); } } @@ -165,7 +166,8 @@ class Input_test extends CI_TestCase { $this->assertEquals('4', $this->input->ip_version($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->assertEquals('6', $this->input->ip_version($ip)); } } -- cgit v1.2.3-24-g4f1b From 5ace440aa4dbd948191c37b67b01871b3a7593e9 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 14:52:15 +0200 Subject: change ellipsizing to ellipsize --- tests/codeigniter/helpers/text_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 584066b0c..a83c7e74d 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -122,7 +122,7 @@ class Text_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ - public function test_ellipsizing() + public function test_ellipsize() { $strs = array( '0' => array( -- cgit v1.2.3-24-g4f1b From 0ef92f6fa4a40d4a689eee3ebd7eb7d632fe29c0 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:12:37 +0200 Subject: test for word_wrap() --- tests/codeigniter/helpers/text_helper_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index a83c7e74d..974247c4f 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -156,4 +156,12 @@ class Text_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ + public function test_word_wrap() + { + $string = "Here is a simple string of text that will help us demonstrate this function."; + $word_wraped = word_wrap($string, 25); + preg_match_all("/\r\n|\n/", $word_wraped, $matches); + $this->assertEquals(count($matches[0]), 4); + } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4221b980b66bbaebc23a0f9cc5dee7d649948e15 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:38:35 +0200 Subject: add test for word_wrap default charlim --- tests/codeigniter/helpers/text_helper_test.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 974247c4f..d59b2743d 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -160,8 +160,17 @@ class Text_helper_test extends CI_TestCase { { $string = "Here is a simple string of text that will help us demonstrate this function."; $word_wraped = word_wrap($string, 25); - preg_match_all("/\r\n|\n/", $word_wraped, $matches); - $this->assertEquals(count($matches[0]), 4); + $this->assertEquals(substr_count($word_wraped, "\n"), 4); + } + + // ------------------------------------------------------------------------ + + public function test_default_word_wrap_charlim() + { + $string = "Here is a simple string of text that will help us demonstrate this function."; + $word_wraped = word_wrap($string); + $matches = preg_split("/\n/", $word_wraped, 1); + $this->assertEquals(strlen($matches[0]) - 1, 76); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From bfaf50258b6f33961210ecc3df4ade2e0a4512b4 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:39:45 +0200 Subject: typo word_wraped -> word_wrapped --- tests/codeigniter/helpers/text_helper_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index d59b2743d..3bc83f050 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -159,8 +159,8 @@ class Text_helper_test extends CI_TestCase { public function test_word_wrap() { $string = "Here is a simple string of text that will help us demonstrate this function."; - $word_wraped = word_wrap($string, 25); - $this->assertEquals(substr_count($word_wraped, "\n"), 4); + $word_wrapped = word_wrap($string, 25); + $this->assertEquals(substr_count($word_wrapped, "\n"), 4); } // ------------------------------------------------------------------------ @@ -168,8 +168,8 @@ class Text_helper_test extends CI_TestCase { public function test_default_word_wrap_charlim() { $string = "Here is a simple string of text that will help us demonstrate this function."; - $word_wraped = word_wrap($string); - $matches = preg_split("/\n/", $word_wraped, 1); + $word_wrapped = word_wrap($string); + $matches = preg_split("/\n/", $word_wrapped, 1); $this->assertEquals(strlen($matches[0]) - 1, 76); } -- cgit v1.2.3-24-g4f1b From 385452c2ca1f9ce00668ca6d77c6fd0ad1ea4771 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:43:18 +0200 Subject: correction of the test and longer test string --- tests/codeigniter/helpers/text_helper_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 3bc83f050..3c590538a 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -167,10 +167,10 @@ class Text_helper_test extends CI_TestCase { public function test_default_word_wrap_charlim() { - $string = "Here is a simple string of text that will help us demonstrate this function."; + $string = "Here is a longer string of text that will help us demonstrate the default charlim of this function."; $word_wrapped = word_wrap($string); - $matches = preg_split("/\n/", $word_wrapped, 1); - $this->assertEquals(strlen($matches[0]) - 1, 76); + $matches = preg_split("/\n/", $word_wrapped, 0); + $this->assertEquals(strlen($matches[0]), 73); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 908f36a583384b0314d04c4cfe71992746e35daa Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:47:22 +0200 Subject: ip_version() now returns int instead of string --- tests/codeigniter/core/Input_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 2aa3a6246..98d6299f8 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -163,12 +163,12 @@ class Input_test extends CI_TestCase { public function test_ip_version() { $ip_v4 = '175.123.74.43'; - $this->assertEquals('4', $this->input->ip_version($ip_v4)); + $this->assertEquals(4, $this->input->ip_version($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) { - $this->assertEquals('6', $this->input->ip_version($ip)); + $this->assertEquals(6, $this->input->ip_version($ip)); } } -- cgit v1.2.3-24-g4f1b From 4215ddccd369ae8894c1031b97a344ae76eef5f6 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:58:28 +0200 Subject: remove regex in favor of strpos --- tests/codeigniter/helpers/text_helper_test.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 3c590538a..73e2b9429 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -169,8 +169,7 @@ class Text_helper_test extends CI_TestCase { { $string = "Here is a longer string of text that will help us demonstrate the default charlim of this function."; $word_wrapped = word_wrap($string); - $matches = preg_split("/\n/", $word_wrapped, 0); - $this->assertEquals(strlen($matches[0]), 73); + $this->assertEquals(strpos($word_wrapped, "\n"), 73); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 70b5d3b4eb74ad27da7eac29ef5d349be944ba15 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 18:22:36 +0200 Subject: use an ip of the range 192.18.0.0/15 --- tests/codeigniter/core/Input_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 98d6299f8..3682d308d 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -148,7 +148,7 @@ class Input_test extends CI_TestCase { public function test_valid_ip() { - $ip_v4 = '175.123.74.43'; + $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'); @@ -162,7 +162,7 @@ class Input_test extends CI_TestCase { public function test_ip_version() { - $ip_v4 = '175.123.74.43'; + $ip_v4 = '192.18.0.1'; $this->assertEquals(4, $this->input->ip_version($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'); -- cgit v1.2.3-24-g4f1b From 1ab6f6520ebfc016c49cfbe3a4d9d009be5da268 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 20:14:13 +0200 Subject: removed ip_version() --- tests/codeigniter/core/Input_test.php | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 3682d308d..c9322c027 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -158,18 +158,4 @@ class Input_test extends CI_TestCase { } } - // -------------------------------------------------------------------- - - public function test_ip_version() - { - $ip_v4 = '192.18.0.1'; - $this->assertEquals(4, $this->input->ip_version($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) - { - $this->assertEquals(6, $this->input->ip_version($ip)); - } - } - } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9d1407523ae585d45171b54123ba29c0ec831f79 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 01:40:18 +0200 Subject: tests for encryption class --- tests/codeigniter/libraries/Encrypt_test.php | 71 ++++++++++++++++++++++++++++ tests/mocks/libraries/encrypt.php | 15 ++++++ 2 files changed, 86 insertions(+) create mode 100644 tests/codeigniter/libraries/Encrypt_test.php create mode 100644 tests/mocks/libraries/encrypt.php (limited to 'tests') diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php new file mode 100644 index 000000000..066990186 --- /dev/null +++ b/tests/codeigniter/libraries/Encrypt_test.php @@ -0,0 +1,71 @@ +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/mocks/libraries/encrypt.php b/tests/mocks/libraries/encrypt.php new file mode 100644 index 000000000..a9bbaafdc --- /dev/null +++ b/tests/mocks/libraries/encrypt.php @@ -0,0 +1,15 @@ + Date: Thu, 7 Jun 2012 23:40:33 +0200 Subject: update vfsStream pear url --- tests/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index c8fc608e8..d600951ee 100644 --- a/tests/README.md +++ b/tests/README.md @@ -21,8 +21,8 @@ PHP Unit >= 3.5.6 vfsStream - pear channel-discover pear.php-tools.net - pear install pat/vfsStream-alpha + pear channel-discover pear.bovigo.org + pear install bovigo/vfsStream-beta #### Installation of PEAR and PHPUnit on Ubuntu @@ -37,11 +37,11 @@ vfsStream pear channel-discover pear.phpunit.de pear channel-discover pear.symfony-project.com pear channel-discover components.ez.no - pear channel-discover pear.php-tools.net + pear channel-discover pear.bovigo.org # Finally install PHPUnit and vfsStream (including dependencies) pear install --alldeps phpunit/PHPUnit - pear install --alldeps pat/vfsStream-alpha + pear install --alldeps bovigo/vfsStream-beta # Finally, run 'phpunit' from within the ./tests directory # and you should be on your way! -- cgit v1.2.3-24-g4f1b From 1b60fda70ff1e1801c133575c530ef0a5a450029 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 9 Jun 2012 21:07:40 +0300 Subject: Modified date helper tests for better accuracy --- tests/codeigniter/helpers/date_helper_test.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 17d1ef21e..df03fe32c 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -16,13 +16,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,7 +32,7 @@ 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); @@ -204,8 +202,7 @@ class Date_helper_test extends CI_TestCase { public function test_mysql_to_unix() { $time = time(); - $this->assertEquals($time, - mysql_to_unix(date("Y-m-d H:i:s", $time))); + $this->assertEquals($time, mysql_to_unix(date("Y-m-d H:i:s", $time))); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 99b782d8a3d92c4703a059cbd62e2f1e6fea689c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 9 Jun 2012 22:24:46 +0300 Subject: Cleanup and optimize helper tests for speed --- tests/codeigniter/helpers/array_helper_test.php | 22 ++-- tests/codeigniter/helpers/date_helper_test.php | 127 +++++++++--------- .../codeigniter/helpers/directory_helper_test.php | 47 ++++--- tests/codeigniter/helpers/email_helper_test.php | 2 +- tests/codeigniter/helpers/file_helper_test.php | 143 ++++++++++----------- tests/codeigniter/helpers/form_helper_test.php | 112 ++++++++-------- tests/codeigniter/helpers/html_helper_test.php | 28 ++-- .../codeigniter/helpers/inflector_helper_test.php | 31 ++--- tests/codeigniter/helpers/number_helper_test.php | 35 +++-- tests/codeigniter/helpers/path_helper_test.php | 5 +- tests/codeigniter/helpers/string_helper_test.php | 9 +- tests/codeigniter/helpers/text_helper_test.php | 70 +++++----- tests/codeigniter/helpers/url_helper_test.php | 1 + tests/codeigniter/helpers/xml_helper_test.php | 4 +- 14 files changed, 317 insertions(+), 319 deletions(-) (limited to 'tests') 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 @@ 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 df03fe32c..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(); } // ------------------------------------------------------------------------ @@ -37,119 +39,120 @@ class Date_helper_test extends CI_TestCase { $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) + ); } // ------------------------------------------------------------------------ @@ -181,38 +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')); } // ------------------------------------------------------------------------ @@ -220,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()); } @@ -280,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 @@ 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; - + $this->assertEquals($expected, form_hidden('username', 'johndoe')); } - + public function test_form_input() { $expected = << 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; - + $this->assertEquals($expected, form_password('password')); } - + public function test_form_upload() - { + { $expected = << EOH; - + $this->assertEquals($expected, form_upload('attachment')); } - + public function test_form_textarea() - { + { $expected = <<Notes EOH; - + $this->assertEquals($expected, form_textarea('notes', 'Notes')); } - + public function test_form_dropdown() { $expected = << 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 = << @@ -95,22 +95,22 @@ EOH; 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 = << @@ -124,13 +124,10 @@ EOH; 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; - + $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 = <<Address Information EOH; - + $this->assertEquals($expected, form_fieldset('Address Information')); } @@ -169,10 +166,10 @@ EOH; $expected = << EOH; - + $this->assertEquals($expected, form_fieldset_close('')); } - + public function test_form_checkbox() { $expected = <<assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE)); } - + public function test_form_radio() { $expected = <<assertEquals($expected, form_radio('newsletter', 'accept', TRUE)); } - + public function test_form_submit() { $expected = <<assertEquals($expected, form_submit('mysubmit', 'Submit Post!')); } - + public function test_form_label() { $expected = <<assertEquals($expected, form_label('What is your Name', 'username')); } - + public function test_form_reset() { $expected = <<assertEquals($expected, form_reset('myreset', 'Reset')); } - + public function test_form_button() { $expected = <<assertEquals($expected, form_button('name','content')); + $this->assertEquals($expected, form_button('name', 'content')); } - + public function test_form_close() { $expected = <<assertEquals($expected, form_close('')); } - + public function test_form_prep() { - $expected = "Here is a string containing "quoted" text."; - + $expected = 'Here is a string containing "quoted" 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(2)); } - + // ------------------------------------------------------------------------ - + public function test_heading() { $this->assertEquals('

foobar

', heading('foobar')); @@ -23,7 +23,7 @@ class Html_helper_test extends CI_TestCase { } // ------------------------------------------------------------------------ - + public function test_Ul() { $expect = <<assertEquals($expect, ul($list)); + $this->assertEquals(ltrim($expect), ul($list)); $expect = << @@ -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("\n", meta('test', 'foo')); - + $expect = "\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 @@ 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..23d5c5c1a 100644 --- a/tests/codeigniter/helpers/number_helper_test.php +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -1,35 +1,35 @@ 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->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,…', 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…', 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”' => '“‘ “test”', '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' ); - + 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 { '“‘ “test”' => '“‘ “test”', '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' ); - + 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 = ''; $expect = "\n<?php var_dump(\$this); ?> \n\n"; - $this->assertEquals($expect, highlight_code($code)); + $this->assertEquals($expect, highlight_code('')); } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ 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 this is', '' => '' ); - + 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('<tag>my & test - </tag>', xml_convert('my & test - ')); } - + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c186288755aba46a2b6f0c3f104d9a6ce6b11a7f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 9 Jun 2012 23:16:58 +0300 Subject: Cleanup/optimize tests/codeigniter/ --- tests/codeigniter/Setup_test.php | 6 +- tests/codeigniter/core/Benchmark_test.php | 11 +- tests/codeigniter/core/Common_test.php | 6 +- tests/codeigniter/core/Config_test.php | 38 ++-- tests/codeigniter/core/Input_test.php | 28 +-- tests/codeigniter/core/Lang_test.php | 12 +- tests/codeigniter/core/Loader_test.php | 132 ++++++------ tests/codeigniter/core/Security_test.php | 23 ++- tests/codeigniter/core/URI_test.php | 225 +++++++++------------ .../database/query_builder/count_test.php | 12 +- .../database/query_builder/delete_test.php | 16 +- .../database/query_builder/distinct_test.php | 9 +- .../database/query_builder/escape_test.php | 5 +- .../database/query_builder/from_test.php | 18 +- .../database/query_builder/get_test.php | 6 +- .../database/query_builder/group_test.php | 26 ++- .../database/query_builder/join_test.php | 2 +- .../database/query_builder/like_test.php | 2 +- .../database/query_builder/limit_test.php | 7 +- .../database/query_builder/order_test.php | 6 +- .../database/query_builder/select_test.php | 12 +- .../database/query_builder/truncate_test.php | 7 +- .../database/query_builder/update_test.php | 26 +-- .../database/query_builder/where_test.php | 28 +-- tests/codeigniter/helpers/number_helper_test.php | 2 +- tests/codeigniter/libraries/Encrypt_test.php | 131 ++++++------ tests/codeigniter/libraries/Parser_test.php | 61 +++--- tests/codeigniter/libraries/Table_test.php | 153 ++++++-------- tests/codeigniter/libraries/Typography_test.php | 40 ++-- tests/codeigniter/libraries/Useragent_test.php | 6 +- 30 files changed, 463 insertions(+), 593 deletions(-) (limited to 'tests') 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 = '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 = '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. '; - $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 @@ 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 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 = '<div>Hello <b>Booya</b></div>'; @@ -94,7 +94,7 @@ class Security_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_sanitize_filename() { $filename = './'; @@ -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 @@ 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, '$destroy_app(foo)'); } // -------------------------------------------------------------------- - 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/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php index 23d5c5c1a..ef6aae138 100644 --- a/tests/codeigniter/helpers/number_helper_test.php +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -25,7 +25,7 @@ class Number_helper_test extends CI_TestCase { // 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); } 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 @@ 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' => '')); $this->table->compile_template(); - + $this->assertArrayHasKey('table_close', $this->table->template); $this->assertEquals('', $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   $this->assertEquals( array( array('Laura', 'Red', '15'), - array('Katie', 'Blue', ' ') + array('Katie', 'Blue', ' ') ), $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, 'Blue') !== FALSE); $this->assertTrue(strpos($table, 'Small') !== 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…bar.', 'test. new' => 'test.  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 = << 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 = "

This has way too many linebreaks.

\n\n

See?

"; - + $this->assertEquals($expect, $this->type->auto_typography($str, TRUE)); } @@ -141,7 +140,7 @@ EOH; { $str = ' But no!'; $expect = '

  But no!

'; - + $this->assertEquals($expect, $this->type->auto_typography($str)); } @@ -151,7 +150,7 @@ EOH; { $str = '

My Sentence

var_dump($this);
'; $expect = '

My Sentence

var_dump($this);
'; - + $this->assertEquals($expect, $this->type->auto_typography($str)); } @@ -161,7 +160,7 @@ EOH; { $str = 'My Sentence
var_dump($this);
'; $expect = '

My Sentence

var_dump($this);
'; - + $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 = '

Test {parse="foobar"}

'; - + $this->assertEquals($expect, $this->type->auto_typography($str)); $this->type->protect_braced_quotes = FALSE; - + $str = 'Test {parse="foobar"}'; $expect = '

Test {parse=“foobar”}

'; - - $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 @@ _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 -- cgit v1.2.3-24-g4f1b From f243ce13b4baf5bf8bebf36586514bb243dfc355 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 9 Jun 2012 23:34:21 +0300 Subject: Cleanup/optimize tests/mocks/ --- tests/mocks/autoloader.php | 4 +- tests/mocks/ci_testcase.php | 84 +++++++++++++++--------------- tests/mocks/core/common.php | 36 ++++++------- tests/mocks/core/input.php | 6 +-- tests/mocks/core/loader.php | 7 +-- tests/mocks/core/security.php | 2 +- tests/mocks/core/uri.php | 9 ++-- tests/mocks/core/utf8.php | 11 ++-- tests/mocks/database/config/mysql.php | 10 ++-- tests/mocks/database/config/pdo/mysql.php | 12 ++--- tests/mocks/database/config/pdo/pgsql.php | 12 ++--- tests/mocks/database/config/pdo/sqlite.php | 12 ++--- tests/mocks/database/config/pgsql.php | 10 ++-- tests/mocks/database/config/sqlite.php | 10 ++-- tests/mocks/database/db.php | 18 +++---- tests/mocks/database/db/driver.php | 7 ++- tests/mocks/database/db/querybuilder.php | 9 +--- tests/mocks/database/drivers/mysql.php | 9 ++-- tests/mocks/database/drivers/pdo.php | 8 +-- tests/mocks/database/drivers/postgre.php | 9 ++-- tests/mocks/database/drivers/sqlite.php | 7 +-- tests/mocks/database/schema/skeleton.php | 48 ++++++++--------- tests/mocks/libraries/encrypt.php | 21 ++++---- tests/mocks/libraries/table.php | 3 +- 24 files changed, 180 insertions(+), 184 deletions(-) (limited to 'tests') 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 @@ '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..8466e47f8 100644 --- a/tests/mocks/core/common.php +++ b/tests/mocks/core/common.php @@ -4,11 +4,10 @@ if ( ! function_exists('get_instance')) { - function &get_instance() + function &get_instance() { $test = CI_TestCase::instance(); - $instance = $test->ci_instance(); - return $instance; + return $test->ci_instance(); } } @@ -16,11 +15,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; + return $test->ci_get_config(); } } @@ -29,12 +27,12 @@ if ( ! function_exists('config_item')) function config_item($item) { $config =& get_config(); - + if ( ! isset($config[$item])) { return FALSE; } - + return $config[$item]; } } @@ -49,16 +47,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 +72,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 +164,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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ Date: Sun, 10 Jun 2012 07:11:41 +0300 Subject: Revert a change in tests/mocks/core/common.php --- tests/mocks/core/common.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php index 8466e47f8..55506a1f6 100644 --- a/tests/mocks/core/common.php +++ b/tests/mocks/core/common.php @@ -18,7 +18,8 @@ if ( ! function_exists('get_config')) function &get_config() { $test = CI_TestCase::instance(); - return $test->ci_get_config(); + $config = $test->ci_get_config(); + return $config; } } -- cgit v1.2.3-24-g4f1b From 36de42e4a6c1ef552be8b7b3cb0fb86a4363c7d6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 10 Jun 2012 13:55:55 +0300 Subject: Revert a change in tests/mocks/core/common.php --- tests/mocks/core/common.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php index 55506a1f6..a655ee1db 100644 --- a/tests/mocks/core/common.php +++ b/tests/mocks/core/common.php @@ -7,7 +7,8 @@ if ( ! function_exists('get_instance')) function &get_instance() { $test = CI_TestCase::instance(); - return $test->ci_instance(); + $test = $test->ci_instance(); + return $test; } } -- cgit v1.2.3-24-g4f1b From 43cfd0c37ca241618f33eae87fec720a5bcf13d6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 11:18:26 +0300 Subject: Comment out _set_uri_string() test as it is no longer callable from outside the class --- tests/codeigniter/core/URI_test.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php index 0ba694b46..60ed1a4e9 100644 --- a/tests/codeigniter/core/URI_test.php +++ b/tests/codeigniter/core/URI_test.php @@ -9,6 +9,10 @@ class URI_test extends CI_TestCase { // -------------------------------------------------------------------- + /* As of the following commit, _set_uri_string() is a protected method: + + https://github.com/EllisLab/CodeIgniter/commit/d461934184d95b0cfb2feec93f27b621ef72a5c2 + public function test_set_uri_string() { // Slashes get killed @@ -18,6 +22,7 @@ class URI_test extends CI_TestCase { $this->uri->_set_uri_string('nice/uri'); $this->assertEquals('nice/uri', $this->uri->uri_string); } + */ // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e1c8ee76f4756442094106320d9577c2c7595959 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 11:35:11 +0300 Subject: Alter now() tests --- tests/codeigniter/helpers/date_helper_test.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 4b747b864..bcb1477bc 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -13,6 +13,8 @@ class Date_helper_test extends CI_TestCase { public function test_now_local() { + /* + // This stub job, is simply to cater $config['time_reference'] $config = $this->getMock('CI_Config'); $config->expects($this->any()) @@ -22,6 +24,10 @@ class Date_helper_test extends CI_TestCase { // Add the stub to our test instance $this->ci_instance_var('config', $config); + */ + + $this->ci_set_config('time_reference', 'local'); + $this->assertEquals(time(), now()); } @@ -29,6 +35,8 @@ class Date_helper_test extends CI_TestCase { public function test_now_gmt() { + /* + // This stub job, is simply to cater $config['time_reference'] $config = $this->getMock('CI_Config'); $config->expects($this->any()) @@ -38,6 +46,10 @@ class Date_helper_test extends CI_TestCase { // Add the stub to our stdClass $this->ci_instance_var('config', $config); + */ + + $this->ci_set_config('time_reference', 'gmt'); + $t = time(); $this->assertEquals( mktime(gmdate('H', $t), gmdate('i', $t), gmdate('s', $t), gmdate('m', $t), gmdate('d', $t), gmdate('Y', $t)), -- cgit v1.2.3-24-g4f1b From 0ddff314d619e5d24bdf07f3da33c779f5b6e2c0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 13:18:07 +0300 Subject: test_now_gmt() -> test_now_utc() --- tests/codeigniter/helpers/date_helper_test.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index bcb1477bc..242935116 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -33,7 +33,7 @@ class Date_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ - public function test_now_gmt() + public function test_now_utc() { /* @@ -41,18 +41,17 @@ class Date_helper_test extends CI_TestCase { $config = $this->getMock('CI_Config'); $config->expects($this->any()) ->method('item') - ->will($this->returnValue('gmt')); + ->will($this->returnValue('UTC')); // Add the stub to our stdClass $this->ci_instance_var('config', $config); */ - $this->ci_set_config('time_reference', 'gmt'); + $this->ci_set_config('time_reference', 'UTC'); - $t = time(); $this->assertEquals( - mktime(gmdate('H', $t), gmdate('i', $t), gmdate('s', $t), gmdate('m', $t), gmdate('d', $t), gmdate('Y', $t)), + gmmktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y')), now() ); } -- cgit v1.2.3-24-g4f1b From 3ed533109309326a858c778dfea5cb9186f965b4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 13:21:07 +0300 Subject: Some optimizations to the date helper tests --- tests/codeigniter/helpers/date_helper_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 242935116..1d397ac81 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -51,7 +51,7 @@ class Date_helper_test extends CI_TestCase { $this->ci_set_config('time_reference', 'UTC'); $this->assertEquals( - gmmktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y')), + gmmktime(date('G'), date('i'), date('s'), date('n'), date('j'), date('Y')), now() ); } @@ -196,9 +196,9 @@ class Date_helper_test extends CI_TestCase { public function test_local_to_gmt() { $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) + gmmktime( + date('G', $this->time), date('i', $this->time), date('s', $this->time), + date('n', $this->time), date('j', $this->time), date('Y', $this->time) ), local_to_gmt($this->time) ); -- cgit v1.2.3-24-g4f1b From b089e15b1510de6b6a034631c80d3d5e830ff9f3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 16 Jun 2012 19:11:40 +0300 Subject: Fix local_to_gmt() --- tests/codeigniter/helpers/date_helper_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 1d397ac81..8258c9248 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -196,9 +196,9 @@ class Date_helper_test extends CI_TestCase { public function test_local_to_gmt() { $this->assertEquals( - gmmktime( - date('G', $this->time), date('i', $this->time), date('s', $this->time), - date('n', $this->time), date('j', $this->time), date('Y', $this->time) + mktime( + gmdate('G', $this->time), gmdate('i', $this->time), gmdate('s', $this->time), + gmdate('n', $this->time), gmdate('j', $this->time), gmdate('Y', $this->time) ), local_to_gmt($this->time) ); -- cgit v1.2.3-24-g4f1b From a84055b49539da1faa2893618b2475d1888a9fea Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 20 Jun 2012 14:37:59 +0300 Subject: Fix issue #1510 --- tests/codeigniter/helpers/date_helper_test.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 8258c9248..4e01b1aa3 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -48,11 +48,9 @@ class Date_helper_test extends CI_TestCase { */ - $this->ci_set_config('time_reference', 'UTC'); - $this->assertEquals( - gmmktime(date('G'), date('i'), date('s'), date('n'), date('j'), date('Y')), - now() + mktime(gmdate('G'), gmdate('i'), gmdate('s'), gmdate('n'), gmdate('j'), gmdate('Y')), + now('UTC') ); } -- cgit v1.2.3-24-g4f1b From fbba54ea6c896e0545d4d20a19abe06d57ffc97b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 23 Jun 2012 20:26:31 +0300 Subject: Rename pdodriver property to subdriver and make it available to all drivers --- tests/mocks/database/config/pdo/mysql.php | 6 +++--- tests/mocks/database/config/pdo/pgsql.php | 6 +++--- tests/mocks/database/config/pdo/sqlite.php | 6 +++--- tests/mocks/database/db.php | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/mocks/database/config/pdo/mysql.php b/tests/mocks/database/config/pdo/mysql.php index fefe0d624..97ea24b65 100644 --- a/tests/mocks/database/config/pdo/mysql.php +++ b/tests/mocks/database/config/pdo/mysql.php @@ -10,7 +10,7 @@ return array( 'password' => '', 'database' => 'ci_test', 'dbdriver' => 'pdo', - 'pdodriver' => 'mysql' + 'subdriver' => 'mysql' ), // Database configuration with failover @@ -21,7 +21,7 @@ return array( 'password' => 'wrong password', 'database' => 'not_ci_test', 'dbdriver' => 'pdo', - 'pdodriver' => 'mysql', + 'subdriver' => 'mysql', 'failover' => array( array( 'dsn' => '', @@ -30,7 +30,7 @@ return array( 'password' => '', 'database' => 'ci_test', 'dbdriver' => 'pdo', - 'pdodriver' => 'mysql' + 'subdriver' => 'mysql' ) ) ) diff --git a/tests/mocks/database/config/pdo/pgsql.php b/tests/mocks/database/config/pdo/pgsql.php index ddd638c8a..e55e3ea77 100644 --- a/tests/mocks/database/config/pdo/pgsql.php +++ b/tests/mocks/database/config/pdo/pgsql.php @@ -10,7 +10,7 @@ return array( 'password' => '', 'database' => 'ci_test', 'dbdriver' => 'pdo', - 'pdodriver' => 'pgsql' + 'subdriver' => 'pgsql' ), // Database configuration with failover @@ -21,7 +21,7 @@ return array( 'password' => 'wrong password', 'database' => 'not_ci_test', 'dbdriver' => 'pdo', - 'pdodriver' => 'pgsql', + 'subdriver' => 'pgsql', 'failover' => array( array( 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;', @@ -30,7 +30,7 @@ return array( 'password' => '', 'database' => 'ci_test', 'dbdriver' => 'pdo', - 'pdodriver' => 'pgsql' + 'subdriver' => 'pgsql' ) ) ) diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php index 36461843d..1bf56b3ac 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' + 'subdriver' => 'sqlite' ), // Database configuration with failover @@ -21,7 +21,7 @@ return array( 'password' => 'sqlite', 'database' => 'sqlite', 'dbdriver' => 'pdo', - 'pdodriver' => 'sqlite', + 'subdriver' => 'sqlite', 'failover' => array( array( 'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite', @@ -30,7 +30,7 @@ return array( 'password' => 'sqlite', 'database' => 'sqlite', 'dbdriver' => 'pdo', - 'pdodriver' => 'sqlite' + 'subdriver' => 'sqlite' ) ) ) diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php index 30504bba6..75658530b 100644 --- a/tests/mocks/database/db.php +++ b/tests/mocks/database/db.php @@ -45,9 +45,9 @@ class Mock_Database_DB { ); $config = array_merge($this->config[$group], $params); - $dsnstring = ( ! empty($config['dsn'])) ? $config['dsn'] : FALSE; - $pdodriver = ( ! empty($config['pdodriver'])) ? $config['pdodriver'] : FALSE; - $failover = ( ! empty($config['failover'])) ? $config['failover'] : FALSE; + $dsnstring = empty($config['dsn']) ? FALSE : $config['dsn']; + $subdriver = empty($config['subdriver']) ? FALSE: $config['subdriver']; + $failover = empty($config['failover']) ? FALSE : $config['failover']; $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password'] .'@'.$config['hostname'].'/'.$config['database']; @@ -55,7 +55,7 @@ class Mock_Database_DB { // Build the parameter $other_params = array_slice($config, 6); if ($dsnstring) $other_params['dsn'] = $dsnstring; - if ($pdodriver) $other_params['pdodriver'] = $pdodriver; + if ($subdriver) $other_params['subdriver'] = $subdriver; if ($failover) $other_params['failover'] = $failover; return $dsn.'?'.http_build_query($other_params); -- cgit v1.2.3-24-g4f1b From 0bb13811397a730444437702bbc1b01a29c27a46 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 26 Jun 2012 00:44:42 +0300 Subject: Work-around for a failover test (currently DSNs are only built on class initialization) --- tests/mocks/database/config/pdo/mysql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mocks/database/config/pdo/mysql.php b/tests/mocks/database/config/pdo/mysql.php index 97ea24b65..38f822fd7 100644 --- a/tests/mocks/database/config/pdo/mysql.php +++ b/tests/mocks/database/config/pdo/mysql.php @@ -24,7 +24,7 @@ return array( 'subdriver' => 'mysql', 'failover' => array( array( - 'dsn' => '', + 'dsn' => 'mysql:host=localhost;dbname=ci_test', 'hostname' => 'localhost', 'username' => 'travis', 'password' => '', -- cgit v1.2.3-24-g4f1b From cbd78d826b965ad6dfc953686594749cbdf21af3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 26 Jun 2012 01:03:34 +0300 Subject: Alter test pdo/mysql config --- tests/mocks/database/config/pdo/mysql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mocks/database/config/pdo/mysql.php b/tests/mocks/database/config/pdo/mysql.php index 38f822fd7..96608f787 100644 --- a/tests/mocks/database/config/pdo/mysql.php +++ b/tests/mocks/database/config/pdo/mysql.php @@ -4,7 +4,7 @@ return array( // Typical Database configuration 'pdo/mysql' => array( - 'dsn' => '', + 'dsn' => 'mysql:host=localhost;dbname=ci_test', 'hostname' => 'localhost', 'username' => 'travis', 'password' => '', -- cgit v1.2.3-24-g4f1b From b8b7dbe7a459c3fe705ca0da8600c1a8544b27cc Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 27 Jun 2012 03:05:35 +0700 Subject: Allow extra SPL autoloader --- tests/mocks/autoloader.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index e3ff7a8bd..1fcba788f 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -69,20 +69,25 @@ function autoload($class) } } - $file = isset($file) ? $file : $dir.$class.'.php'; + $file = (isset($file)) ? $file : $dir.$class.'.php'; if ( ! file_exists($file)) { $trace = debug_backtrace(); - // If the autoload call came from `class_exists` or `file_exists`, - // we skipped and return FALSE if ($trace[2]['function'] === 'class_exists' OR $trace[2]['function'] === 'file_exists') { + // If the autoload call came from `class_exists` or `file_exists`, + // we skipped and return FALSE + return FALSE; + } + elseif (($autoloader = spl_autoload_functions()) && end($autoloader) !== __FUNCTION__) + { + // If there was other custom autoloader, passed away return FALSE; } - throw new InvalidArgumentException("Unable to load {$class}."); + throw new InvalidArgumentException("Unable to load $class."); } include_once($file); -- cgit v1.2.3-24-g4f1b From eb22d544c4ea1993fcbdad0404ce9ec65d0410be Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 26 Jun 2012 23:16:35 +0300 Subject: Fix get_where() test --- tests/codeigniter/database/query_builder/get_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php index 699d2906a..156027537 100644 --- a/tests/codeigniter/database/query_builder/get_test.php +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -41,7 +41,7 @@ class Get_test extends CI_TestCase { */ public function test_get_where() { - $job1 = $this->db->get('job', array('id' => 1))->result_array(); + $job1 = $this->db->get_where('job', array('id' => 1))->result_array(); // Dummy jobs contain 1 rows $this->assertCount(1, $job1); -- cgit v1.2.3-24-g4f1b From 8f490da4cb6ad4ffa2c75cfcbd0e7896cdb4cd8c Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 27 Jun 2012 03:31:22 +0700 Subject: Comply styleguide --- tests/mocks/autoloader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 1fcba788f..be1c2220c 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -87,7 +87,7 @@ function autoload($class) return FALSE; } - throw new InvalidArgumentException("Unable to load $class."); + throw new InvalidArgumentException("Unable to load {$class}."); } include_once($file); -- cgit v1.2.3-24-g4f1b From 5211c094c930d69d52539591b306c293c99689ad Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 2 Jul 2012 16:47:12 +0300 Subject: Fix standard_date() tests --- tests/codeigniter/helpers/date_helper_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 4e01b1aa3..eaf4cf8a5 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -79,7 +79,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_atom() { $this->assertEquals( - date("Y-m-d\TH:i:sO", $this->time), + date('Y-m-d\TH:i:sP', $this->time), standard_date('DATE_ATOM', $this->time) ); } @@ -99,7 +99,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_iso8601() { $this->assertEquals( - date("Y-m-d\TH:i:sO", $this->time), + date('Y-m-d\TH:i:sP', $this->time), standard_date('DATE_ISO8601', $this->time) ); } @@ -139,7 +139,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc2822() { $this->assertEquals( - date('D, d M Y H:i:s O', $this->time), + date('r', $this->time), standard_date('DATE_RFC2822', $this->time) ); } @@ -159,7 +159,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_w3c() { $this->assertEquals( - date("Y-m-d\TH:i:sO", $this->time), + date('Y-m-d\TH:i:sP', $this->time), standard_date('DATE_W3C', $this->time) ); } -- cgit v1.2.3-24-g4f1b From dd6f32b3b506d29da38f41d307e5ea217c21cb51 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 4 Jul 2012 10:08:54 +0300 Subject: Optimize standard_date() --- tests/codeigniter/helpers/date_helper_test.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index eaf4cf8a5..1b79b9480 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -69,7 +69,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc822() { $this->assertEquals( - date('D, d M y H:i:s O', $this->time), + date(DATE_RFC822, $this->time), standard_date('DATE_RFC822', $this->time) ); } @@ -79,7 +79,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_atom() { $this->assertEquals( - date('Y-m-d\TH:i:sP', $this->time), + date(DATE_ATOM, $this->time), standard_date('DATE_ATOM', $this->time) ); } @@ -89,7 +89,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_cookie() { $this->assertEquals( - date("l, d-M-y H:i:s \U\T\C", $this->time), + date(DATE_COOKIE, $this->time), standard_date('DATE_COOKIE', $this->time) ); } @@ -99,7 +99,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_iso8601() { $this->assertEquals( - date('Y-m-d\TH:i:sP', $this->time), + date(DATE_ISO8601, $this->time), standard_date('DATE_ISO8601', $this->time) ); } @@ -109,7 +109,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc850() { $this->assertEquals( - date("l, d-M-y H:i:s \U\T\C", $this->time), + date(DATE_RFC850, $this->time), standard_date('DATE_RFC850', $this->time) ); } @@ -119,7 +119,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc1036() { $this->assertEquals( - date('D, d M y H:i:s O', $this->time), + date(DATE_RFC1036, $this->time), standard_date('DATE_RFC1036', $this->time) ); } @@ -129,7 +129,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc1123() { $this->assertEquals( - date('D, d M Y H:i:s O', $this->time), + date(DATE_RFC1123, $this->time), standard_date('DATE_RFC1123', $this->time) ); } @@ -139,7 +139,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc2822() { $this->assertEquals( - date('r', $this->time), + date(DATE_RFC2822, $this->time), standard_date('DATE_RFC2822', $this->time) ); } @@ -149,7 +149,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rss() { $this->assertEquals( - date('D, d M Y H:i:s O', $this->time), + date(DATE_RSS, $this->time), standard_date('DATE_RSS', $this->time) ); } @@ -159,7 +159,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_w3c() { $this->assertEquals( - date('Y-m-d\TH:i:sP', $this->time), + date(DATE_W3C, $this->time), standard_date('DATE_W3C', $this->time) ); } -- cgit v1.2.3-24-g4f1b From 49aa45b45e1cc83cb61d1524ba32d6c188dac2e1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 6 Jul 2012 16:22:21 +0300 Subject: Fix a few join() bugs --- .../codeigniter/database/query_builder/join_test.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php index b8cf2a822..6d5fc64af 100644 --- a/tests/codeigniter/database/query_builder/join_test.php +++ b/tests/codeigniter/database/query_builder/join_test.php @@ -35,4 +35,24 @@ class Join_test extends CI_TestCase { $this->assertEquals('Developer', $job_user[0]['job_name']); } + // ------------------------------------------------------------------------ + + public function test_join_escape_multiple_conditions() + { + // We just need a valid query produced, not one that makes sense + $fields = array($this->db->protect_identifiers('table1.field1'), $this->db->protect_identifiers('table2.field2')); + + $expected = 'SELECT '.implode(', ', $fields) + ."\nFROM ".$this->db->escape_identifiers('table1') + ."\nLEFT JOIN ".$this->db->escape_identifiers('table2').' ON '.implode(' = ', $fields) + .' AND '.$fields[0]." = 'foo' AND ".$fields[1].' = 0'; + + $result = $this->db->select('table1.field1, table2.field2') + ->from('table1') + ->join('table2', "table1.field1 = table2.field2 AND table1.field1 = 'foo' AND table2.field2 = 0", 'LEFT') + ->get_compiled_select(); + + $this->assertEquals($sql, $result); + } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b6490f507e6c0c470b91d50eb550cda96199d591 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 6 Jul 2012 16:32:16 +0300 Subject: Fix a join() test ... doh --- tests/codeigniter/database/query_builder/join_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php index 6d5fc64af..25bd4accb 100644 --- a/tests/codeigniter/database/query_builder/join_test.php +++ b/tests/codeigniter/database/query_builder/join_test.php @@ -52,7 +52,7 @@ class Join_test extends CI_TestCase { ->join('table2', "table1.field1 = table2.field2 AND table1.field1 = 'foo' AND table2.field2 = 0", 'LEFT') ->get_compiled_select(); - $this->assertEquals($sql, $result); + $this->assertEquals($expected, $result); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 62ab8b24fc37a25eab9205c46321fa41729e5faf Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sat, 28 Jul 2012 14:57:04 -0400 Subject: Adding optional attributes as array or object for html helper --- tests/codeigniter/helpers/html_helper_test.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 9a7bb48bf..4dd717ff7 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -22,6 +22,22 @@ class Html_helper_test extends CI_TestCase { $this->assertEquals('

foobar

', heading('foobar', 2, 'class="bar"')); } + public function test_heading_array_attributes() + { + // Test array of attributes + $this->assertEquals('

foobar

', heading('foobar', 2, array('class' => 'bar', 'id' => 'foo'))); + } + + public function test_heading_object_attributes() + { + // Test array of attributes + $this->assertEquals('

foobar

', heading('foobar', 2, array('class' => 'bar', 'id' => 'foo'))); + $test = new stdClass; + $test->class = "bar"; + $test->id = "foo"; + $this->assertEquals('

foobar

', heading('foobar', 2, $test)); + } + // ------------------------------------------------------------------------ public function test_Ul() @@ -72,5 +88,4 @@ EOH; $this->assertEquals($expect, meta(array('name' => 'foo'))); } - } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From acedd2b1a37b22cb04b01038f21876ddfe38b83a Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 29 Jul 2012 00:15:40 -0400 Subject: Adding a common stringify_attributes function for dealing with attributes through out various helpers. Signed-off-by: Eric Barnes --- tests/codeigniter/core/Common_test.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php index f9bf6c27f..27d48efc2 100644 --- a/tests/codeigniter/core/Common_test.php +++ b/tests/codeigniter/core/Common_test.php @@ -10,4 +10,35 @@ class Common_test extends CI_TestCase { $this->assertEquals(FALSE, is_php('9999.9.9')); } + // ------------------------------------------------------------------------ + + public function test_stringify_attributes() + { + $this->assertEquals(' class="foo" id="bar"', _stringify_attributes(array('class' => 'foo', 'id' => 'bar'))); + + $atts = new Stdclass; + $atts->class = 'foo'; + $atts->id = 'bar'; + $this->assertEquals(' class="foo" id="bar"', _stringify_attributes($atts)); + + $atts = new Stdclass; + $this->assertEquals('', _stringify_attributes($atts)); + + $this->assertEquals(' class="foo" id="bar"', _stringify_attributes('class="foo" id="bar"')); + + $this->assertEquals('', _stringify_attributes(array())); + } + + // ------------------------------------------------------------------------ + + public function test_stringify_js_attributes() + { + $this->assertEquals('width=800,height=600', _stringify_attributes(array('width' => '800', 'height' => '600'), TRUE)); + + $atts = new Stdclass; + $atts->width = 800; + $atts->height = 600; + $this->assertEquals('width=800,height=600', _stringify_attributes($atts, TRUE)); + } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 57486009573a86d9e286a49c92216ba17aae0d5a Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 31 Jul 2012 09:39:53 -0400 Subject: Added Session driver library unit tests and added driver library autoloading to test framework --- tests/codeigniter/libraries/Session_test.php | 304 +++++++++++++++++++++++++++ tests/mocks/autoloader.php | 23 +- tests/mocks/libraries/session.php | 43 ++++ 3 files changed, 365 insertions(+), 5 deletions(-) create mode 100644 tests/codeigniter/libraries/Session_test.php create mode 100644 tests/mocks/libraries/session.php (limited to 'tests') diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php new file mode 100644 index 000000000..db7efb6b7 --- /dev/null +++ b/tests/codeigniter/libraries/Session_test.php @@ -0,0 +1,304 @@ + 0, 'use_only_cookies' => 0, 'cache_limiter' => false); + protected $setting_vals = array(); + protected $cookie_vals; + protected $session; + + /** + * Set up test framework + */ + public function set_up() + { + // Override settings + foreach ($this->settings as $name => $value) { + $this->setting_vals[$name] = ini_get('session.'.$name); + ini_set('session.'.$name, $value); + } + + // Start with clean environment + $this->cookie_vals = $_COOKIE; + $_COOKIE = array(); + + // Establish necessary support classes + $obj = new stdClass; + foreach (array('config' => 'cfg', 'load' => 'load', 'input' => 'in') as $name => $abbr) { + $class = $this->ci_core_class($abbr); + $obj->$name = new $class; + } + $this->ci_instance($obj); + + // Attach session instance locally + $config = array('sess_encrypt_cookie' => FALSE, 'sess_use_database' => FALSE, 'sess_table_name' => '', + 'sess_expiration' => 7200, 'sess_expire_on_close' => FALSE, 'sess_match_ip' => FALSE, + 'sess_match_useragent' => TRUE, 'sess_cookie_name' => 'ci_session', 'cookie_path' => '', + 'cookie_domain' => '', 'cookie_secure' => FALSE, 'cookie_httponly' => FALSE, 'sess_time_to_update' => 300, + 'time_reference' => 'local', 'cookie_prefix' => '', 'encryption_key' => 'foobar', + 'sess_valid_drivers' => array('Mock_Libraries_Session_native', 'Mock_Libraries_Session_cookie')); + $this->session = new Mock_Libraries_Session($config); + } + + /** + * Tear down test framework + */ + public function tear_down() + { + // Restore environment + if (session_id()) session_destroy(); + $_SESSION = array(); + $_COOKIE = $this->cookie_vals; + + // Restore settings + foreach ($this->settings as $name => $value) { + ini_set('session.'.$name, $this->setting_vals[$name]); + } + } + + /** + * Test set_userdata() function + */ + public function test_set_userdata() + { + // Set a userdata message for each driver + $cmsg = 'Some test data'; + $this->session->cookie->set_userdata('test1', $cmsg); + $nmsg = 'Other test data'; + $this->session->native->set_userdata('test1', $nmsg); + + // Verify independent messages + $this->assertEquals($this->session->cookie->userdata('test1'), $cmsg); + $this->assertEquals($this->session->native->userdata('test1'), $nmsg); + } + + /** + * Test the has_userdata() function + */ + public function test_has_userdata() + { + // Set a userdata message for each driver + $cmsg = 'My test data'; + $this->session->cookie->set_userdata('test2', $cmsg); + $nmsg = 'Your test data'; + $this->session->native->set_userdata('test2', $nmsg); + + // Verify independent messages + $this->assertTrue($this->session->cookie->has_userdata('test2')); + $this->assertTrue($this->session->native->has_userdata('test2')); + } + + /** + * Test the all_userdata() function + */ + public function test_all_userdata() + { + // Set a specific series of data for each driver + $cdata = array('one' => 'first', 'two' => 'second', 'three' => 'third', 'foo' => 'bar', 'bar' => 'baz'); + $this->session->cookie->set_userdata($cdata); + $ndata = array('one' => 'gold', 'two' => 'silver', 'three' => 'bronze', 'foo' => 'baz', 'bar' => 'foo'); + $this->session->native->set_userdata($ndata); + + // Make sure all values are present + $call = $this->session->cookie->all_userdata(); + foreach ($cdata as $key => $value) { + $this->assertEquals($value, $call[$key]); + } + $nall = $this->session->native->all_userdata(); + foreach ($ndata as $key => $value) { + $this->assertEquals($value, $nall[$key]); + } + } + + /** + * Test the unset_userdata() function + */ + public function test_unset_userdata() + { + // Set a userdata message for each driver + $cmsg = 'Other test data'; + $this->session->cookie->set_userdata('test3', $cmsg); + $nmsg = 'Sundry test data'; + $this->session->native->set_userdata('test3', $nmsg); + + // Verify independent messages + $this->assertEquals($this->session->cookie->userdata('test3'), $cmsg); + $this->assertEquals($this->session->native->userdata('test3'), $nmsg); + + // Unset them and verify absence + $this->session->cookie->unset_userdata('test3'); + $this->session->native->unset_userdata('test3'); + $this->assertEquals($this->session->cookie->userdata('test3'), NULL); + $this->assertEquals($this->session->native->userdata('test3'), NULL); + } + + /** + * Test the set_flashdata() function + */ + public function test_set_flashdata() + { + // Set flashdata message for each driver + $cmsg = 'Some flash data'; + $this->session->cookie->set_flashdata('test4', $cmsg); + $nmsg = 'Other flash data'; + $this->session->native->set_flashdata('test4', $nmsg); + + // Simulate page reload + $this->session->cookie->reload(); + $this->session->native->reload(); + + // Verify independent messages + $this->assertEquals($this->session->cookie->flashdata('test4'), $cmsg); + $this->assertEquals($this->session->native->flashdata('test4'), $nmsg); + + // Simulate next page reload + $this->session->cookie->reload(); + $this->session->native->reload(); + + // Verify absence of messages + $this->assertEquals($this->session->cookie->flashdata('test4'), NULL); + $this->assertEquals($this->session->native->flashdata('test4'), NULL); + } + + /** + * Test the keep_flashdata() function + */ + public function test_keep_flashdata() + { + // Set flashdata message for each driver + $cmsg = 'My flash data'; + $this->session->cookie->set_flashdata('test5', $cmsg); + $nmsg = 'Your flash data'; + $this->session->native->set_flashdata('test5', $nmsg); + + // Simulate page reload and verify independent messages + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->flashdata('test5'), $cmsg); + $this->assertEquals($this->session->native->flashdata('test5'), $nmsg); + + // Keep messages + $this->session->cookie->keep_flashdata('test5'); + $this->session->native->keep_flashdata('test5'); + + // Simulate next page reload and verify message persistence + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->flashdata('test5'), $cmsg); + $this->assertEquals($this->session->native->flashdata('test5'), $nmsg); + + // Simulate next page reload and verify absence of messages + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->flashdata('test5'), NULL); + $this->assertEquals($this->session->native->flashdata('test5'), NULL); + } + + /** + * Test the all_flashdata() function + */ + public function test_all_flashdata() + { + // Set a specific series of data for each driver + $cdata = array('one' => 'first', 'two' => 'second', 'three' => 'third', 'foo' => 'bar', 'bar' => 'baz'); + $this->session->cookie->set_flashdata($cdata); + $ndata = array('one' => 'gold', 'two' => 'silver', 'three' => 'bronze', 'foo' => 'baz', 'bar' => 'foo'); + $this->session->native->set_flashdata($ndata); + + // Simulate page reload and make sure all values are present + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($cdata, $this->session->cookie->all_flashdata()); + $this->assertEquals($ndata, $this->session->native->all_flashdata()); + } + + /** + * Test the set_tempdata() function + */ + public function test_set_tempdata() + { + // Set tempdata message for each driver - 1 second timeout + $cmsg = 'Some temp data'; + $this->session->cookie->set_tempdata('test6', $cmsg, 1); + $nmsg = 'Other temp data'; + $this->session->native->set_tempdata('test6', $nmsg, 1); + + // Simulate page reload and verify independent messages + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->tempdata('test6'), $cmsg); + $this->assertEquals($this->session->native->tempdata('test6'), $nmsg); + + // Wait 2 seconds, simulate page reload and verify message absence + sleep(2); + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->tempdata('test6'), NULL); + $this->assertEquals($this->session->native->tempdata('test6'), NULL); + } + + /** + * Test the unset_tempdata() function + */ + public function test_unset_tempdata() + { + // Set tempdata message for each driver - 1 second timeout + $cmsg = 'My temp data'; + $this->session->cookie->set_tempdata('test7', $cmsg, 1); + $nmsg = 'Your temp data'; + $this->session->native->set_tempdata('test7', $nmsg, 1); + + // Verify independent messages + $this->assertEquals($this->session->cookie->tempdata('test7'), $cmsg); + $this->assertEquals($this->session->native->tempdata('test7'), $nmsg); + + // Unset data and verify message absence + $this->session->cookie->unset_tempdata('test7'); + $this->session->native->unset_tempdata('test7'); + $this->assertEquals($this->session->cookie->tempdata('test7'), NULL); + $this->assertEquals($this->session->native->tempdata('test7'), NULL); + } + + /** + * Test the sess_regenerate() function + */ + public function test_sess_regenerate() + { + // Get current session id, regenerate, and compare + // Cookie driver + $oldid = $this->session->cookie->userdata('session_id'); + $this->session->cookie->sess_regenerate(); + $newid = $this->session->cookie->userdata('session_id'); + $this->assertFalse($oldid === $newid); + + // Native driver - bug #55267 (https://bugs.php.net/bug.php?id=55267) prevents testing this + /*$oldid = session_id(); + $this->session->native->sess_regenerate(); + $oldid = session_id(); + $this->assertFalse($oldid === $newid);*/ + } + + /** + * Test the sess_destroy() function + */ + public function test_sess_destroy() + { + // Set a userdata message, destroy session, and verify absence + $msg = 'More test data'; + + // Cookie driver + $this->session->cookie->set_userdata('test8', $msg); + $this->assertEquals($this->session->cookie->userdata('test8'), $msg); + $this->session->cookie->sess_destroy(); + $this->assertEquals($this->session->cookie->userdata('test8'), NULL); + + // Native driver + $this->session->native->set_userdata('test8', $msg); + $this->assertEquals($this->session->native->userdata('test8'), $msg); + $this->session->native->sess_destroy(); + $this->assertEquals($this->session->native->userdata('test8'), NULL); + } +} + diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index be1c2220c..88d016bba 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -26,10 +26,14 @@ function autoload($class) 'Email', 'Encrypt', 'Form_validation', 'Ftp', 'Image_lib', 'Javascript', 'Log', 'Migration', 'Pagination', - 'Parser', 'Profiler', 'Session', - 'Table', 'Trackback', 'Typography', - 'Unit_test', 'Upload', 'User_agent', - 'Xmlrpc', 'Zip', + 'Parser', 'Profiler', 'Table', + 'Trackback', 'Typography', 'Unit_test', + 'Upload', 'User_agent', 'Xmlrpc', + 'Zip', + ); + + $ci_drivers = array( + 'Session', ); if (strpos($class, 'Mock_') === 0) @@ -52,6 +56,15 @@ function autoload($class) $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR; $class = ($subclass === 'Driver_Library') ? 'Driver' : $subclass; } + elseif (in_array($subclass, $ci_drivers)) + { + $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR.$subclass.DIRECTORY_SEPARATOR; + $class = $subclass; + } + elseif (in_array(($parent = strtok($subclass, '_')), $ci_drivers)) { + $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR.$parent.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; + $class = $subclass; + } elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 3) { $driver_path = BASEPATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; @@ -91,4 +104,4 @@ function autoload($class) } include_once($file); -} \ No newline at end of file +} diff --git a/tests/mocks/libraries/session.php b/tests/mocks/libraries/session.php new file mode 100644 index 000000000..9d6feee42 --- /dev/null +++ b/tests/mocks/libraries/session.php @@ -0,0 +1,43 @@ +_flashdata_sweep(); + $this->_flashdata_mark(); + $this->_tempdata_sweep(); + } +} + +/** + * Mock cookie driver to overload cookie setting + */ +class Mock_Libraries_Session_cookie extends CI_Session_cookie { + /** + * Overload _setcookie to manage $_COOKIE values, since actual cookies can't be set in unit testing + */ + protected function _setcookie($name, $value = '', $expire = 0, $path = '', $domain = '', $secure = false, + $httponly = false) + { + if (empty($value) || $expire <= time()) { + // Clear cookie + unset($_COOKIE[$name]); + } + else { + // Set cookie + $_COOKIE[$name] = $value; + } + } +} + +/** + * Mock native driver (just for consistency in loading) + */ +class Mock_Libraries_Session_native extends CI_Session_native { } + -- cgit v1.2.3-24-g4f1b From 4153c928229ff174743b78472ae27138cd715efe Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 31 Jul 2012 10:38:21 -0400 Subject: Coding standard cleanup and added userdata resync on sess_regenerate() --- tests/codeigniter/libraries/Session_test.php | 73 +++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php index db7efb6b7..5d58a9e69 100644 --- a/tests/codeigniter/libraries/Session_test.php +++ b/tests/codeigniter/libraries/Session_test.php @@ -4,7 +4,11 @@ * Session driver library unit test */ class Session_test extends CI_TestCase { - protected $settings = array('use_cookies' => 0, 'use_only_cookies' => 0, 'cache_limiter' => false); + protected $settings = array( + 'use_cookies' => 0, + 'use_only_cookies' => 0, + 'cache_limiter' => false + ); protected $setting_vals = array(); protected $cookie_vals; protected $session; @@ -26,19 +30,40 @@ class Session_test extends CI_TestCase { // Establish necessary support classes $obj = new stdClass; - foreach (array('config' => 'cfg', 'load' => 'load', 'input' => 'in') as $name => $abbr) { + $classes = array( + 'config' => 'cfg', + 'load' => 'load', + 'input' => 'in' + ); + foreach ($classes as $name => $abbr) { $class = $this->ci_core_class($abbr); $obj->$name = new $class; } $this->ci_instance($obj); // Attach session instance locally - $config = array('sess_encrypt_cookie' => FALSE, 'sess_use_database' => FALSE, 'sess_table_name' => '', - 'sess_expiration' => 7200, 'sess_expire_on_close' => FALSE, 'sess_match_ip' => FALSE, - 'sess_match_useragent' => TRUE, 'sess_cookie_name' => 'ci_session', 'cookie_path' => '', - 'cookie_domain' => '', 'cookie_secure' => FALSE, 'cookie_httponly' => FALSE, 'sess_time_to_update' => 300, - 'time_reference' => 'local', 'cookie_prefix' => '', 'encryption_key' => 'foobar', - 'sess_valid_drivers' => array('Mock_Libraries_Session_native', 'Mock_Libraries_Session_cookie')); + $config = array( + 'sess_encrypt_cookie' => FALSE, + 'sess_use_database' => FALSE, + 'sess_table_name' => '', + 'sess_expiration' => 7200, + 'sess_expire_on_close' => FALSE, + 'sess_match_ip' => FALSE, + 'sess_match_useragent' => TRUE, + 'sess_cookie_name' => 'ci_session', + 'cookie_path' => '', + 'cookie_domain' => '', + 'cookie_secure' => FALSE, + 'cookie_httponly' => FALSE, + 'sess_time_to_update' => 300, + 'time_reference' => 'local', + 'cookie_prefix' => '', + 'encryption_key' => 'foobar', + 'sess_valid_drivers' => array( + 'Mock_Libraries_Session_native', + 'Mock_Libraries_Session_cookie' + ) + ); $this->session = new Mock_Libraries_Session($config); } @@ -96,9 +121,21 @@ class Session_test extends CI_TestCase { public function test_all_userdata() { // Set a specific series of data for each driver - $cdata = array('one' => 'first', 'two' => 'second', 'three' => 'third', 'foo' => 'bar', 'bar' => 'baz'); + $cdata = array( + 'one' => 'first', + 'two' => 'second', + 'three' => 'third', + 'foo' => 'bar', + 'bar' => 'baz' + ); + $ndata = array( + 'one' => 'gold', + 'two' => 'silver', + 'three' => 'bronze', + 'foo' => 'baz', + 'bar' => 'foo' + ); $this->session->cookie->set_userdata($cdata); - $ndata = array('one' => 'gold', 'two' => 'silver', 'three' => 'bronze', 'foo' => 'baz', 'bar' => 'foo'); $this->session->native->set_userdata($ndata); // Make sure all values are present @@ -202,9 +239,21 @@ class Session_test extends CI_TestCase { public function test_all_flashdata() { // Set a specific series of data for each driver - $cdata = array('one' => 'first', 'two' => 'second', 'three' => 'third', 'foo' => 'bar', 'bar' => 'baz'); + $cdata = array( + 'one' => 'first', + 'two' => 'second', + 'three' => 'third', + 'foo' => 'bar', + 'bar' => 'baz' + ); + $ndata = array( + 'one' => 'gold', + 'two' => 'silver', + 'three' => 'bronze', + 'foo' => 'baz', + 'bar' => 'foo' + ); $this->session->cookie->set_flashdata($cdata); - $ndata = array('one' => 'gold', 'two' => 'silver', 'three' => 'bronze', 'foo' => 'baz', 'bar' => 'foo'); $this->session->native->set_flashdata($ndata); // Simulate page reload and make sure all values are present -- cgit v1.2.3-24-g4f1b From 6030719346e9b0eb0e0ea99c679cadeb1fe4afde Mon Sep 17 00:00:00 2001 From: dchill42 Date: Mon, 27 Aug 2012 23:59:31 -0400 Subject: Improved VFS usage in Loader and Config units, added Loader driver test, and moved config load testing to Config unit Signed-off-by: dchill42 --- tests/codeigniter/core/Config_test.php | 52 +++++- tests/codeigniter/core/Loader_test.php | 287 ++++++++++++++++++++++++++++----- tests/mocks/core/loader.php | 32 ++-- 3 files changed, 312 insertions(+), 59 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php index 30cb90a28..7782a7898 100644 --- a/tests/codeigniter/core/Config_test.php +++ b/tests/codeigniter/core/Config_test.php @@ -90,4 +90,54 @@ class Config_test extends CI_TestCase { $this->assertEquals('http://example.com/system/', $this->config->system_url()); } -} \ No newline at end of file + // -------------------------------------------------------------------- + + public function test_load() + { + // Create VFS tree of application config files + $file1 = 'test.php'; + $file2 = 'secttest'; + $key1 = 'testconfig'; + $val1 = 'my_value'; + $cfg1 = array( + $key1 => $val1 + ); + $cfg2 = array( + 'one' => 'prime', + 'two' => 2, + 'three' => true + ); + $tree = array( + 'application' => array( + 'config' => array( + $file1 => ' 'config->_config_paths = array(vfsStream::url('application').'/'); + + // Test regular load + $this->assertTrue($this->config->load($file1)); + $this->assertEquals($val1, $this->config->item($key1)); + + // Test section load + $this->assertTrue($this->config->load($file2, TRUE)); + $this->assertEquals($cfg2, $this->config->item($file2)); + + // Test graceful fail + $this->assertFalse($this->config->load('not_config_file', FALSE, TRUE)); + + // Test regular fail + $file3 = 'absentia'; + $this->setExpectedException( + 'RuntimeException', + 'CI Error: The configuration file '.$file3.'.php does not exist.' + ); + $this->assertNull($this->config->load($file3)); + } + +} diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index fdea962b7..bb8bfd733 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -18,54 +18,123 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + /** + * @covers CI_Loader::library + */ public function test_library() { $this->_setup_config_mock(); + // Create libraries directory with test library + $lib = 'unit_test_lib'; + $class = 'CI_'.ucfirst($lib); + $content = '_create_content('libraries', $lib, $content, NULL, TRUE); + // 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); + $this->assertNull($this->load->library(array($lib))); + $this->assertTrue(class_exists($class), $class.' does not exist'); + $this->assertAttributeInstanceOf($class, $lib, $this->ci_obj); // Test no lib given - $this->assertEquals(FALSE, $this->load->library()); + $this->assertFalse($this->load->library()); // Test a string given to params - $this->assertEquals(NULL, $this->load->library('table', ' ')); + $this->assertNull($this->load->library($lib, ' ')); + } + + // -------------------------------------------------------------------- + + /** + * @covers CI_Loader::library + */ + public function test_library_config() + { + $this->_setup_config_mock(); + + // Create libraries directory with test library + $lib = 'unit_test_config_lib'; + $class = 'CI_'.ucfirst($lib); + $content = 'config = $params; } } '; + $this->_create_content('libraries', $lib, $content, NULL, TRUE); + + // Create config file + $cfg = array( + 'foo' => 'bar', + 'bar' => 'baz', + 'baz' => false + ); + $this->_create_content('config', $lib, 'assertNull($this->load->library($lib, NULL, $obj)); + $this->assertTrue(class_exists($class), $class.' does not exist'); + $this->assertAttributeInstanceOf($class, $obj, $this->ci_obj); + $this->assertEquals($cfg, $this->ci_obj->$obj->config); } // -------------------------------------------------------------------- + /** + * @covers CI_Loader::library + */ public function test_load_library_in_application_dir() { $this->_setup_config_mock(); - $content = '_create_content('libraries', $lib, $content); - $model = vfsStream::newFile('Super_test_library.php')->withContent($content)->at($this->load->libs_dir); - $this->assertNull($this->load->library('super_test_library')); + // Load library + $this->assertNull($this->load->library($lib)); // Was the model class instantiated. - $this->assertTrue(class_exists('Super_test_library')); + $this->assertTrue(class_exists($class), $class.' does not exist'); + $this->assertAttributeInstanceOf($class, $lib, $this->ci_obj); } // -------------------------------------------------------------------- - private function _setup_config_mock() + /** + * @covers CI_Loader::driver + */ + public function test_driver() { - // Mock up a config object until we - // figure out how to test the library configs - $config = $this->getMock('CI_Config', NULL, array(), '', FALSE); - $config->expects($this->any()) - ->method('load') - ->will($this->returnValue(TRUE)); + $this->_setup_config_mock(); - // Add the mock to our stdClass - $this->ci_instance_var('config', $config); + // Create libraries directory with test driver + $driver = 'unit_test_driver'; + $dir = ucfirst($driver); + $class = 'CI_'.$dir; + $content = '_create_content('libraries', $driver, $content, $dir, TRUE); + + // Test loading as an array. + $this->assertNull($this->load->driver(array($driver))); + $this->assertTrue(class_exists($class), $class.' does not exist'); + $this->assertAttributeInstanceOf($class, $driver, $this->ci_obj); + + // Test loading as a library with a name + $obj = 'testdrive'; + $this->assertNull($this->load->library($driver, NULL, $obj)); + $this->assertAttributeInstanceOf($class, $obj, $this->ci_obj); + + // Test no driver given + $this->assertFalse($this->load->driver()); + + // Test a string given to params + $this->assertNull($this->load->driver($driver, ' ')); } // -------------------------------------------------------------------- + /** + * @covers CI_Loader::model + */ public function test_non_existent_model() { $this->setExpectedException( @@ -79,20 +148,23 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- /** - * @coverts CI_Loader::model + * @covers CI_Loader::model */ public function test_models() { $this->ci_set_core_class('model', 'CI_Model'); - $content = 'withContent($content)->at($this->load->models_dir); + // Create models directory with test model + $model = 'unit_test_model'; + $class = ucfirst($model); + $content = '_create_content('models', $model, $content); - $this->assertNull($this->load->model('unit_test_model')); + // Load model + $this->assertNull($this->load->model($model)); // Was the model class instantiated. - $this->assertTrue(class_exists('Unit_test_model')); + $this->assertTrue(class_exists($class)); // Test no model given $this->assertNull($this->load->model('')); @@ -109,26 +181,27 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- /** - * @coverts CI_Loader::view + * @covers CI_Loader::view */ public function test_load_view() { $this->ci_set_core_class('output', 'CI_Output'); + // Create views directory with test view + $view = 'unit_test_view'; $content = 'This is my test page. '; - $view = vfsStream::newFile('unit_test_view.php')->withContent($content)->at($this->load->views_dir); + $this->_create_content('views', $view, $content); // 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)); - + $out = $this->load->view($view, array('hello' => "World!"), TRUE); + $this->assertEquals('This is my test page. World!', $out); } // -------------------------------------------------------------------- /** - * @coverts CI_Loader::view + * @covers CI_Loader::view */ public function test_non_existent_view() { @@ -142,16 +215,22 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + /** + * @covers CI_Loader::file + */ public function test_file() { + // Create views directory with test file + $dir = 'views'; + $file = 'ci_test_mock_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); + $this->_create_content($dir, $file, $content); // 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); - - $this->assertEquals($content, $load); + $out = $this->load->file($this->load->app_path.$dir.'/'.$file.'.php', TRUE); + $this->assertEquals($content, $out); + // Test non-existent file $this->setExpectedException( 'RuntimeException', 'CI Error: Unable to load the requested file: ci_test_file_not_exists' @@ -162,6 +241,9 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + /** + * @covers CI_Loader::vars + */ public function test_vars() { $this->assertNull($this->load->vars(array('foo' => 'bar'))); @@ -170,10 +252,22 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + /** + * @covers CI_Loader::helper + */ public function test_helper() { - $this->assertEquals(NULL, $this->load->helper('array')); + // Create helper directory in app path with test helper + $helper = 'test'; + $func = '_my_helper_test_func'; + $content = '_create_content('helpers', $helper.'_helper', $content); + + // Load helper + $this->assertEquals(NULL, $this->load->helper($helper)); + $this->assertTrue(function_exists($func), $func.' does not exist'); + // Test non-existent helper $this->setExpectedException( 'RuntimeException', 'CI Error: Unable to load the requested file: helpers/bad_helper.php' @@ -184,9 +278,31 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + /** + * @covers CI_Loader::helper + */ public function test_loading_multiple_helpers() { - $this->assertEquals(NULL, $this->load->helpers(array('file', 'array', 'string'))); + // Create helper directory in base path with test helpers + $helpers = array(); + $funcs = array(); + $files = array(); + for ($i = 1; $i <= 3; ++$i) { + $helper = 'test'.$i; + $helpers[] = $helper; + $func = '_my_helper_test_func'.$i; + $funcs[] = $func; + $files[$helper.'_helper'] = '_create_content('helpers', $files, NULL, NULL, TRUE); + + // Load helpers + $this->assertEquals(NULL, $this->load->helpers($helpers)); + + // Verify helper existence + foreach ($funcs as $func) { + $this->assertTrue(function_exists($func), $func.' does not exist'); + } } // -------------------------------------------------------------------- @@ -198,6 +314,52 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + /** + * @covers CI_Loader::add_package_path + * @covers CI_Loader::get_package_paths + * @covers CI_Loader::remove_package_path + */ + public function test_packages() + { + $this->_setup_config_mock(); + + // Create third-party directory in app path with model + $dir = 'third-party'; + $lib = 'unit_test_package'; + $class = 'CI_'.ucfirst($lib); + $content = '_create_content($dir, $lib, $content); + + // Test failed load without path + $this->setExpectedException( + 'RuntimeException', + 'CI Error: Unable to load the requested class: '.$lib + ); + $this->load->library($lib); + + // Clear exception and get paths + $this->setExpectedException(NULL); + $paths = $this->load->get_package_paths(TRUE); + + // Add path and verify + $path = $this->load->app_path.$dir; + $this->assertNull($this->load->add_package_path($path)); + $this->assertContains($path, $this->load->get_package_paths(TRUE)); + + // Test successful load + $this->assertNull($this->load->library($lib)); + $this->assertTrue(class_exists($class), $class.' does not exist'); + + // Remove path and verify restored paths + $this->assertNull($this->load->remove_package_path($path)); + $this->assertEquals($paths, $this->load->get_package_paths(TRUE)); + } + + // -------------------------------------------------------------------- + + /** + * @covers CI_Loader::config + */ public function test_load_config() { $this->_setup_config_mock(); @@ -206,16 +368,53 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - public function test_load_bad_config() + private function _setup_config_mock() { - $this->_setup_config_mock(); + // Mock up a config object so config() has something to call + $config = $this->getMock('CI_Config', array('load'), array(), '', FALSE); + $config->expects($this->any()) + ->method('load') + ->will($this->returnValue(TRUE)); - $this->setExpectedException( - 'RuntimeException', - 'CI Error: The configuration file foobar.php does not exist.' - ); + // Reinitialize config paths to use VFS + $config->_config_paths = array($this->load->app_path); - $this->load->config('foobar', FALSE); + // Add the mock to our stdClass + $this->ci_instance_var('config', $config); + } + + // -------------------------------------------------------------------- + + private function _create_content($dir, $file, $content, $sub = NULL, $base = FALSE) + { + // Create structure containing directory + $tree = array($dir => array()); + + // Check for subdirectory + if ($sub) { + // Add subdirectory to tree and get reference + $tree[$dir][$sub] = array(); + $leaf =& $tree[$dir][$sub]; + } + else { + // Get reference to main directory + $leaf =& $tree[$dir]; + } + + // Check for multiple files + if (is_array($file)) { + // Add multiple files to directory + foreach ($file as $name => $data) { + $leaf[$name.'.php'] = $data; + } + } + else { + // Add single file with content + $leaf[$file.'.php'] = $content; + } + + // Create structure under app or base path + vfsStream::create($tree, $base ? $this->load->base_root : $this->load->app_root); } -} \ No newline at end of file +} diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php index 53d88d55b..e28650dba 100644 --- a/tests/mocks/core/loader.php +++ b/tests/mocks/core/loader.php @@ -5,27 +5,31 @@ 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 - * in the application directory. this will give finer grained control over - * these tests. So yeah, while this looks odd, I need to overwrite protected - * class vars in the loader. So here we go... + * in the application directory. This will give finer grained control over + * these tests. Also, by mocking the system directory, we eliminate dependency + * on any other classes so errors in libraries, helpers, etc. don't give false + * negatives for the actual loading process. So yeah, while this looks odd, + * I need to overwrite protected class vars in the loader. So here we go... * * @covers CI_Loader::__construct() */ public function __construct() { - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('application')); + // Create VFS tree of loader locations + $this->root = vfsStream::setup(); + $this->app_root = vfsStream::newDirectory('application')->at($this->root); + $this->base_root = vfsStream::newDirectory('system')->at($this->root); - $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()); + // Get VFS app and base path URLs + $this->app_path = vfsStream::url('application').'/'; + $this->base_path = vfsStream::url('system').'/'; + // Set loader paths with VFS URLs $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); + $this->_ci_library_paths = array($this->app_path, $this->base_path); + $this->_ci_helper_paths = array($this->app_path, $this->base_path); + $this->_ci_model_paths = array($this->app_path); + $this->_ci_view_paths = array($this->app_path.'views/' => TRUE); } -} \ No newline at end of file +} -- cgit v1.2.3-24-g4f1b From 08c8304778e573d725b5565f350e44c34fb0d830 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 28 Aug 2012 17:35:56 -0400 Subject: Minor session test improvements Signed-off-by: dchill42 --- tests/codeigniter/libraries/Session_test.php | 182 +++++++++++++++++---------- 1 file changed, 117 insertions(+), 65 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php index 5d58a9e69..135f71806 100644 --- a/tests/codeigniter/libraries/Session_test.php +++ b/tests/codeigniter/libraries/Session_test.php @@ -85,38 +85,66 @@ class Session_test extends CI_TestCase { /** * Test set_userdata() function + * + * @covers CI_Session::set_userdata + * @covers CI_Session::userdata */ public function test_set_userdata() { - // Set a userdata message for each driver - $cmsg = 'Some test data'; - $this->session->cookie->set_userdata('test1', $cmsg); - $nmsg = 'Other test data'; - $this->session->native->set_userdata('test1', $nmsg); + // Set userdata values for each driver + $key1 = 'test1'; + $ckey2 = 'test2'; + $nkey2 = 'test3'; + $cmsg1 = 'Some test data'; + $cmsg2 = 42; + $nmsg1 = 'Other test data'; + $nmsg2 = true; + $this->session->cookie->set_userdata($key1, $cmsg1); + $this->session->set_userdata($ckey2, $cmsg2); + $this->session->native->set_userdata($key1, $nmsg1); + $this->session->set_userdata($nkey2, $nmsg2); // Verify independent messages - $this->assertEquals($this->session->cookie->userdata('test1'), $cmsg); - $this->assertEquals($this->session->native->userdata('test1'), $nmsg); + $this->assertEquals($cmsg1, $this->session->cookie->userdata($key1)); + $this->assertEquals($nmsg1, $this->session->native->userdata($key1)); + + // Verify pre-selected driver sets + $this->assertEquals($cmsg2, $this->session->cookie->userdata($ckey2)); + $this->assertEquals($nmsg2, $this->session->native->userdata($nkey2)); + + // Verify no crossover + $this->assertNull($this->session->cookie->userdata($nkey2)); + $this->assertNull($this->session->native->userdata($ckey2)); } /** * Test the has_userdata() function + * + * @covers CI_Session::has_userdata */ public function test_has_userdata() { - // Set a userdata message for each driver + // Set a userdata value for each driver + $key = 'hastest'; $cmsg = 'My test data'; - $this->session->cookie->set_userdata('test2', $cmsg); + $this->session->cookie->set_userdata($key, $cmsg); $nmsg = 'Your test data'; - $this->session->native->set_userdata('test2', $nmsg); + $this->session->native->set_userdata($key, $nmsg); - // Verify independent messages - $this->assertTrue($this->session->cookie->has_userdata('test2')); - $this->assertTrue($this->session->native->has_userdata('test2')); + // Verify values exist + $this->assertTrue($this->session->cookie->has_userdata($key)); + $this->assertTrue($this->session->native->has_userdata($key)); + + // Verify non-existent values + $nokey = 'hasnot'; + $this->assertFalse($this->session->cookie->has_userdata($nokey)); + $this->assertFalse($this->session->native->has_userdata($nokey)); } /** * Test the all_userdata() function + * + * @covers CI_Session::all_userdata */ public function test_all_userdata() { @@ -151,90 +179,102 @@ class Session_test extends CI_TestCase { /** * Test the unset_userdata() function + * + * @covers CI_Session::unset_userdata */ public function test_unset_userdata() { // Set a userdata message for each driver + $key = 'untest'; $cmsg = 'Other test data'; - $this->session->cookie->set_userdata('test3', $cmsg); + $this->session->cookie->set_userdata($key, $cmsg); $nmsg = 'Sundry test data'; - $this->session->native->set_userdata('test3', $nmsg); + $this->session->native->set_userdata($key, $nmsg); // Verify independent messages - $this->assertEquals($this->session->cookie->userdata('test3'), $cmsg); - $this->assertEquals($this->session->native->userdata('test3'), $nmsg); + $this->assertEquals($this->session->cookie->userdata($key), $cmsg); + $this->assertEquals($this->session->native->userdata($key), $nmsg); // Unset them and verify absence - $this->session->cookie->unset_userdata('test3'); - $this->session->native->unset_userdata('test3'); - $this->assertEquals($this->session->cookie->userdata('test3'), NULL); - $this->assertEquals($this->session->native->userdata('test3'), NULL); + $this->session->cookie->unset_userdata($key); + $this->session->native->unset_userdata($key); + $this->assertNull($this->session->cookie->userdata($key)); + $this->assertNull($this->session->native->userdata($key)); } /** - * Test the set_flashdata() function + * Test the flashdata() functions + * + * @covers CI_Session::set_flashdata + * @covers CI_Session::flashdata */ - public function test_set_flashdata() + public function test_flashdata() { // Set flashdata message for each driver + $key = 'fltest'; $cmsg = 'Some flash data'; - $this->session->cookie->set_flashdata('test4', $cmsg); + $this->session->cookie->set_flashdata($key, $cmsg); $nmsg = 'Other flash data'; - $this->session->native->set_flashdata('test4', $nmsg); + $this->session->native->set_flashdata($key, $nmsg); // Simulate page reload $this->session->cookie->reload(); $this->session->native->reload(); // Verify independent messages - $this->assertEquals($this->session->cookie->flashdata('test4'), $cmsg); - $this->assertEquals($this->session->native->flashdata('test4'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); + $this->assertEquals($nmsg, $this->session->native->flashdata($key)); // Simulate next page reload $this->session->cookie->reload(); $this->session->native->reload(); // Verify absence of messages - $this->assertEquals($this->session->cookie->flashdata('test4'), NULL); - $this->assertEquals($this->session->native->flashdata('test4'), NULL); + $this->assertNull($this->session->cookie->flashdata($key)); + $this->assertNull($this->session->native->flashdata($key)); } /** * Test the keep_flashdata() function + * + * @covers CI_Session::keep_flashdata */ public function test_keep_flashdata() { // Set flashdata message for each driver + $key = 'kfltest'; $cmsg = 'My flash data'; - $this->session->cookie->set_flashdata('test5', $cmsg); + $this->session->cookie->set_flashdata($key, $cmsg); $nmsg = 'Your flash data'; - $this->session->native->set_flashdata('test5', $nmsg); + $this->session->native->set_flashdata($key, $nmsg); // Simulate page reload and verify independent messages $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->flashdata('test5'), $cmsg); - $this->assertEquals($this->session->native->flashdata('test5'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); + $this->assertEquals($nmsg, $this->session->native->flashdata($key)); // Keep messages - $this->session->cookie->keep_flashdata('test5'); - $this->session->native->keep_flashdata('test5'); + $this->session->cookie->keep_flashdata($key); + $this->session->native->keep_flashdata($key); // Simulate next page reload and verify message persistence $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->flashdata('test5'), $cmsg); - $this->assertEquals($this->session->native->flashdata('test5'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); + $this->assertEquals($nmsg, $this->session->native->flashdata($key)); // Simulate next page reload and verify absence of messages $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->flashdata('test5'), NULL); - $this->assertEquals($this->session->native->flashdata('test5'), NULL); + $this->assertNull($this->session->cookie->flashdata($key)); + $this->assertNull($this->session->native->flashdata($key)); } /** * Test the all_flashdata() function + * + * @covers CI_Session::all_flashdata */ public function test_all_flashdata() { @@ -264,54 +304,63 @@ class Session_test extends CI_TestCase { } /** - * Test the set_tempdata() function + * Test the tempdata() functions + * + * @covers CI_Session::set_tempdata + * @covers CI_Session::tempdata */ public function test_set_tempdata() { // Set tempdata message for each driver - 1 second timeout + $key = 'tmptest'; $cmsg = 'Some temp data'; - $this->session->cookie->set_tempdata('test6', $cmsg, 1); + $this->session->cookie->set_tempdata($key, $cmsg, 1); $nmsg = 'Other temp data'; - $this->session->native->set_tempdata('test6', $nmsg, 1); + $this->session->native->set_tempdata($key, $nmsg, 1); // Simulate page reload and verify independent messages $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->tempdata('test6'), $cmsg); - $this->assertEquals($this->session->native->tempdata('test6'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->tempdata($key)); + $this->assertEquals($nmsg, $this->session->native->tempdata($key)); // Wait 2 seconds, simulate page reload and verify message absence sleep(2); $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->tempdata('test6'), NULL); - $this->assertEquals($this->session->native->tempdata('test6'), NULL); + $this->assertNull($this->session->cookie->tempdata($key)); + $this->assertNull($this->session->native->tempdata($key)); } /** * Test the unset_tempdata() function + * + * @covers CI_Session::unset_tempdata */ public function test_unset_tempdata() { // Set tempdata message for each driver - 1 second timeout + $key = 'utmptest'; $cmsg = 'My temp data'; - $this->session->cookie->set_tempdata('test7', $cmsg, 1); + $this->session->cookie->set_tempdata($key, $cmsg, 1); $nmsg = 'Your temp data'; - $this->session->native->set_tempdata('test7', $nmsg, 1); + $this->session->native->set_tempdata($key, $nmsg, 1); // Verify independent messages - $this->assertEquals($this->session->cookie->tempdata('test7'), $cmsg); - $this->assertEquals($this->session->native->tempdata('test7'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->tempdata($key)); + $this->assertEquals($nmsg, $this->session->native->tempdata($key)); // Unset data and verify message absence - $this->session->cookie->unset_tempdata('test7'); - $this->session->native->unset_tempdata('test7'); - $this->assertEquals($this->session->cookie->tempdata('test7'), NULL); - $this->assertEquals($this->session->native->tempdata('test7'), NULL); + $this->session->cookie->unset_tempdata($key); + $this->session->native->unset_tempdata($key); + $this->assertNull($this->session->cookie->tempdata($key)); + $this->assertNull($this->session->native->tempdata($key)); } /** * Test the sess_regenerate() function + * + * @covers CI_Session::sess_regenerate */ public function test_sess_regenerate() { @@ -320,34 +369,37 @@ class Session_test extends CI_TestCase { $oldid = $this->session->cookie->userdata('session_id'); $this->session->cookie->sess_regenerate(); $newid = $this->session->cookie->userdata('session_id'); - $this->assertFalse($oldid === $newid); + $this->assertNotEquals($oldid, $newid); // Native driver - bug #55267 (https://bugs.php.net/bug.php?id=55267) prevents testing this - /*$oldid = session_id(); - $this->session->native->sess_regenerate(); - $oldid = session_id(); - $this->assertFalse($oldid === $newid);*/ + // $oldid = session_id(); + // $this->session->native->sess_regenerate(); + // $oldid = session_id(); + // $this->assertNotEquals($oldid, $newid); } /** * Test the sess_destroy() function + * + * @covers CI_Session::sess_destroy */ public function test_sess_destroy() { // Set a userdata message, destroy session, and verify absence + $key = 'dsttest'; $msg = 'More test data'; // Cookie driver - $this->session->cookie->set_userdata('test8', $msg); - $this->assertEquals($this->session->cookie->userdata('test8'), $msg); + $this->session->cookie->set_userdata($key, $msg); + $this->assertEquals($msg, $this->session->cookie->userdata($key)); $this->session->cookie->sess_destroy(); - $this->assertEquals($this->session->cookie->userdata('test8'), NULL); + $this->assertNull($this->session->cookie->userdata($key)); // Native driver - $this->session->native->set_userdata('test8', $msg); - $this->assertEquals($this->session->native->userdata('test8'), $msg); + $this->session->native->set_userdata($key, $msg); + $this->assertEquals($msg, $this->session->native->userdata($key)); $this->session->native->sess_destroy(); - $this->assertEquals($this->session->native->userdata('test8'), NULL); + $this->assertNull($this->session->native->userdata($key)); } } -- cgit v1.2.3-24-g4f1b From 60d100f0fde3fba4fa4015f44f490b7ecac16138 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Wed, 29 Aug 2012 12:58:26 -0400 Subject: Added autoloader unit test with minor supporting change in Loader Signed-off-by: dchill42 --- tests/codeigniter/core/Loader_test.php | 70 ++++++++++++++++++++++++++++++++++ tests/mocks/core/loader.php | 9 +++++ 2 files changed, 79 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index bb8bfd733..db79e6a8b 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -368,6 +368,76 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + /** + * @covers CI_Loader::_ci_autoloader + */ + public function test_autoloader() + { + $this->_setup_config_mock(); + + // Create helper directory in app path with test helper + $helper = 'autohelp'; + $hlp_func = '_autohelp_test_func'; + $this->_create_content('helpers', $helper.'_helper', '_create_content('libraries', $lib, ' array($drv.'.php' => 'load->base_root->getChild('libraries')); + + // Create package directory in app path with model + $dir = 'testdir'; + $path = $this->load->app_path.$dir.'/'; + $model = 'automod'; + $mod_class = ucfirst($model); + $this->_create_content($dir, $model, ' array($path), + 'helper' => array($helper), + 'libraries' => array($lib), + 'drivers' => array($drv), + 'model' => array($model), + 'config' => array() + ); + $this->_create_content('config', 'autoload', 'load->autoload(); + + // Verify path + $this->assertContains($path, $this->load->get_package_paths()); + + // Verify helper + $this->assertTrue(function_exists($hlp_func), $hlp_func.' does not exist'); + + // Verify library + $this->assertTrue(class_exists($lib_class), $lib_class.' does not exist'); + $this->assertAttributeInstanceOf($lib_class, $lib, $this->ci_obj); + + // Verify driver + $this->assertTrue(class_exists($drv_class), $drv_class.' does not exist'); + $this->assertAttributeInstanceOf($drv_class, $drv, $this->ci_obj); + + // Verify model + $this->assertTrue(class_exists($mod_class), $mod_class.' does not exist'); + $this->assertAttributeInstanceOf($mod_class, $model, $this->ci_obj); + } + + // -------------------------------------------------------------------- + private function _setup_config_mock() { // Mock up a config object so config() has something to call diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php index e28650dba..c0e02139e 100644 --- a/tests/mocks/core/loader.php +++ b/tests/mocks/core/loader.php @@ -30,6 +30,15 @@ class Mock_Core_Loader extends CI_Loader { $this->_ci_helper_paths = array($this->app_path, $this->base_path); $this->_ci_model_paths = array($this->app_path); $this->_ci_view_paths = array($this->app_path.'views/' => TRUE); + $this->_ci_autoloader_path = $this->app_path; + } + + /** + * Give public access to _ci_autoloader for testing + */ + public function autoload() + { + $this->_ci_autoloader(); } } -- cgit v1.2.3-24-g4f1b From 0c886901bc013e477b8c5eb9bc5e60c91d1fac56 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Wed, 29 Aug 2012 23:23:22 +0100 Subject: Added lang mock and upload mock --- tests/mocks/core/lang.php | 15 +++++++++++++++ tests/mocks/libraries/upload.php | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 tests/mocks/core/lang.php create mode 100644 tests/mocks/libraries/upload.php (limited to 'tests') diff --git a/tests/mocks/core/lang.php b/tests/mocks/core/lang.php new file mode 100644 index 000000000..1b99aedb3 --- /dev/null +++ b/tests/mocks/core/lang.php @@ -0,0 +1,15 @@ + Date: Wed, 29 Aug 2012 23:23:37 +0100 Subject: Added initial upload library tests --- tests/codeigniter/libraries/Upload_test.php | 231 ++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 tests/codeigniter/libraries/Upload_test.php (limited to 'tests') diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php new file mode 100644 index 000000000..021af28a7 --- /dev/null +++ b/tests/codeigniter/libraries/Upload_test.php @@ -0,0 +1,231 @@ +upload = new Mock_Libraries_Upload(); + $obj->security = new Mock_Core_Security(); + $obj->lang = new Mock_Core_Lang(); + + $this->ci_instance($obj); + $this->upload = $obj->upload; + + vfsStreamWrapper::register(); + vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); + + $this->_test_dir = vfsStreamWrapper::getRoot(); + } + + function test_do_upload() + { + $this->markTestIncomplete('TODO'); + } + + function test_data() + { + $data = array( + 'file_name' => 'hello.txt', + 'file_type' => 'text/plain', + 'file_path' => '/tmp/', + 'full_path' => '/tmp/hello.txt', + 'raw_name' => 'hello', + 'orig_name' => 'hello.txt', + 'client_name' => '', + 'file_ext' => '.txt', + 'file_size' => 100, + 'is_image' => FALSE, + 'image_width' => '', + 'image_height' => '', + 'image_type' => '', + 'image_size_str' => '' + ); + + $this->upload->set_upload_path('/tmp/'); + + foreach ($data as $k => $v) + { + $this->upload->{$k} = $v; + } + + $this->assertEquals('hello.txt', $this->upload->data('file_name')); + $this->assertEquals($data, $this->upload->data()); + } + + function test_set_upload_path() + { + $this->upload->set_upload_path('/tmp/'); + $this->assertEquals('/tmp/', $this->upload->upload_path); + + $this->upload->set_upload_path('/tmp'); + $this->assertEquals('/tmp/', $this->upload->upload_path); + } + + function test_set_filename() + { + $this->markTestIncomplete('TODO'); + } + + function test_set_max_filesize() + { + $this->upload->set_max_filesize(100); + $this->assertEquals(100, $this->upload->max_size); + } + + function test_set_max_filename() + { + $this->upload->set_max_filename(100); + $this->assertEquals(100, $this->upload->max_filename); + } + + function test_set_max_width() + { + $this->upload->set_max_width(100); + $this->assertEquals(100, $this->upload->max_width); + } + + function test_set_max_height() + { + $this->upload->set_max_height(100); + $this->assertEquals(100, $this->upload->max_height); + } + + function test_set_allowed_types() + { + $this->upload->set_allowed_types('*'); + $this->assertEquals('*', $this->upload->allowed_types); + + $this->upload->set_allowed_types('foo|bar'); + $this->assertEquals(array('foo', 'bar'), $this->upload->allowed_types); + } + + function test_set_image_properties() + { + $this->markTestIncomplete('TODO'); + } + + function test_set_xss_clean() + { + $this->upload->set_xss_clean(TRUE); + $this->assertTrue($this->upload->xss_clean); + + $this->upload->set_xss_clean(FALSE); + $this->assertFalse($this->upload->xss_clean); + } + + function test_is_image() + { + $this->upload->file_type = 'image/x-png'; + $this->assertTrue($this->upload->is_image()); + + $this->upload->file_type = 'text/plain'; + $this->assertFalse($this->upload->is_image()); + } + + function test_is_allowed_filetype() + { + $this->upload->allowed_types = array('html'); + + $this->upload->file_ext = '.txt'; + $this->upload->file_type = 'text/plain'; + $this->assertFalse($this->upload->is_allowed_filetype(FALSE)); + $this->assertFalse($this->upload->is_allowed_filetype(TRUE)); + + $this->upload->file_ext = '.html'; + $this->upload->file_type = 'text/html'; + $this->assertTrue($this->upload->is_allowed_filetype(FALSE)); + $this->assertTrue($this->upload->is_allowed_filetype(TRUE)); + + $this->markTestIncomplete('Image tests'); + } + + function test_is_allowed_filesize() + { + $this->upload->max_size = 100; + $this->upload->file_size = 99; + + $this->assertTrue($this->upload->is_allowed_filesize()); + + $this->upload->file_size = 101; + $this->assertFalse($this->upload->is_allowed_filesize()); + } + + function test_is_allowed_dimensions() + { + $this->markTestIncomplete('TODO'); + } + + function test_validate_upload_path() + { + $this->upload->upload_path = ''; + $this->assertFalse($this->upload->validate_upload_path()); + + $this->upload->upload_path = vfsStream::url('testDir'); + $this->assertTrue($this->upload->validate_upload_path()); + } + + function test_get_extension() + { + $this->assertEquals('.txt', $this->upload->get_extension('hello.txt')); + $this->assertEquals('.htaccess', $this->upload->get_extension('.htaccess')); + $this->assertEquals('', $this->upload->get_extension('hello')); + } + + function test_clean_file_name() + { + $this->assertEquals('hello.txt', $this->upload->clean_file_name('hello.txt')); + $this->assertEquals('hello.txt', $this->upload->clean_file_name('%253chell>o.txt')); + } + + function test_limit_filename_length() + { + $this->assertEquals('hello.txt', $this->upload->limit_filename_length('hello.txt', 10)); + $this->assertEquals('hello.txt', $this->upload->limit_filename_length('hello-world.txt', 9)); + } + + function test_do_xss_clean() + { + $file1 = vfsStream::newFile('file1.txt')->withContent('The billy goat was waiting for them.')->at($this->_test_dir); + $file2 = vfsStream::newFile('file2.txt')->at($this->_test_dir); + $file3 = vfsStream::newFile('file3.txt')->withContent('')->at($this->_test_dir); + + $this->upload->file_temp = vfsStream::url('file1.txt'); + $this->assertTrue($this->upload->do_xss_clean()); + + $this->upload->file_temp = vfsStream::url('file2.txt'); + $this->assertFalse($this->upload->do_xss_clean()); + + $this->upload->file_temp = vfsStream::url('file3.txt'); + $this->assertFalse($this->upload->do_xss_clean()); + } + + function test_set_error() + { + $errors = array( + 'An error!' + ); + + $another = 'Another error!'; + + $this->upload->set_error($errors); + $this->assertEquals($errors, $this->upload->error_msg); + + $errors[] = $another; + $this->upload->set_error($another); + $this->assertEquals($errors, $this->upload->error_msg); + } + + function test_display_errors() + { + $this->upload->error_msg[] = 'Error test'; + $this->assertEquals('

Error test

', $this->upload->display_errors()); + } + + function test_mimes_types() + { + $this->assertEquals('text/plain', $this->upload->mimes_types('txt')); + $this->assertFalse($this->upload->mimes_types('foobar')); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 096b894c7eb0db6ab13aa4478ebf52524b429fcb Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 30 Aug 2012 00:20:36 +0100 Subject: Finished the final tests (except do_upload) --- tests/codeigniter/libraries/Upload_test.php | 53 ++++++++++++++++++++++++---- tests/mocks/uploads/ci_logo.gif | Bin 0 -> 3270 bytes 2 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 tests/mocks/uploads/ci_logo.gif (limited to 'tests') diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php index 021af28a7..d79a3ffc9 100644 --- a/tests/codeigniter/libraries/Upload_test.php +++ b/tests/codeigniter/libraries/Upload_test.php @@ -18,9 +18,9 @@ class Upload_test extends CI_TestCase { $this->_test_dir = vfsStreamWrapper::getRoot(); } - function test_do_upload() + function test_do_upload() { - $this->markTestIncomplete('TODO'); + $this->markTestIncomplete('We can\'t really test this at the moment because of the call to `is_uploaded_file` in do_upload which isn\'t supported by vfsStream'); } function test_data() @@ -64,7 +64,11 @@ class Upload_test extends CI_TestCase { function test_set_filename() { - $this->markTestIncomplete('TODO'); + $file1 = vfsStream::newFile('hello-world.txt')->withContent('Hello world.')->at($this->_test_dir); + $this->upload->file_ext = '.txt'; + + $this->assertEquals('helloworld.txt', $this->upload->set_filename(vfsStream::url('testDir').'/', 'helloworld.txt')); + $this->assertEquals('hello-world1.txt', $this->upload->set_filename(vfsStream::url('testDir').'/', 'hello-world.txt')); } function test_set_max_filesize() @@ -102,7 +106,22 @@ class Upload_test extends CI_TestCase { function test_set_image_properties() { - $this->markTestIncomplete('TODO'); + $this->upload->file_type = 'image/gif'; + $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif'; + + $props = array( + 'image_width' => 170, + 'image_height' => 73, + 'image_type' => 'gif', + 'image_size_str' => 'width="170" height="73"' + ); + + $this->upload->set_image_properties($this->upload->file_temp); + + $this->assertEquals($props['image_width'], $this->upload->image_width); + $this->assertEquals($props['image_height'], $this->upload->image_height); + $this->assertEquals($props['image_type'], $this->upload->image_type); + $this->assertEquals($props['image_size_str'], $this->upload->image_size_str); } function test_set_xss_clean() @@ -125,7 +144,7 @@ class Upload_test extends CI_TestCase { function test_is_allowed_filetype() { - $this->upload->allowed_types = array('html'); + $this->upload->allowed_types = array('html', 'gif'); $this->upload->file_ext = '.txt'; $this->upload->file_type = 'text/plain'; @@ -137,7 +156,10 @@ class Upload_test extends CI_TestCase { $this->assertTrue($this->upload->is_allowed_filetype(FALSE)); $this->assertTrue($this->upload->is_allowed_filetype(TRUE)); - $this->markTestIncomplete('Image tests'); + $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif'; + $this->upload->file_ext = '.gif'; + $this->upload->file_type = 'image/gif'; + $this->assertTrue($this->upload->is_allowed_filetype()); } function test_is_allowed_filesize() @@ -153,7 +175,21 @@ class Upload_test extends CI_TestCase { function test_is_allowed_dimensions() { - $this->markTestIncomplete('TODO'); + $this->upload->file_type = 'text/plain'; + $this->assertTrue($this->upload->is_allowed_dimensions()); + + $this->upload->file_type = 'image/gif'; + $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif'; + + $this->upload->max_width = 10; + $this->assertFalse($this->upload->is_allowed_dimensions()); + + $this->upload->max_width = 170; + $this->upload->max_height = 10; + $this->assertFalse($this->upload->is_allowed_dimensions()); + + $this->upload->max_height = 73; + $this->assertTrue($this->upload->is_allowed_dimensions()); } function test_validate_upload_path() @@ -198,6 +234,9 @@ class Upload_test extends CI_TestCase { $this->upload->file_temp = vfsStream::url('file3.txt'); $this->assertFalse($this->upload->do_xss_clean()); + + $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif'; + $this->assertTrue($this->upload->do_xss_clean()); } function test_set_error() diff --git a/tests/mocks/uploads/ci_logo.gif b/tests/mocks/uploads/ci_logo.gif new file mode 100644 index 000000000..073ec14b4 Binary files /dev/null and b/tests/mocks/uploads/ci_logo.gif differ -- cgit v1.2.3-24-g4f1b From eeb6a480a4a25b7fe96e9ba0cf3aef273fd13c67 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Thu, 30 Aug 2012 09:46:20 -0400 Subject: Better way - autoloader uses first config path Signed-off-by: dchill42 --- tests/mocks/core/loader.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php index c0e02139e..9eb78253b 100644 --- a/tests/mocks/core/loader.php +++ b/tests/mocks/core/loader.php @@ -30,7 +30,6 @@ class Mock_Core_Loader extends CI_Loader { $this->_ci_helper_paths = array($this->app_path, $this->base_path); $this->_ci_model_paths = array($this->app_path); $this->_ci_view_paths = array($this->app_path.'views/' => TRUE); - $this->_ci_autoloader_path = $this->app_path; } /** -- cgit v1.2.3-24-g4f1b From 5e9710842dc6981f4eb03c1622eabee9b3171dea Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Mon, 3 Sep 2012 18:57:35 +0100 Subject: Added Calendar library unit test --- tests/codeigniter/libraries/Calendar_test.php | 204 ++++++++++++++++++++++++++ tests/mocks/libraries/calendar.php | 25 ++++ 2 files changed, 229 insertions(+) create mode 100644 tests/codeigniter/libraries/Calendar_test.php create mode 100644 tests/mocks/libraries/calendar.php (limited to 'tests') diff --git a/tests/codeigniter/libraries/Calendar_test.php b/tests/codeigniter/libraries/Calendar_test.php new file mode 100644 index 000000000..95668d70d --- /dev/null +++ b/tests/codeigniter/libraries/Calendar_test.php @@ -0,0 +1,204 @@ +calendar = new Mock_Libraries_Calendar(); + + $this->calendar = $obj->calendar; + } + + function test_initialize() + { + $this->calendar->initialize(array( + 'month_type' => 'short', + 'start_day' => 'monday' + )); + $this->assertEquals('short', $this->calendar->month_type); + $this->assertEquals('monday', $this->calendar->start_day); + } + + /** + * @covers Mock_Libraries_Calendar::parse_template + */ + function test_generate() + { + $no_events = ' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
September 2011
SuMoTuWeThFrSa
    123
45678910
11121314151617
18192021222324
252627282930 
'; + + $this->assertEquals($no_events, $this->calendar->generate(2011, 9)); + + $data = array( + 3 => 'http://example.com/news/article/2006/03/', + 7 => 'http://example.com/news/article/2006/07/', + 13 => 'http://example.com/news/article/2006/13/', + 26 => 'http://example.com/news/article/2006/26/' + ); + + $events = ' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
September 2011
SuMoTuWeThFrSa
    123
45678910
11121314151617
18192021222324
252627282930 
'; + + $this->assertEquals($events, $this->calendar->generate(2011, 9, $data)); + } + + function test_get_month_name() + { + $this->calendar->month_type = NULL; + $this->assertEquals('January', $this->calendar->get_month_name('01')); + + $this->calendar->month_type = 'short'; + $this->assertEquals('Jan', $this->calendar->get_month_name('01')); + } + + function test_get_day_names() + { + $this->assertEquals(array( + 'Sunday', + 'Monday', + 'Tuesday', + 'Wednesday', + 'Thursday', + 'Friday', + 'Saturday' + ), $this->calendar->get_day_names('long')); + + $this->assertEquals(array( + 'Sun', + 'Mon', + 'Tue', + 'Wed', + 'Thu', + 'Fri', + 'Sat' + ), $this->calendar->get_day_names('short')); + + $this->calendar->day_type = NULL; + + $this->assertEquals(array( + 'Su', + 'Mo', + 'Tu', + 'We', + 'Th', + 'Fr', + 'Sa' + ), $this->calendar->get_day_names()); + } + + function test_adjust_date() + { + $this->assertEquals(array('month' => 8, 'year' => 2012), $this->calendar->adjust_date(8, 2012)); + $this->assertEquals(array('month' => 1, 'year' => 2013), $this->calendar->adjust_date(13, 2012)); + } + + function test_get_total_days() + { + $this->assertEquals(0, $this->calendar->get_total_days(13, 2012)); + + $this->assertEquals(31, $this->calendar->get_total_days(1, 2012)); + $this->assertEquals(28, $this->calendar->get_total_days(2, 2011)); + $this->assertEquals(29, $this->calendar->get_total_days(2, 2012)); + $this->assertEquals(31, $this->calendar->get_total_days(3, 2012)); + $this->assertEquals(30, $this->calendar->get_total_days(4, 2012)); + $this->assertEquals(31, $this->calendar->get_total_days(5, 2012)); + $this->assertEquals(30, $this->calendar->get_total_days(6, 2012)); + $this->assertEquals(31, $this->calendar->get_total_days(7, 2012)); + $this->assertEquals(31, $this->calendar->get_total_days(8, 2012)); + $this->assertEquals(30, $this->calendar->get_total_days(9, 2012)); + $this->assertEquals(31, $this->calendar->get_total_days(10, 2012)); + $this->assertEquals(30, $this->calendar->get_total_days(11, 2012)); + $this->assertEquals(31, $this->calendar->get_total_days(12, 2012)); + } + + function test_default_template() + { + $array = array( + 'table_open' => '', + 'heading_row_start' => '', + 'heading_previous_cell' => '', + 'heading_title_cell' => '', + 'heading_next_cell' => '', + 'heading_row_end' => '', + 'week_row_start' => '', + 'week_day_cell' => '', + 'week_row_end' => '', + 'cal_row_start' => '', + 'cal_cell_start' => '', + 'cal_cell_end_today' => '', + 'cal_row_end' => '', + 'table_close' => '
<<{heading}>>
{week_day}
', + 'cal_cell_start_today' => '', + 'cal_cell_content' => '{day}', + 'cal_cell_content_today' => '{day}', + 'cal_cell_no_content' => '{day}', + 'cal_cell_no_content_today' => '{day}', + 'cal_cell_blank' => ' ', + 'cal_cell_end' => '
' + ); + + $this->assertEquals($array, $this->calendar->default_template()); + } + +} \ No newline at end of file diff --git a/tests/mocks/libraries/calendar.php b/tests/mocks/libraries/calendar.php new file mode 100644 index 000000000..8fee5365e --- /dev/null +++ b/tests/mocks/libraries/calendar.php @@ -0,0 +1,25 @@ +CI = new stdClass; + $this->CI->lang = new Mock_Core_Lang(); + + if ( ! in_array('calendar_lang.php', $this->CI->lang->is_loaded, TRUE)) + { + $this->CI->lang->load('calendar'); + } + + $this->local_time = time(); + + if (count($config) > 0) + { + $this->initialize($config); + } + + log_message('debug', 'Calendar Class Initialized'); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 8280885499ca4b1cffacc9ad78a9eff07a84de25 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Thu, 13 Sep 2012 05:19:59 +0200 Subject: directory_map() was skipping files and directories named "0" Close #1757. Thanks @BennyC! --- tests/codeigniter/helpers/directory_helper_test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php index 176ff1d78..c39ccd8d0 100644 --- a/tests/codeigniter/helpers/directory_helper_test.php +++ b/tests/codeigniter/helpers/directory_helper_test.php @@ -19,6 +19,7 @@ class Directory_helper_test extends CI_TestCase { 'benchmark.html' => '', 'database' => array('active_record.html' => '', 'binds.html' => ''), 'email.html' => '', + '0' => '', '.hiddenfile.txt' => '' ) ); @@ -30,7 +31,8 @@ class Directory_helper_test extends CI_TestCase { 'libraries' => array( 'benchmark.html', 'database' => array('active_record.html', 'binds.html'), - 'email.html' + 'email.html', + '0' ) ); -- cgit v1.2.3-24-g4f1b From 431afaedaea55bc20716babe21557fd2b0ad531c Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 14 Sep 2012 00:57:41 +0700 Subject: Set code-coverage limit scope Signed-off-by: Taufan Aditya --- tests/travis/mysql.phpunit.xml | 2 +- tests/travis/pdo/mysql.phpunit.xml | 2 +- tests/travis/pdo/pgsql.phpunit.xml | 2 +- tests/travis/pdo/sqlite.phpunit.xml | 2 +- tests/travis/pgsql.phpunit.xml | 2 +- tests/travis/sqlite.phpunit.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml index 38c8eba48..06d4a011b 100644 --- a/tests/travis/mysql.phpunit.xml +++ b/tests/travis/mysql.phpunit.xml @@ -18,7 +18,7 @@ - + ../../system diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml index c3113a66f..7121edc45 100644 --- a/tests/travis/pdo/mysql.phpunit.xml +++ b/tests/travis/pdo/mysql.phpunit.xml @@ -18,7 +18,7 @@ - + ../../../system diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml index 232025523..df3ff986e 100644 --- a/tests/travis/pdo/pgsql.phpunit.xml +++ b/tests/travis/pdo/pgsql.phpunit.xml @@ -18,7 +18,7 @@ - + ../../../system diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml index 3d1256721..7d867f6d1 100644 --- a/tests/travis/pdo/sqlite.phpunit.xml +++ b/tests/travis/pdo/sqlite.phpunit.xml @@ -18,7 +18,7 @@ - + ../../../system diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml index 51e433d76..bfddbf6b5 100644 --- a/tests/travis/pgsql.phpunit.xml +++ b/tests/travis/pgsql.phpunit.xml @@ -18,7 +18,7 @@ - + ../../system diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml index 701165734..75c946aee 100644 --- a/tests/travis/sqlite.phpunit.xml +++ b/tests/travis/sqlite.phpunit.xml @@ -18,7 +18,7 @@ - + ../../system -- cgit v1.2.3-24-g4f1b From 13be5578e7ea440f4f33bc4c5c22096686224d66 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 4 Oct 2012 12:43:03 +0300 Subject: Fix escape_like_str() tests --- tests/codeigniter/database/query_builder/escape_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index c6380ddf1..27e678f22 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -27,7 +27,7 @@ class Escape_test extends CI_TestCase { if (strpos(DB_DRIVER, 'mysql') !== FALSE) { - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '';"; + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '!';"; } else { @@ -52,7 +52,7 @@ class Escape_test extends CI_TestCase { if (strpos(DB_DRIVER, 'mysql') !== FALSE) { - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '';"; + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '!';"; } else { -- cgit v1.2.3-24-g4f1b From 0df3585eec575d2d2e7d17c5339ed219a33dfde8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 23:10:23 +0300 Subject: Add unit test --- tests/codeigniter/helpers/date_helper_test.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 1b79b9480..9feade71c 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -290,6 +290,29 @@ class Date_helper_test extends CI_TestCase { $this->assertEquals(0, timezones('non_existant')); } + // ------------------------------------------------------------------------ + + public function test_date_range() + { + $dates = array( + '29-01-2012', '30-01-2012', '31-01-2012', + '01-02-2012', '02-02-2012', '03-02-2012', + '04-02-2012', '05-02-2012', '06-02-2012', + '07-02-2012', '08-02-2012', '09-02-2012', + '10-02-2012', '11-02-2012', '12-02-2012', + '13-02-2012', '14-02-2012', '15-02-2012', + '16-02-2012', '17-02-2012', '18-02-2012', + '19-02-2012', '20-02-2012', '21-02-2012', + '22-02-2012', '23-02-2012', '24-02-2012', + '25-02-2012', '26-02-2012', '27-02-2012', + '28-02-2012', '29-02-2012', '01-03-2012' + ); + + $this->assertEquals($dates, date_range(mktime(12, 0, 0, 1, 29, 2012), mktime(12, 0, 0, 3, 1, 2012), TRUE, 'd-m-Y')); + array_pop($dates); + $this->assertEquals($dates, date_range(mktime(12, 0, 0, 1, 29, 2012), 31, FALSE, 'd-m-Y')); + } + } /* End of file date_helper_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 580fe8ec482f5df7ca5b91e11b13b72a8f3ed0b8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 9 Oct 2012 13:27:50 +0300 Subject: Set REMOTE_ADDR in tests --- tests/Bootstrap.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 5216038c6..1c666d503 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -11,6 +11,7 @@ defined('PROJECT_BASE') OR define('PROJECT_BASE', realpath($dir.'/../').'/'); defined('BASEPATH') OR define('BASEPATH', PROJECT_BASE.'system/'); defined('APPPATH') OR define('APPPATH', PROJECT_BASE.'application/'); defined('VIEWPATH') OR define('VIEWPATH', PROJECT_BASE.''); +isset($_SERVER['REMOTE_ADDR']) OR $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // Get vfsStream either via PEAR or composer foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) -- cgit v1.2.3-24-g4f1b From 82003dac7e1da25ffb0d925ba197121b5b7b27f5 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 9 Oct 2012 13:28:17 -0400 Subject: Overloaded is_cli_request in Input mock for Session test Signed-off-by: dchill42 --- tests/codeigniter/libraries/Session_test.php | 17 ++++++----------- tests/mocks/core/input.php | 10 ++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php index 135f71806..60d3a5b30 100644 --- a/tests/codeigniter/libraries/Session_test.php +++ b/tests/codeigniter/libraries/Session_test.php @@ -30,15 +30,11 @@ class Session_test extends CI_TestCase { // Establish necessary support classes $obj = new stdClass; - $classes = array( - 'config' => 'cfg', - 'load' => 'load', - 'input' => 'in' - ); - foreach ($classes as $name => $abbr) { - $class = $this->ci_core_class($abbr); - $obj->$name = new $class; - } + $cfg = $this->ci_core_class('cfg'); + $obj->config = new $cfg(); + $ldr = $this->ci_core_class('load'); + $obj->load = new $ldr(); + $obj->input = new Mock_Core_Input(NULL, NULL); $this->ci_instance($obj); // Attach session instance locally @@ -401,5 +397,4 @@ class Session_test extends CI_TestCase { $this->session->native->sess_destroy(); $this->assertNull($this->session->native->userdata($key)); } -} - +} \ No newline at end of file diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php index 2a4aa4997..0d1873849 100644 --- a/tests/mocks/core/input.php +++ b/tests/mocks/core/input.php @@ -28,4 +28,14 @@ class Mock_Core_Input extends CI_Input { return parent::_fetch_from_array($array, $index, $xss_clean); } + /** + * Lie about being a CLI request + * + * We take advantage of this in libraries/Session_test + */ + public function is_cli_request() + { + return FALSE; + } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 7ecc5cda6647a4b316b44dc40d5925d9ef63c908 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Fri, 12 Oct 2012 16:25:51 -0400 Subject: Integrated vfsStream better and made paths constants VFS-based Signed-off-by: dchill42 --- tests/Bootstrap.php | 14 +- tests/codeigniter/core/Lang_test.php | 2 + tests/codeigniter/core/Loader_test.php | 124 ++++----------- tests/codeigniter/helpers/date_helper_test.php | 2 + tests/codeigniter/helpers/form_helper_test.php | 8 +- tests/codeigniter/helpers/number_helper_test.php | 17 +- tests/codeigniter/helpers/text_helper_test.php | 1 + tests/codeigniter/libraries/Encrypt_test.php | 7 +- tests/codeigniter/libraries/Parser_test.php | 8 +- tests/codeigniter/libraries/Session_test.php | 12 +- tests/codeigniter/libraries/Table_test.php | 8 +- tests/codeigniter/libraries/Typography_test.php | 8 +- tests/codeigniter/libraries/Upload_test.php | 57 +++---- tests/codeigniter/libraries/Useragent_test.php | 7 +- tests/mocks/autoloader.php | 12 +- tests/mocks/ci_testcase.php | 192 ++++++++++++++++++++++- tests/mocks/ci_testconfig.php | 18 +++ tests/mocks/core/common.php | 26 ++- tests/mocks/core/loader.php | 30 ---- 19 files changed, 330 insertions(+), 223 deletions(-) create mode 100644 tests/mocks/ci_testconfig.php (limited to 'tests') diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 1c666d503..ea8d8aea8 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -8,10 +8,7 @@ $dir = realpath(dirname(__FILE__)); // Path constants defined('PROJECT_BASE') OR define('PROJECT_BASE', realpath($dir.'/../').'/'); -defined('BASEPATH') OR define('BASEPATH', PROJECT_BASE.'system/'); -defined('APPPATH') OR define('APPPATH', PROJECT_BASE.'application/'); -defined('VIEWPATH') OR define('VIEWPATH', PROJECT_BASE.''); -isset($_SERVER['REMOTE_ADDR']) OR $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; +defined('SYSTEM_PATH') OR define('SYSTEM_PATH', PROJECT_BASE.'system/'); // Get vfsStream either via PEAR or composer foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) @@ -31,8 +28,17 @@ if ( ! class_exists('vfsStream') && file_exists(PROJECT_BASE.'vendor/autoload.ph class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper'); } +// Define CI path constants to VFS (filesystem setup in CI_TestCase::setUp) +defined('BASEPATH') OR define('BASEPATH', vfsStream::url('system/')); +defined('APPPATH') OR define('APPPATH', vfsStream::url('application/')); +defined('VIEWPATH') OR define('VIEWPATH', APPPATH.'views/'); + +// Set localhost "remote" IP +isset($_SERVER['REMOTE_ADDR']) OR $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; + // Prep our test environment include_once $dir.'/mocks/core/common.php'; +include_once SYSTEM_PATH.'core/common.php'; include_once $dir.'/mocks/autoloader.php'; spl_autoload_register('autoload'); diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php index a410dabfa..3364362e0 100644 --- a/tests/codeigniter/core/Lang_test.php +++ b/tests/codeigniter/core/Lang_test.php @@ -17,6 +17,7 @@ class Lang_test extends CI_TestCase { public function test_load() { + $this->ci_vfs_clone('system/language/english/profiler_lang.php'); $this->assertTrue($this->lang->load('profiler', 'english')); $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); } @@ -25,6 +26,7 @@ class Lang_test extends CI_TestCase { public function test_load_with_unspecified_language() { + $this->ci_vfs_clone('system/language/english/profiler_lang.php'); $this->assertTrue($this->lang->load('profiler')); $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); } diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index db79e6a8b..69b2afb63 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -9,11 +9,11 @@ class Loader_test extends CI_TestCase { // Instantiate a new loader $this->load = new Mock_Core_Loader(); - // mock up a ci instance - $this->ci_obj = new stdClass; + // Get CI instance + $this->ci_obj = $this->ci_instance(); - // Fix get_instance() - $this->ci_instance($this->ci_obj); + // Set subclass prefix + $this->ci_set_config('subclass_prefix', 'MY_'); } // -------------------------------------------------------------------- @@ -23,13 +23,10 @@ class Loader_test extends CI_TestCase { */ public function test_library() { - $this->_setup_config_mock(); - // Create libraries directory with test library $lib = 'unit_test_lib'; $class = 'CI_'.ucfirst($lib); - $content = '_create_content('libraries', $lib, $content, NULL, TRUE); + $this->ci_vfs_create($lib, 'ci_base_root, 'libraries'); // Test loading as an array. $this->assertNull($this->load->library(array($lib))); @@ -50,13 +47,11 @@ class Loader_test extends CI_TestCase { */ public function test_library_config() { - $this->_setup_config_mock(); - // Create libraries directory with test library $lib = 'unit_test_config_lib'; $class = 'CI_'.ucfirst($lib); - $content = 'config = $params; } } '; - $this->_create_content('libraries', $lib, $content, NULL, TRUE); + $content = 'config = $params; } }'; + $this->ci_vfs_create($lib, $content, $this->ci_base_root, 'libraries'); // Create config file $cfg = array( @@ -64,7 +59,7 @@ class Loader_test extends CI_TestCase { 'bar' => 'baz', 'baz' => false ); - $this->_create_content('config', $lib, 'ci_vfs_create($lib, 'ci_app_root, 'config'); // Test object name and config $obj = 'testy'; @@ -81,13 +76,10 @@ class Loader_test extends CI_TestCase { */ public function test_load_library_in_application_dir() { - $this->_setup_config_mock(); - // Create libraries directory in app path with test library $lib = 'super_test_library'; $class = ucfirst($lib); - $content = '_create_content('libraries', $lib, $content); + $this->ci_vfs_create($lib, 'ci_app_root, 'libraries'); // Load library $this->assertNull($this->load->library($lib)); @@ -104,14 +96,12 @@ class Loader_test extends CI_TestCase { */ public function test_driver() { - $this->_setup_config_mock(); - // Create libraries directory with test driver $driver = 'unit_test_driver'; $dir = ucfirst($driver); $class = 'CI_'.$dir; $content = '_create_content('libraries', $driver, $content, $dir, TRUE); + $this->ci_vfs_create($driver, $content, $this->ci_base_root, 'libraries/'.$dir); // Test loading as an array. $this->assertNull($this->load->driver(array($driver))); @@ -158,7 +148,7 @@ class Loader_test extends CI_TestCase { $model = 'unit_test_model'; $class = ucfirst($model); $content = '_create_content('models', $model, $content); + $this->ci_vfs_create($model, $content, $this->ci_app_root, 'models'); // Load model $this->assertNull($this->load->model($model)); @@ -190,7 +180,7 @@ class Loader_test extends CI_TestCase { // Create views directory with test view $view = 'unit_test_view'; $content = 'This is my test page. '; - $this->_create_content('views', $view, $content); + $this->ci_vfs_create($view, $content, $this->ci_app_root, 'views'); // Use the optional return parameter in this test, so the view is not // run through the output class. @@ -224,10 +214,10 @@ class Loader_test extends CI_TestCase { $dir = 'views'; $file = 'ci_test_mock_file'; $content = 'Here is a test file, which we will load now.'; - $this->_create_content($dir, $file, $content); + $this->ci_vfs_create($file, $content, $this->ci_app_root, $dir); // Just like load->view(), take the output class out of the mix here. - $out = $this->load->file($this->load->app_path.$dir.'/'.$file.'.php', TRUE); + $out = $this->load->file(APPPATH.$dir.'/'.$file.'.php', TRUE); $this->assertEquals($content, $out); // Test non-existent file @@ -261,7 +251,7 @@ class Loader_test extends CI_TestCase { $helper = 'test'; $func = '_my_helper_test_func'; $content = '_create_content('helpers', $helper.'_helper', $content); + $this->ci_vfs_create($helper.'_helper', $content, $this->ci_app_root, 'helpers'); // Load helper $this->assertEquals(NULL, $this->load->helper($helper)); @@ -294,7 +284,7 @@ class Loader_test extends CI_TestCase { $funcs[] = $func; $files[$helper.'_helper'] = '_create_content('helpers', $files, NULL, NULL, TRUE); + $this->ci_vfs_create($files, NULL, $this->ci_base_root, 'helpers'); // Load helpers $this->assertEquals(NULL, $this->load->helpers($helpers)); @@ -321,14 +311,12 @@ class Loader_test extends CI_TestCase { */ public function test_packages() { - $this->_setup_config_mock(); - // Create third-party directory in app path with model $dir = 'third-party'; $lib = 'unit_test_package'; $class = 'CI_'.ucfirst($lib); $content = '_create_content($dir, $lib, $content); + $this->ci_vfs_create($lib, $content, $this->ci_app_root, $dir); // Test failed load without path $this->setExpectedException( @@ -342,7 +330,7 @@ class Loader_test extends CI_TestCase { $paths = $this->load->get_package_paths(TRUE); // Add path and verify - $path = $this->load->app_path.$dir; + $path = APPPATH.$dir; $this->assertNull($this->load->add_package_path($path)); $this->assertContains($path, $this->load->get_package_paths(TRUE)); @@ -362,7 +350,6 @@ class Loader_test extends CI_TestCase { */ public function test_load_config() { - $this->_setup_config_mock(); $this->assertNull($this->load->config('config', FALSE)); } @@ -373,35 +360,29 @@ class Loader_test extends CI_TestCase { */ public function test_autoloader() { - $this->_setup_config_mock(); - // Create helper directory in app path with test helper $helper = 'autohelp'; $hlp_func = '_autohelp_test_func'; - $this->_create_content('helpers', $helper.'_helper', 'ci_vfs_create($helper.'_helper', $content, $this->ci_app_root, 'helpers'); // Create libraries directory in base path with test library $lib = 'autolib'; $lib_class = 'CI_'.ucfirst($lib); - $this->_create_content('libraries', $lib, 'ci_vfs_create($lib, 'ci_base_root, 'libraries'); - // Create libraries subdirectory with test driver - // Since libraries/ now exists, we have to look it up and - // add the subdir directly instead of using _create_content + // Create test driver $drv = 'autodrv'; $subdir = ucfirst($drv); $drv_class = 'CI_'.$subdir; - $tree = array( - $subdir => array($drv.'.php' => 'load->base_root->getChild('libraries')); + $this->ci_vfs_create($drv, 'ci_base_root, 'libraries/'.$subdir); // Create package directory in app path with model $dir = 'testdir'; - $path = $this->load->app_path.$dir.'/'; + $path = APPPATH.$dir.'/'; $model = 'automod'; $mod_class = ucfirst($model); - $this->_create_content($dir, $model, 'ci_vfs_create($model, 'ci_app_root, $dir.'/models'); // Create autoloader config $cfg = array( @@ -412,7 +393,7 @@ class Loader_test extends CI_TestCase { 'model' => array($model), 'config' => array() ); - $this->_create_content('config', 'autoload', 'ci_vfs_create('autoload', 'ci_app_root, 'config'); // Run autoloader $this->load->autoload(); @@ -436,55 +417,4 @@ class Loader_test extends CI_TestCase { $this->assertAttributeInstanceOf($mod_class, $model, $this->ci_obj); } - // -------------------------------------------------------------------- - - private function _setup_config_mock() - { - // Mock up a config object so config() has something to call - $config = $this->getMock('CI_Config', array('load'), array(), '', FALSE); - $config->expects($this->any()) - ->method('load') - ->will($this->returnValue(TRUE)); - - // Reinitialize config paths to use VFS - $config->_config_paths = array($this->load->app_path); - - // Add the mock to our stdClass - $this->ci_instance_var('config', $config); - } - - // -------------------------------------------------------------------- - - private function _create_content($dir, $file, $content, $sub = NULL, $base = FALSE) - { - // Create structure containing directory - $tree = array($dir => array()); - - // Check for subdirectory - if ($sub) { - // Add subdirectory to tree and get reference - $tree[$dir][$sub] = array(); - $leaf =& $tree[$dir][$sub]; - } - else { - // Get reference to main directory - $leaf =& $tree[$dir]; - } - - // Check for multiple files - if (is_array($file)) { - // Add multiple files to directory - foreach ($file as $name => $data) { - $leaf[$name.'.php'] = $data; - } - } - else { - // Add single file with content - $leaf[$file.'.php'] = $content; - } - - // Create structure under app or base path - vfsStream::create($tree, $base ? $this->load->base_root : $this->load->app_root); - } - -} +} \ No newline at end of file diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 9feade71c..1458acd3e 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -168,6 +168,8 @@ class Date_helper_test extends CI_TestCase { public function test_timespan() { + $this->ci_vfs_clone('system/language/english/date_lang.php'); + $loader_cls = $this->ci_core_class('load'); $this->ci_instance_var('load', new $loader_cls); diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php index 1a30ed993..48628d2e5 100644 --- a/tests/codeigniter/helpers/form_helper_test.php +++ b/tests/codeigniter/helpers/form_helper_test.php @@ -1,10 +1,12 @@ helper('form'); + } + public function test_form_hidden() { $expected = <<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'); + $lang->language = $this->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->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) - { - require BASEPATH.'language/english/'.$name.'_lang.php'; - return $lang; + $this->ci_instance_var('lang', $lang); } public function test_byte_format() diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index f131469cb..d75d26208 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -64,6 +64,7 @@ class Text_helper_test extends CI_TestCase { public function test_convert_accented_characters() { + $this->ci_vfs_clone('application/config/foreign_chars.php'); $this->assertEquals('AAAeEEEIIOOEUUUeY', convert_accented_characters('ÀÂÄÈÊËÎÏÔŒÙÛÜŸ')); $this->assertEquals('a e i o u n ue', convert_accented_characters('á é í ó ú ñ ü')); } diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php index 153a25e1d..998d806b3 100644 --- a/tests/codeigniter/libraries/Encrypt_test.php +++ b/tests/codeigniter/libraries/Encrypt_test.php @@ -4,11 +4,8 @@ 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->encrypt = new Mock_Libraries_Encrypt(); + $this->ci_instance_var('encrypt', $this->encrypt); $this->ci_set_config('encryption_key', "Encryptin'glike@boss!"); $this->msg = 'My secret message'; diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php index b68f44a33..394c22692 100644 --- a/tests/codeigniter/libraries/Parser_test.php +++ b/tests/codeigniter/libraries/Parser_test.php @@ -4,12 +4,8 @@ class Parser_test extends CI_TestCase { public function set_up() { - $obj = new stdClass; - $obj->parser = new Mock_Libraries_Parser(); - - $this->ci_instance($obj); - - $this->parser = $obj->parser; + $this->parser = new Mock_Libraries_Parser(); + $this->ci_instance_var('parser', $this->parser); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php index 60d3a5b30..14469f7fa 100644 --- a/tests/codeigniter/libraries/Session_test.php +++ b/tests/codeigniter/libraries/Session_test.php @@ -29,13 +29,15 @@ class Session_test extends CI_TestCase { $_COOKIE = array(); // Establish necessary support classes - $obj = new stdClass; $cfg = $this->ci_core_class('cfg'); - $obj->config = new $cfg(); $ldr = $this->ci_core_class('load'); - $obj->load = new $ldr(); - $obj->input = new Mock_Core_Input(NULL, NULL); - $this->ci_instance($obj); + $ci = $this->ci_instance(); + $ci->config = new $cfg(); + $ci->load = new $ldr(); + $ci->input = new Mock_Core_Input(NULL, NULL); + + // Make sure string helper is available + $this->ci_vfs_clone('system/helpers/string_helper.php'); // Attach session instance locally $config = array( diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index edfc83dd0..ce04b6a6d 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -4,12 +4,8 @@ class Table_test extends CI_TestCase { public function set_up() { - $obj = new stdClass; - $obj->table = new Mock_Libraries_Table(); - - $this->ci_instance($obj); - - $this->table = $obj->table; + $this->table = new Mock_Libraries_Table(); + $this->ci_instance_var('table', $this->table); } // Setter Methods diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php index eb6dacb73..5dba06243 100644 --- a/tests/codeigniter/libraries/Typography_test.php +++ b/tests/codeigniter/libraries/Typography_test.php @@ -4,12 +4,8 @@ class Typography_test extends CI_TestCase { public function set_up() { - $obj = new stdClass; - $obj->type = new Mock_Libraries_Typography(); - - $this->ci_instance($obj); - - $this->type = $obj->type; + $this->type = new Mock_Libraries_Typography(); + $this->ci_instance('type', $this->type); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php index d79a3ffc9..827942773 100644 --- a/tests/codeigniter/libraries/Upload_test.php +++ b/tests/codeigniter/libraries/Upload_test.php @@ -4,18 +4,11 @@ class Upload_test extends CI_TestCase { function set_up() { - $obj = new stdClass; - $obj->upload = new Mock_Libraries_Upload(); - $obj->security = new Mock_Core_Security(); - $obj->lang = new Mock_Core_Lang(); - - $this->ci_instance($obj); - $this->upload = $obj->upload; - - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); - - $this->_test_dir = vfsStreamWrapper::getRoot(); + $ci = $this->ci_instance(); + $ci->upload = new Mock_Libraries_Upload(); + $ci->security = new Mock_Core_Security(); + $ci->lang = new Mock_Core_Lang(); + $this->upload = $ci->upload; } function test_do_upload() @@ -64,11 +57,15 @@ class Upload_test extends CI_TestCase { function test_set_filename() { - $file1 = vfsStream::newFile('hello-world.txt')->withContent('Hello world.')->at($this->_test_dir); + $dir = 'uploads'; + $isnew = 'helloworld.txt'; + $exists = 'hello-world.txt'; + $this->ci_vfs_create($exists, 'Hello world.', $this->ci_app_root, $dir); + $path = $this->ci_vfs_path($dir.'/', APPPATH); $this->upload->file_ext = '.txt'; - $this->assertEquals('helloworld.txt', $this->upload->set_filename(vfsStream::url('testDir').'/', 'helloworld.txt')); - $this->assertEquals('hello-world1.txt', $this->upload->set_filename(vfsStream::url('testDir').'/', 'hello-world.txt')); + $this->assertEquals($isnew, $this->upload->set_filename($path, $isnew)); + $this->assertEquals('hello-world1.txt', $this->upload->set_filename($path, $exists)); } function test_set_max_filesize() @@ -107,7 +104,7 @@ class Upload_test extends CI_TestCase { function test_set_image_properties() { $this->upload->file_type = 'image/gif'; - $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif'; + $this->upload->file_temp = realpath(PROJECT_BASE.'tests/mocks/uploads/ci_logo.gif'); $props = array( 'image_width' => 170, @@ -156,7 +153,7 @@ class Upload_test extends CI_TestCase { $this->assertTrue($this->upload->is_allowed_filetype(FALSE)); $this->assertTrue($this->upload->is_allowed_filetype(TRUE)); - $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif'; + $this->upload->file_temp = realpath(PROJECT_BASE.'tests/mocks/uploads/ci_logo.gif'); $this->upload->file_ext = '.gif'; $this->upload->file_type = 'image/gif'; $this->assertTrue($this->upload->is_allowed_filetype()); @@ -179,7 +176,7 @@ class Upload_test extends CI_TestCase { $this->assertTrue($this->upload->is_allowed_dimensions()); $this->upload->file_type = 'image/gif'; - $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif'; + $this->upload->file_temp = realpath(PROJECT_BASE.'tests/mocks/uploads/ci_logo.gif'); $this->upload->max_width = 10; $this->assertFalse($this->upload->is_allowed_dimensions()); @@ -197,7 +194,9 @@ class Upload_test extends CI_TestCase { $this->upload->upload_path = ''; $this->assertFalse($this->upload->validate_upload_path()); - $this->upload->upload_path = vfsStream::url('testDir'); + $dir = 'uploads'; + $this->ci_vfs_mkdir($dir); + $this->upload->upload_path = $this->ci_vfs_path($dir); $this->assertTrue($this->upload->validate_upload_path()); } @@ -222,20 +221,24 @@ class Upload_test extends CI_TestCase { function test_do_xss_clean() { - $file1 = vfsStream::newFile('file1.txt')->withContent('The billy goat was waiting for them.')->at($this->_test_dir); - $file2 = vfsStream::newFile('file2.txt')->at($this->_test_dir); - $file3 = vfsStream::newFile('file3.txt')->withContent('')->at($this->_test_dir); - - $this->upload->file_temp = vfsStream::url('file1.txt'); + $dir = 'uploads'; + $file1 = 'file1.txt'; + $file2 = 'file2.txt'; + $file3 = 'file3.txt'; + $this->ci_vfs_create($file1, 'The billy goat was waiting for them.', $this->ci_vfs_root, $dir); + $this->ci_vfs_create($file2, '', $this->ci_vfs_root, $dir); + $this->ci_vfs_create($file3, '', $this->ci_vfs_root, $dir); + + $this->upload->file_temp = $this->ci_vfs_path($file1, $dir); $this->assertTrue($this->upload->do_xss_clean()); - $this->upload->file_temp = vfsStream::url('file2.txt'); + $this->upload->file_temp = $this->ci_vfs_path($file2, $dir); $this->assertFalse($this->upload->do_xss_clean()); - $this->upload->file_temp = vfsStream::url('file3.txt'); + $this->upload->file_temp = $this->ci_vfs_path($file3, $dir); $this->assertFalse($this->upload->do_xss_clean()); - $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif'; + $this->upload->file_temp = realpath(PROJECT_BASE.'tests/mocks/uploads/ci_logo.gif'); $this->assertTrue($this->upload->do_xss_clean()); } diff --git a/tests/codeigniter/libraries/Useragent_test.php b/tests/codeigniter/libraries/Useragent_test.php index 89383f807..e3726554e 100644 --- a/tests/codeigniter/libraries/Useragent_test.php +++ b/tests/codeigniter/libraries/Useragent_test.php @@ -10,12 +10,11 @@ class UserAgent_test extends CI_TestCase { // set a baseline user agent $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent; - $obj = new stdClass; - $obj->agent = new Mock_Libraries_UserAgent(); + $this->ci_vfs_clone('application/config/user_agents.php'); - $this->ci_instance($obj); + $this->agent = new Mock_Libraries_UserAgent(); - $this->agent = $obj->agent; + $this->ci_instance_var('agent', $this->agent); } // -------------------------------------------------------------------- diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 88d016bba..431c310d4 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -48,32 +48,32 @@ function autoload($class) if (in_array($subclass, $ci_core)) { - $dir = BASEPATH.'core'.DIRECTORY_SEPARATOR; + $dir = SYSTEM_PATH.'core'.DIRECTORY_SEPARATOR; $class = $subclass; } elseif (in_array($subclass, $ci_libraries)) { - $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR; + $dir = SYSTEM_PATH.'libraries'.DIRECTORY_SEPARATOR; $class = ($subclass === 'Driver_Library') ? 'Driver' : $subclass; } elseif (in_array($subclass, $ci_drivers)) { - $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR.$subclass.DIRECTORY_SEPARATOR; + $dir = SYSTEM_PATH.'libraries'.DIRECTORY_SEPARATOR.$subclass.DIRECTORY_SEPARATOR; $class = $subclass; } elseif (in_array(($parent = strtok($subclass, '_')), $ci_drivers)) { - $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR.$parent.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; + $dir = SYSTEM_PATH.'libraries'.DIRECTORY_SEPARATOR.$parent.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; $class = $subclass; } elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 3) { - $driver_path = BASEPATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; + $driver_path = SYSTEM_PATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; $dir = $driver_path.$m[1].DIRECTORY_SEPARATOR; $file = $dir.$m[1].'_'.$m[2].'.php'; } elseif (strpos($class, 'CI_DB') === 0) { - $dir = BASEPATH.'database'.DIRECTORY_SEPARATOR; + $dir = SYSTEM_PATH.'database'.DIRECTORY_SEPARATOR; $file = $dir.str_replace(array('CI_DB','active_record'), array('DB', 'active_rec'), $subclass).'.php'; } else diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php index eda9e1b60..980e912c5 100644 --- a/tests/mocks/ci_testcase.php +++ b/tests/mocks/ci_testcase.php @@ -2,7 +2,9 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { - protected $ci_config; + public $ci_vfs_root; + public $ci_app_root; + public $ci_base_root; protected $ci_instance; protected static $ci_test_instance; @@ -25,13 +27,18 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { public function __construct() { parent::__construct(); - $this->ci_config = array(); + $this->ci_instance = new StdClass(); } // -------------------------------------------------------------------- public function setUp() { + // Setup VFS with base directories + $this->ci_vfs_root = vfsStream::setup(); + $this->ci_app_root = vfsStream::newDirectory('application')->at($this->ci_vfs_root); + $this->ci_base_root = vfsStream::newDirectory('system')->at($this->ci_vfs_root); + if (method_exists($this, 'set_up')) { $this->set_up(); @@ -57,15 +64,27 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { // -------------------------------------------------------------------- - public function ci_set_config($key, $val = '') + public function ci_set_config($key = '', $val = '') { + // Add test config + if ( ! isset($this->ci_instance->config)) + { + $this->ci_instance->config = new CI_TestConfig(); + } + + // Empty key means just do setup above + if ($key === '') + { + return; + } + if (is_array($key)) { - $this->ci_config = $key; + $this->ci_instance->config->config = $key; } else { - $this->ci_config[$key] = $val; + $this->ci_instance->config->config[$key] = $val; } } @@ -73,7 +92,7 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { public function ci_get_config() { - return $this->ci_config; + return isset($this->ci_instance->config) ? $this->ci_instance->config->config : array(); } // -------------------------------------------------------------------- @@ -132,7 +151,7 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { if ( ! class_exists('CI_'.$class_name)) { - require_once BASEPATH.'core/'.$class_name.'.php'; + require_once SYSTEM_PATH.'core/'.$class_name.'.php'; } $GLOBALS[strtoupper($global_name)] = 'CI_'.$class_name; @@ -148,6 +167,155 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { $orig = $obj; } + /** + * Create VFS directory + * + * @param string Directory name + * @param object Optional root to create in + * @return object New directory object + */ + public function ci_vfs_mkdir($name, $root = NULL) + { + // Check for root + if ( ! $root) + { + $root = $this->ci_vfs_root; + } + + // Return new directory object + return vfsStream::newDirectory($name)->at($root); + } + + // -------------------------------------------------------------------- + + /** + * Create VFS content + * + * @param string File name + * @param string File content + * @param object VFS directory object + * @param mixed Optional subdirectory path or array of subs + * @return void + */ + public function ci_vfs_create($file, $content = '', $root = NULL, $path = NULL) + { + // Check for array + if (is_array($file)) + { + foreach ($file as $name => $content) + { + $this->ci_vfs_create($name, $content, $root, $path); + } + return; + } + + // Assert .php extension if none given + if (pathinfo($file, PATHINFO_EXTENSION) == '') + { + $file .= '.php'; + } + + // Build content + $tree = array($file => $content); + + // Check for path + $subs = array(); + if ($path) + { + // Explode if not array + $subs = is_array($path) ? $path : explode('/', trim($path, '/')); + } + + // Check for root + if ( ! $root) + { + // Use base VFS root + $root = $this->ci_vfs_root; + } + + // Handle subdirectories + while (($dir = array_shift($subs))) + { + // See if subdir exists under current root + $dir_root = $root->getChild($dir); + if ($dir_root) + { + // Yes - recurse into subdir + $root = $dir_root; + } + else + { + // No - put subdirectory back and quit + array_unshift($subs, $dir); + break; + } + } + + // Create any remaining subdirectories + if ($subs) + { + foreach (array_reverse($subs) as $dir) + { + // Wrap content in subdirectory for creation + $tree = array($dir => $tree); + } + } + + // Create tree + vfsStream::create($tree, $root); + } + + // -------------------------------------------------------------------- + + /** + * Clone a real file into VFS + * + * @param string Path from base directory + * @return bool TRUE on success, otherwise FALSE + */ + public function ci_vfs_clone($path) + { + // Get real file contents + $content = file_get_contents(PROJECT_BASE.$path); + if ($content === FALSE) + { + // Couldn't find file to clone + return FALSE; + } + + $this->ci_vfs_create(basename($path), $content, NULL, dirname($path)); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Helper to get a VFS URL path + * + * @param string Path + * @param string Optional base path + * @return string Path URL + */ + public function ci_vfs_path($path, $base = '') + { + // Check for base path + if ($base) + { + // Prepend to path + $path = rtrim($base, '/').'/'.ltrim($path, '/'); + + // Is it already in URL form? + if (strpos($path, '://') !== FALSE) + { + // Done - return path + return $path; + } + } + + // Trim leading slash and return URL + return vfsStream::url(ltrim($path, '/')); + } + // -------------------------------------------------------------------- // Internals // -------------------------------------------------------------------- @@ -171,7 +339,15 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { public function helper($name) { - require_once(BASEPATH.'helpers/'.$name.'_helper.php'); + require_once(SYSTEM_PATH.'helpers/'.$name.'_helper.php'); + } + + // -------------------------------------------------------------------- + + public function lang($name) + { + require(SYSTEM_PATH.'language/english/'.$name.'_lang.php'); + return $lang; } // -------------------------------------------------------------------- diff --git a/tests/mocks/ci_testconfig.php b/tests/mocks/ci_testconfig.php new file mode 100644 index 000000000..eb318ddeb --- /dev/null +++ b/tests/mocks/ci_testconfig.php @@ -0,0 +1,18 @@ +config[$key]) ? $this->config[$key] : FALSE; + } + + public function load($arg1, $arg2, $arg3) + { + return TRUE; + } + +} diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php index a655ee1db..b001074c8 100644 --- a/tests/mocks/core/common.php +++ b/tests/mocks/core/common.php @@ -39,6 +39,30 @@ if ( ! function_exists('config_item')) } } +if ( ! function_exists('get_mimes')) +{ + /** + * Returns the MIME types array from config/mimes.php + * + * @return array + */ + function &get_mimes() + { + static $_mimes = array(); + + if (empty($_mimes)) + { + $path = realpath(PROJECT_BASE.'application/config/mimes.php'); + if (is_file($path)) + { + $_mimes = include($path); + } + } + + return $_mimes; + } +} + // -------------------------------------------------------------------- if ( ! function_exists('load_class')) @@ -166,4 +190,4 @@ if ( ! function_exists('set_status_header')) { return TRUE; } -} \ No newline at end of file +} diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php index 9eb78253b..7ea4da369 100644 --- a/tests/mocks/core/loader.php +++ b/tests/mocks/core/loader.php @@ -2,36 +2,6 @@ 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 - * in the application directory. This will give finer grained control over - * these tests. Also, by mocking the system directory, we eliminate dependency - * on any other classes so errors in libraries, helpers, etc. don't give false - * negatives for the actual loading process. So yeah, while this looks odd, - * I need to overwrite protected class vars in the loader. So here we go... - * - * @covers CI_Loader::__construct() - */ - public function __construct() - { - // Create VFS tree of loader locations - $this->root = vfsStream::setup(); - $this->app_root = vfsStream::newDirectory('application')->at($this->root); - $this->base_root = vfsStream::newDirectory('system')->at($this->root); - - // Get VFS app and base path URLs - $this->app_path = vfsStream::url('application').'/'; - $this->base_path = vfsStream::url('system').'/'; - - // Set loader paths with VFS URLs - $this->_ci_ob_level = ob_get_level(); - $this->_ci_library_paths = array($this->app_path, $this->base_path); - $this->_ci_helper_paths = array($this->app_path, $this->base_path); - $this->_ci_model_paths = array($this->app_path); - $this->_ci_view_paths = array($this->app_path.'views/' => TRUE); - } - /** * Give public access to _ci_autoloader for testing */ -- cgit v1.2.3-24-g4f1b From e9435dc7e5a4a9779eb83d8adf172fabf47ab5a6 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Sun, 14 Oct 2012 15:44:39 -0400 Subject: Adapted DB for VFS changes and fixed Common case in Bootstrap.php Signed-off-by: dchill42 --- tests/Bootstrap.php | 2 +- tests/mocks/autoloader.php | 8 +++++++- tests/mocks/ci_testcase.php | 10 ++++++++++ tests/mocks/database/db.php | 45 +++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 61 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index ea8d8aea8..8ce80b3fd 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -38,7 +38,7 @@ isset($_SERVER['REMOTE_ADDR']) OR $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // Prep our test environment include_once $dir.'/mocks/core/common.php'; -include_once SYSTEM_PATH.'core/common.php'; +include_once SYSTEM_PATH.'core/Common.php'; include_once $dir.'/mocks/autoloader.php'; spl_autoload_register('autoload'); diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 431c310d4..5b202f159 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -65,6 +65,12 @@ function autoload($class) $dir = SYSTEM_PATH.'libraries'.DIRECTORY_SEPARATOR.$parent.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; $class = $subclass; } + elseif (preg_match('/^CI_DB_(.+)_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 4) + { + $driver_path = SYSTEM_PATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; + $dir = $driver_path.$m[1].DIRECTORY_SEPARATOR.'subdrivers'.DIRECTORY_SEPARATOR; + $file = $dir.$m[1].'_'.$m[2].'_'.$m[3].'.php'; + } elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 3) { $driver_path = SYSTEM_PATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; @@ -104,4 +110,4 @@ function autoload($class) } include_once($file); -} +} \ No newline at end of file diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php index 980e912c5..e581d4b02 100644 --- a/tests/mocks/ci_testcase.php +++ b/tests/mocks/ci_testcase.php @@ -275,6 +275,16 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { */ public function ci_vfs_clone($path) { + // Check for array + if (is_array($path)) + { + foreach ($path as $file) + { + $this->ci_vfs_clone($file); + } + return; + } + // Get real file contents $content = file_get_contents(PROJECT_BASE.$path); if ($content === FALSE) diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php index 75658530b..7e0030e15 100644 --- a/tests/mocks/database/db.php +++ b/tests/mocks/database/db.php @@ -7,6 +7,16 @@ class Mock_Database_DB { */ private $config = array(); + /** + * @var string DB driver name + */ + private static $dbdriver = ''; + + /** + * @var string DB sub-driver name + */ + private static $subdriver = ''; + /** * Prepare database configuration skeleton * @@ -31,6 +41,12 @@ class Mock_Database_DB { throw new InvalidArgumentException('Group '.$group.' not exists'); } + self::$dbdriver = $this->config[$group]['dbdriver']; + if (isset($this->config[$group]['subdriver'])) + { + self::$subdriver = $this->config[$group]['subdriver']; + } + $params = array( 'dbprefix' => '', 'pconnect' => FALSE, @@ -50,7 +66,7 @@ class Mock_Database_DB { $failover = empty($config['failover']) ? FALSE : $config['failover']; $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password'] - .'@'.$config['hostname'].'/'.$config['database']; + .'@'.$config['hostname'].'/'.$config['database']; // Build the parameter $other_params = array_slice($config, 6); @@ -83,7 +99,32 @@ class Mock_Database_DB { */ public static function DB($group, $query_builder = FALSE) { - include_once(BASEPATH.'database/DB.php'); + // Create dummy driver and builder files to "load" - the mocks have + // already triggered autoloading of the real files + $case = CI_TestCase::instance(); + $driver = self::$dbdriver; + $subdriver = self::$subdriver; + $case->ci_vfs_create(array( + 'DB_driver.php' => '', + 'DB_forge.php' => '', + 'DB_query_builder.php' => '' + ), '', $case->ci_base_root, 'database'); + if (file_exists(SYSTEM_PATH.'database/drivers/'.$driver.'/'.$driver.'_driver.php')) + { + $case->ci_vfs_create(array( + $driver.'_driver.php' => '', + $driver.'_forge.php' => '' + ), '', $case->ci_base_root, 'database/drivers/'.$driver); + } + if ($subdriver) + { + $case->ci_vfs_create(array( + $driver.'_'.$subdriver.'_driver.php' => '', + $driver.'_'.$subdriver.'_forge.php' => '' + ), '', $case->ci_base_root, 'database/drivers/'.$driver.'/subdrivers'); + } + + include_once(SYSTEM_PATH.'database/DB.php'); try { -- cgit v1.2.3-24-g4f1b From e3621cc79fa4b4658768fea0694cc0ae52835d85 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Sun, 14 Oct 2012 18:23:52 -0400 Subject: Adapted Config load test to VFS APPPATH Signed-off-by: dchill42 --- tests/codeigniter/core/Config_test.php | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php index 7782a7898..80e0862ff 100644 --- a/tests/codeigniter/core/Config_test.php +++ b/tests/codeigniter/core/Config_test.php @@ -94,7 +94,7 @@ class Config_test extends CI_TestCase { public function test_load() { - // Create VFS tree of application config files + // Create config files in VFS $file1 = 'test.php'; $file2 = 'secttest'; $key1 = 'testconfig'; @@ -107,18 +107,10 @@ class Config_test extends CI_TestCase { 'two' => 2, 'three' => true ); - $tree = array( - 'application' => array( - 'config' => array( - $file1 => ' 'config->_config_paths = array(vfsStream::url('application').'/'); + $this->ci_vfs_create(array( + $file1 => ' 'ci_app_root, 'config'); // Test regular load $this->assertTrue($this->config->load($file1)); @@ -140,4 +132,4 @@ class Config_test extends CI_TestCase { $this->assertNull($this->config->load($file3)); } -} +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 60108a735fa7c9af4ab0b71e74b226d4b554e32f Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Tue, 16 Oct 2012 17:35:54 +0100 Subject: Cookie helper testsuite --- tests/codeigniter/helpers/cookie_helper_test.php | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/codeigniter/helpers/cookie_helper_test.php (limited to 'tests') diff --git a/tests/codeigniter/helpers/cookie_helper_test.php b/tests/codeigniter/helpers/cookie_helper_test.php new file mode 100644 index 000000000..3c7c9fd2e --- /dev/null +++ b/tests/codeigniter/helpers/cookie_helper_test.php @@ -0,0 +1,59 @@ +helper('cookie'); + } + + // ------------------------------------------------------------------------ + + function test_set_cookie() + { + /*$input_cls = $this->ci_core_class('input'); + $this->ci_instance_var('input', new $input_cls); + + $this->assertTrue(set_cookie( + 'my_cookie', + 'foobar' + ));*/ + + $this->markTestIncomplete('Need to find a way to overcome a headers already set exception'); + } + + // ------------------------------------------------------------------------ + + function test_get_cookie() + { + $_COOKIE['foo'] = 'bar'; + + $security = new Mock_Core_Security(); + $utf8 = new Mock_Core_Utf8(); + $input_cls = $this->ci_core_class('input'); + $this->ci_instance_var('input', new Mock_Core_Input($security, $utf8)); + + $this->assertEquals('bar', get_cookie('foo', FALSE)); + $this->assertEquals('bar', get_cookie('foo', TRUE)); + + $_COOKIE['bar'] = "Hello, i try to your site"; + + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", get_cookie('bar', TRUE)); + $this->assertEquals("Hello, i try to your site", get_cookie('bar', FALSE)); + } + + // ------------------------------------------------------------------------ + + function test_delete_cookie() + { + /*$input_cls = $this->ci_core_class('input'); + $this->ci_instance_var('input', new $input_cls); + + $this->assertTrue(delete_cookie( + 'my_cookie' + ));*/ + + $this->markTestIncomplete('Need to find a way to overcome a headers already set exception'); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a0f99d8930f175b7869ccaca834b3437b1a7b4ef Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Tue, 16 Oct 2012 18:18:54 +0100 Subject: Added captcha helper test Note, test isn't implemented Signed-off-by: Alex Bilbie --- tests/codeigniter/helpers/captcha_helper_test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/codeigniter/helpers/captcha_helper_test.php (limited to 'tests') diff --git a/tests/codeigniter/helpers/captcha_helper_test.php b/tests/codeigniter/helpers/captcha_helper_test.php new file mode 100644 index 000000000..4fbda2a88f --- /dev/null +++ b/tests/codeigniter/helpers/captcha_helper_test.php @@ -0,0 +1,10 @@ +markTestIncomplete(); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1624b4297c89334362f6ade5f5b766c916ffcbb1 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Tue, 16 Oct 2012 18:19:06 +0100 Subject: Added download helper test Note, test isn't implemented Signed-off-by: Alex Bilbie --- tests/codeigniter/helpers/download_helper_test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/codeigniter/helpers/download_helper_test.php (limited to 'tests') diff --git a/tests/codeigniter/helpers/download_helper_test.php b/tests/codeigniter/helpers/download_helper_test.php new file mode 100644 index 000000000..b41a8532a --- /dev/null +++ b/tests/codeigniter/helpers/download_helper_test.php @@ -0,0 +1,10 @@ +markTestIncomplete(); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 526d88f7d1d91bd51b3aa27ee8e170b7fa39a639 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Tue, 16 Oct 2012 18:19:30 +0100 Subject: Added language helper unit test Signed-off-by: Alex Bilbie --- tests/codeigniter/helpers/language_helper_test.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/codeigniter/helpers/language_helper_test.php (limited to 'tests') diff --git a/tests/codeigniter/helpers/language_helper_test.php b/tests/codeigniter/helpers/language_helper_test.php new file mode 100644 index 000000000..06932b9fd --- /dev/null +++ b/tests/codeigniter/helpers/language_helper_test.php @@ -0,0 +1,14 @@ +helper('language'); + $this->ci_instance_var('lang', new Mock_Core_Lang()); + + $this->assertFalse(lang(1)); + $this->assertEquals('', lang(1, 'foo')); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0f5b3060ff04b064b1a4bee9b114357ccd5a57de Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Tue, 16 Oct 2012 18:19:40 +0100 Subject: Added security helper unit test Signed-off-by: Alex Bilbie --- tests/codeigniter/helpers/security_helper_test.php | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/codeigniter/helpers/security_helper_test.php (limited to 'tests') diff --git a/tests/codeigniter/helpers/security_helper_test.php b/tests/codeigniter/helpers/security_helper_test.php new file mode 100644 index 000000000..effd3ec02 --- /dev/null +++ b/tests/codeigniter/helpers/security_helper_test.php @@ -0,0 +1,64 @@ +helper('security'); + $obj = new stdClass; + $obj->security = new Mock_Core_Security(); + $this->ci_instance($obj); + } + + function test_xss_clean() + { + $this->assertEquals('foo', xss_clean('foo')); + + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", xss_clean("Hello, i try to your site")); + } + + function test_sanitize_filename() + { + $this->assertEquals('hello.doc', sanitize_filename('hello.doc')); + + $filename = './'; + $this->assertEquals('foo', sanitize_filename($filename)); + } + + function test_do_hash() + { + $md5 = md5('foo'); + $sha1 = sha1('foo'); + + $algos = hash_algos(); + $algo_results = array(); + foreach ($algos as $k => $v) + { + $algo_results[$v] = hash($v, 'foo'); + } + + $this->assertEquals($sha1, do_hash('foo')); + $this->assertEquals($sha1, do_hash('foo', 'sha1')); + $this->assertEquals($md5, do_hash('foo', 'md5')); + $this->assertEquals($md5, do_hash('foo', 'foobar')); + + // Test each algorithm available to PHP + foreach ($algo_results as $algo => $result) + { + $this->assertEquals($result, do_hash('foo', $algo)); + } + } + + function test_strip_image_tags() + { + $this->assertEquals('http://example.com/spacer.gif', strip_image_tags('http://example.com/spacer.gif')); + + $this->assertEquals('http://example.com/spacer.gif', strip_image_tags('Who needs CSS when you have a spacer.gif?')); + } + + function test_encode_php_tags() + { + $this->assertEquals('<? echo $foo; ?>', encode_php_tags('')); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4b3cf8d825e13d4f24654fc6b26f2ca15d73c4f8 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 18 Oct 2012 16:44:54 +0100 Subject: Marked tests that can't easily be tests as skipped Signed-off-by: Alex Bilbie --- tests/codeigniter/helpers/captcha_helper_test.php | 2 +- tests/codeigniter/helpers/cookie_helper_test.php | 4 ++-- tests/codeigniter/helpers/download_helper_test.php | 2 +- tests/codeigniter/libraries/Upload_test.php | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/captcha_helper_test.php b/tests/codeigniter/helpers/captcha_helper_test.php index 4fbda2a88f..fc86305e3 100644 --- a/tests/codeigniter/helpers/captcha_helper_test.php +++ b/tests/codeigniter/helpers/captcha_helper_test.php @@ -4,7 +4,7 @@ class Captcha_helper_test extends CI_TestCase { public function test_create_captcha() { - $this->markTestIncomplete(); + $this->markTestSkipped('Cant easily test'); } } \ No newline at end of file diff --git a/tests/codeigniter/helpers/cookie_helper_test.php b/tests/codeigniter/helpers/cookie_helper_test.php index 3c7c9fd2e..fba68f20f 100644 --- a/tests/codeigniter/helpers/cookie_helper_test.php +++ b/tests/codeigniter/helpers/cookie_helper_test.php @@ -19,7 +19,7 @@ class Cookie_helper_test extends CI_TestCase { 'foobar' ));*/ - $this->markTestIncomplete('Need to find a way to overcome a headers already set exception'); + $this->markTestSkipped('Need to find a way to overcome a headers already set exception'); } // ------------------------------------------------------------------------ @@ -53,7 +53,7 @@ class Cookie_helper_test extends CI_TestCase { 'my_cookie' ));*/ - $this->markTestIncomplete('Need to find a way to overcome a headers already set exception'); + $this->markTestSkipped('Need to find a way to overcome a headers already set exception'); } } \ No newline at end of file diff --git a/tests/codeigniter/helpers/download_helper_test.php b/tests/codeigniter/helpers/download_helper_test.php index b41a8532a..d2b42e46b 100644 --- a/tests/codeigniter/helpers/download_helper_test.php +++ b/tests/codeigniter/helpers/download_helper_test.php @@ -4,7 +4,7 @@ class Download_helper_test extends CI_TestCase { public function test_force_download() { - $this->markTestIncomplete(); + $this->markTestSkipped('Cant easily test'); } } \ No newline at end of file diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php index d79a3ffc9..b4ef7bbd1 100644 --- a/tests/codeigniter/libraries/Upload_test.php +++ b/tests/codeigniter/libraries/Upload_test.php @@ -18,9 +18,9 @@ class Upload_test extends CI_TestCase { $this->_test_dir = vfsStreamWrapper::getRoot(); } - function test_do_upload() + function test_do_upload() { - $this->markTestIncomplete('We can\'t really test this at the moment because of the call to `is_uploaded_file` in do_upload which isn\'t supported by vfsStream'); + $this->markTestSkipped('We can\'t really test this at the moment because of the call to `is_uploaded_file` in do_upload which isn\'t supported by vfsStream'); } function test_data() @@ -75,7 +75,7 @@ class Upload_test extends CI_TestCase { { $this->upload->set_max_filesize(100); $this->assertEquals(100, $this->upload->max_size); - } + } function test_set_max_filename() { @@ -87,7 +87,7 @@ class Upload_test extends CI_TestCase { { $this->upload->set_max_width(100); $this->assertEquals(100, $this->upload->max_width); - } + } function test_set_max_height() { @@ -181,7 +181,7 @@ class Upload_test extends CI_TestCase { $this->upload->file_type = 'image/gif'; $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif'; - $this->upload->max_width = 10; + $this->upload->max_width = 10; $this->assertFalse($this->upload->is_allowed_dimensions()); $this->upload->max_width = 170; -- cgit v1.2.3-24-g4f1b From 187632748fd2694dd735b48eee157744dd83f3b4 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 18 Oct 2012 16:45:20 +0100 Subject: Exclude libs installed via Composer from code coverage tests Signed-off-by: Alex Bilbie --- tests/phpunit.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 56cb8841c..96c3af9bb 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -1,6 +1,6 @@ -./codeigniter/libraries - + PEAR_INSTALL_DIR PHP_LIBDIR + ../vendor - + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 929e1241879c94bff85203d2e00623284d72dc87 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 19 Oct 2012 10:09:28 +0300 Subject: Manually apply an improved version of PR #1797 (auto_link() URL helper) --- tests/codeigniter/helpers/url_helper_test.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index c81c5f1b8..5fc364238 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -51,6 +51,8 @@ class Url_helper_test extends CI_TestCase { 'www.codeigniter.com test' => 'http://www.codeigniter.com test', 'This is my noreply@codeigniter.com test' => 'This is my noreply@codeigniter.com test', '
www.google.com' => '
http://www.google.com', + 'Download CodeIgniter at www.codeigniter.com. Period test.' => 'Download CodeIgniter at http://www.codeigniter.com. Period test.', + 'Download CodeIgniter at www.codeigniter.com, comma test' => 'Download CodeIgniter at http://www.codeigniter.com, comma test' ); foreach ($strings as $in => $out) -- cgit v1.2.3-24-g4f1b From 3a43f130a02be38b7244ffe4507c6cefd874f285 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Sat, 20 Oct 2012 22:44:16 -0400 Subject: Raised CI_Config test coverage to 100% Signed-off-by: dchill42 --- tests/codeigniter/core/Config_test.php | 197 ++++++++++++++++++++++++++------- 1 file changed, 158 insertions(+), 39 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php index 80e0862ff..d652a625e 100644 --- a/tests/codeigniter/core/Config_test.php +++ b/tests/codeigniter/core/Config_test.php @@ -7,11 +7,12 @@ class Config_test extends CI_TestCase { $cls =& $this->ci_core_class('cfg'); // set predictable config values - $this->ci_set_config(array( + $this->cfg = array( 'index_page' => 'index.php', 'base_url' => 'http://example.com/', 'subclass_prefix' => 'MY_' - )); + ); + $this->ci_set_config($this->cfg); $this->config = new $cls; } @@ -20,7 +21,7 @@ class Config_test extends CI_TestCase { public function test_item() { - $this->assertEquals('http://example.com/', $this->config->item('base_url')); + $this->assertEquals($this->cfg['base_url'], $this->config->item('base_url')); // Bad Config value $this->assertFalse($this->config->item('no_good_item')); @@ -48,36 +49,103 @@ class Config_test extends CI_TestCase { // 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($this->cfg['base_url'], $this->config->slash_item('base_url')); - $this->assertEquals('MY_/', $this->config->slash_item('subclass_prefix')); + $this->assertEquals($this->cfg['subclass_prefix'].'/', $this->config->slash_item('subclass_prefix')); } // -------------------------------------------------------------------- - public function test_site_url() + public function test_base_url() { - $this->assertEquals('http://example.com/index.php', $this->config->site_url()); + // Test regular base URL + $base_url = $this->cfg['base_url']; + $this->assertEquals($base_url, $this->config->base_url()); + + // Test with URI + $uri = 'test'; + $this->assertEquals($base_url.$uri, $this->config->base_url($uri)); + + // Clear base_url + $this->ci_set_config('base_url', ''); + + // Rerun constructor + $cls =& $this->ci_core_class('cfg'); + $this->config = new $cls; - $base_url = $this->config->item('base_url'); + // Test default base + $this->assertEquals('http://localhost/', $this->config->base_url()); + // Capture server vars + $old_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : NULL; + $old_script = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : NULL; + $old_https = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : NULL; + + // Setup server vars for detection + $host = 'test.com'; + $path = '/path/'; + $script = 'base_test.php'; + $_SERVER['HTTP_HOST'] = $host; + $_SERVER['SCRIPT_NAME'] = $path.$script; + + // Rerun constructor + $this->config = new $cls; + + // Test plain detected + $this->assertEquals('http://'.$host.$path, $this->config->base_url()); + + // Rerun constructor + $_SERVER['HTTPS'] = 'on'; + $this->config = new $cls; + + // Test secure detected + $this->assertEquals('https://'.$host.$path, $this->config->base_url()); + + // Restore server vars + if ($old_host === NULL) unset($_SERVER['HTTP_HOST']); + else $_SERVER['HTTP_HOST'] = $old_host; + if ($old_script === NULL) unset($_SERVER['SCRIPT_NAME']); + else $_SERVER['SCRIPT_NAME'] = $old_script; + if ($old_https === NULL) unset($_SERVER['HTTPS']); + else $_SERVER['HTTPS'] = $old_https; + } + + // -------------------------------------------------------------------- + + public function test_site_url() + { + $base_url = $this->cfg['base_url']; + $index_page = $this->cfg['index_page']; + $this->assertEquals($base_url.$index_page, $this->config->site_url()); + + $old_base = $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'))); + $uri= 'test'; + $uri2 = '1'; + $this->assertEquals($index_page.'/'.$uri, $this->config->site_url($uri)); + $this->assertEquals($index_page.'/'.$uri.'/'.$uri2, $this->config->site_url(array($uri, $uri2))); + + $suffix = 'ing'; + $this->config->set_item('url_suffix', $suffix); + + $arg = 'pass'; + $this->assertEquals($index_page.'/'.$uri.$suffix, $this->config->site_url($uri)); + $this->assertEquals($index_page.'/'.$uri.$suffix.'?'.$arg, $this->config->site_url($uri.'?'.$arg)); + + $this->config->set_item('url_suffix', FALSE); $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->assertEquals($index_page.'?'.$uri, $this->config->site_url($uri)); + $this->assertEquals($index_page.'?0='.$uri.'&1='.$uri2, $this->config->site_url(array($uri, $uri2))); - $this->config->set_item('base_url', $base_url); + $this->config->set_item('base_url', $old_base); - $this->assertEquals('http://example.com/index.php?test', $this->config->site_url('test')); + $this->assertEquals($base_url.$index_page.'?'.$uri, $this->config->site_url($uri)); // back to home base $this->config->set_item('enable_query_strings', $q_string); @@ -87,49 +155,100 @@ class Config_test extends CI_TestCase { public function test_system_url() { - $this->assertEquals('http://example.com/system/', $this->config->system_url()); + $this->assertEquals($this->cfg['base_url'].'system/', $this->config->system_url()); } // -------------------------------------------------------------------- public function test_load() { - // Create config files in VFS - $file1 = 'test.php'; - $file2 = 'secttest'; - $key1 = 'testconfig'; - $val1 = 'my_value'; - $cfg1 = array( - $key1 => $val1 - ); - $cfg2 = array( + // Test regular load + $file = 'test.php'; + $key = 'testconfig'; + $val = 'my_value'; + $cfg = array($key => $val); + $this->ci_vfs_create($file, 'ci_app_root, 'config'); + $this->assertTrue($this->config->load($file)); + $this->assertEquals($val, $this->config->item($key)); + + // Test reload - value should not change + $val2 = 'new_value'; + $cfg = array($key => $val2); + $this->ci_vfs_create($file, 'ci_app_root, 'config'); + $this->assertTrue($this->config->load($file)); + $this->assertEquals($val, $this->config->item($key)); + + // Test section load + $file = 'secttest'; + $cfg = array( 'one' => 'prime', 'two' => 2, 'three' => true ); - $this->ci_vfs_create(array( - $file1 => ' 'ci_app_root, 'config'); + $this->ci_vfs_create($file.'.php', 'ci_app_root, 'config'); + $this->assertTrue($this->config->load($file, TRUE)); + $this->assertEquals($cfg, $this->config->item($file)); - // Test regular load - $this->assertTrue($this->config->load($file1)); - $this->assertEquals($val1, $this->config->item($key1)); + // Test section merge + $cfg2 = array( + 'three' => 'tres', + 'number' => 42, + 'letter' => 'Z' + ); + $pkg_dir = 'package'; + $this->ci_vfs_create($file.'.php', 'ci_app_root, + array($pkg_dir, 'config')); + array_push($this->config->_config_paths, $this->ci_vfs_path($pkg_dir.'/', APPPATH)); + $this->assertTrue($this->config->load($file, TRUE)); + $this->assertEquals(array_merge($cfg, $cfg2), $this->config->item($file)); + array_pop($this->config->_config_paths); + + // Test graceful fail of invalid file + $file = 'badfile'; + $this->ci_vfs_create($file, '', $this->ci_app_root, 'config'); + $this->assertFalse($this->config->load($file, FALSE, TRUE)); + + // Test regular fail of invalid file + $this->setExpectedException( + 'RuntimeException', + 'CI Error: Your '.$this->ci_vfs_path('config/'.$file.'.php', APPPATH). + ' file does not appear to contain a valid configuration array.' + ); + $this->assertNull($this->config->load($file)); + } - // Test section load - $this->assertTrue($this->config->load($file2, TRUE)); - $this->assertEquals($cfg2, $this->config->item($file2)); + // -------------------------------------------------------------------- - // Test graceful fail + public function test_load_nonexistent() + { + // Test graceful fail of nonexistent file $this->assertFalse($this->config->load('not_config_file', FALSE, TRUE)); // Test regular fail - $file3 = 'absentia'; + $file = 'absentia'; $this->setExpectedException( 'RuntimeException', - 'CI Error: The configuration file '.$file3.'.php does not exist.' + 'CI Error: The configuration file '.$file.'.php does not exist.' + ); + $this->assertNull($this->config->load($file)); + } + + // -------------------------------------------------------------------- + + public function test_assign_to_config() + { + $key1 = 'test'; + $key2 = '1'; + $val1 = 'foo'; + $val2 = 'bar'; + $cfg = array( + $key1 => $val1, + $key2 => $val2 ); - $this->assertNull($this->config->load($file3)); + + $this->assertNull($this->config->_assign_to_config($cfg)); + $this->assertEquals($val1, $this->config->item($key1)); + $this->assertEquals($val2, $this->config->item($key2)); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4f42be55dc5ca3141f3d93f7f59989d3e52bc5a3 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Sun, 21 Oct 2012 21:31:19 -0400 Subject: Raised CI_Loader test coverage to 93% Signed-off-by: dchill42 --- tests/codeigniter/core/Loader_test.php | 343 ++++++++++++++++++++----------- tests/mocks/ci_testcase.php | 1 + tests/mocks/ci_testconfig.php | 4 +- tests/mocks/core/common.php | 7 +- tests/mocks/core/loader.php | 13 -- tests/mocks/database/schema/skeleton.php | 2 +- 6 files changed, 235 insertions(+), 135 deletions(-) delete mode 100644 tests/mocks/core/loader.php (limited to 'tests') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 69b2afb63..a8a2de78f 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -7,27 +7,29 @@ class Loader_test extends CI_TestCase { public function set_up() { // Instantiate a new loader - $this->load = new Mock_Core_Loader(); + $loader = $this->ci_core_class('loader'); + $this->load = new $loader(); // Get CI instance $this->ci_obj = $this->ci_instance(); // Set subclass prefix - $this->ci_set_config('subclass_prefix', 'MY_'); + $this->prefix = 'MY_'; + $this->ci_set_config('subclass_prefix', $this->prefix); } // -------------------------------------------------------------------- - /** - * @covers CI_Loader::library - */ public function test_library() { - // Create libraries directory with test library + // Create library in VFS $lib = 'unit_test_lib'; $class = 'CI_'.ucfirst($lib); $this->ci_vfs_create($lib, 'ci_base_root, 'libraries'); + // Test is_loaded fail + $this->assertFalse($this->load->is_loaded($lib)); + // Test loading as an array. $this->assertNull($this->load->library(array($lib))); $this->assertTrue(class_exists($class), $class.' does not exist'); @@ -38,16 +40,68 @@ class Loader_test extends CI_TestCase { // Test a string given to params $this->assertNull($this->load->library($lib, ' ')); + + // Create library w/o class + $lib = 'bad_test_lib'; + $this->ci_vfs_create($lib, '', $this->ci_base_root, 'libraries'); + + // Test non-existent class + $this->setExpectedException( + 'RuntimeException', + 'CI Error: Non-existent class: '.$lib + ); + $this->assertNull($this->load->library($lib)); + } + + // -------------------------------------------------------------------- + + public function test_library_extension() + { + // Create library and extension in VFS + $name = 'ext_test_lib'; + $lib = ucfirst($name); + $class = 'CI_'.$lib; + $ext = $this->prefix.$lib; + $this->ci_vfs_create($lib, 'ci_base_root, 'libraries'); + $this->ci_vfs_create($ext, 'ci_app_root, 'libraries'); + + // Test loading with extension + $this->assertNull($this->load->library($lib)); + $this->assertTrue(class_exists($class), $class.' does not exist'); + $this->assertTrue(class_exists($ext), $ext.' does not exist'); + $this->assertAttributeInstanceOf($class, $name, $this->ci_obj); + $this->assertAttributeInstanceOf($ext, $name, $this->ci_obj); + + // Test reloading with object name + $obj = 'exttest'; + $this->assertNull($this->load->library($lib, NULL, $obj)); + $this->assertAttributeInstanceOf($class, $obj, $this->ci_obj); + $this->assertAttributeInstanceOf($ext, $obj, $this->ci_obj); + + // Test reloading + unset($this->ci_obj->$name); + $this->assertNull($this->load->library($lib)); + $this->assertObjectNotHasAttribute($name, $this->ci_obj); + + // Create baseless library + $name = 'ext_baseless_lib'; + $lib = ucfirst($name); + $class = $this->prefix.$lib; + $this->ci_vfs_create($class, 'ci_app_root, 'libraries'); + + // Test missing base class + $this->setExpectedException( + 'RuntimeException', + 'CI Error: Unable to load the requested class: '.$lib + ); + $this->assertNull($this->load->library($lib)); } // -------------------------------------------------------------------- - /** - * @covers CI_Loader::library - */ public function test_library_config() { - // Create libraries directory with test library + // Create library in VFS $lib = 'unit_test_config_lib'; $class = 'CI_'.ucfirst($lib); $content = 'config = $params; } }'; @@ -67,16 +121,16 @@ class Loader_test extends CI_TestCase { $this->assertTrue(class_exists($class), $class.' does not exist'); $this->assertAttributeInstanceOf($class, $obj, $this->ci_obj); $this->assertEquals($cfg, $this->ci_obj->$obj->config); + + // Test is_loaded + $this->assertEquals($obj, $this->load->is_loaded($lib)); } // -------------------------------------------------------------------- - /** - * @covers CI_Loader::library - */ public function test_load_library_in_application_dir() { - // Create libraries directory in app path with test library + // Create library in VFS $lib = 'super_test_library'; $class = ucfirst($lib); $this->ci_vfs_create($lib, 'ci_app_root, 'libraries'); @@ -91,12 +145,9 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - /** - * @covers CI_Loader::driver - */ public function test_driver() { - // Create libraries directory with test driver + // Create driver in VFS $driver = 'unit_test_driver'; $dir = ucfirst($driver); $class = 'CI_'.$dir; @@ -122,29 +173,11 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - /** - * @covers CI_Loader::model - */ - public function test_non_existent_model() - { - $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'); - } - - // -------------------------------------------------------------------- - - /** - * @covers CI_Loader::model - */ public function test_models() { $this->ci_set_core_class('model', 'CI_Model'); - // Create models directory with test model + // Create model in VFS $model = 'unit_test_model'; $class = ucfirst($model); $content = 'ci_core_class('model'); + + // Create modelin VFS + $model = 'test_sub_model'; + $base = 'CI_Model'; + $class = ucfirst($model); + $subdir = 'cars'; + $this->ci_vfs_create($model, 'ci_app_root, + array('models', $subdir)); + + // Load model + $name = 'testors'; + $this->assertNull($this->load->model($subdir.'/'.$model, $name)); + + // Was the model class instantiated? + $this->assertTrue(class_exists($class)); + $this->assertObjectHasAttribute($name, $this->ci_obj); + $this->assertAttributeInstanceOf($base, $name, $this->ci_obj); + $this->assertAttributeInstanceOf($class, $name, $this->ci_obj); + + // Test name conflict + $obj = 'conflict'; + $this->ci_obj->$obj = new StdClass(); + $this->setExpectedException( + 'RuntimeException', + 'CI Error: The model name you are loading is the name of a resource that is already being used: '.$obj + ); + $this->load->model('not_real', $obj); + } + + // -------------------------------------------------------------------- + + public function test_non_existent_model() + { + $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'); + } + + // -------------------------------------------------------------------- + // public function testDatabase() // { - // $this->assertEquals(NULL, $this->load->database()); - // $this->assertEquals(NULL, $this->load->dbutil()); + // $this->assertNull($this->load->database()); + // $this->assertNull($this->load->dbutil()); // } // -------------------------------------------------------------------- - /** - * @covers CI_Loader::view - */ public function test_load_view() { - $this->ci_set_core_class('output', 'CI_Output'); - - // Create views directory with test view + // Create view in VFS $view = 'unit_test_view'; - $content = 'This is my test page. '; - $this->ci_vfs_create($view, $content, $this->ci_app_root, 'views'); - - // Use the optional return parameter in this test, so the view is not - // run through the output class. - $out = $this->load->view($view, array('hello' => "World!"), TRUE); - $this->assertEquals('This is my test page. World!', $out); + $var = 'hello'; + $value = 'World!'; + $content = 'This is my test page. '; + $this->ci_vfs_create($view, $content.'ci_app_root, 'views'); + + // Test returning view + $out = $this->load->view($view, array($var => $value), TRUE); + $this->assertEquals($content.$value, $out); + + // Mock output class + $class = 'Mock_Load_Output'; + $prop = 'output'; + eval('class '.$class.' { public function append_output($out) { $this->'.$prop.' = $out; } }'); + $this->ci_instance_var('output', new $class()); + + // Test view output + $this->load->view($view, array($var => $value)); + $this->assertObjectHasAttribute($prop, $this->ci_obj->output); + $this->assertEquals($content.$value, $this->ci_obj->output->$prop); } // -------------------------------------------------------------------- - /** - * @covers CI_Loader::view - */ public function test_non_existent_view() { $this->setExpectedException( @@ -205,12 +289,9 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - /** - * @covers CI_Loader::file - */ public function test_file() { - // Create views directory with test file + // Create view in VFS $dir = 'views'; $file = 'ci_test_mock_file'; $content = 'Here is a test file, which we will load now.'; @@ -231,49 +312,66 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - /** - * @covers CI_Loader::vars - */ public function test_vars() { - $this->assertNull($this->load->vars(array('foo' => 'bar'))); - $this->assertNull($this->load->vars('foo', 'bar')); + $key1 = 'foo'; + $val1 = 'bar'; + $key2 = 'boo'; + $val2 = 'hoo'; + $this->assertNull($this->load->vars(array($key1 => $val1))); + $this->assertNull($this->load->vars($key2, $val2)); + $this->assertEquals($val1, $this->load->get_var($key1)); + $this->assertEquals(array($key1 => $val1, $key2 => $val2), $this->load->get_vars()); } // -------------------------------------------------------------------- - /** - * @covers CI_Loader::helper - */ public function test_helper() { - // Create helper directory in app path with test helper + // Create helper in VFS $helper = 'test'; $func = '_my_helper_test_func'; $content = 'ci_vfs_create($helper.'_helper', $content, $this->ci_app_root, 'helpers'); + $this->ci_vfs_create($helper.'_helper', $content, $this->ci_base_root, 'helpers'); + + // Create helper extension + $exfunc = '_my_extension_func'; + $content = 'ci_vfs_create($this->prefix.$helper.'_helper', $content, $this->ci_app_root, 'helpers'); // Load helper - $this->assertEquals(NULL, $this->load->helper($helper)); + $this->assertNull($this->load->helper($helper)); $this->assertTrue(function_exists($func), $func.' does not exist'); + $this->assertTrue(function_exists($exfunc), $exfunc.' does not exist'); + + // Create baseless extension + $ext = 'bad_ext'; + $this->ci_vfs_create($this->prefix.$ext.'_helper', '', $this->ci_app_root, 'helpers'); - // Test non-existent helper + // Test bad extension $this->setExpectedException( 'RuntimeException', - 'CI Error: Unable to load the requested file: helpers/bad_helper.php' + 'CI Error: Unable to load the requested file: helpers/'.$ext.'_helper.php' ); + $this->load->helper($ext); + } + + // -------------------------------------------------------------------- + public function test_non_existent_helper() + { + $this->setExpectedException( + 'RuntimeException', + 'CI Error: Unable to load the requested file: helpers/bad_helper.php' + ); $this->load->helper('bad'); } // -------------------------------------------------------------------- - /** - * @covers CI_Loader::helper - */ public function test_loading_multiple_helpers() { - // Create helper directory in base path with test helpers + // Create helpers in VFS $helpers = array(); $funcs = array(); $files = array(); @@ -287,7 +385,7 @@ class Loader_test extends CI_TestCase { $this->ci_vfs_create($files, NULL, $this->ci_base_root, 'helpers'); // Load helpers - $this->assertEquals(NULL, $this->load->helpers($helpers)); + $this->assertNull($this->load->helpers($helpers)); // Verify helper existence foreach ($funcs as $func) { @@ -297,40 +395,36 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - // public function testLanguage() - // { - // $this->assertEquals(NULL, $this->load->language('test')); - // } + public function test_language() + { + // Create mock Lang class with load stub + $class = 'Mock_Load_Lang'; + $prop = '_file'; + eval('class '.$class.' { public function load($file, $lang) { $this->'.$prop.' = $file; } }'); + $this->ci_instance_var('lang', new $class()); + + // Does the right file get loaded? + $file = 'test'; + $this->assertNull($this->load->language($file)); + $this->assertObjectHasAttribute($prop, $this->ci_obj->lang); + $this->assertEquals($file, $this->ci_obj->lang->$prop); + } // -------------------------------------------------------------------- - /** - * @covers CI_Loader::add_package_path - * @covers CI_Loader::get_package_paths - * @covers CI_Loader::remove_package_path - */ public function test_packages() { - // Create third-party directory in app path with model + // Create model in VFS package path $dir = 'third-party'; $lib = 'unit_test_package'; $class = 'CI_'.ucfirst($lib); - $content = 'ci_vfs_create($lib, $content, $this->ci_app_root, $dir); - - // Test failed load without path - $this->setExpectedException( - 'RuntimeException', - 'CI Error: Unable to load the requested class: '.$lib - ); - $this->load->library($lib); + $this->ci_vfs_create($lib, 'ci_app_root, array($dir, 'libraries')); - // Clear exception and get paths - $this->setExpectedException(NULL); + // Get paths $paths = $this->load->get_package_paths(TRUE); // Add path and verify - $path = APPPATH.$dir; + $path = APPPATH.$dir.'/'; $this->assertNull($this->load->add_package_path($path)); $this->assertContains($path, $this->load->get_package_paths(TRUE)); @@ -338,51 +432,63 @@ class Loader_test extends CI_TestCase { $this->assertNull($this->load->library($lib)); $this->assertTrue(class_exists($class), $class.' does not exist'); + // Add another path + $path2 = APPPATH.'another/'; + $this->assertNull($this->load->add_package_path($path2)); + $this->assertContains($path2, $this->load->get_package_paths(TRUE)); + + // Remove last path + $this->assertNull($this->load->remove_package_path()); + $this->assertNotContains($path2, $this->load->get_package_paths(TRUE)); + // Remove path and verify restored paths $this->assertNull($this->load->remove_package_path($path)); $this->assertEquals($paths, $this->load->get_package_paths(TRUE)); + + // Test failed load without path + $this->setExpectedException( + 'RuntimeException', + 'CI Error: Unable to load the requested class: '.$lib + ); + $this->load->library($lib); } // -------------------------------------------------------------------- - /** - * @covers CI_Loader::config - */ public function test_load_config() { - $this->assertNull($this->load->config('config', FALSE)); + $cfg = 'someconfig'; + $this->assertNull($this->load->config($cfg, FALSE)); + $this->assertContains($cfg, $this->ci_obj->config->loaded); } // -------------------------------------------------------------------- - /** - * @covers CI_Loader::_ci_autoloader - */ - public function test_autoloader() + public function test_initialize() { - // Create helper directory in app path with test helper + // Create helper in VFS $helper = 'autohelp'; $hlp_func = '_autohelp_test_func'; - $content = 'ci_vfs_create($helper.'_helper', $content, $this->ci_app_root, 'helpers'); - // Create libraries directory in base path with test library + // Create library in VFS $lib = 'autolib'; $lib_class = 'CI_'.ucfirst($lib); $this->ci_vfs_create($lib, 'ci_base_root, 'libraries'); - // Create test driver + // Create driver in VFS $drv = 'autodrv'; $subdir = ucfirst($drv); $drv_class = 'CI_'.$subdir; - $this->ci_vfs_create($drv, 'ci_base_root, 'libraries/'.$subdir); + $this->ci_vfs_create($drv, 'ci_base_root, array('libraries', $subdir)); - // Create package directory in app path with model + // Create model in VFS package path $dir = 'testdir'; $path = APPPATH.$dir.'/'; $model = 'automod'; $mod_class = ucfirst($model); - $this->ci_vfs_create($model, 'ci_app_root, $dir.'/models'); + $this->ci_vfs_create($model, 'ci_app_root, array($dir, 'models')); // Create autoloader config $cfg = array( @@ -391,12 +497,12 @@ class Loader_test extends CI_TestCase { 'libraries' => array($lib), 'drivers' => array($drv), 'model' => array($model), - 'config' => array() + 'config' => array('config1', 'config2') ); $this->ci_vfs_create('autoload', 'ci_app_root, 'config'); - // Run autoloader - $this->load->autoload(); + // Run initialize and autoloader + $this->load->initialize(); // Verify path $this->assertContains($path, $this->load->get_package_paths()); @@ -415,6 +521,9 @@ class Loader_test extends CI_TestCase { // Verify model $this->assertTrue(class_exists($mod_class), $mod_class.' does not exist'); $this->assertAttributeInstanceOf($mod_class, $model, $this->ci_obj); + + // Verify config calls + $this->assertEquals($cfg['config'], $this->ci_obj->config->loaded); } } \ No newline at end of file diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php index e581d4b02..f16492945 100644 --- a/tests/mocks/ci_testcase.php +++ b/tests/mocks/ci_testcase.php @@ -38,6 +38,7 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { $this->ci_vfs_root = vfsStream::setup(); $this->ci_app_root = vfsStream::newDirectory('application')->at($this->ci_vfs_root); $this->ci_base_root = vfsStream::newDirectory('system')->at($this->ci_vfs_root); + $this->ci_view_root = vfsStream::newDirectory('views')->at($this->ci_app_root); if (method_exists($this, 'set_up')) { diff --git a/tests/mocks/ci_testconfig.php b/tests/mocks/ci_testconfig.php index eb318ddeb..0c52bb984 100644 --- a/tests/mocks/ci_testconfig.php +++ b/tests/mocks/ci_testconfig.php @@ -4,14 +4,16 @@ class CI_TestConfig { public $config = array(); public $_config_paths = array(APPPATH); + public $loaded = array(); public function item($key) { return isset($this->config[$key]) ? $this->config[$key] : FALSE; } - public function load($arg1, $arg2, $arg3) + public function load($file, $arg2 = FALSE, $arg3 = FALSE) { + $this->loaded[] = $file; return TRUE; } diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php index b001074c8..9289b2716 100644 --- a/tests/mocks/core/common.php +++ b/tests/mocks/core/common.php @@ -170,9 +170,10 @@ if ( ! function_exists('is_really_writable')) if ( ! function_exists('is_loaded')) { - function is_loaded() + function &is_loaded() { - throw new Exception('Bad Isolation: mock up environment'); + $loaded = array(); + return $loaded; } } @@ -190,4 +191,4 @@ if ( ! function_exists('set_status_header')) { return TRUE; } -} +} \ No newline at end of file diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php deleted file mode 100644 index 7ea4da369..000000000 --- a/tests/mocks/core/loader.php +++ /dev/null @@ -1,13 +0,0 @@ -_ci_autoloader(); - } - -} diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index 18e1ddd4d..69e3c187e 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -30,7 +30,7 @@ class Mock_Database_Schema_Skeleton { CI_TestCase::instance()->ci_instance_var('db', $db); - $loader = new Mock_Core_Loader(); + $loader = new CI_Loader(); $loader->dbforge(); $forge = CI_TestCase::instance()->ci_instance_var('dbforge'); -- cgit v1.2.3-24-g4f1b From cf99aac39914d821e8864443d3aaa759f87258e9 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Sun, 21 Oct 2012 21:32:20 -0400 Subject: Added documentation of new unit test tools and VFS additions Signed-off-by: dchill42 --- tests/README.md | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index d600951ee..a5f89a2b1 100644 --- a/tests/README.md +++ b/tests/README.md @@ -64,6 +64,30 @@ with a base for application and package tests. That gives us: 3. Application Test - bootstrapping for application/tests [not started] 4. Package Test - bootstrapping for /tests [not started] +### Test Environment: + +The test/Bootstrap.php file establishes global constants such as BASEPATH, +APPPATH, and VIEWPATH, initializing them to point to VFS locations. The +test case class employs vfsStream to make a clean virtual filesystem with +the necessary paths for every individual test. + +Within each test case, VFS directory objects are available to use as arguments +to the VFS convenience functions (see below): + +- ci_vfs_root: VFS filesystem root +- ci_app_root: Application directory +- ci_base_root: System directory +- ci_view_root: Views directory + +Classes being instantiated for testing are read from the actual filesystem +by the unit test autoloader, as are mockups created in tests/mocks. If you +need access to the real system directory, the SYSTEM_PATH constant always +points to it. + +Any other resources which need to be read from the path constants must be +created or cloned within your test. Functions for doing so are outlined +below. + ### CI_TestCase Documentation Test cases should extend CI_TestCase. This internally extends @@ -78,8 +102,14 @@ Current API is *not stable*. Names and implementations will change. $this->ci_set_config($key, $val) -Set the global config variables. If key is an array, it will -replace the entire config array. They are _not_ merged. +Set the global config variables in a mock Config object. If key is an array, +it will replace the entire config array. They are _not_ merged. If called +without any parameters, it will create the mock object but not set any values. +The mock Config object also provides rudimentary item() and load() stubs for +delivering configured values to classes being tested and handling config load +calls, respectively. The load() stub does _not_ actually load any files, it +only records the filename provided. Check the config->loaded array to verify +calls made. $this->ci_instance($obj) @@ -103,11 +133,48 @@ $GLOBALS key. For example: $cfg = new $cfg; // instantiates config and overwrites the CFG global $this->ci_set_core_class($name, $obj) - + An alternative way to set one of the core globals. + $this->ci_vfs_mkdir($name, $root) + +Creates a new directory in the test VFS. Pass a directory object to be the +parent directory or none to create a root-level directory. Returns the new +directory object. + + $this->ci_vfs_create($file, $content, $root, $path) + +Creates a new VFS file. '.php' is automatically appended to the filename if +it has no extension. Pass a directory object as the root, and an optional path +to recurse and/or create for containing the file. Path may be a string (such +as 'models/subdir') or an array (e.g. - array('models', 'subdir') ). Existing +directories in the VFS root will be recursed until a new directory is +identified - all others in the path will be created, so you can mix-and-match +old and new directories. If $file is an array (key = name, value = content), +multiple files will be created in the same path. + + $this->ci_vfs_clone($path) + +Clones an existing file from the real filesystem to exist in the same path of +the VFS. Path must be relative to the project root (i.e. - starting with +'system' or 'application'). + + $this->ci_vfs_path($path, $base) + +Creates a VFS file path string suitable for use with PHP file operations. Path +may be absolute from the VFS root, or relative to a base path. It is often +useful to use APPPATH or BASEPATH as the base. + + $this->helper($name) + +Loads a helper from the real filesystem. + + $this->lang($name) + +Loads a language file from the real filesystem and returns the $lang array. + $this->ci_get_config() __internal__ - + Returns the global config array. Internal as you shouldn't need to call this (you're setting it, after all). Used internally to make CI's get_config() work. @@ -155,4 +222,4 @@ I don't have a clue how this will work. Needs to be able to handle packages that are used multiple times within the application (i.e. EE/Pyro modules) -as well as packages that are used by multiple applications (library distributions) +as well as packages that are used by multiple applications (library distributions) \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 96a4ca6605d6a8a94eea96ed00ab1cf31a8cdd35 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 23 Oct 2012 01:11:48 +0300 Subject: Add a test for issue #273 --- tests/codeigniter/database/query_builder/like_test.php | 16 ++++++++++++++++ tests/mocks/database/schema/skeleton.php | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php index 5f3e52228..20ce5d99c 100644 --- a/tests/codeigniter/database/query_builder/like_test.php +++ b/tests/codeigniter/database/query_builder/like_test.php @@ -87,4 +87,20 @@ class Like_test extends CI_TestCase { $this->assertEquals('Musician', $jobs[2]['name']); } + // ------------------------------------------------------------------------ + + /** + * GitHub issue #273 + * + * @see ./mocks/schema/skeleton.php + */ + public function test_like_spaces_and_tabs() + { + $spaces = $this->db->like('key', ' ')->get('misc')->result_array(); + $tabs = $this->db->like('key', "\t")->get('misc')->result_array(); + + $this->assertEquals(1, count($spaces)); + $this->assertEquals(1, count($tabs)); + } + } \ No newline at end of file diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index 18e1ddd4d..fb9aaefee 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -129,7 +129,8 @@ class Mock_Database_Schema_Skeleton { ), 'misc' => array( array('id' => 1, 'key' => '\\xxxfoo456', 'value' => 'Entry with \\xxx'), - array('id' => 2, 'key' => '\\%foo456', 'value' => 'Entry with \\%') + array('id' => 2, 'key' => '\\%foo456', 'value' => 'Entry with \\%'), + array('id' => 3, 'key' => ' One two three tab') ) ); -- cgit v1.2.3-24-g4f1b From 348bd1e2623ae13ef0dc576464d98eb3673ef15a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 23 Oct 2012 01:24:11 +0300 Subject: Fix a mock db entry --- tests/codeigniter/database/query_builder/like_test.php | 4 ++-- tests/mocks/database/schema/skeleton.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php index 20ce5d99c..2736fbe0b 100644 --- a/tests/codeigniter/database/query_builder/like_test.php +++ b/tests/codeigniter/database/query_builder/like_test.php @@ -96,8 +96,8 @@ class Like_test extends CI_TestCase { */ public function test_like_spaces_and_tabs() { - $spaces = $this->db->like('key', ' ')->get('misc')->result_array(); - $tabs = $this->db->like('key', "\t")->get('misc')->result_array(); + $spaces = $this->db->like('value', ' ')->get('misc')->result_array(); + $tabs = $this->db->like('value', "\t")->get('misc')->result_array(); $this->assertEquals(1, count($spaces)); $this->assertEquals(1, count($tabs)); diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index fb9aaefee..2226835c4 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -130,7 +130,7 @@ class Mock_Database_Schema_Skeleton { 'misc' => array( array('id' => 1, 'key' => '\\xxxfoo456', 'value' => 'Entry with \\xxx'), array('id' => 2, 'key' => '\\%foo456', 'value' => 'Entry with \\%'), - array('id' => 3, 'key' => ' One two three tab') + array('id' => 3, 'key' => 'spaces and tabs', 'value' => ' One two three tab') ) ); -- cgit v1.2.3-24-g4f1b From f5f898f8f30968fb36413a14de2dc6a4599b79a6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 23 Oct 2012 02:13:29 +0300 Subject: Fix issue #779 --- tests/codeigniter/core/URI_test.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php index 60ed1a4e9..e2deabe51 100644 --- a/tests/codeigniter/core/URI_test.php +++ b/tests/codeigniter/core/URI_test.php @@ -40,13 +40,13 @@ class URI_test extends CI_TestCase { '/index.php?/controller/method/?var=foo' => 'controller/method' ); - foreach($requests as $request => $expected) + 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 ); + $this->assertEquals($expected, $this->uri->uri_string); } // Test a subfolder @@ -60,10 +60,10 @@ class URI_test extends CI_TestCase { unset($_SERVER['REQUEST_URI']); // life to path info - $_SERVER['PATH_INFO'] = $a = '/controller/method/'; + $_SERVER['PATH_INFO'] = '/controller/method/'; $this->uri->_fetch_uri_string(); - $this->assertEquals($a, $this->uri->uri_string); + $this->assertEquals('controller/method', $this->uri->uri_string); // death to path info // At this point your server must be seriously drunk @@ -72,7 +72,7 @@ class URI_test extends CI_TestCase { $_SERVER['QUERY_STRING'] = '/controller/method/'; $this->uri->_fetch_uri_string(); - $this->assertEquals($a, $this->uri->uri_string); + $this->assertEquals('controller/method', $this->uri->uri_string); // At this point your server is a labotomy victim unset($_SERVER['QUERY_STRING']); @@ -80,7 +80,7 @@ class URI_test extends CI_TestCase { $_GET['/controller/method/'] = ''; $this->uri->_fetch_uri_string(); - $this->assertEquals($a, $this->uri->uri_string); + $this->assertEquals('controller/method', $this->uri->uri_string); // Test coverage implies that these will work // uri_protocol: REQUEST_URI -- cgit v1.2.3-24-g4f1b From 8889db7e1b1768ecfb76e9e73598541042a9edc1 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Mon, 22 Oct 2012 23:16:26 -0400 Subject: Replaced evals with getMock usage in Loader tests Signed-off-by: dchill42 --- tests/codeigniter/core/Loader_test.php | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index a8a2de78f..f7c338a20 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -264,15 +264,12 @@ class Loader_test extends CI_TestCase { $this->assertEquals($content.$value, $out); // Mock output class - $class = 'Mock_Load_Output'; - $prop = 'output'; - eval('class '.$class.' { public function append_output($out) { $this->'.$prop.' = $out; } }'); - $this->ci_instance_var('output', new $class()); + $output = $this->getMock('CI_Output', array('append_output')); + $output->expects($this->once())->method('append_output')->with($content.$value); + $this->ci_instance_var('output', $output); // Test view output - $this->load->view($view, array($var => $value)); - $this->assertObjectHasAttribute($prop, $this->ci_obj->output); - $this->assertEquals($content.$value, $this->ci_obj->output->$prop); + $this->assertNull($this->load->view($view, array($var => $value))); } // -------------------------------------------------------------------- @@ -397,17 +394,12 @@ class Loader_test extends CI_TestCase { public function test_language() { - // Create mock Lang class with load stub - $class = 'Mock_Load_Lang'; - $prop = '_file'; - eval('class '.$class.' { public function load($file, $lang) { $this->'.$prop.' = $file; } }'); - $this->ci_instance_var('lang', new $class()); - - // Does the right file get loaded? + // Mock lang class and test load call $file = 'test'; + $lang = $this->getMock('CI_Lang', array('load')); + $lang->expects($this->once())->method('load')->with($file); + $this->ci_instance_var('lang', $lang); $this->assertNull($this->load->language($file)); - $this->assertObjectHasAttribute($prop, $this->ci_obj->lang); - $this->assertEquals($file, $this->ci_obj->lang->$prop); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 5fd3ae8d33a4f5d3159b86683b9a670e973a63f5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 24 Oct 2012 14:55:35 +0300 Subject: [ci skip] style and phpdoc-related changes (rel #1295) --- tests/mocks/core/lang.php | 4 ++-- tests/mocks/libraries/session.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/mocks/core/lang.php b/tests/mocks/core/lang.php index 1b99aedb3..27ea3faba 100644 --- a/tests/mocks/core/lang.php +++ b/tests/mocks/core/lang.php @@ -2,12 +2,12 @@ class Mock_Core_Lang extends CI_Lang { - function line($line = '') + public function line($line = '') { return FALSE; } - function load($langfile, $idiom = '', $return = false, $add_suffix = true, $alt_path = '') + public function load($langfile, $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '') { return; } diff --git a/tests/mocks/libraries/session.php b/tests/mocks/libraries/session.php index 9d6feee42..c6e194f58 100644 --- a/tests/mocks/libraries/session.php +++ b/tests/mocks/libraries/session.php @@ -4,6 +4,7 @@ * Mock library to add testing features to Session driver library */ class Mock_Libraries_Session extends CI_Session { + /** * Simulate new page load */ @@ -19,18 +20,18 @@ class Mock_Libraries_Session extends CI_Session { * Mock cookie driver to overload cookie setting */ class Mock_Libraries_Session_cookie extends CI_Session_cookie { + /** * Overload _setcookie to manage $_COOKIE values, since actual cookies can't be set in unit testing */ - protected function _setcookie($name, $value = '', $expire = 0, $path = '', $domain = '', $secure = false, - $httponly = false) + protected function _setcookie($name, $value = '', $expire = 0, $path = '', $domain = '', $secure = FALSE, $httponly = FALSE) { - if (empty($value) || $expire <= time()) { - // Clear cookie + if (empty($value) OR $expire <= time()) + { unset($_COOKIE[$name]); } - else { - // Set cookie + else + { $_COOKIE[$name] = $value; } } @@ -39,5 +40,4 @@ class Mock_Libraries_Session_cookie extends CI_Session_cookie { /** * Mock native driver (just for consistency in loading) */ -class Mock_Libraries_Session_native extends CI_Session_native { } - +class Mock_Libraries_Session_native extends CI_Session_native { } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d98785a1661b46f0a1cb83168347fda4c4c7dde9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 24 Oct 2012 15:33:35 +0300 Subject: Fix #1922 --- tests/codeigniter/libraries/Encrypt_test.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php index 998d806b3..21ac85f03 100644 --- a/tests/codeigniter/libraries/Encrypt_test.php +++ b/tests/codeigniter/libraries/Encrypt_test.php @@ -9,6 +9,7 @@ class Encrypt_test extends CI_TestCase { $this->ci_set_config('encryption_key', "Encryptin'glike@boss!"); $this->msg = 'My secret message'; + $this->mcrypt = extension_loaded('mcrypt'); } // -------------------------------------------------------------------- @@ -39,6 +40,12 @@ class Encrypt_test extends CI_TestCase { public function test_default_cipher() { + if ( ! $this->mcrypt) + { + $this->markTestSkipped('MCrypt not available'); + return; + } + $this->assertEquals('rijndael-256', $this->encrypt->get_cipher()); } @@ -47,6 +54,12 @@ class Encrypt_test extends CI_TestCase { public function test_set_cipher() { + if ( ! $this->mcrypt) + { + $this->markTestSkipped('MCrypt not available'); + return; + } + $this->encrypt->set_cipher(MCRYPT_BLOWFISH); $this->assertEquals('blowfish', $this->encrypt->get_cipher()); } @@ -55,6 +68,12 @@ class Encrypt_test extends CI_TestCase { public function test_default_mode() { + if ( ! $this->mcrypt) + { + $this->markTestSkipped('MCrypt not available'); + return; + } + $this->assertEquals('cbc', $this->encrypt->get_mode()); } @@ -62,6 +81,12 @@ class Encrypt_test extends CI_TestCase { public function test_set_mode() { + if ( ! $this->mcrypt) + { + $this->markTestSkipped('MCrypt not available'); + return; + } + $this->encrypt->set_mode(MCRYPT_MODE_CFB); $this->assertEquals('cfb', $this->encrypt->get_mode()); } -- cgit v1.2.3-24-g4f1b From a7001e968a4791312391eb245ad84888893cda8f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 24 Oct 2012 18:51:15 +0300 Subject: Fix insert_batch() test case --- tests/codeigniter/database/query_builder/insert_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index a9aafb66e..30c055680 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -52,7 +52,7 @@ class Insert_test extends CI_TestCase { // Do insert batch except for sqlite driver if (strpos(DB_DRIVER, 'sqlite') === FALSE) { - $this->assertTrue($this->db->insert_batch('job', $job_datas)); + $this->assertEquals(2, $this->db->insert_batch('job', $job_datas)); $job_2 = $this->db->where('id', 2)->get('job')->row(); $job_3 = $this->db->where('id', 3)->get('job')->row(); -- cgit v1.2.3-24-g4f1b From 74ffd17ab06327ca62ddfe28a186cae7ba6bd459 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 27 Oct 2012 00:41:03 +0300 Subject: Deprecated form helper function form_prep(). This function has been broken for YEARS and it's value-caching logic has only introduced various problems. We have html_escape() since CI 2.1.0 which is a perfect replacement, so it should be used instead. Fixes #228 & #1630 --- tests/codeigniter/core/Common_test.php | 18 ++++++++---- tests/codeigniter/helpers/form_helper_test.php | 39 +++++++++++++++++++++----- 2 files changed, 45 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php index 27d48efc2..999b49cb3 100644 --- a/tests/codeigniter/core/Common_test.php +++ b/tests/codeigniter/core/Common_test.php @@ -2,8 +2,6 @@ class Common_test extends CI_TestCase { - // ------------------------------------------------------------------------ - public function test_is_php() { $this->assertEquals(TRUE, is_php('1.2.0')); @@ -16,12 +14,12 @@ class Common_test extends CI_TestCase { { $this->assertEquals(' class="foo" id="bar"', _stringify_attributes(array('class' => 'foo', 'id' => 'bar'))); - $atts = new Stdclass; + $atts = new stdClass; $atts->class = 'foo'; $atts->id = 'bar'; $this->assertEquals(' class="foo" id="bar"', _stringify_attributes($atts)); - $atts = new Stdclass; + $atts = new stdClass; $this->assertEquals('', _stringify_attributes($atts)); $this->assertEquals(' class="foo" id="bar"', _stringify_attributes('class="foo" id="bar"')); @@ -35,10 +33,20 @@ class Common_test extends CI_TestCase { { $this->assertEquals('width=800,height=600', _stringify_attributes(array('width' => '800', 'height' => '600'), TRUE)); - $atts = new Stdclass; + $atts = new stdClass; $atts->width = 800; $atts->height = 600; $this->assertEquals('width=800,height=600', _stringify_attributes($atts, TRUE)); } + // ------------------------------------------------------------------------ + + public function test_html_escape() + { + $this->assertEquals( + html_escape('Here is a string containing "quoted" text.'), + 'Here is a string containing "quoted" text.' + ); + } + } \ 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 48628d2e5..03278581d 100644 --- a/tests/codeigniter/helpers/form_helper_test.php +++ b/tests/codeigniter/helpers/form_helper_test.php @@ -7,6 +7,8 @@ class Form_helper_test extends CI_TestCase $this->helper('form'); } + // ------------------------------------------------------------------------ + public function test_form_hidden() { $expected = <<assertEquals($expected, form_hidden('username', 'johndoe')); } + // ------------------------------------------------------------------------ + public function test_form_input() { $expected = <<assertEquals($expected, form_input($data)); } + // ------------------------------------------------------------------------ + public function test_form_password() { $expected = <<assertEquals($expected, form_password('password')); } + // ------------------------------------------------------------------------ + public function test_form_upload() { $expected = <<assertEquals($expected, form_upload('attachment')); } + // ------------------------------------------------------------------------ + public function test_form_textarea() { $expected = <<assertEquals($expected, form_textarea('notes', 'Notes')); } + // ------------------------------------------------------------------------ + public function test_form_dropdown() { $expected = <<assertEquals($expected, form_dropdown('cars', $options, array('volvo', 'audi'))); } + // ------------------------------------------------------------------------ + public function test_form_multiselect() { $expected = <<assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large'))); } + // ------------------------------------------------------------------------ + public function test_form_fieldset() { $expected = <<assertEquals($expected, form_fieldset('Address Information')); } + // ------------------------------------------------------------------------ + public function test_form_fieldset_close() { $expected = <<assertEquals($expected, form_fieldset_close('')); } + // ------------------------------------------------------------------------ + public function test_form_checkbox() { $expected = <<assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE)); } + // ------------------------------------------------------------------------ + public function test_form_radio() { $expected = <<assertEquals($expected, form_radio('newsletter', 'accept', TRUE)); } + // ------------------------------------------------------------------------ + public function test_form_submit() { $expected = <<assertEquals($expected, form_submit('mysubmit', 'Submit Post!')); } + // ------------------------------------------------------------------------ + public function test_form_label() { $expected = <<assertEquals($expected, form_label('What is your Name', 'username')); } + // ------------------------------------------------------------------------ + public function test_form_reset() { $expected = <<assertEquals($expected, form_reset('myreset', 'Reset')); } + // ------------------------------------------------------------------------ + public function test_form_button() { $expected = <<assertEquals($expected, form_button('name', 'content')); } + // ------------------------------------------------------------------------ + public function test_form_close() { $expected = <<assertEquals($expected, form_close('')); } - public function test_form_prep() - { - $expected = 'Here is a string containing "quoted" 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 -- cgit v1.2.3-24-g4f1b From 5232ba07752ffa783d03754c3a869d9f73ccae69 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 27 Oct 2012 15:25:05 +0300 Subject: Docblock improvements to the Config library and remove CI_Config::_assign_to_config() Existance of _assign_to_config() is pointless as this method consists just of a foreach calling CI_Config::set_item() and is only called by CodeIgniter.php - moved that foreach() in there instead. --- tests/codeigniter/core/Config_test.php | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php index d652a625e..be426d070 100644 --- a/tests/codeigniter/core/Config_test.php +++ b/tests/codeigniter/core/Config_test.php @@ -9,7 +9,7 @@ class Config_test extends CI_TestCase { // set predictable config values $this->cfg = array( 'index_page' => 'index.php', - 'base_url' => 'http://example.com/', + 'base_url' => 'http://example.com/', 'subclass_prefix' => 'MY_' ); $this->ci_set_config($this->cfg); @@ -38,7 +38,6 @@ class Config_test extends CI_TestCase { $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')); } @@ -50,7 +49,6 @@ class Config_test extends CI_TestCase { $this->assertFalse($this->config->slash_item('no_good_item')); $this->assertEquals($this->cfg['base_url'], $this->config->slash_item('base_url')); - $this->assertEquals($this->cfg['subclass_prefix'].'/', $this->config->slash_item('subclass_prefix')); } @@ -124,7 +122,7 @@ class Config_test extends CI_TestCase { $q_string = $this->config->item('enable_query_strings'); $this->config->set_item('enable_query_strings', FALSE); - $uri= 'test'; + $uri = 'test'; $uri2 = '1'; $this->assertEquals($index_page.'/'.$uri, $this->config->site_url($uri)); $this->assertEquals($index_page.'/'.$uri.'/'.$uri2, $this->config->site_url(array($uri, $uri2))); @@ -137,7 +135,6 @@ class Config_test extends CI_TestCase { $this->assertEquals($index_page.'/'.$uri.$suffix.'?'.$arg, $this->config->site_url($uri.'?'.$arg)); $this->config->set_item('url_suffix', FALSE); - $this->config->set_item('enable_query_strings', TRUE); $this->assertEquals($index_page.'?'.$uri, $this->config->site_url($uri)); @@ -233,22 +230,4 @@ class Config_test extends CI_TestCase { $this->assertNull($this->config->load($file)); } - // -------------------------------------------------------------------- - - public function test_assign_to_config() - { - $key1 = 'test'; - $key2 = '1'; - $val1 = 'foo'; - $val2 = 'bar'; - $cfg = array( - $key1 => $val1, - $key2 => $val2 - ); - - $this->assertNull($this->config->_assign_to_config($cfg)); - $this->assertEquals($val1, $this->config->item($key1)); - $this->assertEquals($val2, $this->config->item($key2)); - } - } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9aced4a0b04632b6e5737fd11de9a10fad87653d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 27 Oct 2012 18:04:40 +0300 Subject: Fix Loader tests --- tests/codeigniter/core/Loader_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index f7c338a20..816587a49 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -36,7 +36,7 @@ class Loader_test extends CI_TestCase { $this->assertAttributeInstanceOf($class, $lib, $this->ci_obj); // Test no lib given - $this->assertFalse($this->load->library()); + $this->assertNull($this->load->library()); // Test a string given to params $this->assertNull($this->load->library($lib, ' ')); @@ -450,7 +450,7 @@ class Loader_test extends CI_TestCase { public function test_load_config() { $cfg = 'someconfig'; - $this->assertNull($this->load->config($cfg, FALSE)); + $this->assertTrue($this->load->config($cfg, FALSE)); $this->assertContains($cfg, $this->ci_obj->config->loaded); } -- cgit v1.2.3-24-g4f1b From 7c4d10660a0a47446474bf97e3cb65f80693f1ee Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 15:14:34 +0200 Subject: Fix issue #1953 (form values being escaped twice) Re-instaing an improved form_prep() function, reverting most of the changes from 74ffd17ab06327ca62ddfe28a186cae7ba6bd459. --- tests/codeigniter/helpers/form_helper_test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php index 03278581d..89165271e 100644 --- a/tests/codeigniter/helpers/form_helper_test.php +++ b/tests/codeigniter/helpers/form_helper_test.php @@ -272,6 +272,21 @@ EOH; $this->assertEquals($expected, form_close('')); } + // ------------------------------------------------------------------------ + + public function test_form_prep() + { + $this->assertEquals( + 'Here is a string containing "quoted" text.', + form_prep('Here is a string containing "quoted" text.') + ); + + $this->assertEquals( + 'Here is a string containing a <tag>.', + form_prep('Here is a string containing a .', TRUE) + ); + } + } /* End of file form_helper_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e24eed7e4e410fabf7479a67d3a27e2596444505 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Nov 2012 23:33:45 +0200 Subject: Some micro-optimizations --- tests/codeigniter/database/DB_driver_test.php | 2 +- tests/mocks/autoloader.php | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php index 9e16e29b4..1f48ca984 100644 --- a/tests/codeigniter/database/DB_driver_test.php +++ b/tests/codeigniter/database/DB_driver_test.php @@ -5,7 +5,7 @@ class DB_driver_test extends CI_TestCase { public function test_initialize() { $config = Mock_Database_DB::config(DB_DRIVER); - $driver_name = current(explode('/', DB_DRIVER)); + sscanf(DB_DRIVER, '%[^/]/', $driver_name); $driver = $this->$driver_name($config[DB_DRIVER]); $this->assertTrue($driver->initialize()); diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 5b202f159..4fc9c63b6 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -38,13 +38,11 @@ function autoload($class) if (strpos($class, 'Mock_') === 0) { - $class = str_replace(array('Mock_', '_'), array('', DIRECTORY_SEPARATOR), $class); - $class = strtolower($class); + $class = strtolower(str_replace(array('Mock_', '_'), array('', DIRECTORY_SEPARATOR), $class)); } elseif (strpos($class, 'CI_') === 0) { - $fragments = explode('_', $class, 2); - $subclass = next($fragments); + $subclass = substr($class, 3); if (in_array($subclass, $ci_core)) { @@ -88,7 +86,7 @@ function autoload($class) } } - $file = (isset($file)) ? $file : $dir.$class.'.php'; + $file = isset($file) ? $file : $dir.$class.'.php'; if ( ! file_exists($file)) { -- cgit v1.2.3-24-g4f1b From 1712f1191f0027b61ca06dae7be303ea1b52f867 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 3 Nov 2012 00:40:33 +0200 Subject: An attempt to fix Loader tests --- tests/codeigniter/core/Loader_test.php | 73 ++++++++++++++++------------------ 1 file changed, 35 insertions(+), 38 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 816587a49..02629908f 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -6,6 +6,41 @@ class Loader_test extends CI_TestCase { public function set_up() { + // Create helper in VFS + $helper = 'autohelp'; + $hlp_func = '_autohelp_test_func'; + $content = 'ci_vfs_create($helper.'_helper', $content, $this->ci_app_root, 'helpers'); + + // Create library in VFS + $lib = 'autolib'; + $lib_class = 'CI_'.ucfirst($lib); + $this->ci_vfs_create($lib, 'ci_base_root, 'libraries'); + + // Create driver in VFS + $drv = 'autodrv'; + $subdir = ucfirst($drv); + $drv_class = 'CI_'.$subdir; + $this->ci_vfs_create($drv, 'ci_base_root, array('libraries', $subdir)); + + // Create model in VFS package path + $dir = 'testdir'; + $path = APPPATH.$dir.'/'; + $model = 'automod'; + $mod_class = ucfirst($model); + $this->ci_vfs_create($model, 'ci_app_root, array($dir, 'models')); + + // Create autoloader config + $cfg = array( + 'packages' => array($path), + 'helper' => array($helper), + 'libraries' => array($lib), + 'drivers' => array($drv), + 'model' => array($model), + 'config' => array('config1', 'config2') + ); + $this->ci_vfs_create('autoload', 'ci_app_root, 'config'); + // Instantiate a new loader $loader = $this->ci_core_class('loader'); $this->load = new $loader(); @@ -458,44 +493,6 @@ class Loader_test extends CI_TestCase { public function test_initialize() { - // Create helper in VFS - $helper = 'autohelp'; - $hlp_func = '_autohelp_test_func'; - $content = 'ci_vfs_create($helper.'_helper', $content, $this->ci_app_root, 'helpers'); - - // Create library in VFS - $lib = 'autolib'; - $lib_class = 'CI_'.ucfirst($lib); - $this->ci_vfs_create($lib, 'ci_base_root, 'libraries'); - - // Create driver in VFS - $drv = 'autodrv'; - $subdir = ucfirst($drv); - $drv_class = 'CI_'.$subdir; - $this->ci_vfs_create($drv, 'ci_base_root, array('libraries', $subdir)); - - // Create model in VFS package path - $dir = 'testdir'; - $path = APPPATH.$dir.'/'; - $model = 'automod'; - $mod_class = ucfirst($model); - $this->ci_vfs_create($model, 'ci_app_root, array($dir, 'models')); - - // Create autoloader config - $cfg = array( - 'packages' => array($path), - 'helper' => array($helper), - 'libraries' => array($lib), - 'drivers' => array($drv), - 'model' => array($model), - 'config' => array('config1', 'config2') - ); - $this->ci_vfs_create('autoload', 'ci_app_root, 'config'); - - // Run initialize and autoloader - $this->load->initialize(); - // Verify path $this->assertContains($path, $this->load->get_package_paths()); -- cgit v1.2.3-24-g4f1b From dd8d3d366bef1bc3fcb4476e88e8e6af44b89973 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 3 Nov 2012 02:09:05 +0200 Subject: Fix the bloody tests --- tests/codeigniter/core/Loader_test.php | 72 +++++++++++++++++----------------- tests/mocks/ci_testcase.php | 2 + 2 files changed, 39 insertions(+), 35 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 02629908f..be223f97d 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -6,41 +6,6 @@ class Loader_test extends CI_TestCase { public function set_up() { - // Create helper in VFS - $helper = 'autohelp'; - $hlp_func = '_autohelp_test_func'; - $content = 'ci_vfs_create($helper.'_helper', $content, $this->ci_app_root, 'helpers'); - - // Create library in VFS - $lib = 'autolib'; - $lib_class = 'CI_'.ucfirst($lib); - $this->ci_vfs_create($lib, 'ci_base_root, 'libraries'); - - // Create driver in VFS - $drv = 'autodrv'; - $subdir = ucfirst($drv); - $drv_class = 'CI_'.$subdir; - $this->ci_vfs_create($drv, 'ci_base_root, array('libraries', $subdir)); - - // Create model in VFS package path - $dir = 'testdir'; - $path = APPPATH.$dir.'/'; - $model = 'automod'; - $mod_class = ucfirst($model); - $this->ci_vfs_create($model, 'ci_app_root, array($dir, 'models')); - - // Create autoloader config - $cfg = array( - 'packages' => array($path), - 'helper' => array($helper), - 'libraries' => array($lib), - 'drivers' => array($drv), - 'model' => array($model), - 'config' => array('config1', 'config2') - ); - $this->ci_vfs_create('autoload', 'ci_app_root, 'config'); - // Instantiate a new loader $loader = $this->ci_core_class('loader'); $this->load = new $loader(); @@ -493,6 +458,43 @@ class Loader_test extends CI_TestCase { public function test_initialize() { + // Create helper in VFS + $helper = 'autohelp'; + $hlp_func = '_autohelp_test_func'; + $content = 'ci_vfs_create($helper.'_helper', $content, $this->ci_app_root, 'helpers'); + + // Create library in VFS + $lib = 'autolib'; + $lib_class = 'CI_'.ucfirst($lib); + $this->ci_vfs_create($lib, 'ci_base_root, 'libraries'); + + // Create driver in VFS + $drv = 'autodrv'; + $subdir = ucfirst($drv); + $drv_class = 'CI_'.$subdir; + $this->ci_vfs_create($drv, 'ci_base_root, array('libraries', $subdir)); + + // Create model in VFS package path + $dir = 'testdir'; + $path = APPPATH.$dir.'/'; + $model = 'automod'; + $mod_class = ucfirst($model); + $this->ci_vfs_create($model, 'ci_app_root, array($dir, 'models')); + + // Create autoloader config + $cfg = array( + 'packages' => array($path), + 'helper' => array($helper), + 'libraries' => array($lib), + 'drivers' => array($drv), + 'model' => array($model), + 'config' => array('config1', 'config2') + ); + $this->ci_vfs_create('autoload', 'ci_app_root, 'config'); + + $this->load->__construct(); + // Verify path $this->assertContains($path, $this->load->get_package_paths()); diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php index f16492945..2d0a26830 100644 --- a/tests/mocks/ci_testcase.php +++ b/tests/mocks/ci_testcase.php @@ -39,6 +39,8 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { $this->ci_app_root = vfsStream::newDirectory('application')->at($this->ci_vfs_root); $this->ci_base_root = vfsStream::newDirectory('system')->at($this->ci_vfs_root); $this->ci_view_root = vfsStream::newDirectory('views')->at($this->ci_app_root); + vfsStream::newDirectory('config')->at($this->ci_app_root); + $this->ci_vfs_clone('application/config/autoload.php'); if (method_exists($this, 'set_up')) { -- cgit v1.2.3-24-g4f1b From cdac248e9cf7a8ea3ed426f189bb52254800bc2a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 3 Nov 2012 18:09:01 +0200 Subject: Revert 679525d0237ac2e0a94d7b05377eb31eb3398f19 It appears to break get_instance()->*_package_path*() usage which is very common. Need to figure out how to resolve this. --- tests/codeigniter/core/Loader_test.php | 2 +- tests/mocks/ci_testcase.php | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index be223f97d..ecc5ca933 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -493,7 +493,7 @@ class Loader_test extends CI_TestCase { ); $this->ci_vfs_create('autoload', 'ci_app_root, 'config'); - $this->load->__construct(); + $this->load->initialize(); // Verify path $this->assertContains($path, $this->load->get_package_paths()); diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php index 2d0a26830..f16492945 100644 --- a/tests/mocks/ci_testcase.php +++ b/tests/mocks/ci_testcase.php @@ -39,8 +39,6 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { $this->ci_app_root = vfsStream::newDirectory('application')->at($this->ci_vfs_root); $this->ci_base_root = vfsStream::newDirectory('system')->at($this->ci_vfs_root); $this->ci_view_root = vfsStream::newDirectory('views')->at($this->ci_app_root); - vfsStream::newDirectory('config')->at($this->ci_app_root); - $this->ci_vfs_clone('application/config/autoload.php'); if (method_exists($this, 'set_up')) { -- cgit v1.2.3-24-g4f1b From a287a34c215903d3452023d74149eb5880125715 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 5 Nov 2012 23:19:59 +0200 Subject: Refactored DB Forge - PDO subdrivers are isolated from each other now. - Added compatibility for pretty much all of the features, for every DB platform. - Unified the way that stuff works in general. - Fixes issue #1005. --- tests/mocks/database/db/driver.php | 1 + tests/mocks/database/schema/skeleton.php | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php index 65ac2c4cc..2cf54b97b 100644 --- a/tests/mocks/database/db/driver.php +++ b/tests/mocks/database/db/driver.php @@ -34,6 +34,7 @@ class Mock_Database_DB_Driver extends CI_DB_driver { return call_user_func_array(array($this->ci_db_driver, $method), $arguments); } + } class CI_DB extends Mock_Database_DB_QueryBuilder {} \ No newline at end of file diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index d72244528..e5c536090 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -69,7 +69,7 @@ class Mock_Database_Schema_Skeleton { ) )); static::$forge->add_key('id', TRUE); - static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE)); + static::$forge->create_table('user', TRUE); // Job Table static::$forge->add_field(array( @@ -86,7 +86,7 @@ class Mock_Database_Schema_Skeleton { ) )); static::$forge->add_key('id', TRUE); - static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE)); + static::$forge->create_table('job', TRUE); // Misc Table static::$forge->add_field(array( @@ -103,7 +103,7 @@ class Mock_Database_Schema_Skeleton { ) )); static::$forge->add_key('id', TRUE); - static::$forge->create_table('misc', (strpos(static::$driver, 'pgsql') === FALSE)); + static::$forge->create_table('misc', TRUE); } /** -- cgit v1.2.3-24-g4f1b From ac68a3cadae94324d7de00bcb183ba19025e9ca2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 6 Nov 2012 15:44:00 +0200 Subject: Fix directory_map() tests --- tests/codeigniter/helpers/directory_helper_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php index c39ccd8d0..b7d52661f 100644 --- a/tests/codeigniter/helpers/directory_helper_test.php +++ b/tests/codeigniter/helpers/directory_helper_test.php @@ -28,7 +28,7 @@ class Directory_helper_test extends CI_TestCase { // test default recursive behavior $expected = array( - 'libraries' => array( + 'libraries/' => array( 'benchmark.html', 'database' => array('active_record.html', 'binds.html'), 'email.html', @@ -39,12 +39,12 @@ class Directory_helper_test extends CI_TestCase { $this->assertEquals($expected, directory_map(vfsStream::url('testDir'))); // test detection of hidden files - $expected['libraries'][] = '.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)); + $this->assertEquals(array('libraries/'), directory_map(vfsStream::url('testDir'), 1)); } } -- cgit v1.2.3-24-g4f1b From e8b8904bdfd6f8320beb67fb6daa96ee14c3b917 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 6 Nov 2012 15:50:17 +0200 Subject: directory_map() ... the final one --- tests/codeigniter/helpers/directory_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php index b7d52661f..41370e6e7 100644 --- a/tests/codeigniter/helpers/directory_helper_test.php +++ b/tests/codeigniter/helpers/directory_helper_test.php @@ -30,7 +30,7 @@ class Directory_helper_test extends CI_TestCase { $expected = array( 'libraries/' => array( 'benchmark.html', - 'database' => array('active_record.html', 'binds.html'), + 'database/' => array('active_record.html', 'binds.html'), 'email.html', '0' ) -- cgit v1.2.3-24-g4f1b From 1f884d6fece302ba53f106516880da4dd91f5660 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Nov 2012 19:57:14 +0200 Subject: Move Log class to core in tests as well --- tests/mocks/autoloader.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 4fc9c63b6..3d216da1f 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -16,7 +16,7 @@ function autoload($class) $ci_core = array( 'Benchmark', 'Config', 'Controller', 'Exceptions', 'Hooks', 'Input', - 'Lang', 'Loader', 'Model', + 'Lang', 'Loader', 'Log', 'Model', 'Output', 'Router', 'Security', 'URI', 'Utf8', ); @@ -25,11 +25,10 @@ function autoload($class) 'Calendar', 'Cart', 'Driver_Library', 'Email', 'Encrypt', 'Form_validation', 'Ftp', 'Image_lib', 'Javascript', - 'Log', 'Migration', 'Pagination', - 'Parser', 'Profiler', 'Table', - 'Trackback', 'Typography', 'Unit_test', - 'Upload', 'User_agent', 'Xmlrpc', - 'Zip', + 'Migration', 'Pagination', 'Parser', + 'Profiler', 'Table', 'Trackback', + 'Typography', 'Unit_test', 'Upload', + 'User_agent', 'Xmlrpc', 'Zip' ); $ci_drivers = array( -- cgit v1.2.3-24-g4f1b From 87c7813015483820eb2884d9e3695f2773c1b2b2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Nov 2012 16:44:58 +0200 Subject: Update tests following 77bd21b15305412b63c8f448787d5b275efd07e2 --- tests/codeigniter/core/Input_test.php | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index fe8738832..ca1c6dfd7 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -22,18 +22,7 @@ class Input_test extends CI_TestCase { public function test_get_not_exists() { - $this->assertEmpty($this->input->get()); - $this->assertEmpty($this->input->get('foo')); - - $this->assertTrue( ! $this->input->get()); - $this->assertTrue( ! $this->input->get('foo')); - - // Test we're getting empty results - $this->assertTrue($this->input->get() === NULL); - $this->assertTrue($this->input->get('foo') === NULL); - - // Test new 3.0 behaviour for non existant results (used to be FALSE) - $this->assertTrue($this->input->get() === NULL); + $this->assertTrue($this->input->get() === array()); $this->assertTrue($this->input->get('foo') === NULL); } @@ -64,16 +53,7 @@ class Input_test extends CI_TestCase { public function test_post_not_exists() { - $this->assertEmpty($this->input->post()); - $this->assertEmpty($this->input->post('foo')); - - $this->assertTrue( ! $this->input->post()); - $this->assertTrue( ! $this->input->post('foo')); - - $this->assertTrue($this->input->post() === NULL); - $this->assertTrue($this->input->post('foo') === NULL); - - $this->assertTrue($this->input->post() === NULL); + $this->assertTrue($this->input->post() === array()); $this->assertTrue($this->input->post('foo') === NULL); } -- cgit v1.2.3-24-g4f1b From 6262d053db57957c4445ef7fce76070854c3e30d Mon Sep 17 00:00:00 2001 From: dchill42 Date: Sat, 24 Nov 2012 18:41:13 -0500 Subject: Added support for extending individual driver classes and driver unit tests Signed-off-by: dchill42 --- tests/codeigniter/libraries/Driver_test.php | 176 +++++++++++++++++++++++++++ tests/codeigniter/libraries/Session_test.php | 74 ++++------- tests/mocks/libraries/driver.php | 27 ++++ tests/mocks/libraries/session.php | 7 -- 4 files changed, 226 insertions(+), 58 deletions(-) create mode 100644 tests/codeigniter/libraries/Driver_test.php create mode 100644 tests/mocks/libraries/driver.php (limited to 'tests') diff --git a/tests/codeigniter/libraries/Driver_test.php b/tests/codeigniter/libraries/Driver_test.php new file mode 100644 index 000000000..0186cfe97 --- /dev/null +++ b/tests/codeigniter/libraries/Driver_test.php @@ -0,0 +1,176 @@ +subclass = 'Mock_Libraries_'; + $this->ci_set_config('subclass_prefix', $this->subclass); + + // Mock Loader->get_package_paths + $paths = 'get_package_paths'; + $ldr = $this->getMock('CI_Loader', array($paths)); + $ldr->expects($this->any())->method($paths)->will($this->returnValue(array(APPPATH, BASEPATH))); + $this->ci_instance_var('load', $ldr); + + // Create mock driver library + $this->name = 'Driver'; + $this->lib = new Mock_Libraries_Driver(); + } + + /** + * Test driver child loading + */ + public function test_load_driver() + { + // Create driver file + $driver = 'basic'; + $file = $this->name.'_'.$driver; + $class = 'CI_'.$file; + $prop = 'called'; + $content = ''.$prop.' = TRUE; } }'; + $this->ci_vfs_create($file, $content, $this->ci_base_root, array('libraries', $this->name, 'drivers')); + + // Make driver valid + $this->lib->driver_list($driver); + + // Load driver + $this->assertNotNull($this->lib->load_driver($driver)); + + // Did lib name get set? + $this->assertEquals($this->name, $this->lib->get_name()); + + // Was driver loaded? + $this->assertObjectHasAttribute($driver, $this->lib); + $this->assertAttributeInstanceOf($class, $driver, $this->lib); + $this->assertAttributeInstanceOf('CI_Driver', $driver, $this->lib); + + // Was decorate called? + $this->assertObjectHasAttribute($prop, $this->lib->$driver); + $this->assertTrue($this->lib->$driver->$prop); + + // Do we get an error for an invalid driver? + $driver = 'unlisted'; + $this->setExpectedException('RuntimeException', 'CI Error: Invalid driver requested: '.$this->name.'_'.$driver); + $this->lib->load_driver($driver); + } + + /** + * Test loading lowercase from app path + */ + public function test_load_app_driver() + { + // Create driver file + $driver = 'lowpack'; + $file = $this->name.'_'.$driver; + $class = 'CI_'.$file; + $content = 'ci_vfs_create(strtolower($file), $content, $this->ci_app_root, + array('libraries', $this->name, 'drivers')); + + // Make valid list + $nodriver = 'absent'; + $this->lib->driver_list(array($driver, $nodriver)); + + // Load driver + $this->assertNotNull($this->lib->load_driver($driver)); + + // Was driver loaded? + $this->assertObjectHasAttribute($driver, $this->lib); + $this->assertAttributeInstanceOf($class, $driver, $this->lib); + $this->assertAttributeInstanceOf('CI_Driver', $driver, $this->lib); + + // Do we get an error for a non-existent driver? + $this->setExpectedException('RuntimeException', 'CI Error: Unable to load the requested driver: CI_'. + $this->name.'_'.$nodriver); + $this->lib->load_driver($nodriver); + } + + /** + * Test loading driver extension + */ + public function test_load_driver_ext() + { + // Create base file + $driver = 'extend'; + $base = $this->name.'_'.$driver; + $baseclass = 'CI_'.$base; + $content = 'ci_vfs_create($base, $content, $this->ci_base_root, array('libraries', $this->name, 'drivers')); + + // Create driver file + $class = $this->subclass.$base; + $content = 'ci_vfs_create($class, $content, $this->ci_app_root, array('libraries', $this->name, 'drivers')); + + // Make valid list + $this->lib->driver_list($driver); + + // Load driver + $this->assertNotNull($this->lib->load_driver($driver)); + + // Was driver loaded? + $this->assertObjectHasAttribute($driver, $this->lib); + $this->assertAttributeInstanceOf($class, $driver, $this->lib); + $this->assertAttributeInstanceOf($baseclass, $driver, $this->lib); + $this->assertAttributeInstanceOf('CI_Driver', $driver, $this->lib); + + // Create driver extension without base + $driver = 'baseless'; + $base = $this->name.'_'.$driver; + $class = $this->subclass.$base; + $content = 'ci_vfs_create($class, $content, $this->ci_app_root, array('libraries', $this->name, 'drivers')); + $this->lib->driver_list($driver); + + // Do we get an error when base class isn't found? + $this->setExpectedException('RuntimeException', 'CI Error: Unable to load the requested class: CI_'.$base); + $this->lib->load_driver($driver); + } + + /** + * Test decorating driver with parent attributes + */ + public function test_decorate() + { + // Create parent with a method and property to access + $pclass = 'Test_Parent'; + $prop = 'parent_prop'; + $value = 'initial'; + $method = 'parent_func'; + $return = 'func return'; + $code = 'class '.$pclass.' { public $'.$prop.' = \''.$value.'\'; '. + 'public function '.$method.'() { return \''.$return.'\'; } }'; + eval($code); + $parent = new $pclass(); + + // Create child driver to decorate + $class = 'Test_Driver'; + eval('class '.$class.' extends CI_Driver { }'); + $child = new $class(); + + // Decorate child + $child->decorate($parent); + + // Do we get the initial parent property value? + $this->assertEquals($value, $child->$prop); + + // Can we change the parent property? + $newval = 'changed'; + $child->$prop = $newval; + $this->assertEquals($newval, $parent->$prop); + + // Do we get back the updated value? + $this->assertEquals($newval, $child->$prop); + + // Can we call the parent method? + $this->assertEquals($return, $child->$method()); + } +} diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php index 14469f7fa..e675b4ed7 100644 --- a/tests/codeigniter/libraries/Session_test.php +++ b/tests/codeigniter/libraries/Session_test.php @@ -6,8 +6,8 @@ class Session_test extends CI_TestCase { protected $settings = array( 'use_cookies' => 0, - 'use_only_cookies' => 0, - 'cache_limiter' => false + 'use_only_cookies' => 0, + 'cache_limiter' => false ); protected $setting_vals = array(); protected $cookie_vals; @@ -28,11 +28,12 @@ class Session_test extends CI_TestCase { $this->cookie_vals = $_COOKIE; $_COOKIE = array(); + // Set subclass prefix to match our mock + $this->ci_set_config('subclass_prefix', 'Mock_Libraries_'); + // Establish necessary support classes - $cfg = $this->ci_core_class('cfg'); - $ldr = $this->ci_core_class('load'); $ci = $this->ci_instance(); - $ci->config = new $cfg(); + $ldr = $this->ci_core_class('load'); $ci->load = new $ldr(); $ci->input = new Mock_Core_Input(NULL, NULL); @@ -56,11 +57,7 @@ class Session_test extends CI_TestCase { 'sess_time_to_update' => 300, 'time_reference' => 'local', 'cookie_prefix' => '', - 'encryption_key' => 'foobar', - 'sess_valid_drivers' => array( - 'Mock_Libraries_Session_native', - 'Mock_Libraries_Session_cookie' - ) + 'encryption_key' => 'foobar' ); $this->session = new Mock_Libraries_Session($config); } @@ -83,9 +80,6 @@ class Session_test extends CI_TestCase { /** * Test set_userdata() function - * - * @covers CI_Session::set_userdata - * @covers CI_Session::userdata */ public function test_set_userdata() { @@ -117,8 +111,6 @@ class Session_test extends CI_TestCase { /** * Test the has_userdata() function - * - * @covers CI_Session::has_userdata */ public function test_has_userdata() { @@ -141,8 +133,6 @@ class Session_test extends CI_TestCase { /** * Test the all_userdata() function - * - * @covers CI_Session::all_userdata */ public function test_all_userdata() { @@ -150,16 +140,16 @@ class Session_test extends CI_TestCase { $cdata = array( 'one' => 'first', 'two' => 'second', - 'three' => 'third', - 'foo' => 'bar', - 'bar' => 'baz' + 'three' => 'third', + 'foo' => 'bar', + 'bar' => 'baz' ); $ndata = array( 'one' => 'gold', - 'two' => 'silver', - 'three' => 'bronze', - 'foo' => 'baz', - 'bar' => 'foo' + 'two' => 'silver', + 'three' => 'bronze', + 'foo' => 'baz', + 'bar' => 'foo' ); $this->session->cookie->set_userdata($cdata); $this->session->native->set_userdata($ndata); @@ -177,8 +167,6 @@ class Session_test extends CI_TestCase { /** * Test the unset_userdata() function - * - * @covers CI_Session::unset_userdata */ public function test_unset_userdata() { @@ -202,9 +190,6 @@ class Session_test extends CI_TestCase { /** * Test the flashdata() functions - * - * @covers CI_Session::set_flashdata - * @covers CI_Session::flashdata */ public function test_flashdata() { @@ -234,8 +219,6 @@ class Session_test extends CI_TestCase { /** * Test the keep_flashdata() function - * - * @covers CI_Session::keep_flashdata */ public function test_keep_flashdata() { @@ -271,25 +254,23 @@ class Session_test extends CI_TestCase { /** * Test the all_flashdata() function - * - * @covers CI_Session::all_flashdata */ public function test_all_flashdata() { // Set a specific series of data for each driver $cdata = array( 'one' => 'first', - 'two' => 'second', - 'three' => 'third', - 'foo' => 'bar', - 'bar' => 'baz' + 'two' => 'second', + 'three' => 'third', + 'foo' => 'bar', + 'bar' => 'baz' ); $ndata = array( 'one' => 'gold', - 'two' => 'silver', - 'three' => 'bronze', - 'foo' => 'baz', - 'bar' => 'foo' + 'two' => 'silver', + 'three' => 'bronze', + 'foo' => 'baz', + 'bar' => 'foo' ); $this->session->cookie->set_flashdata($cdata); $this->session->native->set_flashdata($ndata); @@ -303,9 +284,6 @@ class Session_test extends CI_TestCase { /** * Test the tempdata() functions - * - * @covers CI_Session::set_tempdata - * @covers CI_Session::tempdata */ public function test_set_tempdata() { @@ -332,8 +310,6 @@ class Session_test extends CI_TestCase { /** * Test the unset_tempdata() function - * - * @covers CI_Session::unset_tempdata */ public function test_unset_tempdata() { @@ -357,8 +333,6 @@ class Session_test extends CI_TestCase { /** * Test the sess_regenerate() function - * - * @covers CI_Session::sess_regenerate */ public function test_sess_regenerate() { @@ -378,8 +352,6 @@ class Session_test extends CI_TestCase { /** * Test the sess_destroy() function - * - * @covers CI_Session::sess_destroy */ public function test_sess_destroy() { @@ -399,4 +371,4 @@ class Session_test extends CI_TestCase { $this->session->native->sess_destroy(); $this->assertNull($this->session->native->userdata($key)); } -} \ No newline at end of file +} diff --git a/tests/mocks/libraries/driver.php b/tests/mocks/libraries/driver.php new file mode 100644 index 000000000..91bb01596 --- /dev/null +++ b/tests/mocks/libraries/driver.php @@ -0,0 +1,27 @@ +valid_drivers; + } + + $this->valid_drivers = (array) $drivers; + } + + /** + * Get library name + */ + public function get_name() + { + return $this->lib_name; + } +} diff --git a/tests/mocks/libraries/session.php b/tests/mocks/libraries/session.php index c6e194f58..11b27cf67 100644 --- a/tests/mocks/libraries/session.php +++ b/tests/mocks/libraries/session.php @@ -4,7 +4,6 @@ * Mock library to add testing features to Session driver library */ class Mock_Libraries_Session extends CI_Session { - /** * Simulate new page load */ @@ -20,7 +19,6 @@ class Mock_Libraries_Session extends CI_Session { * Mock cookie driver to overload cookie setting */ class Mock_Libraries_Session_cookie extends CI_Session_cookie { - /** * Overload _setcookie to manage $_COOKIE values, since actual cookies can't be set in unit testing */ @@ -36,8 +34,3 @@ class Mock_Libraries_Session_cookie extends CI_Session_cookie { } } } - -/** - * Mock native driver (just for consistency in loading) - */ -class Mock_Libraries_Session_native extends CI_Session_native { } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1713d322a309d9cf405cfe83e2131368f29b222b Mon Sep 17 00:00:00 2001 From: dchill42 Date: Sat, 24 Nov 2012 20:23:21 -0500 Subject: Replaced Mock_Core_Lang with PHPUnit mockups Signed-off-by: dchill42 --- tests/codeigniter/helpers/language_helper_test.php | 4 +++- tests/codeigniter/libraries/Calendar_test.php | 13 +++++------ tests/codeigniter/libraries/Upload_test.php | 3 ++- tests/mocks/core/lang.php | 15 ------------- tests/mocks/libraries/calendar.php | 25 ---------------------- 5 files changed, 10 insertions(+), 50 deletions(-) delete mode 100644 tests/mocks/core/lang.php delete mode 100644 tests/mocks/libraries/calendar.php (limited to 'tests') diff --git a/tests/codeigniter/helpers/language_helper_test.php b/tests/codeigniter/helpers/language_helper_test.php index 06932b9fd..1fe0ef17b 100644 --- a/tests/codeigniter/helpers/language_helper_test.php +++ b/tests/codeigniter/helpers/language_helper_test.php @@ -5,7 +5,9 @@ class Language_helper_test extends CI_TestCase { public function test_lang() { $this->helper('language'); - $this->ci_instance_var('lang', new Mock_Core_Lang()); + $lang = $this->getMock('CI_Lang', array('line')); + $lang->expects($this->any())->method('line')->will($this->returnValue(FALSE)); + $this->ci_instance_var('lang', $lang); $this->assertFalse(lang(1)); $this->assertEquals('', lang(1, 'foo')); diff --git a/tests/codeigniter/libraries/Calendar_test.php b/tests/codeigniter/libraries/Calendar_test.php index 95668d70d..952e8a8d2 100644 --- a/tests/codeigniter/libraries/Calendar_test.php +++ b/tests/codeigniter/libraries/Calendar_test.php @@ -2,12 +2,12 @@ class Calendar_test extends CI_TestCase { - function __construct() + function set_up() { - $obj = new stdClass; - $obj->calendar = new Mock_Libraries_Calendar(); - - $this->calendar = $obj->calendar; + $lang = $this->getMock('CI_Lang', array('load', 'line')); + $lang->expects($this->any())->method('line')->will($this->returnValue(FALSE)); + $this->ci_instance_var('lang', $lang); + $this->calendar = new CI_Calendar(); } function test_initialize() @@ -20,9 +20,6 @@ class Calendar_test extends CI_TestCase { $this->assertEquals('monday', $this->calendar->start_day); } - /** - * @covers Mock_Libraries_Calendar::parse_template - */ function test_generate() { $no_events = ' diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php index 546cebc59..1bd8f1430 100644 --- a/tests/codeigniter/libraries/Upload_test.php +++ b/tests/codeigniter/libraries/Upload_test.php @@ -7,7 +7,8 @@ class Upload_test extends CI_TestCase { $ci = $this->ci_instance(); $ci->upload = new Mock_Libraries_Upload(); $ci->security = new Mock_Core_Security(); - $ci->lang = new Mock_Core_Lang(); + $ci->lang = $this->getMock('CI_Lang', array('load', 'line')); + $ci->lang->expects($this->any())->method('line')->will($this->returnValue(FALSE)); $this->upload = $ci->upload; } diff --git a/tests/mocks/core/lang.php b/tests/mocks/core/lang.php deleted file mode 100644 index 27ea3faba..000000000 --- a/tests/mocks/core/lang.php +++ /dev/null @@ -1,15 +0,0 @@ -CI = new stdClass; - $this->CI->lang = new Mock_Core_Lang(); - - if ( ! in_array('calendar_lang.php', $this->CI->lang->is_loaded, TRUE)) - { - $this->CI->lang->load('calendar'); - } - - $this->local_time = time(); - - if (count($config) > 0) - { - $this->initialize($config); - } - - log_message('debug', 'Calendar Class Initialized'); - } - -} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 7e83f32e3844ba8ee34c8a79ee6fa3f558fcb46a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 25 Nov 2012 16:03:21 +0200 Subject: Revert some of the changes from PR #2029 We have file naming conventions and any extension filename needs to match MY_, so we don't need to check for lowercase equivalents. --- tests/codeigniter/libraries/Driver_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Driver_test.php b/tests/codeigniter/libraries/Driver_test.php index 0186cfe97..fb5f3f020 100644 --- a/tests/codeigniter/libraries/Driver_test.php +++ b/tests/codeigniter/libraries/Driver_test.php @@ -72,7 +72,7 @@ class Driver_test extends CI_TestCase { $file = $this->name.'_'.$driver; $class = 'CI_'.$file; $content = 'ci_vfs_create(strtolower($file), $content, $this->ci_app_root, + $this->ci_vfs_create($file, $content, $this->ci_app_root, array('libraries', $this->name, 'drivers')); // Make valid list -- cgit v1.2.3-24-g4f1b From 79980e4ddc3dd312e31523c2ecf3042cd9010bde Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 25 Nov 2012 16:32:05 +0200 Subject: MySQLi tests --- tests/codeigniter/database/DB_driver_test.php | 5 ++++ tests/mocks/database/config/mysqli.php | 34 +++++++++++++++++++++++++++ tests/mocks/database/drivers/mysqli.php | 17 ++++++++++++++ tests/travis/mysqli.phpunit.xml | 25 ++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 tests/mocks/database/config/mysqli.php create mode 100644 tests/mocks/database/drivers/mysqli.php create mode 100644 tests/travis/mysqli.phpunit.xml (limited to 'tests') diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php index 1f48ca984..c04c42b09 100644 --- a/tests/codeigniter/database/DB_driver_test.php +++ b/tests/codeigniter/database/DB_driver_test.php @@ -21,6 +21,11 @@ class DB_driver_test extends CI_TestCase { return new Mock_Database_Drivers_Mysql($config); } + protected function mysqli($config) + { + return new Mock_Database_Drivers_Mysqli($config); + } + protected function sqlite($config) { return new Mock_Database_Drivers_Sqlite($config); diff --git a/tests/mocks/database/config/mysqli.php b/tests/mocks/database/config/mysqli.php new file mode 100644 index 000000000..5dd08abb2 --- /dev/null +++ b/tests/mocks/database/config/mysqli.php @@ -0,0 +1,34 @@ + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'travis', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'mysqli' + ), + + // Database configuration with failover + 'mysqli_failover' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'not_travis', + 'password' => 'wrong password', + 'database' => 'not_ci_test', + 'dbdriver' => 'mysqli', + 'failover' => array( + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'travis', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'mysqli', + ) + ) + ) +); \ No newline at end of file diff --git a/tests/mocks/database/drivers/mysqli.php b/tests/mocks/database/drivers/mysqli.php new file mode 100644 index 000000000..73c35b609 --- /dev/null +++ b/tests/mocks/database/drivers/mysqli.php @@ -0,0 +1,17 @@ + + + + + + + + + ../codeigniter + + + + + ../../system + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From feb1e0578194fc1ca114bcafe46cba3f86245bef Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Nov 2012 23:57:04 +0200 Subject: Update Language helper test case --- tests/codeigniter/helpers/language_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/language_helper_test.php b/tests/codeigniter/helpers/language_helper_test.php index 1fe0ef17b..176da689a 100644 --- a/tests/codeigniter/helpers/language_helper_test.php +++ b/tests/codeigniter/helpers/language_helper_test.php @@ -10,7 +10,7 @@ class Language_helper_test extends CI_TestCase { $this->ci_instance_var('lang', $lang); $this->assertFalse(lang(1)); - $this->assertEquals('', lang(1, 'foo')); + $this->assertEquals('', lang(1, 'foo', array('class' => 'bar'))); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From cc4b00347c9ff061488bc88194002be701f4190f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 29 Nov 2012 17:21:43 +0200 Subject: Added CI_Output::get_header() (an improved version of PR #645) Also fixed get_content_type() to only return the MIME value and created Output library unit tests for both of these methods. --- tests/codeigniter/core/Output_test.php | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/codeigniter/core/Output_test.php (limited to 'tests') diff --git a/tests/codeigniter/core/Output_test.php b/tests/codeigniter/core/Output_test.php new file mode 100644 index 000000000..3384143e9 --- /dev/null +++ b/tests/codeigniter/core/Output_test.php @@ -0,0 +1,35 @@ +ci_set_config('charset', 'UTF-8'); + $output = $this->ci_core_class('output'); + $this->output = new $output(); + } + + // -------------------------------------------------------------------- + + public function test_get_content_type() + { + $this->assertEquals('text/html', $this->output->get_content_type()); + } + + // -------------------------------------------------------------------- + + public function test_get_header() + { + $this->assertNull($this->output->get_header('Non-Existent-Header')); + + // TODO: Find a way to test header() values as well. Currently, + // PHPUnit prevents this by not using output buffering. + + $this->output->set_content_type('text/plain', 'WINDOWS-1251'); + $this->assertEquals( + 'text/plain; charset=windows-1251', // Character set is converted to lowercase + $this->output->get_header('content-type') // Case-insensitive comparison + ); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4173823ba1b45955d63cb5e8d60f02312e345bda Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 30 Nov 2012 00:13:17 +0200 Subject: Fix #2041 --- tests/codeigniter/core/Output_test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Output_test.php b/tests/codeigniter/core/Output_test.php index 3384143e9..d8252403d 100644 --- a/tests/codeigniter/core/Output_test.php +++ b/tests/codeigniter/core/Output_test.php @@ -2,11 +2,13 @@ class Output_test extends CI_TestCase { + public $output; + public function set_up() { $this->ci_set_config('charset', 'UTF-8'); $output = $this->ci_core_class('output'); - $this->output = new $output(); + $this->output = new $output(); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 66b36efa5df371874dda1bf4f4843384b6acfa06 Mon Sep 17 00:00:00 2001 From: Johnathan Croom Date: Thu, 29 Nov 2012 17:54:28 -0700 Subject: keep_flashdata array test --- tests/codeigniter/libraries/Session_test.php | 52 +++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php index 14469f7fa..50d263827 100644 --- a/tests/codeigniter/libraries/Session_test.php +++ b/tests/codeigniter/libraries/Session_test.php @@ -269,6 +269,56 @@ class Session_test extends CI_TestCase { $this->assertNull($this->session->native->flashdata($key)); } + public function test_keep_flashdata_with_array() + { + // Set flashdata array for each driver + $cdata = array( + 'one' => 'first', + 'two' => 'second', + 'three' => 'third', + 'foo' => 'bar', + 'bar' => 'baz' + ); + $ndata = array( + 'one' => 'gold', + 'two' => 'silver', + 'three' => 'bronze', + 'foo' => 'baz', + 'bar' => 'foo' + ); + $kdata = array( + 'one', + 'two', + 'three', + 'foo', + 'bar' + ); + $this->session->cookie->set_flashdata($cdata); + $this->session->native->set_flashdata($ndata); + + // Simulate page reload and verify independent messages + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($cdata, $this->session->cookie->all_flashdata()); + $this->assertEquals($ndata, $this->session->native->all_flashdata()); + + // Keep messages + $this->session->cookie->keep_flashdata($kdata); + $this->session->native->keep_flashdata($kdata); + + // Simulate next page reload and verify message persistence + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($cdata, $this->session->cookie->all_flashdata()); + $this->assertEquals($ndata, $this->session->native->all_flashdata()); + + // Simulate next page reload and verify absence of messages + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEmpty($this->session->cookie->all_flashdata()); + $this->assertEmpty($this->session->native->all_flashdata()); + } + /** * Test the all_flashdata() function * @@ -399,4 +449,4 @@ class Session_test extends CI_TestCase { $this->session->native->sess_destroy(); $this->assertNull($this->session->native->userdata($key)); } -} \ No newline at end of file +} -- cgit v1.2.3-24-g4f1b From 838a9d69a9139b6bcd6f8765fdd2d58b929e70ad Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 3 Dec 2012 14:37:47 +0200 Subject: [ci skip] Cleaned some spaces --- tests/codeigniter/helpers/date_helper_test.php | 1 - tests/codeigniter/helpers/file_helper_test.php | 2 -- tests/codeigniter/helpers/html_helper_test.php | 1 + tests/codeigniter/helpers/path_helper_test.php | 1 + tests/codeigniter/libraries/Driver_test.php | 3 ++- tests/codeigniter/libraries/Encrypt_test.php | 1 - tests/codeigniter/libraries/Session_test.php | 4 +++- tests/mocks/ci_testconfig.php | 2 +- tests/mocks/core/common.php | 1 - tests/mocks/libraries/driver.php | 2 +- tests/mocks/libraries/session.php | 2 +- 11 files changed, 10 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 1458acd3e..0f16e6c49 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -5,7 +5,6 @@ class Date_helper_test extends CI_TestCase { public function set_up() { $this->helper('date'); - $this->time = time(); } diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php index 9b03da9d7..3a6c73a5c 100644 --- a/tests/codeigniter/helpers/file_helper_test.php +++ b/tests/codeigniter/helpers/file_helper_test.php @@ -148,6 +148,4 @@ class File_helper_Test extends CI_TestCase { // // } - // -------------------------------------------------------------------- - } \ 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 4dd717ff7..d66ad895c 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -88,4 +88,5 @@ EOH; $this->assertEquals($expect, meta(array('name' => 'foo'))); } + } \ 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 0faf6f383..d25c3ed9b 100644 --- a/tests/codeigniter/helpers/path_helper_test.php +++ b/tests/codeigniter/helpers/path_helper_test.php @@ -26,6 +26,7 @@ class Path_helper_test extends CI_TestCase { set_realpath('/path/to/nowhere', TRUE); } + } /* End of file path_helper_test.php */ \ No newline at end of file diff --git a/tests/codeigniter/libraries/Driver_test.php b/tests/codeigniter/libraries/Driver_test.php index fb5f3f020..d98e8ab98 100644 --- a/tests/codeigniter/libraries/Driver_test.php +++ b/tests/codeigniter/libraries/Driver_test.php @@ -173,4 +173,5 @@ class Driver_test extends CI_TestCase { // Can we call the parent method? $this->assertEquals($return, $child->$method()); } -} + +} \ No newline at end of file diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php index 21ac85f03..a08db8ed0 100644 --- a/tests/codeigniter/libraries/Encrypt_test.php +++ b/tests/codeigniter/libraries/Encrypt_test.php @@ -51,7 +51,6 @@ class Encrypt_test extends CI_TestCase { // -------------------------------------------------------------------- - public function test_set_cipher() { if ( ! $this->mcrypt) diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php index 7ef3a3667..6edda99d7 100644 --- a/tests/codeigniter/libraries/Session_test.php +++ b/tests/codeigniter/libraries/Session_test.php @@ -4,6 +4,7 @@ * Session driver library unit test */ class Session_test extends CI_TestCase { + protected $settings = array( 'use_cookies' => 0, 'use_only_cookies' => 0, @@ -421,4 +422,5 @@ class Session_test extends CI_TestCase { $this->session->native->sess_destroy(); $this->assertNull($this->session->native->userdata($key)); } -} + +} \ No newline at end of file diff --git a/tests/mocks/ci_testconfig.php b/tests/mocks/ci_testconfig.php index 0c52bb984..f80adc5d4 100644 --- a/tests/mocks/ci_testconfig.php +++ b/tests/mocks/ci_testconfig.php @@ -17,4 +17,4 @@ class CI_TestConfig { return TRUE; } -} +} \ No newline at end of file diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php index 9289b2716..24d645ae3 100644 --- a/tests/mocks/core/common.php +++ b/tests/mocks/core/common.php @@ -148,7 +148,6 @@ if ( ! function_exists('_exception_handler')) } } - // We assume a few things about our environment ... // -------------------------------------------------------------------- diff --git a/tests/mocks/libraries/driver.php b/tests/mocks/libraries/driver.php index 91bb01596..633194345 100644 --- a/tests/mocks/libraries/driver.php +++ b/tests/mocks/libraries/driver.php @@ -24,4 +24,4 @@ class Mock_Libraries_Driver extends CI_Driver_Library { { return $this->lib_name; } -} +} \ No newline at end of file diff --git a/tests/mocks/libraries/session.php b/tests/mocks/libraries/session.php index 11b27cf67..562033bbf 100644 --- a/tests/mocks/libraries/session.php +++ b/tests/mocks/libraries/session.php @@ -33,4 +33,4 @@ class Mock_Libraries_Session_cookie extends CI_Session_cookie { $_COOKIE[$name] = $value; } } -} +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b