* @license PHP License * @package WB * @subpackage unittest */ /** * Unit Test * * Test Mime Type * * @version 0.1 * @package WB * @subpackage unittest */ class TestCaseVFSMime extends UnitTestCase { /** * file * @var WBVFS_File */ protected $file; /** * mime handler * @var WBVFS_Mime */ protected $hdl; /** * name of concrete mime class * @var string */ protected $name; /** * list of test files * @var array */ protected $fileIds = array(); /** * constructor * * - start objects * - source SQL * */ public function __construct() { $this->name = null; $class = get_class($this); if ($class == __CLASS__) { return; } $this->name = ucfirst(substr($class, strlen(__CLASS__) + 1)); WBClass::load('WBUnitTest_SQLUte'); WBUnitTest_SQLUte::source(__FILE__, 'construct'); $parameter = array( 'user' => '42' ); $this->file = WBClass::create('WBVFS_File', $parameter); $this->hdl = WBClass::create('WBVFS_Mime_' . $this->name); } /** * destruct * * Remove testing tables */ public function __destruct() { if (!$this->name) { return; } $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 instances * * Generic initial tests for all mime types */ public function testInit() { if (!$this->name) { return; } $this->assertTrue(class_exists('WBVFS_Mime', false)); $this->assertTrue(class_exists('WBVFS_Mime_' . $this->name, false)); $this->assertIsA($this->hdl, 'WBVFS_Mime'); $this->assertIsA($this->hdl, 'WBVFS_Mime_' . $this->name); $this->assertIsA($this->file, 'WBVFS_File'); } /** * execute command for all files * * General method to iterate through all files and execute a command. * After processing each file, onExecuted() will be called. * * @see onExecute() * @param string $cmd * @param array $args */ final protected function execute($cmd, $args) { $ids = $this->import(); foreach ($ids as $id) { $file = $this->file->loadById($id); $this->hdl->setVirtualFile($file); $this->hdl->execute($cmd, $args); $this->assertTrue(true); $this->onExecuted($cmd, $args); } } /** * Callback after command executed * * Implement this method to validate execute results * * @param string $cmd * @param array $args */ protected function onExecuted($cmd, $args) { } /** * import test files * * Import some real files to work with. * * @return array list of imported file ids */ final public function import() { if (!empty($this->fileIds)) { return $this->fileIds; } $dir = UnitTest_VFS_Sample::getDirIterator(strtolower($this->name)); foreach ($dir as $name) { if ($name->isDot() || $name->isDir()) { continue; } $path = $name->getPath() . '/' . $name->getFilename(); if (!$this->isImportable($path)) { continue; } $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()); $name = ucfirst($fileCopy->getMime()); $this->assertEqual($name, $this->name); $this->fileIds[] = $file->getId(); } return $this->fileIds; } /** * Check whether this file should be importerd * * Do any required check. This ist just to avoid importing useless files * * @param string $file realpath of file * @return bool true to import */ protected function isImportable($file) { return false; } } ?>