summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-04-06 20:21:13 +0200
committerAndrey Andreev <narf@bofh.bg>2012-04-06 20:21:13 +0200
commit8e286e96af6f0487e9339d5d87c35a539a6879c6 (patch)
tree8e089bcb41f1d7cd81d2f1a9afe77ddd998e0ff9 /tests/codeigniter
parent98350a59e21a7f5d38664a59170de91771c99a4b (diff)
parentea09a8a5552f2aacdeab0c88a605fe44047ebd0a (diff)
Merge upstream branch
Diffstat (limited to 'tests/codeigniter')
-rw-r--r--tests/codeigniter/core/Common_test.php5
-rw-r--r--tests/codeigniter/core/Loader_test.php38
-rw-r--r--tests/codeigniter/core/URI_test.php33
-rw-r--r--tests/codeigniter/database/DB_test.php49
-rw-r--r--tests/codeigniter/database/query_builder/.gitkeep0
-rw-r--r--tests/codeigniter/helpers/array_helper_test.php10
-rw-r--r--tests/codeigniter/helpers/date_helper_test.php10
-rw-r--r--tests/codeigniter/helpers/directory_helper_test.php9
-rw-r--r--tests/codeigniter/helpers/email_helper_test.php10
-rw-r--r--tests/codeigniter/helpers/file_helper_test.php7
-rw-r--r--tests/codeigniter/helpers/form_helper_test.php252
-rw-r--r--tests/codeigniter/helpers/html_helper_test.php8
-rw-r--r--tests/codeigniter/helpers/inflector_helper_test.php6
-rw-r--r--tests/codeigniter/helpers/number_helper_test.php7
-rw-r--r--tests/codeigniter/helpers/path_helper_test.php9
-rw-r--r--tests/codeigniter/helpers/string_helper_test.php9
-rw-r--r--tests/codeigniter/helpers/text_helper_test.php6
-rw-r--r--tests/codeigniter/helpers/url_helper_test.php9
-rw-r--r--tests/codeigniter/helpers/xml_helper_test.php8
-rw-r--r--tests/codeigniter/libraries/Parser_test.php7
-rw-r--r--tests/codeigniter/libraries/Table_test.php74
-rw-r--r--tests/codeigniter/libraries/Typography_test.php7
-rw-r--r--tests/codeigniter/libraries/Useragent_test.php (renamed from tests/codeigniter/libraries/User_agent_test.php)10
23 files changed, 386 insertions, 197 deletions
diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php
index cec12982d..dded2e824 100644
--- a/tests/codeigniter/core/Common_test.php
+++ b/tests/codeigniter/core/Common_test.php
@@ -1,9 +1,6 @@
<?php
-require_once(BASEPATH.'helpers/email_helper.php');
-
-class Common_test extends CI_TestCase
-{
+class Common_test extends CI_TestCase {
// ------------------------------------------------------------------------
diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php
index b86fd3477..43008651e 100644
--- a/tests/codeigniter/core/Loader_test.php
+++ b/tests/codeigniter/core/Loader_test.php
@@ -1,38 +1,5 @@
<?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;
@@ -40,7 +7,7 @@ class Loader_test extends CI_TestCase {
public function set_up()
{
// Instantiate a new loader
- $this->load = new Extended_Loader();
+ $this->load = new Mock_Core_Loader();
// mock up a ci instance
$this->ci_obj = new StdClass;
@@ -265,7 +232,4 @@ class Loader_test extends CI_TestCase {
// --------------------------------------------------------------------
-
-
-
}
diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php
index 40252aa14..e340ddf73 100644
--- a/tests/codeigniter/core/URI_test.php
+++ b/tests/codeigniter/core/URI_test.php
@@ -1,41 +1,10 @@
<?php
-require BASEPATH.'core/URI.php';
-
-/**
- * Extend the URI class
- * - override contructor
- * - override CLI detection
- */
-class URI_extended extends CI_URI {
-
- public function __construct()
- {
- $test = CI_TestCase::instance();
- $cls =& $test->ci_core_class('cfg');
-
- // set predictable config values
- $test->ci_set_config(array(
- 'index_page' => 'index.php',
- 'base_url' => 'http://example.com/',
- 'subclass_prefix' => 'MY_'
- ));
-
- $this->config = new $cls;
-
- }
-
- protected function _is_cli_request()
- {
- return FALSE;
- }
-}
-
class URI_test extends CI_TestCase {
public function set_up()
{
- $this->uri = new URI_extended();
+ $this->uri = new Mock_Core_URI();
}
// --------------------------------------------------------------------
diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php
new file mode 100644
index 000000000..9b93e223d
--- /dev/null
+++ b/tests/codeigniter/database/DB_test.php
@@ -0,0 +1,49 @@
+<?php
+
+class DB_test extends CI_TestCase {
+
+ // ------------------------------------------------------------------------
+
+ public function test_db_invalid()
+ {
+ $connection = new Mock_Database_DB(array(
+ 'undefined' => array(
+ 'dsn' => '',
+ 'hostname' => 'undefined',
+ 'username' => 'undefined',
+ 'password' => 'undefined',
+ 'database' => 'undefined',
+ 'dbdriver' => 'undefined',
+ ),
+ ));
+
+ $this->setExpectedException('InvalidArgumentException', 'CI Error: Invalid DB driver');
+
+ Mock_Database_DB::DB($connection->set_dsn('undefined'), TRUE);
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_db_valid()
+ {
+ $config = Mock_Database_DB::config(DB_DRIVER);
+ $connection = new Mock_Database_DB($config);
+ $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER), TRUE);
+
+ $this->assertTrue($db instanceof CI_DB);
+ $this->assertTrue($db instanceof CI_DB_Driver);
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_db_failover()
+ {
+ $config = Mock_Database_DB::config(DB_DRIVER);
+ $connection = new Mock_Database_DB($config);
+ $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER.'_failover'), TRUE);
+
+ $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/.gitkeep b/tests/codeigniter/database/query_builder/.gitkeep
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/.gitkeep
diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php
index 62559de83..9cd15960f 100644
--- a/tests/codeigniter/helpers/array_helper_test.php
+++ b/tests/codeigniter/helpers/array_helper_test.php
@@ -1,13 +1,11 @@
<?php
-// OLD TEST FORMAT: DO NOT COPY
-
-require_once(BASEPATH.'helpers/array_helper.php');
-
-class Array_helper_test extends CI_TestCase
-{
+class Array_helper_test extends CI_TestCase {
+
public function set_up()
{
+ $this->helper('array');
+
$this->my_array = array(
'foo' => 'bar',
'sally' => 'jim',
diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php
index 662d16485..17d1ef21e 100644
--- a/tests/codeigniter/helpers/date_helper_test.php
+++ b/tests/codeigniter/helpers/date_helper_test.php
@@ -1,8 +1,12 @@
<?php
-require_once BASEPATH.'helpers/date_helper.php';
-class Date_helper_test extends CI_TestCase
-{
+class Date_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('date');
+ }
+
// ------------------------------------------------------------------------
public function test_now_local()
diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php
index 3fae81b82..3937d2913 100644
--- a/tests/codeigniter/helpers/directory_helper_test.php
+++ b/tests/codeigniter/helpers/directory_helper_test.php
@@ -1,12 +1,11 @@
<?php
-require_once 'vfsStream/vfsStream.php';
-require BASEPATH.'helpers/directory_helper.php';
-
-class Directory_helper_test extends CI_TestCase
-{
+class Directory_helper_test extends CI_TestCase {
+
public function set_up()
{
+ $this->helper('directory');
+
vfsStreamWrapper::register();
vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir'));
diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php
index 7324e8109..a01f3d5af 100644
--- a/tests/codeigniter/helpers/email_helper_test.php
+++ b/tests/codeigniter/helpers/email_helper_test.php
@@ -1,10 +1,12 @@
<?php
-require_once(BASEPATH.'helpers/email_helper.php');
+class Email_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('email');
+ }
-class Email_helper_test extends CI_TestCase
-{
-
public function test_valid_email()
{
$this->assertEquals(FALSE, valid_email('test'));
diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php
index a596a0375..4b9c29485 100644
--- a/tests/codeigniter/helpers/file_helper_test.php
+++ b/tests/codeigniter/helpers/file_helper_test.php
@@ -1,12 +1,11 @@
<?php
-require_once 'vfsStream/vfsStream.php';
-require BASEPATH.'helpers/file_helper.php';
+class File_helper_Test extends CI_TestCase {
-class File_helper_Test extends CI_TestCase
-{
public function set_up()
{
+ $this->helper('file');
+
vfsStreamWrapper::register();
vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir'));
diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php
new file mode 100644
index 000000000..80bace9d1
--- /dev/null
+++ b/tests/codeigniter/helpers/form_helper_test.php
@@ -0,0 +1,252 @@
+<?php
+
+require BASEPATH . 'core/Common.php';
+require BASEPATH . 'helpers/form_helper.php';
+
+class Form_helper_test extends CI_TestCase
+{
+ public function test_form_hidden()
+ {
+ $expected = <<<EOH
+
+<input type="hidden" name="username" value="johndoe" />
+
+EOH;
+
+ $this->assertEquals($expected, form_hidden('username', 'johndoe'));
+ }
+
+ public function test_form_input()
+ {
+ $expected = <<<EOH
+<input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%" />
+
+EOH;
+
+ $data = array(
+ 'name' => 'username',
+ 'id' => 'username',
+ 'value' => 'johndoe',
+ 'maxlength' => '100',
+ 'size' => '50',
+ 'style' => 'width:50%',
+ );
+
+ $this->assertEquals($expected, form_input($data));
+ }
+
+ public function test_form_password()
+ {
+ $expected = <<<EOH
+<input type="password" name="password" value="" />
+
+EOH;
+
+ $this->assertEquals($expected, form_password('password'));
+ }
+
+ public function test_form_upload()
+ {
+ $expected = <<<EOH
+<input type="file" name="attachment" value="" />
+
+EOH;
+
+ $this->assertEquals($expected, form_upload('attachment'));
+ }
+
+ public function test_form_textarea()
+ {
+ $expected = <<<EOH
+<textarea name="notes" cols="40" rows="10" >Notes</textarea>
+
+EOH;
+
+ $this->assertEquals($expected, form_textarea('notes', 'Notes'));
+ }
+
+ public function test_form_dropdown()
+ {
+ $expected = <<<EOH
+<select name="shirts">
+<option value="small">Small Shirt</option>
+<option value="med">Medium Shirt</option>
+<option value="large" selected="selected">Large Shirt</option>
+<option value="xlarge">Extra Large Shirt</option>
+</select>
+
+EOH;
+
+ $options = array(
+ 'small' => 'Small Shirt',
+ 'med' => 'Medium Shirt',
+ 'large' => 'Large Shirt',
+ 'xlarge' => 'Extra Large Shirt',
+ );
+
+ $this->assertEquals($expected, form_dropdown('shirts', $options, 'large'));
+
+ $expected = <<<EOH
+<select name="shirts" multiple="multiple">
+<option value="small" selected="selected">Small Shirt</option>
+<option value="med">Medium Shirt</option>
+<option value="large" selected="selected">Large Shirt</option>
+<option value="xlarge">Extra Large Shirt</option>
+</select>
+
+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'
+ ),
+ 'German Cars' => array(
+ 'mercedes' => 'Mercedes',
+ 'audi' => 'Audi'
+ )
+ );
+
+ $expected = <<<EOH
+<select name="cars" multiple="multiple">
+<optgroup label="Swedish Cars">
+<option value="volvo" selected="selected">Volvo</option>
+<option value="saab">Saab</option>
+</optgroup>
+<optgroup label="German Cars">
+<option value="mercedes">Mercedes</option>
+<option value="audi" selected="selected">Audi</option>
+</optgroup>
+</select>
+
+EOH;
+
+ $cars_on_sale = array('volvo', 'audi');
+
+ $this->assertEquals($expected, form_dropdown('cars', $options, $cars_on_sale));
+
+ }
+
+ public function test_form_multiselect()
+ {
+ $expected = <<<EOH
+<select name="shirts[]" multiple="multiple">
+<option value="small">Small Shirt</option>
+<option value="med" selected="selected">Medium Shirt</option>
+<option value="large" selected="selected">Large Shirt</option>
+<option value="xlarge">Extra Large Shirt</option>
+</select>
+
+EOH;
+
+ $options = array(
+ '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 = <<<EOH
+<fieldset>
+<legend>Address Information</legend>
+
+EOH;
+
+ $this->assertEquals($expected, form_fieldset('Address Information'));
+ }
+
+ public function test_form_fieldset_close()
+ {
+ $expected = <<<EOH
+</fieldset></div></div>
+EOH;
+
+ $this->assertEquals($expected, form_fieldset_close('</div></div>'));
+ }
+
+ public function test_form_checkbox()
+ {
+ $expected = <<<EOH
+<input type="checkbox" name="newsletter" value="accept" checked="checked" />
+
+EOH;
+
+ $this->assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE));
+ }
+
+ public function test_form_radio()
+ {
+ $expected = <<<EOH
+<input type="radio" name="newsletter" value="accept" checked="checked" />
+
+EOH;
+
+ $this->assertEquals($expected, form_radio('newsletter', 'accept', TRUE));
+ }
+
+ public function test_form_submit()
+ {
+ $expected = <<<EOH
+<input type="submit" name="mysubmit" value="Submit Post!" />
+
+EOH;
+
+ $this->assertEquals($expected, form_submit('mysubmit', 'Submit Post!'));
+ }
+
+ public function test_form_label()
+ {
+ $expected = <<<EOH
+<label for="username">What is your Name</label>
+EOH;
+
+ $this->assertEquals($expected, form_label('What is your Name', 'username'));
+ }
+
+ public function test_form_reset()
+ {
+ $expected = <<<EOH
+<input type="reset" name="myreset" value="Reset" />
+
+EOH;
+
+ $this->assertEquals($expected, form_reset('myreset', 'Reset'));
+ }
+
+ public function test_form_button()
+ {
+ $expected = <<<EOH
+<button name="name" type="button" >content</button>
+
+EOH;
+
+ $this->assertEquals($expected, form_button('name','content'));
+ }
+
+ public function test_form_close()
+ {
+ $expected = <<<EOH
+</form></div></div>
+EOH;
+
+ $this->assertEquals($expected, form_close('</div></div>'));
+ }
+
+ public function test_form_prep()
+ {
+ $expected = "Here is a string containing &quot;quoted&quot; 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 553fc2bb1..28974b0f8 100644
--- a/tests/codeigniter/helpers/html_helper_test.php
+++ b/tests/codeigniter/helpers/html_helper_test.php
@@ -1,9 +1,11 @@
<?php
-require_once(BASEPATH.'helpers/html_helper.php');
+class Html_helper_test extends CI_TestCase {
-class Html_helper_test extends CI_TestCase
-{
+ public function set_up()
+ {
+ $this->helper('html');
+ }
// ------------------------------------------------------------------------
diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php
index 472e28adb..9e9478711 100644
--- a/tests/codeigniter/helpers/inflector_helper_test.php
+++ b/tests/codeigniter/helpers/inflector_helper_test.php
@@ -1,9 +1,11 @@
<?php
-require_once(BASEPATH.'helpers/inflector_helper.php');
-
class Inflector_helper_test extends CI_TestCase {
+ public function set_up()
+ {
+ $this->helper('inflector');
+ }
public function test_singular()
{
diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php
index 3322b2475..4bb9a918a 100644
--- a/tests/codeigniter/helpers/number_helper_test.php
+++ b/tests/codeigniter/helpers/number_helper_test.php
@@ -1,12 +1,11 @@
<?php
-require_once BASEPATH.'helpers/number_helper.php';
-
-class Number_helper_test extends CI_TestCase
-{
+class Number_helper_test extends CI_TestCase {
public function set_up()
{
+ $this->helper('number');
+
// Grab the core lang class
$lang_cls = $this->ci_core_class('lang');
diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php
index 2e6cc6391..632f57501 100644
--- a/tests/codeigniter/helpers/path_helper_test.php
+++ b/tests/codeigniter/helpers/path_helper_test.php
@@ -1,9 +1,12 @@
<?php
-require BASEPATH . 'helpers/path_helper.php';
+class Path_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('path');
+ }
-class Path_helper_test extends CI_TestCase
-{
public function test_set_realpath()
{
$expected = getcwd() . DIRECTORY_SEPARATOR;
diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php
index a884d6284..29c3d6594 100644
--- a/tests/codeigniter/helpers/string_helper_test.php
+++ b/tests/codeigniter/helpers/string_helper_test.php
@@ -1,9 +1,12 @@
<?php
-require_once(BASEPATH.'helpers/string_helper.php');
+class String_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('string');
+ }
-class String_helper_test extends CI_TestCase
-{
public function test_strip_slashes()
{
$expected = array(
diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php
index a0866e638..584066b0c 100644
--- a/tests/codeigniter/helpers/text_helper_test.php
+++ b/tests/codeigniter/helpers/text_helper_test.php
@@ -1,13 +1,13 @@
<?php
-require_once(BASEPATH.'helpers/text_helper.php');
+class Text_helper_test extends CI_TestCase {
-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.';
}
diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php
index 51a8cc7c0..c561809ce 100644
--- a/tests/codeigniter/helpers/url_helper_test.php
+++ b/tests/codeigniter/helpers/url_helper_test.php
@@ -1,9 +1,12 @@
<?php
-require_once(BASEPATH.'helpers/url_helper.php');
+class Url_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('url');
+ }
-class Url_helper_test extends CI_TestCase
-{
public function test_url_title()
{
$words = array(
diff --git a/tests/codeigniter/helpers/xml_helper_test.php b/tests/codeigniter/helpers/xml_helper_test.php
index 49f49e166..a83fef91e 100644
--- a/tests/codeigniter/helpers/xml_helper_test.php
+++ b/tests/codeigniter/helpers/xml_helper_test.php
@@ -1,9 +1,11 @@
<?php
-require_once(BASEPATH.'helpers/xml_helper.php');
+class Xml_helper_test extends CI_TestCase {
-class Xml_helper_test extends CI_TestCase
-{
+ public function set_up()
+ {
+ $this->helper('xml');
+ }
public function test_xml_convert()
{
diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php
index b4580a4b1..c3d88fa85 100644
--- a/tests/codeigniter/libraries/Parser_test.php
+++ b/tests/codeigniter/libraries/Parser_test.php
@@ -1,14 +1,11 @@
<?php
-require BASEPATH.'libraries/Parser.php';
-
-class Parser_test extends CI_TestCase
-{
+class Parser_test extends CI_TestCase {
public function set_up()
{
$obj = new StdClass;
- $obj->parser = new CI_Parser();
+ $obj->parser = new Mock_Libraries_Parser();
$this->ci_instance($obj);
diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php
index 0208a465a..13f338c6b 100644
--- a/tests/codeigniter/libraries/Table_test.php
+++ b/tests/codeigniter/libraries/Table_test.php
@@ -1,14 +1,11 @@
<?php
-require BASEPATH.'libraries/Table.php';
-
-class Table_test extends CI_TestCase
-{
+class Table_test extends CI_TestCase {
public function set_up()
{
$obj = new StdClass;
- $obj->table = new CI_table();
+ $obj->table = new Mock_Libraries_Table();
$this->ci_instance($obj);
@@ -103,53 +100,23 @@ class Table_test extends CI_TestCase
array('data' => 'size')
);
- // test what would be discreet args,
- // basically means a single array as the calling method
- // will use func_get_args()
-
- $reflectionOfTable = new ReflectionClass($this->table);
- $method = $reflectionOfTable->getMethod('_prep_args');
-
- $method->setAccessible(true);
-
$this->assertEquals(
$expected,
- $method->invokeArgs(
- $this->table, array(array('name', 'color', 'size'), 'discreet')
- )
+ $this->table->prep_args(array('name', 'color', 'size'))
);
-
- // test what would be a single array argument. Again, nested
- // due to func_get_args on calling methods
- $this->assertEquals(
- $expected,
- $method->invokeArgs(
- $this->table, array(array('name', 'color', 'size'), 'array')
- )
- );
-
-
+
// with cell attributes
-
// need to add that new argument row to our expected outcome
$expected[] = array('data' => 'weight', 'class' => 'awesome');
$this->assertEquals(
$expected,
- $method->invokeArgs(
- $this->table, array(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome')), 'attributes')
- )
+ $this->table->prep_args(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome')))
);
}
public function test_default_template_keys()
{
- $reflectionOfTable = new ReflectionClass($this->table);
- $method = $reflectionOfTable->getMethod('_default_template');
-
- $method->setAccessible(true);
-
- $deft_template = $method->invoke($this->table);
$keys = array(
'table_open',
'thead_open', 'thead_close',
@@ -162,29 +129,24 @@ class Table_test extends CI_TestCase
foreach ($keys as $key)
{
- $this->assertArrayHasKey($key, $deft_template);
+ $this->assertArrayHasKey($key, $this->table->default_template());
}
}
public function test_compile_template()
{
- $reflectionOfTable = new ReflectionClass($this->table);
- $method = $reflectionOfTable->getMethod('_compile_template');
-
- $method->setAccessible(true);
-
$this->assertFalse($this->table->set_template('invalid_junk'));
// non default key
$this->table->set_template(array('nonsense' => 'foo'));
- $method->invoke($this->table);
+ $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' => '</table junk>'));
- $method->invoke($this->table);
+ $this->table->compile_template();
$this->assertArrayHasKey('table_close', $this->table->template);
$this->assertEquals('</table junk>', $this->table->template['table_close']);
@@ -250,13 +212,8 @@ class Table_test extends CI_TestCase
public function test_set_from_array()
{
- $reflectionOfTable = new ReflectionClass($this->table);
- $method = $reflectionOfTable->getMethod('_set_from_array');
-
- $method->setAccessible(true);
-
- $this->assertFalse($method->invokeArgs($this->table, array('bogus')));
- $this->assertFalse($method->invoke($this->table, array()));
+ $this->assertFalse($this->table->set_from_array('bogus'));
+ $this->assertFalse($this->table->set_from_array(NULL));
$data = array(
array('name', 'color', 'number'),
@@ -264,7 +221,7 @@ class Table_test extends CI_TestCase
array('Katie', 'Blue')
);
- $method->invokeArgs($this->table, array($data, FALSE));
+ $this->table->set_from_array($data, FALSE);
$this->assertEmpty($this->table->heading);
$this->table->clear();
@@ -280,7 +237,7 @@ class Table_test extends CI_TestCase
array('data' => 'Blue'),
);
- $method->invokeArgs($this->table, array($data));
+ $this->table->set_from_array($data);
$this->assertEquals(count($this->table->rows), 2);
$this->assertEquals(
@@ -296,11 +253,6 @@ class Table_test extends CI_TestCase
function test_set_from_object()
{
- $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(){
@@ -326,7 +278,7 @@ class Table_test extends CI_TestCase
'email' => array('data' => 'foo@bar.com'),
);
- $method->invokeArgs($this->table, array($query));
+ $this->table->set_from_object($query);
$this->assertEquals(
$expected_heading,
diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php
index a0533bae0..250aefb24 100644
--- a/tests/codeigniter/libraries/Typography_test.php
+++ b/tests/codeigniter/libraries/Typography_test.php
@@ -1,14 +1,11 @@
<?php
-require BASEPATH.'libraries/Typography.php';
-
-class Typography_test extends CI_TestCase
-{
+class Typography_test extends CI_TestCase {
public function set_up()
{
$obj = new StdClass;
- $obj->type = new CI_Typography();
+ $obj->type = new Mock_Libraries_Typography();
$this->ci_instance($obj);
diff --git a/tests/codeigniter/libraries/User_agent_test.php b/tests/codeigniter/libraries/Useragent_test.php
index 6f9e87196..7dad7ac54 100644
--- a/tests/codeigniter/libraries/User_agent_test.php
+++ b/tests/codeigniter/libraries/Useragent_test.php
@@ -1,11 +1,7 @@
<?php
-require BASEPATH.'libraries/User_agent.php';
-
-// This class needs some work...
-
-class UserAgent_test extends CI_TestCase
-{
+class UserAgent_test extends CI_TestCase {
+
protected $_user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27';
protected $_mobile_ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7';
@@ -15,7 +11,7 @@ class UserAgent_test extends CI_TestCase
$_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
$obj = new StdClass;
- $obj->agent = new CI_User_agent();
+ $obj->agent = new Mock_Libraries_UserAgent();
$this->ci_instance($obj);