* @license PHP License * @package WB * @subpackage unittest */ WBClass::load( 'WBException_Datasource'); /** * Unit Test * * Test file * * @version 0.2.1 * @package WB * @subpackage unittest */ class TestCaseVFSFile extends UnitTestCase { /** * file utitlity object * @var WBVFS_File */ protected $file; /** * constructor * * - start objects * - source SQL * */ public function __construct() { WBClass::load('WBUnitTest_SQLUte'); WBUnitTest_SQLUte::source(__FILE__, 'construct'); } /** * destruct * * Remove testing tables */ public function __destruct() { WBClass::load('WBVFS_File'); $config = WBClass::create('WBConfig'); /** @var $config WBConfig */ $config->load('vfs'); $storage = WBParam::get('wb/dir/base') . '/var/' . WBVFS_File::DIR_PREFIX . '/' . $config->get('file/storage'); exec('rm -rf ' . $storage); WBUnitTest_SQLUte::source( __FILE__, 'destruct' ); } /** * check instance * */ public function testInit() { WBClass::load('WBVFS_File'); $this->assertTrue(class_exists('WBVFS_File', false)); $parameter = array( 'user' => '42' ); $this->file = WBClass::create('WBVFS_File', $parameter); $this->assertIsA($this->file, 'WBVFS_File'); } public function testImport() { $nix = '/this/file/does/not/exits.txt'; try{ $file = $this->file->import($nix, true); $this->assertTrue(false); } catch(Exception $e) { $this->assertIsA($e, 'WBException_Argument'); } $majors = UnitTest_VFS_Sample::getMajors(); foreach ($majors as $major) { $dir = UnitTest_VFS_Sample::getDirIterator($major); foreach ($dir as $name) { if ($name->isDot() || $name->isDir()) { continue; } $path = $name->getPath() . '/' . $name->getFilename(); $file = $this->file->import($path, null, true); $this->assertIsA($file, 'WBVFS_File'); $this->assertTrue($file->isOK()); $obscure = $file->getObscureId(); $fileCopy = $this->file->loadByObscureId($obscure); $this->assertTrue($fileCopy->isOK()); } } } public function testImportUrl() { $nix = 'http://lena.sub.org/is/not/there'; try{ $file = $this->file->importUrl($nix); $this->assertTrue(false); } catch(Exception $e) { $this->assertIsA($e, 'WBException_File'); } $urls = array( 'http://php.net', 'http://lena.sub.org', 'http://lena.sub.org/gallery.php?PHPSESSID=miEN5xreeNfwwFf9UWBbh1q9MlyyROKd&img=fun/640', 'http://lena.sub.org/gallery.php?PHPSESSID=miEN5xreeNfwwFf9UWBbh1q9MlyyROKd&img=fun/109', 'http://lena.sub.org/gallery.php?PHPSESSID=miEN5xreeNfwwFf9UWBbh1q9MlyyROKd&img=fun/477' ); foreach ($urls as $url) { $file = $this->file->importUrl($url, true); $this->assertIsA($file, 'WBVFS_File'); $this->assertTrue($file->isOK()); $obscure = $file->getObscureId(); $fileCopy = $this->file->loadByObscureId($obscure); $this->assertTrue($fileCopy->isOK()); } } } ?>