summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter
diff options
context:
space:
mode:
authordchill42 <dchill42@gmail.com>2012-10-10 14:16:39 +0200
committerdchill42 <dchill42@gmail.com>2012-10-10 14:16:39 +0200
commit2716398bd2f2ae36d7420c591fc759e0951ba0e2 (patch)
tree3845d6bacc5660559740a8eddd43210bbb14fefd /tests/codeigniter
parenteeb6a480a4a25b7fe96e9ba0cf3aef273fd13c67 (diff)
parente8bc5f4450381b4f978f274f3e93604301115b64 (diff)
Merge branch 'develop' of github.com:/EllisLab/CodeIgniter into load_config_units
Diffstat (limited to 'tests/codeigniter')
-rw-r--r--tests/codeigniter/database/query_builder/escape_test.php4
-rw-r--r--tests/codeigniter/helpers/date_helper_test.php23
-rw-r--r--tests/codeigniter/helpers/directory_helper_test.php4
-rw-r--r--tests/codeigniter/libraries/Calendar_test.php204
-rw-r--r--tests/codeigniter/libraries/Session_test.php17
-rw-r--r--tests/codeigniter/libraries/Upload_test.php270
6 files changed, 508 insertions, 14 deletions
diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php
index c6380ddf1..27e678f22 100644
--- a/tests/codeigniter/database/query_builder/escape_test.php
+++ b/tests/codeigniter/database/query_builder/escape_test.php
@@ -27,7 +27,7 @@ class Escape_test extends CI_TestCase {
if (strpos(DB_DRIVER, 'mysql') !== FALSE)
{
- $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '';";
+ $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '!';";
}
else
{
@@ -52,7 +52,7 @@ class Escape_test extends CI_TestCase {
if (strpos(DB_DRIVER, 'mysql') !== FALSE)
{
- $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '';";
+ $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '!';";
}
else
{
diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php
index 1b79b9480..9feade71c 100644
--- a/tests/codeigniter/helpers/date_helper_test.php
+++ b/tests/codeigniter/helpers/date_helper_test.php
@@ -290,6 +290,29 @@ class Date_helper_test extends CI_TestCase {
$this->assertEquals(0, timezones('non_existant'));
}
+ // ------------------------------------------------------------------------
+
+ public function test_date_range()
+ {
+ $dates = array(
+ '29-01-2012', '30-01-2012', '31-01-2012',
+ '01-02-2012', '02-02-2012', '03-02-2012',
+ '04-02-2012', '05-02-2012', '06-02-2012',
+ '07-02-2012', '08-02-2012', '09-02-2012',
+ '10-02-2012', '11-02-2012', '12-02-2012',
+ '13-02-2012', '14-02-2012', '15-02-2012',
+ '16-02-2012', '17-02-2012', '18-02-2012',
+ '19-02-2012', '20-02-2012', '21-02-2012',
+ '22-02-2012', '23-02-2012', '24-02-2012',
+ '25-02-2012', '26-02-2012', '27-02-2012',
+ '28-02-2012', '29-02-2012', '01-03-2012'
+ );
+
+ $this->assertEquals($dates, date_range(mktime(12, 0, 0, 1, 29, 2012), mktime(12, 0, 0, 3, 1, 2012), TRUE, 'd-m-Y'));
+ array_pop($dates);
+ $this->assertEquals($dates, date_range(mktime(12, 0, 0, 1, 29, 2012), 31, FALSE, 'd-m-Y'));
+ }
+
}
/* End of file date_helper_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php
index 176ff1d78..c39ccd8d0 100644
--- a/tests/codeigniter/helpers/directory_helper_test.php
+++ b/tests/codeigniter/helpers/directory_helper_test.php
@@ -19,6 +19,7 @@ class Directory_helper_test extends CI_TestCase {
'benchmark.html' => '',
'database' => array('active_record.html' => '', 'binds.html' => ''),
'email.html' => '',
+ '0' => '',
'.hiddenfile.txt' => ''
)
);
@@ -30,7 +31,8 @@ class Directory_helper_test extends CI_TestCase {
'libraries' => array(
'benchmark.html',
'database' => array('active_record.html', 'binds.html'),
- 'email.html'
+ 'email.html',
+ '0'
)
);
diff --git a/tests/codeigniter/libraries/Calendar_test.php b/tests/codeigniter/libraries/Calendar_test.php
new file mode 100644
index 000000000..95668d70d
--- /dev/null
+++ b/tests/codeigniter/libraries/Calendar_test.php
@@ -0,0 +1,204 @@
+<?php
+
+class Calendar_test extends CI_TestCase {
+
+ function __construct()
+ {
+ $obj = new stdClass;
+ $obj->calendar = new Mock_Libraries_Calendar();
+
+ $this->calendar = $obj->calendar;
+ }
+
+ function test_initialize()
+ {
+ $this->calendar->initialize(array(
+ 'month_type' => 'short',
+ 'start_day' => 'monday'
+ ));
+ $this->assertEquals('short', $this->calendar->month_type);
+ $this->assertEquals('monday', $this->calendar->start_day);
+ }
+
+ /**
+ * @covers Mock_Libraries_Calendar::parse_template
+ */
+ function test_generate()
+ {
+ $no_events = '<table border="0" cellpadding="4" cellspacing="0">
+
+<tr>
+<th colspan="7">September&nbsp;2011</th>
+
+</tr>
+
+<tr>
+<td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td>
+</tr>
+
+<tr>
+<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>1</td><td>2</td><td>3</td>
+</tr>
+
+<tr>
+<td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td>
+</tr>
+
+<tr>
+<td>11</td><td>12</td><td>13</td><td>14</td><td>15</td><td>16</td><td>17</td>
+</tr>
+
+<tr>
+<td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td>
+</tr>
+
+<tr>
+<td>25</td><td>26</td><td>27</td><td>28</td><td>29</td><td>30</td><td>&nbsp;</td>
+</tr>
+
+</table>';
+
+ $this->assertEquals($no_events, $this->calendar->generate(2011, 9));
+
+ $data = array(
+ 3 => 'http://example.com/news/article/2006/03/',
+ 7 => 'http://example.com/news/article/2006/07/',
+ 13 => 'http://example.com/news/article/2006/13/',
+ 26 => 'http://example.com/news/article/2006/26/'
+ );
+
+ $events = '<table border="0" cellpadding="4" cellspacing="0">
+
+<tr>
+<th colspan="7">September&nbsp;2011</th>
+
+</tr>
+
+<tr>
+<td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td>
+</tr>
+
+<tr>
+<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>1</td><td>2</td><td><a href="http://example.com/news/article/2006/03/">3</a></td>
+</tr>
+
+<tr>
+<td>4</td><td>5</td><td>6</td><td><a href="http://example.com/news/article/2006/07/">7</a></td><td>8</td><td>9</td><td>10</td>
+</tr>
+
+<tr>
+<td>11</td><td>12</td><td><a href="http://example.com/news/article/2006/13/">13</a></td><td>14</td><td>15</td><td>16</td><td>17</td>
+</tr>
+
+<tr>
+<td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td>
+</tr>
+
+<tr>
+<td>25</td><td><a href="http://example.com/news/article/2006/26/">26</a></td><td>27</td><td>28</td><td>29</td><td>30</td><td>&nbsp;</td>
+</tr>
+
+</table>';
+
+ $this->assertEquals($events, $this->calendar->generate(2011, 9, $data));
+ }
+
+ function test_get_month_name()
+ {
+ $this->calendar->month_type = NULL;
+ $this->assertEquals('January', $this->calendar->get_month_name('01'));
+
+ $this->calendar->month_type = 'short';
+ $this->assertEquals('Jan', $this->calendar->get_month_name('01'));
+ }
+
+ function test_get_day_names()
+ {
+ $this->assertEquals(array(
+ 'Sunday',
+ 'Monday',
+ 'Tuesday',
+ 'Wednesday',
+ 'Thursday',
+ 'Friday',
+ 'Saturday'
+ ), $this->calendar->get_day_names('long'));
+
+ $this->assertEquals(array(
+ 'Sun',
+ 'Mon',
+ 'Tue',
+ 'Wed',
+ 'Thu',
+ 'Fri',
+ 'Sat'
+ ), $this->calendar->get_day_names('short'));
+
+ $this->calendar->day_type = NULL;
+
+ $this->assertEquals(array(
+ 'Su',
+ 'Mo',
+ 'Tu',
+ 'We',
+ 'Th',
+ 'Fr',
+ 'Sa'
+ ), $this->calendar->get_day_names());
+ }
+
+ function test_adjust_date()
+ {
+ $this->assertEquals(array('month' => 8, 'year' => 2012), $this->calendar->adjust_date(8, 2012));
+ $this->assertEquals(array('month' => 1, 'year' => 2013), $this->calendar->adjust_date(13, 2012));
+ }
+
+ function test_get_total_days()
+ {
+ $this->assertEquals(0, $this->calendar->get_total_days(13, 2012));
+
+ $this->assertEquals(31, $this->calendar->get_total_days(1, 2012));
+ $this->assertEquals(28, $this->calendar->get_total_days(2, 2011));
+ $this->assertEquals(29, $this->calendar->get_total_days(2, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(3, 2012));
+ $this->assertEquals(30, $this->calendar->get_total_days(4, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(5, 2012));
+ $this->assertEquals(30, $this->calendar->get_total_days(6, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(7, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(8, 2012));
+ $this->assertEquals(30, $this->calendar->get_total_days(9, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(10, 2012));
+ $this->assertEquals(30, $this->calendar->get_total_days(11, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(12, 2012));
+ }
+
+ function test_default_template()
+ {
+ $array = array(
+ 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',
+ 'heading_row_start' => '<tr>',
+ 'heading_previous_cell' => '<th><a href="{previous_url}">&lt;&lt;</a></th>',
+ 'heading_title_cell' => '<th colspan="{colspan}">{heading}</th>',
+ 'heading_next_cell' => '<th><a href="{next_url}">&gt;&gt;</a></th>',
+ 'heading_row_end' => '</tr>',
+ 'week_row_start' => '<tr>',
+ 'week_day_cell' => '<td>{week_day}</td>',
+ 'week_row_end' => '</tr>',
+ 'cal_row_start' => '<tr>',
+ 'cal_cell_start' => '<td>',
+ 'cal_cell_start_today' => '<td>',
+ 'cal_cell_content' => '<a href="{content}">{day}</a>',
+ 'cal_cell_content_today' => '<a href="{content}"><strong>{day}</strong></a>',
+ 'cal_cell_no_content' => '{day}',
+ 'cal_cell_no_content_today' => '<strong>{day}</strong>',
+ 'cal_cell_blank' => '&nbsp;',
+ 'cal_cell_end' => '</td>',
+ 'cal_cell_end_today' => '</td>',
+ 'cal_row_end' => '</tr>',
+ 'table_close' => '</table>'
+ );
+
+ $this->assertEquals($array, $this->calendar->default_template());
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php
index 135f71806..60d3a5b30 100644
--- a/tests/codeigniter/libraries/Session_test.php
+++ b/tests/codeigniter/libraries/Session_test.php
@@ -30,15 +30,11 @@ class Session_test extends CI_TestCase {
// Establish necessary support classes
$obj = new stdClass;
- $classes = array(
- 'config' => 'cfg',
- 'load' => 'load',
- 'input' => 'in'
- );
- foreach ($classes as $name => $abbr) {
- $class = $this->ci_core_class($abbr);
- $obj->$name = new $class;
- }
+ $cfg = $this->ci_core_class('cfg');
+ $obj->config = new $cfg();
+ $ldr = $this->ci_core_class('load');
+ $obj->load = new $ldr();
+ $obj->input = new Mock_Core_Input(NULL, NULL);
$this->ci_instance($obj);
// Attach session instance locally
@@ -401,5 +397,4 @@ class Session_test extends CI_TestCase {
$this->session->native->sess_destroy();
$this->assertNull($this->session->native->userdata($key));
}
-}
-
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php
new file mode 100644
index 000000000..d79a3ffc9
--- /dev/null
+++ b/tests/codeigniter/libraries/Upload_test.php
@@ -0,0 +1,270 @@
+<?php
+
+class Upload_test extends CI_TestCase {
+
+ function set_up()
+ {
+ $obj = new stdClass;
+ $obj->upload = new Mock_Libraries_Upload();
+ $obj->security = new Mock_Core_Security();
+ $obj->lang = new Mock_Core_Lang();
+
+ $this->ci_instance($obj);
+ $this->upload = $obj->upload;
+
+ vfsStreamWrapper::register();
+ vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir'));
+
+ $this->_test_dir = vfsStreamWrapper::getRoot();
+ }
+
+ function test_do_upload()
+ {
+ $this->markTestIncomplete('We can\'t really test this at the moment because of the call to `is_uploaded_file` in do_upload which isn\'t supported by vfsStream');
+ }
+
+ function test_data()
+ {
+ $data = array(
+ 'file_name' => 'hello.txt',
+ 'file_type' => 'text/plain',
+ 'file_path' => '/tmp/',
+ 'full_path' => '/tmp/hello.txt',
+ 'raw_name' => 'hello',
+ 'orig_name' => 'hello.txt',
+ 'client_name' => '',
+ 'file_ext' => '.txt',
+ 'file_size' => 100,
+ 'is_image' => FALSE,
+ 'image_width' => '',
+ 'image_height' => '',
+ 'image_type' => '',
+ 'image_size_str' => ''
+ );
+
+ $this->upload->set_upload_path('/tmp/');
+
+ foreach ($data as $k => $v)
+ {
+ $this->upload->{$k} = $v;
+ }
+
+ $this->assertEquals('hello.txt', $this->upload->data('file_name'));
+ $this->assertEquals($data, $this->upload->data());
+ }
+
+ function test_set_upload_path()
+ {
+ $this->upload->set_upload_path('/tmp/');
+ $this->assertEquals('/tmp/', $this->upload->upload_path);
+
+ $this->upload->set_upload_path('/tmp');
+ $this->assertEquals('/tmp/', $this->upload->upload_path);
+ }
+
+ function test_set_filename()
+ {
+ $file1 = vfsStream::newFile('hello-world.txt')->withContent('Hello world.')->at($this->_test_dir);
+ $this->upload->file_ext = '.txt';
+
+ $this->assertEquals('helloworld.txt', $this->upload->set_filename(vfsStream::url('testDir').'/', 'helloworld.txt'));
+ $this->assertEquals('hello-world1.txt', $this->upload->set_filename(vfsStream::url('testDir').'/', 'hello-world.txt'));
+ }
+
+ function test_set_max_filesize()
+ {
+ $this->upload->set_max_filesize(100);
+ $this->assertEquals(100, $this->upload->max_size);
+ }
+
+ function test_set_max_filename()
+ {
+ $this->upload->set_max_filename(100);
+ $this->assertEquals(100, $this->upload->max_filename);
+ }
+
+ function test_set_max_width()
+ {
+ $this->upload->set_max_width(100);
+ $this->assertEquals(100, $this->upload->max_width);
+ }
+
+ function test_set_max_height()
+ {
+ $this->upload->set_max_height(100);
+ $this->assertEquals(100, $this->upload->max_height);
+ }
+
+ function test_set_allowed_types()
+ {
+ $this->upload->set_allowed_types('*');
+ $this->assertEquals('*', $this->upload->allowed_types);
+
+ $this->upload->set_allowed_types('foo|bar');
+ $this->assertEquals(array('foo', 'bar'), $this->upload->allowed_types);
+ }
+
+ function test_set_image_properties()
+ {
+ $this->upload->file_type = 'image/gif';
+ $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif';
+
+ $props = array(
+ 'image_width' => 170,
+ 'image_height' => 73,
+ 'image_type' => 'gif',
+ 'image_size_str' => 'width="170" height="73"'
+ );
+
+ $this->upload->set_image_properties($this->upload->file_temp);
+
+ $this->assertEquals($props['image_width'], $this->upload->image_width);
+ $this->assertEquals($props['image_height'], $this->upload->image_height);
+ $this->assertEquals($props['image_type'], $this->upload->image_type);
+ $this->assertEquals($props['image_size_str'], $this->upload->image_size_str);
+ }
+
+ function test_set_xss_clean()
+ {
+ $this->upload->set_xss_clean(TRUE);
+ $this->assertTrue($this->upload->xss_clean);
+
+ $this->upload->set_xss_clean(FALSE);
+ $this->assertFalse($this->upload->xss_clean);
+ }
+
+ function test_is_image()
+ {
+ $this->upload->file_type = 'image/x-png';
+ $this->assertTrue($this->upload->is_image());
+
+ $this->upload->file_type = 'text/plain';
+ $this->assertFalse($this->upload->is_image());
+ }
+
+ function test_is_allowed_filetype()
+ {
+ $this->upload->allowed_types = array('html', 'gif');
+
+ $this->upload->file_ext = '.txt';
+ $this->upload->file_type = 'text/plain';
+ $this->assertFalse($this->upload->is_allowed_filetype(FALSE));
+ $this->assertFalse($this->upload->is_allowed_filetype(TRUE));
+
+ $this->upload->file_ext = '.html';
+ $this->upload->file_type = 'text/html';
+ $this->assertTrue($this->upload->is_allowed_filetype(FALSE));
+ $this->assertTrue($this->upload->is_allowed_filetype(TRUE));
+
+ $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif';
+ $this->upload->file_ext = '.gif';
+ $this->upload->file_type = 'image/gif';
+ $this->assertTrue($this->upload->is_allowed_filetype());
+ }
+
+ function test_is_allowed_filesize()
+ {
+ $this->upload->max_size = 100;
+ $this->upload->file_size = 99;
+
+ $this->assertTrue($this->upload->is_allowed_filesize());
+
+ $this->upload->file_size = 101;
+ $this->assertFalse($this->upload->is_allowed_filesize());
+ }
+
+ function test_is_allowed_dimensions()
+ {
+ $this->upload->file_type = 'text/plain';
+ $this->assertTrue($this->upload->is_allowed_dimensions());
+
+ $this->upload->file_type = 'image/gif';
+ $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif';
+
+ $this->upload->max_width = 10;
+ $this->assertFalse($this->upload->is_allowed_dimensions());
+
+ $this->upload->max_width = 170;
+ $this->upload->max_height = 10;
+ $this->assertFalse($this->upload->is_allowed_dimensions());
+
+ $this->upload->max_height = 73;
+ $this->assertTrue($this->upload->is_allowed_dimensions());
+ }
+
+ function test_validate_upload_path()
+ {
+ $this->upload->upload_path = '';
+ $this->assertFalse($this->upload->validate_upload_path());
+
+ $this->upload->upload_path = vfsStream::url('testDir');
+ $this->assertTrue($this->upload->validate_upload_path());
+ }
+
+ function test_get_extension()
+ {
+ $this->assertEquals('.txt', $this->upload->get_extension('hello.txt'));
+ $this->assertEquals('.htaccess', $this->upload->get_extension('.htaccess'));
+ $this->assertEquals('', $this->upload->get_extension('hello'));
+ }
+
+ function test_clean_file_name()
+ {
+ $this->assertEquals('hello.txt', $this->upload->clean_file_name('hello.txt'));
+ $this->assertEquals('hello.txt', $this->upload->clean_file_name('%253chell>o.txt'));
+ }
+
+ function test_limit_filename_length()
+ {
+ $this->assertEquals('hello.txt', $this->upload->limit_filename_length('hello.txt', 10));
+ $this->assertEquals('hello.txt', $this->upload->limit_filename_length('hello-world.txt', 9));
+ }
+
+ function test_do_xss_clean()
+ {
+ $file1 = vfsStream::newFile('file1.txt')->withContent('The billy goat was waiting for them.')->at($this->_test_dir);
+ $file2 = vfsStream::newFile('file2.txt')->at($this->_test_dir);
+ $file3 = vfsStream::newFile('file3.txt')->withContent('<script type="text/javascript">alert("Boo! said the billy goat")</script>')->at($this->_test_dir);
+
+ $this->upload->file_temp = vfsStream::url('file1.txt');
+ $this->assertTrue($this->upload->do_xss_clean());
+
+ $this->upload->file_temp = vfsStream::url('file2.txt');
+ $this->assertFalse($this->upload->do_xss_clean());
+
+ $this->upload->file_temp = vfsStream::url('file3.txt');
+ $this->assertFalse($this->upload->do_xss_clean());
+
+ $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif';
+ $this->assertTrue($this->upload->do_xss_clean());
+ }
+
+ function test_set_error()
+ {
+ $errors = array(
+ 'An error!'
+ );
+
+ $another = 'Another error!';
+
+ $this->upload->set_error($errors);
+ $this->assertEquals($errors, $this->upload->error_msg);
+
+ $errors[] = $another;
+ $this->upload->set_error($another);
+ $this->assertEquals($errors, $this->upload->error_msg);
+ }
+
+ function test_display_errors()
+ {
+ $this->upload->error_msg[] = 'Error test';
+ $this->assertEquals('<p>Error test</p>', $this->upload->display_errors());
+ }
+
+ function test_mimes_types()
+ {
+ $this->assertEquals('text/plain', $this->upload->mimes_types('txt'));
+ $this->assertFalse($this->upload->mimes_types('foobar'));
+ }
+
+} \ No newline at end of file