summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter
diff options
context:
space:
mode:
Diffstat (limited to 'tests/codeigniter')
-rw-r--r--tests/codeigniter/core/Lang_test.php10
-rw-r--r--tests/codeigniter/helpers/date_helper_test.php56
-rw-r--r--tests/codeigniter/helpers/inflector_helper_test.php6
-rw-r--r--tests/codeigniter/libraries/Table_test.php51
4 files changed, 98 insertions, 25 deletions
diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php
index dcc3d0879..a414f0ace 100644
--- a/tests/codeigniter/core/Lang_test.php
+++ b/tests/codeigniter/core/Lang_test.php
@@ -6,6 +6,9 @@ class Lang_test extends CI_TestCase {
public function set_up()
{
+ $loader_cls = $this->ci_core_class('load');
+ $this->ci_instance_var('load', new $loader_cls);
+
$cls = $this->ci_core_class('lang');
$this->lang = new $cls;
}
@@ -14,17 +17,14 @@ class Lang_test extends CI_TestCase {
public function test_load()
{
- // get_config needs work
- $this->markTestIncomplete('get_config needs work');
- //$this->assertTrue($this->lang->load('profiler'));
+ $this->assertTrue($this->lang->load('profiler', 'english'));
}
// --------------------------------------------------------------------
public function test_line()
{
- $this->markTestIncomplete('get_config needs work');
-
+ $this->assertTrue($this->lang->load('profiler', 'english'));
$this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string'));
}
diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php
index c7a2c9b6e..662d16485 100644
--- a/tests/codeigniter/helpers/date_helper_test.php
+++ b/tests/codeigniter/helpers/date_helper_test.php
@@ -5,9 +5,39 @@ class Date_helper_test extends CI_TestCase
{
// ------------------------------------------------------------------------
- public function test_now()
+ public function test_now_local()
{
- $this->markTestIncomplete('not implemented yet');
+ // This stub job, is simply to cater $config['time_reference']
+ $config = $this->getMock('CI_Config');
+ $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);
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_now_gmt()
+ {
+ // This stub job, is simply to cater $config['time_reference']
+ $config = $this->getMock('CI_Config');
+ $config->expects($this->any())
+ ->method('item')
+ ->will($this->returnValue('gmt'));
+
+ // Add the stub to our stdClass
+ $this->ci_instance_var('config', $config);
+
+ $t = time();
+ $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t));
+ $test = now();
+ $this->assertEquals($expected, $test);
}
// ------------------------------------------------------------------------
@@ -124,7 +154,16 @@ class Date_helper_test extends CI_TestCase
public function test_timespan()
{
- $this->markTestIncomplete('not implemented yet');
+ $loader_cls = $this->ci_core_class('load');
+ $this->ci_instance_var('load', new $loader_cls);
+
+ $lang_cls = $this->ci_core_class('lang');
+ $this->ci_instance_var('lang', new $lang_cls);
+
+ $this->assertEquals('1 Second', timespan(time(), time()+1));
+ $this->assertEquals('1 Minute', timespan(time(), time()+60));
+ $this->assertEquals('1 Hour', timespan(time(), time()+3600));
+ $this->assertEquals('2 Hours', timespan(time(), time()+7200));
}
// ------------------------------------------------------------------------
@@ -140,7 +179,9 @@ class Date_helper_test extends CI_TestCase
public function test_local_to_gmt()
{
- $this->markTestIncomplete('not implemented yet');
+ $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));
}
// ------------------------------------------------------------------------
@@ -177,9 +218,10 @@ class Date_helper_test extends CI_TestCase
public function test_human_to_unix()
{
- $time = time();
- $this->markTestIncomplete('Failed Test');
- // $this->assertEquals($time, human_to_unix(unix_to_human($time)));
+ $date = '2000-12-31 10:00:00 PM';
+ $expected = strtotime($date);
+ $this->assertEquals($expected, human_to_unix($date));
+ $this->assertFalse(human_to_unix());
}
// ------------------------------------------------------------------------
diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php
index ef1f54afc..e476f6dc8 100644
--- a/tests/codeigniter/helpers/inflector_helper_test.php
+++ b/tests/codeigniter/helpers/inflector_helper_test.php
@@ -24,14 +24,10 @@ class Inflector_helper_test extends CI_TestCase {
public function test_plural()
{
- $this->markTestSkipped(
- 'abjectness is breaking. SKipping for the time being.'
- );
-
$strs = array(
'telly' => 'tellies',
'smelly' => 'smellies',
- 'abjectness' => 'abjectness',
+ 'abjectness' => 'abjectnesses', // ref : http://en.wiktionary.org/wiki/abjectnesses
'smell' => 'smells',
'witch' => 'witches'
);
diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php
index 045216b16..0208a465a 100644
--- a/tests/codeigniter/libraries/Table_test.php
+++ b/tests/codeigniter/libraries/Table_test.php
@@ -194,11 +194,8 @@ class Table_test extends CI_TestCase
{
// 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' // not an integer!
- // );
+ $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
@@ -222,8 +219,6 @@ class Table_test extends CI_TestCase
),
$this->table->make_columns($five_values, 3)
);
-
- $this->markTestSkipped('Look at commented assertFalse above');
}
public function test_clear()
@@ -301,7 +296,47 @@ class Table_test extends CI_TestCase
function test_set_from_object()
{
- $this->markTestSkipped('Not yet implemented.');
+ $reflectionOfTable = new ReflectionClass($this->table);
+ $method = $reflectionOfTable->getMethod('_set_from_object');
+
+ $method->setAccessible(true);
+
+ // Make a stub of query instance
+ $query = new CI_TestCase();
+ $query->list_fields = function(){
+ return array('name', 'email');
+ };
+ $query->result_array = function(){
+ return array(
+ array('name' => 'John Doe', 'email' => 'john@doe.com'),
+ array('name' => 'Foo Bar', 'email' => 'foo@bar.com'),
+ );
+ };
+ $query->num_rows = function(){
+ return 2;
+ };
+
+ $expected_heading = array(
+ array('data' => 'name'),
+ array('data' => 'email')
+ );
+
+ $expected_second = array(
+ 'name' => array('data' => 'Foo Bar'),
+ 'email' => array('data' => 'foo@bar.com'),
+ );
+
+ $method->invokeArgs($this->table, array($query));
+
+ $this->assertEquals(
+ $expected_heading,
+ $this->table->heading
+ );
+
+ $this->assertEquals(
+ $expected_second,
+ $this->table->rows[1]
+ );
}
// Test main generate method