Beispiel #1
0
 function testRemove()
 {
     $module_plug_test_root = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/module_plug_root/");
     $target_dir = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/module_plug_root/");
     $plug = new DirBridge($target_dir, new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/fakeroot/modules/ecommerce/cart/"));
     $sub_dir = $module_plug_test_root->newSubdir("blocks");
     $block_file = $sub_dir->newFile("test.block.php");
     $block_file->setContent("BLA BLA BLA");
     $this->assertTrue($block_file->exists(), "Il file test.block.php non e' presente!!");
     $plug->remove("blocks/test.block.php");
     $this->assertFalse($block_file->exists(), "Il file test.block.php non e' stato rimosso!!");
     $js_dir = $module_plug_test_root->newSubdir("js");
     $js_dir->touch();
     $my_js_lib_subdir = $js_dir->newSubdir("my_js_lib");
     $my_js_lib_subdir->touch();
     $mylib_file = $my_js_lib_subdir->newFile("mylib.js");
     $mylib_file->setContent("HELLO!!");
     $this->assertTrue($mylib_file->exists(), "Il file non e' stato creato!!");
     $mylib3_file = $my_js_lib_subdir->newFile("mylib3.js");
     $mylib3_file->setContent("WORLD!!");
     $this->assertTrue($mylib3_file->exists(), "Il file non e' stato creato!!");
     $plug->remove("js/");
     $this->assertFalse($mylib_file->exists(), "Il file mylib.js non e' stato rimosso!!");
     $this->assertTrue($mylib3_file->exists(), "Il file mylib3.js e' stato rimosso!!");
     $all_module_plug_files = $module_plug_test_root->listFiles();
     foreach ($all_module_plug_files as $ff) {
         $ff->delete(true);
     }
 }
Beispiel #2
0
 function testAdd()
 {
     $module_plug_test_root = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/modules/module_plug_root/");
     $module_plug_test_root->newSubdir("blocks")->touch();
     ModulePlug::setRootDir($module_plug_test_root->getPath());
     $plug = new ModulePlug(new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/fakeroot/modules/ecommerce/cart/"));
     $plug->add("js/");
     $plug->add("blocks/test.block.php");
     $f_block = new File("/" . FRAMEWORK_CORE_PATH . "tests/modules/module_plug_root/blocks/test.block.php");
     $this->assertTrue($f_block->exists(), "Il file test.block.php non e' stato copiato!!");
     $f_no_plug = new File("/" . FRAMEWORK_CORE_PATH . "tests/modules/module_plug_root/blocks/no_plug.block.php");
     $this->assertFalse($f_no_plug->exists(), "Il file no_plug.block.php e' stato copiato!!");
     $f_jslib1 = new File("/" . FRAMEWORK_CORE_PATH . "tests/modules/module_plug_root/js/my_js_lib/mylib.js");
     $this->assertTrue($f_jslib1->exists(), "Il file libreria js1 non e' stato copiato!!");
     $f_jslib2 = new File("/" . FRAMEWORK_CORE_PATH . "tests/modules/module_plug_root/js/my_js_lib/mylib2.js");
     $this->assertTrue($f_jslib2->exists(), "Il file libreria js2 non e' stato copiato!!");
     ModulePlug::setRootDir("/");
     $all_module_plug_files = $module_plug_test_root->listFiles();
     foreach ($all_module_plug_files as $ff) {
         $ff->delete(true);
     }
 }
Beispiel #3
0
 static function extract($f, $dir)
 {
     if ($f instanceof File) {
         $source_file = $f;
     } else {
         $source_file = new File($f);
     }
     if ($dir instanceof Dir) {
         $target_dir = $dir;
     } else {
         $target_dir = new Dir($dir);
     }
     $reader = $source_file->openReader();
     $binarydata = $reader->read(3);
     $data = unpack("a3", $binarydata);
     if ($data[1] !== self::FF_ARCHIVE_HEADER) {
         throw new InvalidDataException("Intestazione del file non valida : " . $data[1]);
     }
     $binarydata = $reader->read(2 + 2 + 2);
     $data = unpack("v3", $binarydata);
     if ($data[1] !== self::CURRENT_MAJOR || $data[2] !== self::CURRENT_MINOR || $data[3] !== self::CURRENT_REV) {
         throw new InvalidDataException("Versione del file non supportata!! : " . $data[1] . "-" . $data[2] . "-" . $data[3]);
     }
     //properties
     $binarydata = $reader->read(2);
     $data = unpack("v", $binarydata);
     $properties_length = $data[1];
     if ($properties_length > 0) {
         $binarydata = $reader->read($properties_length);
         $data = unpack("a*", $binarydata);
         $properties = PropertiesUtils::readFromString($data[1], false);
     } else {
         $properties = array();
     }
     //num entries
     $binarydata = $reader->read(2);
     $data = unpack("v", $binarydata);
     $num_entries = $data[1];
     $i = 0;
     while ($i < $num_entries) {
         //entry type
         $binarydata = $reader->read(2);
         $data = unpack("v", $binarydata);
         $entry_type = $data[1];
         //path length
         $binarydata = $reader->read(2);
         $data = unpack("v", $binarydata);
         $path_length = $data[1];
         //path
         $binarydata = $reader->read($path_length);
         $data = unpack("a*", $binarydata);
         $path = $data[1];
         if ($entry_type === self::ENTRY_TYPE_DIR) {
             $d = $target_dir->newSubdir($path);
             $d->touch();
         }
         if ($entry_type === self::ENTRY_TYPE_FILE) {
             //compressed size
             $binarydata = $reader->read(4);
             $data = unpack("V", $binarydata);
             $num_bytes = $data[1];
             //compressed data
             $compressed_file_data = $reader->read($num_bytes);
             $uncompressed_file_data = gzuncompress($compressed_file_data);
             $f = new File($target_dir->getPath() . $path);
             $writer = $f->openWriter();
             $writer->write($uncompressed_file_data);
             $writer->close();
             //sha1 sum
             $sha1_checksum = $reader->read(20);
             if (strcmp($sha1_checksum, sha1_file($f->getFullPath(), true)) !== 0) {
                 throw new InvalidDataException("La somma sha1 non corrisponde per il file : " . $f->getPath());
             }
         }
         $i++;
     }
     $reader->close();
     return true;
 }
Beispiel #4
0
 function testDeleteRecursive()
 {
     $d = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/io/delete_test_dir/");
     $this->assertTrue($d->exists(), "La cartella dal eliminare non esiste!!");
     $this->assertTrue($d->isEmpty(), "La cartella da popolare non e' vuota!!");
     $the_dir = $d->newSubdir("the_dir");
     $blabla = $the_dir->newFile("blabla.ini");
     $blabla->setContent("[section]\n\nchiave=valore\n\n");
     $hidden_test = $the_dir->newSubdir("hidden_test");
     $htaccess = $hidden_test->newFile(".htaccess");
     $htaccess->setContent("RewriteEngine on\n\n");
     $prova = $hidden_test->newFile("prova.txt");
     $prova->setContent("Questo e' un file con un testo di prova");
     $the_dir->delete(true);
     $this->assertFalse($the_dir->exists(), "La directory non e' stata eliminata!!");
     $this->assertTrue($d->isEmpty(), "Il contenuto della cartella non e' stato rimosso completamente!!");
 }
Beispiel #5
0
 function copy($path, $new_name = null)
 {
     if ($path instanceof Dir) {
         $target_dir = $path;
     } else {
         $target_dir = new Dir($path);
     }
     if ($target_dir instanceof Dir) {
         if ($new_name == null) {
             $new_name = $this->getName();
         }
         $copy_dir = $target_dir->newSubdir($new_name);
         $all_files = $this->listFiles();
         foreach ($all_files as $elem) {
             $elem->copy($copy_dir);
         }
     }
 }