Exemple #1
0
 /**
     @test
 */
 function testBlackHole()
 {
     $f = new File("/test/BlackHoleTest.php");
     $this->assertTrue($f->exists(), "Il file del test non esiste!!");
     $content = $f->getContent();
     $f->delete();
     $this->assertFalse($f->exists(), "Il file del test black hole non e' stato eliminato!!");
     $f->touch();
     $f->setContent($content);
     $this->assertTrue($f->exists(), "Il file del test black hole non e' stato rigenerato!!");
 }
Exemple #2
0
 function testProps()
 {
     $storage_test_root = "/test/storage_dir/";
     StorageFactory::setStorageRoot($storage_test_root);
     $test_file = new File("/test/FilePropsTest.php");
     $this->assertFalse($test_file->hasAttachedStorage(), "Il file ha delle proprieta' con lo storage vuoto!!");
     $storage = $test_file->getAttachedStorage();
     $storage->add(array("test" => array("hello" => 1, "world" => "good")));
     $this->assertTrue($test_file->hasAttachedStorage(), "Il file storage delle proprieta' non e' stato creato!!");
     $sum = md5("/test/");
     //path is calculated using the parent dir
     $store_subdir = "_" . substr($sum, 0, 1);
     $storage_test_root_dir = new Dir($storage_test_root);
     $real_store_dir = $storage_test_root_dir->getUniqueSubdir();
     $r = $real_store_dir->listElements(Dir::MODE_FILES_AND_FOLDERS);
     $props_file_dir = $r[1][0];
     $this->assertEquals($props_file_dir->getName(), $store_subdir, "La directory creata non corrisponde!!");
     $final_stored_path = new File($real_store_dir->getPath() . $props_file_dir->getName() . DS . md5("FilePropsTest.php") . ".ini");
     $this->assertTrue($final_stored_path->exists(), "Il file finale delle props non e' stato trovato!!");
     $test_file->deleteAttachedStorage();
     $this->assertFalse($test_file->hasAttachedStorage(), "Il file delle proprieta' non e' stato eliminato!!");
     $r = $real_store_dir->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());
 }
 private function hasRoutesCache()
 {
     $routes_cache = new File("/bootstrap/cache/routes.php");
     if (!$routes_cache->exists()) {
         return false;
     }
     return true;
 }
Exemple #4
0
 function testReader2()
 {
     $f = new File("/test/reader_writer/non_existent_file.txt");
     $this->assertFalse($f->exists(), "Il file esiste!!");
     try {
         $f->openReader();
         $this->fail();
     } catch (IOException $ex) {
     }
 }
 function testAddEntriesToFile()
 {
     $file = new File("/test/java_xml_properties_dir/test_folder_2/add_props.xml");
     if ($file->exists()) {
         $file->delete();
     }
     JavaXmlPropertiesUtils::addEntriesToFile($file, array("ciao" => 1, "mondo" => 2, 3 => "pluto"));
     $this->assertTrue($file->exists(), "Il file delle properties non è stato creato!!");
     $props = JavaXmlPropertiesUtils::readFromFile($file);
     $this->assertTrue(count($props) == 3, "Il numero delle properties non corrisponde!");
     $this->assertEquals($props["ciao"], 1);
     $this->assertEquals($props["mondo"], 2);
     $this->assertEquals($props[3], "pluto");
     $file->delete();
 }
 function testaddEntriesToFile()
 {
     $file = new File("/test/properties_dir/test_folder_2/add_props.ini");
     if ($file->exists()) {
         $file->delete();
     }
     IniPropertiesUtils::addEntriesToFile($file, true, array("prova" => array("ciao" => 1, "mondo" => 2, 3 => "pluto")));
     $this->assertTrue($file->exists(), "Il file delle properties non è stato creato!!");
     $props = IniPropertiesUtils::readFromFile($file, true);
     $this->assertTrue(count($props) == 1, "Il numero delle properties non corrisponde!");
     $entry = $props["prova"];
     $this->assertTrue(count($entry) == 3, "Il numero delle voci non corrisponde!");
     $this->assertEquals($entry["ciao"], 1);
     $this->assertEquals($entry["mondo"], 2);
     $this->assertEquals($entry[3], "pluto");
     $file->delete();
 }
