From 742826c26c64656acf5cfc7df4cc5e1c5c8a68cc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 21 Feb 2014 15:50:36 +0200 Subject: Add test cases for CI_Upload::__construct(), CI_Upload::initialize() --- tests/codeigniter/libraries/Upload_test.php | 47 +++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'tests/codeigniter/libraries/Upload_test.php') diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php index 03eb640b7..4fbc11ef0 100644 --- a/tests/codeigniter/libraries/Upload_test.php +++ b/tests/codeigniter/libraries/Upload_test.php @@ -2,7 +2,7 @@ class Upload_test extends CI_TestCase { - function set_up() + public function set_up() { $ci = $this->ci_instance(); $ci->upload = new CI_Upload(); @@ -12,11 +12,52 @@ class Upload_test extends CI_TestCase { $this->upload = $ci->upload; } - function test_do_upload() + // -------------------------------------------------------------------- + + public function test___construct_initialize() + { + // via __construct + + $upload = new CI_Upload( + array( + 'file_name' => 'foo', + 'file_ext_tolower' => TRUE + ) + ); + + // ReflectionProperty::setAccessible() is not available in PHP 5.2.x + if (is_php('5.3')) + { + $reflection = new ReflectionClass($upload); + $reflection = $reflection->getProperty('_file_name_override'); + $reflection->setAccessible(TRUE); + $this->assertEquals('foo', $reflection->getValue($upload)); + } + + $this->assertTrue($upload->file_ext_tolower); + + // reset (defaults to true) + + $upload->initialize(array('file_name' => 'bar')); + $this->assertEquals('bar', $upload->file_name); + $this->assertFalse($upload->file_ext_tolower); + + // no reset + + $upload->initialize(array('file_ext_tolower' => TRUE), FALSE); + $this->assertTrue($upload->file_ext_tolower); + $this->assertEquals('bar', $upload->file_name); + } + + // -------------------------------------------------------------------- + + public function test_do_upload() { - $this->markTestSkipped('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'); + $this->markTestSkipped("We can't 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( -- cgit v1.2.3-24-g4f1b