diff options
author | Greg Aker <greg.aker@ellislab.com> | 2011-04-25 17:51:16 +0200 |
---|---|---|
committer | Greg Aker <greg.aker@ellislab.com> | 2011-04-25 17:51:16 +0200 |
commit | 89c11b1de2b3a19da93e506f095aecf8221c1401 (patch) | |
tree | d12fd0370babd1f5250dd003f81a2857644b9629 /tests/codeigniter/core | |
parent | e70e92bab1de57a0749a31f2889b55cafb46d58e (diff) | |
parent | b9adc1115860f6c69046a08d4d00f7e9986ce33a (diff) |
Merging in default
Diffstat (limited to 'tests/codeigniter/core')
-rw-r--r-- | tests/codeigniter/core/Common_test.php | 16 | ||||
-rw-r--r-- | tests/codeigniter/core/Config_test.php | 93 | ||||
-rw-r--r-- | tests/codeigniter/core/Lang_test.php | 31 | ||||
-rw-r--r-- | tests/codeigniter/core/Loader_test.php | 271 |
4 files changed, 411 insertions, 0 deletions
diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php new file mode 100644 index 000000000..cec12982d --- /dev/null +++ b/tests/codeigniter/core/Common_test.php @@ -0,0 +1,16 @@ +<?php + +require_once(BASEPATH.'helpers/email_helper.php'); + +class Common_test extends CI_TestCase +{ + + // ------------------------------------------------------------------------ + + public function test_is_php() + { + $this->assertEquals(TRUE, is_php('1.2.0')); + $this->assertEquals(FALSE, is_php('9999.9.9')); + } + +}
\ No newline at end of file diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php new file mode 100644 index 000000000..b6c57da70 --- /dev/null +++ b/tests/codeigniter/core/Config_test.php @@ -0,0 +1,93 @@ +<?php + +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', + 'base_url' => 'http://example.com/', + 'subclass_prefix' => 'MY_' + )); + + $this->config = new $cls; + } + + // -------------------------------------------------------------------- + + public function test_item() + { + $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 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')); + } + + // -------------------------------------------------------------------- + + 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); + } + + // -------------------------------------------------------------------- + + public function test_system_url() + { + $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..dcc3d0879 --- /dev/null +++ b/tests/codeigniter/core/Lang_test.php @@ -0,0 +1,31 @@ +<?php + +class Lang_test extends CI_TestCase { + + protected $lang; + + public function set_up() + { + $cls = $this->ci_core_class('lang'); + $this->lang = new $cls; + } + + // -------------------------------------------------------------------- + + public function test_load() + { + // get_config needs work + $this->markTestIncomplete('get_config needs work'); + //$this->assertTrue($this->lang->load('profiler')); + } + + // -------------------------------------------------------------------- + + public function test_line() + { + $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..9ba870b7d --- /dev/null +++ b/tests/codeigniter/core/Loader_test.php @@ -0,0 +1,271 @@ +<?php + +require_once 'vfsStream/vfsStream.php'; +require_once BASEPATH.'/core/Loader.php'; + +class Extended_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... + * + * @covers CI_Loader::__construct() + */ + public function __construct() + { + vfsStreamWrapper::register(); + vfsStreamWrapper::setRoot(new vfsStreamDirectory('application')); + + $this->models_dir = vfsStream::newDirectory('models')->at(vfsStreamWrapper::getRoot()); + $this->libs_dir = vfsStream::newDirectory('libraries')->at(vfsStreamWrapper::getRoot()); + $this->helpers_dir = vfsStream::newDirectory('helpers')->at(vfsStreamWrapper::getRoot()); + $this->views_dir = vfsStream::newDirectory('views')->at(vfsStreamWrapper::getRoot()); + + $this->_ci_ob_level = ob_get_level(); + $this->_ci_library_paths = array(vfsStream::url('application').'/', BASEPATH); + $this->_ci_helper_paths = array(vfsStream::url('application').'/', BASEPATH); + $this->_ci_model_paths = array(vfsStream::url('application').'/'); + $this->_ci_view_paths = array(vfsStream::url('application').'/views/' => TRUE); + } +} + + +class Loader_test extends CI_TestCase { + + private $ci_obj; + + public function set_up() + { + // Instantiate a new loader + $this->load = new Extended_Loader(); + + // mock up a ci instance + $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', ' ')); + } + + // -------------------------------------------------------------------- + + public function test_load_library_in_application_dir() + { + $this->_setup_config_mock(); + + $content = '<?php class Super_test_library {} '; + + $model = vfsStream::newFile('Super_test_library.php')->withContent($content) + ->at($this->load->libs_dir); + + $this->assertNull($this->load->library('super_test_library')); + + // Was the model class instantiated. + $this->assertTrue(class_exists('Super_test_library')); + } + + // -------------------------------------------------------------------- + + private function _setup_config_mock() + { + // 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_instance_var('config', $config); + } + + // -------------------------------------------------------------------- + + public function test_non_existent_model() + { + $this->setExpectedException( + 'Exception', + 'CI Error: Unable to locate the model you have specified: ci_test_nonexistent_model.php' + ); + + $this->load->model('ci_test_nonexistent_model.php'); + } + + // -------------------------------------------------------------------- + + /** + * @coverts CI_Loader::model + */ + public function test_models() + { + $this->ci_set_core_class('model', 'CI_Model'); + + $content = '<?php class Unit_test_model extends CI_Model {} '; + + $model = vfsStream::newFile('unit_test_model.php')->withContent($content) + ->at($this->load->models_dir); + + $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('')); + } + + // -------------------------------------------------------------------- + + // public function testDatabase() + // { + // $this->assertEquals(NULL, $this->load->database()); + // $this->assertEquals(NULL, $this->load->dbutil()); + // } + + // -------------------------------------------------------------------- + + /** + * @coverts CI_Loader::view + */ + public function test_load_view() + { + $this->ci_set_core_class('output', 'CI_Output'); + + $content = 'This is my test page. <?php echo $hello; ?>'; + $view = vfsStream::newFile('unit_test_view.php')->withContent($content) + ->at($this->load->views_dir); + + // 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 + */ + public function test_non_existent_view() + { + $this->setExpectedException( + 'Exception', + 'CI Error: Unable to load the requested file: ci_test_nonexistent_view.php' + ); + + $this->load->view('ci_test_nonexistent_view', array('foo' => 'bar')); + } + + // -------------------------------------------------------------------- + + 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); + + // 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); + + $this->setExpectedException( + 'Exception', + '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('foo', 'bar')); + } + + // -------------------------------------------------------------------- + + public function test_helper() + { + $this->assertEquals(NULL, $this->load->helper('array')); + + $this->setExpectedException( + 'Exception', + '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( + 'Exception', + 'CI Error: The configuration file foobar.php does not exist.' + ); + + $this->load->config('foobar', FALSE); + } + + // -------------------------------------------------------------------- + + + + +}
\ No newline at end of file |