Integrated vfsStream better and made paths constants VFS-based

Signed-off-by: dchill42 <dchill42@gmail.com>
diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php
index 153a25e..998d806 100644
--- a/tests/codeigniter/libraries/Encrypt_test.php
+++ b/tests/codeigniter/libraries/Encrypt_test.php
@@ -4,11 +4,8 @@
 
 	public function set_up()
 	{
-		$obj = new stdClass;
-		$obj->encrypt = new Mock_Libraries_Encrypt();
-
-		$this->ci_instance($obj);
-		$this->encrypt = $obj->encrypt;
+		$this->encrypt = new Mock_Libraries_Encrypt();
+		$this->ci_instance_var('encrypt', $this->encrypt);
 
 		$this->ci_set_config('encryption_key', "Encryptin'glike@boss!");
 		$this->msg = 'My secret message';
diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php
index b68f44a..394c226 100644
--- a/tests/codeigniter/libraries/Parser_test.php
+++ b/tests/codeigniter/libraries/Parser_test.php
@@ -4,12 +4,8 @@
 
 	public function set_up()
 	{
-		$obj = new stdClass;
-		$obj->parser = new Mock_Libraries_Parser();
-
-		$this->ci_instance($obj);
-
-		$this->parser = $obj->parser;
+		$this->parser = new Mock_Libraries_Parser();
+		$this->ci_instance_var('parser', $this->parser);
 	}
 
 	// --------------------------------------------------------------------
diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php
index 60d3a5b..14469f7 100644
--- a/tests/codeigniter/libraries/Session_test.php
+++ b/tests/codeigniter/libraries/Session_test.php
@@ -29,13 +29,15 @@
 		$_COOKIE = array();
 
 		// Establish necessary support classes
-		$obj = new stdClass;
 		$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);
+		$ci = $this->ci_instance();
+		$ci->config = new $cfg();
+		$ci->load = new $ldr();
+		$ci->input = new Mock_Core_Input(NULL, NULL);
+
+		// Make sure string helper is available
+		$this->ci_vfs_clone('system/helpers/string_helper.php');
 
 		// Attach session instance locally
 		$config = array(
diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php
index edfc83d..ce04b6a 100644
--- a/tests/codeigniter/libraries/Table_test.php
+++ b/tests/codeigniter/libraries/Table_test.php
@@ -4,12 +4,8 @@
 
 	public function set_up()
 	{
-		$obj = new stdClass;
-		$obj->table = new Mock_Libraries_Table();
-
-		$this->ci_instance($obj);
-
-		$this->table = $obj->table;
+		$this->table = new Mock_Libraries_Table();
+		$this->ci_instance_var('table', $this->table);
 	}
 
 	// Setter Methods
diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php
index eb6dacb..5dba062 100644
--- a/tests/codeigniter/libraries/Typography_test.php
+++ b/tests/codeigniter/libraries/Typography_test.php
@@ -4,12 +4,8 @@
 
 	public function set_up()
 	{
-		$obj = new stdClass;
-		$obj->type = new Mock_Libraries_Typography();
-
-		$this->ci_instance($obj);
-
-		$this->type = $obj->type;
+		$this->type = new Mock_Libraries_Typography();
+		$this->ci_instance('type', $this->type);
 	}
 
 	// --------------------------------------------------------------------
diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php
index d79a3ff..8279427 100644
--- a/tests/codeigniter/libraries/Upload_test.php
+++ b/tests/codeigniter/libraries/Upload_test.php
@@ -4,18 +4,11 @@
 
 	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();
+		$ci = $this->ci_instance();
+		$ci->upload = new Mock_Libraries_Upload();
+		$ci->security = new Mock_Core_Security();
+		$ci->lang = new Mock_Core_Lang();
+		$this->upload = $ci->upload;
 	}
 
 	function test_do_upload() 
