summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/libraries
diff options
context:
space:
mode:
Diffstat (limited to 'tests/codeigniter/libraries')
-rw-r--r--tests/codeigniter/libraries/Encrypt_test.php71
-rw-r--r--tests/codeigniter/libraries/Parser_test.php7
-rw-r--r--tests/codeigniter/libraries/Table_test.php98
-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
5 files changed, 113 insertions, 80 deletions
diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php
new file mode 100644
index 000000000..066990186
--- /dev/null
+++ b/tests/codeigniter/libraries/Encrypt_test.php
@@ -0,0 +1,71 @@
+<?php
+
+class Encrypt_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $obj = new StdClass;
+ $obj->encrypt = new Mock_Libraries_Encrypt();
+
+ $this->ci_instance($obj);
+ $this->encrypt = $obj->encrypt;
+
+ $this->ci_set_config('encryption_key', "Encryptin'glike@boss!");
+ $this->msg = 'My secret message';
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_encode()
+ {
+ $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_decode()
+ {
+ $encoded_msg = $this->encrypt->encode($this->msg);
+ $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_optional_key()
+ {
+ $key = 'Ohai!ù0129°03182%HD1892P0';
+ $encoded_msg = $this->encrypt->encode($this->msg, $key);
+ $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_default_cipher()
+ {
+ $this->assertEquals('rijndael-256', $this->encrypt->get_cipher());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_set_cipher()
+ {
+ $this->encrypt->set_cipher(MCRYPT_BLOWFISH);
+ $this->assertEquals('blowfish', $this->encrypt->get_cipher());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_default_mode()
+ {
+ $this->assertEquals('cbc', $this->encrypt->get_mode());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_set_mode()
+ {
+ $this->encrypt->set_mode(MCRYPT_MODE_CFB);
+ $this->assertEquals('cfb', $this->encrypt->get_mode());
+ }
+
+} \ No newline at end of file
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..f5133de1e 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')
- )
- );
-
- // 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')
- )
+ $this->table->prep_args(array('name', 'color', 'size'))
);
-
-
+
// 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,
@@ -339,6 +291,26 @@ class Table_test extends CI_TestCase
);
}
- // Test main generate method
- // --------------------------------------------------------------------
+ function test_generate()
+ {
+ // Prepare the data
+ $data = array(
+ array('Name', 'Color', 'Size'),
+ array('Fred', 'Blue', 'Small'),
+ array('Mary', 'Red', 'Large'),
+ array('John', 'Green', 'Medium')
+ );
+
+ $table = $this->table->generate($data);
+
+ // Test the table header
+ $this->assertTrue(strpos($table, '<th>Name</th>') !== FALSE);
+ $this->assertTrue(strpos($table, '<th>Color</th>') !== FALSE);
+ $this->assertTrue(strpos($table, '<th>Size</th>') !== FALSE);
+
+ // Test the first entry
+ $this->assertTrue(strpos($table, '<td>Fred</td>') !== FALSE);
+ $this->assertTrue(strpos($table, '<td>Blue</td>') !== FALSE);
+ $this->assertTrue(strpos($table, '<td>Small</td>') !== FALSE);
+ }
} \ No newline at end of file
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);