Beispiel #1
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());
 }
Beispiel #2
0
 function __construct(File $f)
 {
     $this->name = $f->getName();
     $file_php_content = $f->getContent();
     $pure_php_content = str_replace("<?php", "", $file_php_content);
     $this->data = eval($pure_php_content);
     $this->flattened = LangGeneratorHelper::flattenKeys($this->data);
 }
 private function hasRoutesCache()
 {
     $routes_cache = new File("/bootstrap/cache/routes.php");
     if (!$routes_cache->exists()) {
         return false;
     }
     return true;
 }
 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();
 }
Beispiel #6
0
 /**
  * 
  * Creates a zip archive with the content of the specified folder and saves it to the specified file name.
  * 
  * @param \Mbcraft\Piol\File|string $save_file The \Piol\File instance or the string to use as save path for the archive.
  * @param \Mbcraft\Piol\Dir|string $folder_to_zip The \Piol\Dir or the string path pointing to a folder with the elements to archive.
  * @param string $local_dir The directory to use to contain the files inside the archive, defaults to archive root ('/').
  *
  * @throws IOException if an input/output error occurs.
  * 
  * @api
  */
 public static function createArchive($save_file, $folder_to_zip, $local_dir = "/")
 {
     $real_save_file = File::asFile($save_file);
     $dir_to_zip = Dir::asDir($folder_to_zip);
     $zip_archive = new \ZipArchive();
     $zip_archive->open($real_save_file->getFullPath(), \ZipArchive::CREATE);
     ZipUtils::recursiveZipFolder($zip_archive, $dir_to_zip, $local_dir);
     $zip_archive->close();
 }
Beispiel #7
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!!");
 }
Beispiel #8
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);
     }
 }
 private function loadRoutes()
 {
     $routes_cache = new File("/bootstrap/cache/routes.php");
     $routes_cache->includeFileOnce();
 }
Beispiel #10
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $f = new File("/storage/logs/laravel.log");
     $f->setContent("");
     $this->info("Log cleared succesfully! The log is now empty.");
 }
 private function check_path($path)
 {
     $f = new File('/public/' . $path);
     return $f->exists();
 }
Beispiel #12
0
 function testReadCsv()
 {
     $f = new File("/test/csv_test/test_dati.csv");
     $reader = $f->openReader();
     $header = $reader->readLine();
     //salto la prima riga
     $this->assertEquals("id;nome;cognome;descrizione", $header, "Le intestazioni del csv non corrispondono!!");
     $values = CsvUtils::read($reader);
     $this->assertEquals("1", $values[0], "Il valore letto non corrisponde!!");
     $this->assertEquals("marco", $values[1], "Il valore letto non corrisponde!!");
     $this->assertEquals("bagnaresi", $values[2], "Il valore letto non corrisponde!!");
     $this->assertEquals("programmatore, curioso", $values[3], "Il valore letto non corrisponde!!");
     $values = CsvUtils::read($reader);
     $this->assertEquals("2", $values[0], "Il valore letto non corrisponde!!");
     $this->assertEquals("federica", $values[1], "Il valore letto non corrisponde!!");
     $this->assertEquals("amarisse", $values[2], "Il valore letto non corrisponde!!");
     $this->assertEquals("segretaria, \"puccettosa\"", $values[3], "Il valore letto non corrisponde!!");
     $values = CsvUtils::read($reader);
     $this->assertEquals("3", $values[0], "Il valore letto non corrisponde!!");
     $this->assertEquals("stefano", $values[1], "Il valore letto non corrisponde!!");
     $this->assertEquals("pelloni", $values[2], "Il valore letto non corrisponde!!");
     $this->assertEquals("'cuoco' e responsabile grafica e web", $values[3], "Il valore letto non corrisponde!!");
 }
Beispiel #13
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();
 }
Beispiel #14
0
    private function savePHPArrayProperties($target_props, File $target_lang_file)
    {
        $header = <<<END_OF_HEADER
<?php

END_OF_HEADER;
        $footer = <<<END_OF_FOOTER


END_OF_FOOTER;
        $full_content = $header . "return " . var_export($target_props, true) . ";" . $footer;
        $target_lang_file->setContent($full_content);
    }
Beispiel #15
0
 /**
  * 
  * Checks if this directory is a parent of the provided child.
  * 
  * @param \Mbcraft\Piol\File|\Mbcraft\Piol\Dir $child
  * @return boolean true if the parameter is a direct child of this directory, false otherwise.
  * 
  * @throws IOException if the child is not a valid File or Dir instance.
  * 
  * @api
  */
 public function isParentOf($child)
 {
     if (!$child instanceof __FileSystemElement) {
         throw new IOException("The provided element is not a valid \\Piol\\File or \\Piol\\Dir.");
     }
     $path_p = $this->getFullPath();
     $path_c = $child->getFullPath();
     //for windows dirs
     $parent_path_c = dirname($path_c) . DIRECTORY_SEPARATOR;
     $parent_path_c = str_replace("\\", DS, $parent_path_c);
     return $parent_path_c == $path_p;
 }
Beispiel #16
0
 function testWriteAndTruncate()
 {
     $f = new File("/test/reader_writer/test_truncate.txt");
     $w = $f->openWriter();
     $w->write("abcdefghij");
     $w->write("1234567890");
     $this->assertEquals($f->getSize(), 20, "La dimensione del file non corrisponde!!");
     $w->truncate(10);
     $this->assertEquals($f->getSize(), 10, "La dimensione del file non corrisponde!!");
     $w->close();
     $r = $f->openReader();
     $st = $r->read(10);
     $this->assertEquals("abcdefghij", $st, "La stringa letta dopo la scrittura non corridponde!!");
     $r->close();
     $f->delete();
 }
Beispiel #17
0
 /**
  * 
  * Save the provided properties to a file. Supports sections inside the properties data.
  * 
  * @param \Mbcraft\Piol\File|string $file the file instance or string path pointing to the properties file.
  * @param mixed $properties properties data as array or nested arrays if contained in sections.
  * @param boolean $process_sections true if sections must be processed inside properties data, false otherwise
  * 
  * @api
  */
 public static function saveToFile($file, $properties, $process_sections)
 {
     $prop_string = self::saveToString($properties, $process_sections);
     $real_file = File::asFile($file);
     if (!$real_file->exists()) {
         $real_file->touch();
     }
     $real_file->setContent($prop_string);
 }
Beispiel #18
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!");
 }