Exemple #7
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);
     }
 }
Exemple #8
0
 function testAdvancedPrintfWriteThenRead()
 {
     $f = new File("/test/reader_writer/readwrite2.txt");
     //delete test/reader_writer/readwrite2.txt to fix this test failure
     $this->assertFalse($f->exists(), "Il file esiste gia'!!");
     try {
         $writer = $f->openWriter();
         $this->assertTrue($f->exists(), "Il file non e' stato creato!!");
         $this->assertTrue($writer instanceof FileWriter, "L'oggetto non e' del tipo specificato!!");
         $this->assertTrue($writer->isOpen(), "Il writer non e' aperto!!");
         $writer->write("Ciao mondo!!!");
         $writer->printf(" %02d %02d go", 12, 34);
         $writer->close();
         $reader = $f->openReader();
         $line = $reader->read(22);
         $this->assertEquals("Ciao mondo!!! 12 34 go", $line, "I dati letti non corrispondono!! : " . $line);
         $reader->close();
     } catch (Exception $ex) {
         $this->fail("Errore nell'apertura del writer di un file non esistente!!");
     }
     $f->delete();
 }
 private function check_path($path)
 {
     $f = new File('/public/' . $path);
     return $f->exists();
 }
Exemple #10
0
 private function executeFileComparison(File $ref_lang_file, File $target_lang_file)
 {
     if ($target_lang_file->exists()) {
         $this->compareFiles($ref_lang_file, $target_lang_file);
     } else {
         $this->warn("Skipping missing target file : " . $target_lang_file->getPath());
     }
 }
Exemple #11
0
 private function executeFileComparison(File $ref_lang_file, File $target_lang_file)
 {
     if (!$target_lang_file->exists()) {
         $this->info($target_lang_file->getPath() . " does not exist, creating ...");
         $target_lang_file->setContent("<?php \n\n return array(); \n\n");
     }
     $this->compareFiles($ref_lang_file, $target_lang_file);
 }
Exemple #12
0
 function testRenameDirs()
 {
     $d = new Dir("/test/rename_test/dir/");
     $d->touch();
     $this->assertTrue($d->exists(), "La directory non e' stata creata!!");
     $f1 = $d->newFile("my_file.txt");
     $f1->setContent("Ciao!!");
     $this->assertTrue($f1->exists(), "Il file non e' stato creato nella cartella!!");
     @mkdir(__DIR__ . DIRECTORY_SEPARATOR . "rename_test/target/");
     $d2 = new Dir("/test/rename_test/target/");
     $d2->delete();
     $this->assertFalse($d2->exists(), "La directory esiste gia'!!");
     $this->assertTrue($d->rename("target"));
     $this->assertFalse($d->exists(), "La directory non e' stata rinominata con successo!!");
     $this->assertTrue($d2->exists(), "La directory non e' stata rinominata con successo!!");
     $f2 = new File("/test/rename_test/target/my_file.txt");
     $this->assertTrue($f2->exists(), "Il file non e' stato spostato insieme alla directory!!");
     $d3 = new Dir("/test/rename_test/existing_dir/");
     $this->assertFalse($d2->rename("existing_dir"), "Il rename e' stato effettuato su una directory che gia' esiste!!");
     $this->assertFalse($d2->isEmpty(), "La directory non spostata non contiene piu' il suo file!!");
     $this->assertTrue($d3->isEmpty(), "La directory gia' esistente e' stata riempita con pattume!!");
     try {
         $d4 = new Dir("/test/rename_test/another_target/buh/");
         $this->assertFalse($d4->rename("another_target/buh"), "Rename con spostamento andato a buon fine!!");
         $this->fail();
     } catch (IOException $ex) {
     }
     $d2->delete();
 }
Exemple #13
0
 function testCopyFileWithDifficultName()
 {
     $f = new File("test/difficult_names/src/00 - Época\\ Porteño.txt");
     $d = new Dir("test/difficult_names/dest/");
     $f->copy($d);
     $copied = new File("test/difficult_names/dest/00 - Época\\ Porteño.txt");
     $this->assertTrue($copied->exists(), "Il file non è stato copiato correttamente!");
     $copied->delete();
     $this->assertFalse($copied->exists(), "Il file non è stato eliminato correttamente!");
 }