Ejemplo n.º 1
0
 function testExtractArchive()
 {
     $create_dir = new Dir("/test/zip_test/create/");
     $this->assertTrue($create_dir->exists(), "La directory create non esiste!!");
     $save_dir = new Dir("/test/zip_test/saved/");
     $this->assertTrue($save_dir->exists(), "La directory save non esiste!!");
     $extract_dir = new Dir("/test/zip_test/extract/");
     $this->assertTrue($extract_dir->exists(), "La directory extract non esiste!!");
     $r = $extract_dir->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $extract_dir_files = array_merge($r[0], $r[1]);
     foreach ($extract_dir_files as $f) {
         $f->delete(true);
     }
     $target_file = new File("/test/zip_test/saved/test_archive.zip");
     $this->assertFalse($target_file->exists());
     $dir_to_zip = "/test/zip_test/create/";
     ZipUtils::createArchive($target_file, $dir_to_zip);
     $this->assertTrue($target_file->exists(), "Il file zip non è stato creato!!");
     $this->assertTrue($target_file->getSize() > 0, "Il file creato ha dimensione vuota!!");
     //ora estraggo l'archivio
     $extract_root = "/test/zip_test/extract/";
     ZipUtils::expandArchive($target_file, $extract_root);
     $r = $extract_dir->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $all_elements = array_merge($r[0], $r[1]);
     $this->assertEquals(count($all_elements), 3, "Il numero dei file estratti non corrisponde!!");
     $f1 = new File($extract_root . "my_file_01.php");
     $this->assertTrue($f1->exists(), "Il file my_file_01.php non e' stato estratto!!");
     $this->assertTrue(!$f1->isEmpty(), "Il file my_file_01.php e' vuoto!!");
     //$d1 = new Dir($extract_root."another_dir/");
     //$d2 = new Dir($extract_root."my_subdir/");
     $f2 = new File($extract_root . "another_dir/blabla.ini");
     $this->assertTrue($f2->exists(), "Il file blabla.ini non e' stato estratto!!");
     $this->assertTrue(!$f2->isEmpty(), "Il file blabla.ini e' vuoto!!");
     $r = $save_dir->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $saved_files = array_merge($r[0], $r[1]);
     foreach ($saved_files as $f) {
         $f->delete(true);
     }
     $r = $extract_dir->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $extracted_files = array_merge($r[0], $r[1]);
     foreach ($extracted_files as $f) {
         $f->delete(true);
     }
 }
Ejemplo n.º 2
0
 /**
  * 
  * Recursively inflate the folder into che provided archive, using local_dir as a prefix for archived files.
  * 
  * @param ZipArchive $zip_archive the current archive
  * @param Dir $current_folder the current folder to compress
  * @param string $local_dir the local dir prefix to use for compressed files.
  * 
  * @internal
  */
 private static function recursiveZipFolder($zip_archive, $current_folder, $local_dir)
 {
     $results = $current_folder->listElements();
     $all_elements = array_merge($results[0], $results[1]);
     foreach ($all_elements as $dir_entry) {
         if ($dir_entry->isFile()) {
             $zip_archive->addFile($dir_entry->getFullPath(), $local_dir . $dir_entry->getFullName());
         } else {
             $zip_archive->addEmptyDir($local_dir . $dir_entry->getName() . DS);
             ZipUtils::recursiveZipFolder($zip_archive, $dir_entry, $local_dir . $dir_entry->getName() . DS);
         }
     }
 }
Ejemplo n.º 3
0
 function testCreateStorageOnWrite()
 {
     StorageFactory::setStorageRoot("/test/storage_dir/");
     $d = new Dir("/test/storage_dir/");
     $r = $d->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $all_elements = array_merge($r[0], $r[1]);
     foreach ($all_elements as $f) {
         $f->delete(true);
     }
     $this->assertFalse($d->hasOnlyOneSubdir(), "Lo storage e' gia' presente!!");
     $storage = StorageFactory::getPropertiesStorage("boh", "ciccia");
     $this->assertFalse($storage->exists(), "Lo storage esiste gia'!!");
     $test_props = array("test" => "value", "hello" => "world");
     $storage->add(array("category" => $test_props));
     $this->assertTrue($storage->exists(), "Lo storage non e' stato creato!!");
     $storage->delete();
     $this->assertFalse($storage->exists(), "Lo storage non e' stato eliminato!!");
     $properties = $storage->readAll();
     //readAll
     $this->assertTrue($storage->exists(), "Lo storage non e' stato creato per una lettura!!");
     $this->assertFalse($properties === null, "Il risultato ritornato e' ===null !!");
     $this->assertTrue(is_array($properties), "Il metodo non ha ritornato un array con uno storage inesistente!!");
     $this->assertTrue(count($properties) == 0, "L'array ritornato da una lettura di storage vuoto non e' vuoto!!");
     $storage->delete();
     $storage->remove("blah");
     //remove
     $this->assertTrue($storage->exists(), "Lo storage non e' stato creato per una cancellazione!!");
     $storage->delete();
     $storage->saveAll(array());
     //saveAll
     $this->assertTrue($storage->exists(), "Lo storage non e' stato creato per una cancellazione!!");
     $storage->delete();
     $this->assertFalse($storage->exists(), "Lo storage non e' stato eliminato!!");
     $r = $d->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $all_elements = array_merge($r[0], $r[1]);
     foreach ($all_elements as $f) {
         $f->delete(true);
     }
     StorageFactory::setStorageRoot(StorageFactory::getDefaultStorageRoot());
 }
Ejemplo n.º 4
0
 function testDeleteEmptyWithHidden()
 {
     $d = new Dir("/test/delete_test_dir_empty/the_dir/");
     $this->assertTrue($d->exists(), "La cartella dal eliminare non esiste!!");
     $r = $d->listElements(Dir::MODE_FILES_AND_FOLDERS, Dir::SHOW_HIDDEN_FILES);
     if (count($r[0]) == 0 && count($r[1]) == 0) {
         $d->delete();
         $this->assertFalse($d->exists(), "La cartella dal eliminare e' stata eliminata!!");
     } else {
         $d->delete();
         $this->assertTrue($d->exists(), "La cartella dal eliminare non e' stata eliminata!!");
     }
     $d->touch();
 }