summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/core
diff options
context:
space:
mode:
authorPascal Kriete <pascal.kriete@ellislab.com>2011-04-21 03:44:54 +0200
committerPascal Kriete <pascal.kriete@ellislab.com>2011-04-21 03:44:54 +0200
commit69c97a71476e4eaa6c629022fcd4ec7f36d4ec0d (patch)
tree5cba214cb636df83b41a3aa7f29f9b191c3ab70b /tests/codeigniter/core
parentba2430b5778b5b2414b94b818354fa1ff7cfd0db (diff)
Adding early bootstrap ideas for core test suite
Diffstat (limited to 'tests/codeigniter/core')
-rw-r--r--tests/codeigniter/core/Config_test.php107
-rw-r--r--tests/codeigniter/core/Lang_test.php31
-rw-r--r--tests/codeigniter/core/Loader_test.php144
3 files changed, 282 insertions, 0 deletions
diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php
new file mode 100644
index 000000000..628fc630b
--- /dev/null
+++ b/tests/codeigniter/core/Config_test.php
@@ -0,0 +1,107 @@
+<?php
+
+class Config_test extends CodeIgniterTestCase {
+
+ public function setUp()
+ {
+ $cls =& $this->ci_core_class('cfg');
+
+ $stub = $this->getMock($cls, NULL, array(), '', FALSE);
+
+ //I would prefer this, but it currently
+ // does not work as when you try to pass
+ // null to setMethods it fails on an internal
+ // function call that expects an array =(
+ /*
+ $stub = $this->getMockBuilder($cls)
+ ->disableOriginalConstructor()
+ ->setMethods(null)
+ ->getMock();
+ */
+
+
+ // set predictable config values
+ $stub->config = array(
+ 'index_page' => 'index.php',
+ 'base_url' => 'http://example.com/',
+ 'subclass_prefix' => 'MY_'
+ );
+
+ $this->config = $stub;
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testItem()
+ {
+ $this->assertEquals('http://example.com/', $this->config->item('base_url'));
+
+ // 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 testSetItem()
+ {
+ $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 testSlashItem()
+ {
+ // 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'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testSiteUrl()
+ {
+ $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);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testSystemUrl()
+ {
+ $this->assertEquals('http://example.com/system/', $this->config->system_url());
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php
new file mode 100644
index 000000000..82e279a52
--- /dev/null
+++ b/tests/codeigniter/core/Lang_test.php
@@ -0,0 +1,31 @@
+<?php
+
+class Lang_test extends CodeIgniterTestCase {
+
+ protected $lang;
+
+ public function setUp()
+ {
+ $cls = $this->ci_core_class('lang');
+ $this->lang = new $cls;
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testLoad()
+ {
+ // get_config needs work
+ $this->markTestIncomplete('get_config needs work');
+ //$this->assertTrue($this->lang->load('profiler'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testLine()
+ {
+ $this->markTestIncomplete('get_config needs work');
+
+ $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
new file mode 100644
index 000000000..fd9c63216
--- /dev/null
+++ b/tests/codeigniter/core/Loader_test.php
@@ -0,0 +1,144 @@
+<?php
+
+class Loader_test extends CodeIgniterTestCase {
+
+ private $ci_obj;
+
+ public function setUp()
+ {
+ // Instantiate a new loader
+ $cls = $this->ci_core_class('load');
+ $this->_loader = new $cls;
+
+ // mock up a ci instance
+ $this->ci_obj = new StdClass;
+
+ // Fix get_instance()
+ CodeIgniterTestCase::$test_instance =& $this;
+ $this->ci_instance($this->ci_obj);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testLibrary()
+ {
+ // 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));
+
+ // Add the mock to our stdClass
+ $this->ci_set_instance_var('config', $config);
+
+ // Test loading as an array.
+ $this->assertEquals(NULL, $this->_loader->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->_loader->library());
+
+ // Test a string given to params
+ $this->assertEquals(NULL, $this->_loader->library('table', ' '));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testModels()
+ {
+ // Test loading as an array.
+ $this->assertEquals(NULL, $this->_loader->model(array('foobar')));
+
+ // Test no model given
+ $this->assertEquals(FALSE, $this->_loader->model(''));
+
+ // Test a string given to params
+ $this->assertEquals(NULL, $this->_loader->model('foobar', ' '));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testDatabase()
+ {
+ $this->assertEquals(NULL, $this->_loader->database());
+ $this->assertEquals(NULL, $this->_loader->dbutil());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testView()
+ {
+ // I'm not entirely sure this is the proper way to handle this.
+ // So, let's revist it, m'kay?
+ try
+ {
+ $this->_loader->view('foo');
+ }
+ catch (Exception $expected)
+ {
+ return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testFile()
+ {
+ // I'm not entirely sure this is the proper way to handle this.
+ // So, let's revist it, m'kay?
+ try
+ {
+ $this->_loader->file('foo');
+ }
+ catch (Exception $expected)
+ {
+ return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testVars()
+ {
+ $vars = array(
+ 'foo' => 'bar'
+ );
+
+ $this->assertEquals(NULL, $this->_loader->vars($vars));
+ $this->assertEquals(NULL, $this->_loader->vars('foo', 'bar'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testHelper()
+ {
+ $this->assertEquals(NULL, $this->_loader->helper('array'));
+ $this->assertEquals(NULL, $this->_loader->helper('bad'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function testHelpers()
+ {
+ $this->assertEquals(NULL, $this->_loader->helpers(array('file', 'array', 'string')));
+ }
+
+ // --------------------------------------------------------------------
+
+ // public function testLanguage()
+ // {
+ // $this->assertEquals(NULL, $this->_loader->language('test'));
+ // }
+
+ // --------------------------------------------------------------------
+
+ public function testLoadConfig()
+ {
+ $this->assertEquals(NULL, $this->_loader->config('config', FALSE, TRUE));
+ }
+
+
+
+} \ No newline at end of file