summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter
diff options
context:
space:
mode:
Diffstat (limited to 'tests/codeigniter')
-rw-r--r--tests/codeigniter/core/Output_test.php37
-rw-r--r--tests/codeigniter/database/DB_driver_test.php5
-rw-r--r--tests/codeigniter/helpers/language_helper_test.php6
-rw-r--r--tests/codeigniter/libraries/Calendar_test.php13
-rw-r--r--tests/codeigniter/libraries/Driver_test.php176
-rw-r--r--tests/codeigniter/libraries/Session_test.php72
-rw-r--r--tests/codeigniter/libraries/Upload_test.php3
7 files changed, 251 insertions, 61 deletions
diff --git a/tests/codeigniter/core/Output_test.php b/tests/codeigniter/core/Output_test.php
new file mode 100644
index 000000000..d8252403d
--- /dev/null
+++ b/tests/codeigniter/core/Output_test.php
@@ -0,0 +1,37 @@
+<?php
+
+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();
+ }
+
+ // --------------------------------------------------------------------
+
+ 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
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/codeigniter/helpers/language_helper_test.php b/tests/codeigniter/helpers/language_helper_test.php
index 06932b9fd..176da689a 100644
--- a/tests/codeigniter/helpers/language_helper_test.php
+++ b/tests/codeigniter/helpers/language_helper_test.php
@@ -5,10 +5,12 @@ 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('<label for="foo"></label>', lang(1, 'foo'));
+ $this->assertEquals('<label for="foo" class="bar"></label>', lang(1, 'foo', array('class' => 'bar')));
}
} \ No newline at end of file
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 = '<table border="0" cellpadding="4" cellspacing="0">
diff --git a/tests/codeigniter/libraries/Driver_test.php b/tests/codeigniter/libraries/Driver_test.php
new file mode 100644
index 000000000..fb5f3f020
--- /dev/null
+++ b/tests/codeigniter/libraries/Driver_test.php
@@ -0,0 +1,176 @@
+<?php
+
+/**
+ * Driver library base class unit test
+ */
+class Driver_test extends CI_TestCase {
+ /**
+ * Set up test framework
+ */
+ public function set_up()
+ {
+ // Set our subclass prefix
+ $this->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 = '<?php class '.$class.' extends CI_Driver { public $'.$prop.' = FALSE; '.
+ 'public function decorate($parent) { $this->'.$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 = '<?php class '.$class.' extends CI_Driver { }';
+ $this->ci_vfs_create($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 = '<?php class '.$baseclass.' extends CI_Driver { }';
+ $this->ci_vfs_create($base, $content, $this->ci_base_root, array('libraries', $this->name, 'drivers'));
+
+ // Create driver file
+ $class = $this->subclass.$base;
+ $content = '<?php class '.$class.' extends '.$baseclass.' { }';
+ $this->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 = '<?php class '.$class.' extends CI_Driver { }';
+ $this->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 50d263827..7ef3a3667 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()
{
@@ -321,25 +304,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);
@@ -353,9 +334,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()
{
@@ -382,8 +360,6 @@ class Session_test extends CI_TestCase {
/**
* Test the unset_tempdata() function
- *
- * @covers CI_Session::unset_tempdata
*/
public function test_unset_tempdata()
{
@@ -407,8 +383,6 @@ class Session_test extends CI_TestCase {
/**
* Test the sess_regenerate() function
- *
- * @covers CI_Session::sess_regenerate
*/
public function test_sess_regenerate()
{
@@ -428,8 +402,6 @@ class Session_test extends CI_TestCase {
/**
* Test the sess_destroy() function
- *
- * @covers CI_Session::sess_destroy
*/
public function test_sess_destroy()
{
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;
}