@@ -64,11 +57,15 @@
 
 	function test_set_filename()
 	{
-		$file1 = vfsStream::newFile('hello-world.txt')->withContent('Hello world.')->at($this->_test_dir);
+		$dir = 'uploads';
+		$isnew = 'helloworld.txt';
+		$exists = 'hello-world.txt';
+		$this->ci_vfs_create($exists, 'Hello world.', $this->ci_app_root, $dir);
+		$path = $this->ci_vfs_path($dir.'/', APPPATH);
 		$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'));
+		$this->assertEquals($isnew, $this->upload->set_filename($path, $isnew));
+		$this->assertEquals('hello-world1.txt', $this->upload->set_filename($path, $exists));
 	}
 
 	function test_set_max_filesize()
@@ -107,7 +104,7 @@
 	function test_set_image_properties()
 	{
 		$this->upload->file_type = 'image/gif';
-		$this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif';
+		$this->upload->file_temp = realpath(PROJECT_BASE.'tests/mocks/uploads/ci_logo.gif');
 
 		$props = array(
 			'image_width'	=>	170,
@@ -156,7 +153,7 @@
 		$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_temp = realpath(PROJECT_BASE.'tests/mocks/uploads/ci_logo.gif');
 		$this->upload->file_ext = '.gif';
 		$this->upload->file_type = 'image/gif';
 		$this->assertTrue($this->upload->is_allowed_filetype());
@@ -179,7 +176,7 @@
 		$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->file_temp = realpath(PROJECT_BASE.'tests/mocks/uploads/ci_logo.gif');
 
 		$this->upload->max_width = 10;		
 		$this->assertFalse($this->upload->is_allowed_dimensions());
@@ -197,7 +194,9 @@
 		$this->upload->upload_path = '';
 		$this->assertFalse($this->upload->validate_upload_path());
 
-		$this->upload->upload_path = vfsStream::url('testDir');
+		$dir = 'uploads';
+		$this->ci_vfs_mkdir($dir);
+		$this->upload->upload_path = $this->ci_vfs_path($dir);
 		$this->assertTrue($this->upload->validate_upload_path());
 	}
 
@@ -222,20 +221,24 @@
 
 	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);
+		$dir = 'uploads';
+		$file1 = 'file1.txt';
+		$file2 = 'file2.txt';
+		$file3 = 'file3.txt';
+		$this->ci_vfs_create($file1, 'The billy goat was waiting for them.', $this->ci_vfs_root, $dir);
+		$this->ci_vfs_create($file2, '', $this->ci_vfs_root, $dir);
+		$this->ci_vfs_create($file3, '<script type="text/javascript">alert("Boo! said the billy goat")</script>', $this->ci_vfs_root, $dir);
 
-		$this->upload->file_temp = vfsStream::url('file1.txt');
+		$this->upload->file_temp = $this->ci_vfs_path($file1, $dir);
 		$this->assertTrue($this->upload->do_xss_clean());
 
-		$this->upload->file_temp = vfsStream::url('file2.txt');
+		$this->upload->file_temp = $this->ci_vfs_path($file2, $dir);
 		$this->assertFalse($this->upload->do_xss_clean());
 
-		$this->upload->file_temp = vfsStream::url('file3.txt');
+		$this->upload->file_temp = $this->ci_vfs_path($file3, $dir);
 		$this->assertFalse($this->upload->do_xss_clean());
 
-		$this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif';
+		$this->upload->file_temp = realpath(PROJECT_BASE.'tests/mocks/uploads/ci_logo.gif');
 		$this->assertTrue($this->upload->do_xss_clean());
 	}
 
diff --git a/tests/codeigniter/libraries/Useragent_test.php b/tests/codeigniter/libraries/Useragent_test.php
index 89383f8..e372655 100644
--- a/tests/codeigniter/libraries/Useragent_test.php
+++ b/tests/codeigniter/libraries/Useragent_test.php
@@ -10,12 +10,11 @@
 		// set a baseline user agent
 		$_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
 
-		$obj = new stdClass;
-		$obj->agent = new Mock_Libraries_UserAgent();
+		$this->ci_vfs_clone('application/config/user_agents.php');
 
-		$this->ci_instance($obj);
+		$this->agent = new Mock_Libraries_UserAgent();
 
-		$this->agent = $obj->agent;
+		$this->ci_instance_var('agent', $this->agent);
 	}
 
 	// --------------------------------------------------------------------