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.php131
-rw-r--r--tests/codeigniter/libraries/Parser_test.php61
-rw-r--r--tests/codeigniter/libraries/Table_test.php153
-rw-r--r--tests/codeigniter/libraries/Typography_test.php40
-rw-r--r--tests/codeigniter/libraries/Useragent_test.php6
5 files changed, 183 insertions, 208 deletions
diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php
index 066990186..153a25e1d 100644
--- a/tests/codeigniter/libraries/Encrypt_test.php
+++ b/tests/codeigniter/libraries/Encrypt_test.php
@@ -2,70 +2,71 @@
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());
- }
+ 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 c3d88fa85..b68f44a33 100644
--- a/tests/codeigniter/libraries/Parser_test.php
+++ b/tests/codeigniter/libraries/Parser_test.php
@@ -1,73 +1,74 @@
<?php
class Parser_test extends CI_TestCase {
-
+
public function set_up()
{
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->parser = new Mock_Libraries_Parser();
-
+
$this->ci_instance($obj);
-
+
$this->parser = $obj->parser;
}
+
// --------------------------------------------------------------------
-
+
public function test_set_delimiters()
{
// Make sure default delimiters are there
$this->assertEquals('{', $this->parser->l_delim);
$this->assertEquals('}', $this->parser->r_delim);
-
+
// Change them to square brackets
$this->parser->set_delimiters('[', ']');
-
+
// Make sure they changed
$this->assertEquals('[', $this->parser->l_delim);
$this->assertEquals(']', $this->parser->r_delim);
-
+
// Reset them
$this->parser->set_delimiters();
-
+
// Make sure default delimiters are there
$this->assertEquals('{', $this->parser->l_delim);
$this->assertEquals('}', $this->parser->r_delim);
}
-
+
// --------------------------------------------------------------------
-
+
public function test_parse_simple_string()
{
$data = array(
'title' => 'Page Title',
'body' => 'Lorem ipsum dolor sit amet.'
);
-
+
$template = "{title}\n{body}";
-
+
$result = implode("\n", $data);
-
+
$this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
}
-
+
// --------------------------------------------------------------------
-
+
public function test_parse()
{
$this->_parse_no_template();
$this->_parse_var_pair();
$this->_mismatched_var_pair();
}
-
+
// --------------------------------------------------------------------
-
+
private function _parse_no_template()
{
$this->assertFalse($this->parser->parse_string('', '', TRUE));
}
-
+
// --------------------------------------------------------------------
-
+
private function _parse_var_pair()
{
$data = array(
@@ -78,16 +79,14 @@ class Parser_test extends CI_TestCase {
'flying' => 'no'),
)
);
-
+
$template = "{title}\n{powers}{invisibility}\n{flying}{/powers}";
-
- $result = "Super Heroes\nyes\nno";
-
- $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
+
+ $this->assertEquals("Super Heroes\nyes\nno", $this->parser->parse_string($template, $data, TRUE));
}
-
+
// --------------------------------------------------------------------
-
+
private function _mismatched_var_pair()
{
$data = array(
@@ -98,13 +97,11 @@ class Parser_test extends CI_TestCase {
'flying' => 'no'),
)
);
-
+
$template = "{title}\n{powers}{invisibility}\n{flying}";
-
$result = "Super Heroes\n{powers}{invisibility}\n{flying}";
-
- $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
+
+ $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
}
- // --------------------------------------------------------------------
} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php
index f5133de1e..edfc83dd0 100644
--- a/tests/codeigniter/libraries/Table_test.php
+++ b/tests/codeigniter/libraries/Table_test.php
@@ -4,43 +4,39 @@ class Table_test extends CI_TestCase {
public function set_up()
{
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->table = new Mock_Libraries_Table();
-
+
$this->ci_instance($obj);
-
+
$this->table = $obj->table;
}
-
// Setter Methods
// --------------------------------------------------------------------
-
+
public function test_set_template()
{
$this->assertFalse($this->table->set_template('not an array'));
-
- $template = array(
- 'a' => 'b'
- );
-
+
+ $template = array('a' => 'b');
+
$this->table->set_template($template);
$this->assertEquals($template, $this->table->template);
}
-
+
public function test_set_empty()
{
$this->table->set_empty('nada');
$this->assertEquals('nada', $this->table->empty_cells);
}
-
+
public function test_set_caption()
{
$this->table->set_caption('awesome cap');
$this->assertEquals('awesome cap', $this->table->caption);
}
-
-
+
/*
* @depends testPrepArgs
*/
@@ -49,9 +45,9 @@ class Table_test extends CI_TestCase {
// uses _prep_args internally, so we'll just do a quick
// check to verify that func_get_args and prep_args are
// being called.
-
+
$this->table->set_heading('name', 'color', 'size');
-
+
$this->assertEquals(
array(
array('data' => 'name'),
@@ -61,8 +57,7 @@ class Table_test extends CI_TestCase {
$this->table->heading
);
}
-
-
+
/*
* @depends testPrepArgs
*/
@@ -71,13 +66,13 @@ class Table_test extends CI_TestCase {
// uses _prep_args internally, so we'll just do a quick
// check to verify that func_get_args and prep_args are
// being called.
-
+
$this->table->add_row('my', 'pony', 'sings');
$this->table->add_row('your', 'pony', 'stinks');
$this->table->add_row('my pony', '>', 'your pony');
-
+
$this->assertEquals(count($this->table->rows), 3);
-
+
$this->assertEquals(
array(
array('data' => 'your'),
@@ -87,11 +82,10 @@ class Table_test extends CI_TestCase {
$this->table->rows[1]
);
}
-
-
+
// Uility Methods
// --------------------------------------------------------------------
-
+
public function test_prep_args()
{
$expected = array(
@@ -99,7 +93,7 @@ class Table_test extends CI_TestCase {
array('data' => 'color'),
array('data' => 'size')
);
-
+
$this->assertEquals(
$expected,
$this->table->prep_args(array('name', 'color', 'size'))
@@ -114,7 +108,7 @@ class Table_test extends CI_TestCase {
$this->table->prep_args(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome')))
);
}
-
+
public function test_default_template_keys()
{
$keys = array(
@@ -126,132 +120,124 @@ class Table_test extends CI_TestCase {
'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end',
'table_close'
);
-
+
foreach ($keys as $key)
{
$this->assertArrayHasKey($key, $this->table->default_template());
}
}
-
+
public function test_compile_template()
{
$this->assertFalse($this->table->set_template('invalid_junk'));
-
+
// non default key
$this->table->set_template(array('nonsense' => 'foo'));
$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>'));
$this->table->compile_template();
-
+
$this->assertArrayHasKey('table_close', $this->table->template);
$this->assertEquals('</table junk>', $this->table->template['table_close']);
}
-
+
public function test_make_columns()
{
// 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'));
-
-
+
// Now on to the actual column creation
-
+
$five_values = array(
'Laura', 'Red', '15',
'Katie', 'Blue'
);
-
+
// No column count - no changes to the array
$this->assertEquals(
$five_values,
$this->table->make_columns($five_values)
);
-
+
// Column count of 3 leaves us with one &nbsp;
$this->assertEquals(
array(
array('Laura', 'Red', '15'),
- array('Katie', 'Blue', '&nbsp;')
+ array('Katie', 'Blue', '&nbsp;')
),
$this->table->make_columns($five_values, 3)
);
}
-
+
public function test_clear()
{
$this->table->set_heading('Name', 'Color', 'Size');
-
+
// Make columns changes auto_heading
$rows = $this->table->make_columns(array(
'Laura', 'Red', '15',
'Katie', 'Blue'
), 3);
-
+
foreach ($rows as $row)
{
$this->table->add_row($row);
}
-
+
$this->assertFalse($this->table->auto_heading);
$this->assertEquals(count($this->table->heading), 3);
$this->assertEquals(count($this->table->rows), 2);
-
+
$this->table->clear();
-
+
$this->assertTrue($this->table->auto_heading);
$this->assertEmpty($this->table->heading);
$this->assertEmpty($this->table->rows);
}
-
-
+
public function test_set_from_array()
{
$this->assertFalse($this->table->set_from_array('bogus'));
$this->assertFalse($this->table->set_from_array(NULL));
-
+
$data = array(
array('name', 'color', 'number'),
array('Laura', 'Red', '22'),
- array('Katie', 'Blue')
+ array('Katie', 'Blue')
);
-
+
$this->table->set_from_array($data, FALSE);
$this->assertEmpty($this->table->heading);
-
+
$this->table->clear();
-
- $expected_heading = array(
+
+ $this->table->set_from_array($data);
+ $this->assertEquals(count($this->table->rows), 2);
+
+ $expected = array(
array('data' => 'name'),
array('data' => 'color'),
array('data' => 'number')
);
-
- $expected_second = array(
+
+ $this->assertEquals($expected, $this->table->heading);
+
+ $expected = array(
array('data' => 'Katie'),
array('data' => 'Blue'),
);
-
- $this->table->set_from_array($data);
- $this->assertEquals(count($this->table->rows), 2);
-
- $this->assertEquals(
- $expected_heading,
- $this->table->heading
- );
-
- $this->assertEquals(
- $expected_second,
- $this->table->rows[1]
- );
+
+ $this->assertEquals($expected, $this->table->rows[1]);
}
-
- function test_set_from_object()
+
+ public function test_set_from_object()
{
// Make a stub of query instance
$query = new CI_TestCase();
@@ -268,37 +254,31 @@ class Table_test extends CI_TestCase {
return 2;
};
- $expected_heading = array(
+ $this->table->set_from_object($query);
+
+ $expected = array(
array('data' => 'name'),
array('data' => 'email')
);
- $expected_second = array(
+ $this->assertEquals($expected, $this->table->heading);
+
+ $expected = array(
'name' => array('data' => 'Foo Bar'),
'email' => array('data' => 'foo@bar.com'),
);
- $this->table->set_from_object($query);
-
- $this->assertEquals(
- $expected_heading,
- $this->table->heading
- );
-
- $this->assertEquals(
- $expected_second,
- $this->table->rows[1]
- );
+ $this->assertEquals($expected, $this->table->rows[1]);
}
-
- function test_generate()
+
+ public function test_generate()
{
// Prepare the data
$data = array(
array('Name', 'Color', 'Size'),
array('Fred', 'Blue', 'Small'),
array('Mary', 'Red', 'Large'),
- array('John', 'Green', 'Medium')
+ array('John', 'Green', 'Medium')
);
$table = $this->table->generate($data);
@@ -313,4 +293,5 @@ class Table_test extends CI_TestCase {
$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 250aefb24..eb6dacb73 100644
--- a/tests/codeigniter/libraries/Typography_test.php
+++ b/tests/codeigniter/libraries/Typography_test.php
@@ -4,11 +4,11 @@ class Typography_test extends CI_TestCase {
public function set_up()
{
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->type = new Mock_Libraries_Typography();
-
+
$this->ci_instance($obj);
-
+
$this->type = $obj->type;
}
@@ -33,18 +33,18 @@ class Typography_test extends CI_TestCase {
'foo..' => 'foo..',
'foo...bar.' => 'foo&#8230;bar.',
'test. new' => 'test.&nbsp; new',
- );
-
+ );
+
foreach ($strs as $str => $expected)
{
- $this->assertEquals($expected, $this->type->format_characters($str));
+ $this->assertEquals($expected, $this->type->format_characters($str));
}
}
// --------------------------------------------------------------------
public function test_nl2br_except_pre()
- {
+ {
$str = <<<EOH
Hello, I'm a happy string with some new lines.
@@ -85,12 +85,11 @@ That's my story and I'm sticking to it.<br />
The End.
EOH;
- $this->assertEquals($expected,
- $this->type->nl2br_except_pre($str));
+ $this->assertEquals($expected, $this->type->nl2br_except_pre($str));
}
// --------------------------------------------------------------------
-
+
public function test_auto_typography()
{
$this->_blank_string();
@@ -103,7 +102,7 @@ EOH;
}
// --------------------------------------------------------------------
-
+
private function _blank_string()
{
// Test blank string
@@ -131,7 +130,7 @@ EOH;
{
$str = "This has way too many linebreaks.\n\n\n\nSee?";
$expect = "<p>This has way too many linebreaks.</p>\n\n<p>See?</p>";
-
+
$this->assertEquals($expect, $this->type->auto_typography($str, TRUE));
}
@@ -141,7 +140,7 @@ EOH;
{
$str = '<!-- I can haz comments? --> But no!';
$expect = '<p><!-- I can haz comments? -->&nbsp; But no!</p>';
-
+
$this->assertEquals($expect, $this->type->auto_typography($str));
}
@@ -151,7 +150,7 @@ EOH;
{
$str = '<p>My Sentence</p><pre>var_dump($this);</pre>';
$expect = '<p>My Sentence</p><pre>var_dump($this);</pre>';
-
+
$this->assertEquals($expect, $this->type->auto_typography($str));
}
@@ -161,7 +160,7 @@ EOH;
{
$str = 'My Sentence<pre>var_dump($this);</pre>';
$expect = '<p>My Sentence</p><pre>var_dump($this);</pre>';
-
+
$this->assertEquals($expect, $this->type->auto_typography($str));
}
@@ -170,19 +169,18 @@ EOH;
public function _protect_braced_quotes()
{
$this->type->protect_braced_quotes = TRUE;
-
+
$str = 'Test {parse="foobar"}';
$expect = '<p>Test {parse="foobar"}</p>';
-
+
$this->assertEquals($expect, $this->type->auto_typography($str));
$this->type->protect_braced_quotes = FALSE;
-
+
$str = 'Test {parse="foobar"}';
$expect = '<p>Test {parse=&#8220;foobar&#8221;}</p>';
-
- $this->assertEquals($expect, $this->type->auto_typography($str));
-
+ $this->assertEquals($expect, $this->type->auto_typography($str));
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Useragent_test.php b/tests/codeigniter/libraries/Useragent_test.php
index 7dad7ac54..89383f807 100644
--- a/tests/codeigniter/libraries/Useragent_test.php
+++ b/tests/codeigniter/libraries/Useragent_test.php
@@ -1,7 +1,7 @@
<?php
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';
@@ -10,7 +10,7 @@ class UserAgent_test extends CI_TestCase {
// set a baseline user agent
$_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->agent = new Mock_Libraries_UserAgent();
$this->ci_instance($obj);
@@ -82,6 +82,4 @@ class UserAgent_test extends CI_TestCase {
$this->assertFalse($this->agent->accept_charset());
}
- // --------------------------------------------------------------------
-
} \ No newline at end of file