/** @test */ function testPlainDirCache() { $f = new Dir("/test/cache_test/cc/"); $this->assertFalse($f->exists(), "La directory della cache esiste già!!"); $cache = new FlatDirCache($f); $this->assertFalse($f->exists(), "La directory della cache esiste già!!"); $cache->init(); $this->assertTrue($f->exists(), "La directory della cache non è stata creata!!"); $this->assertFalse($cache->has_key("prova"), "La chiave prova esiste!!"); $cache->set("prova", "Hello!! "); $this->assertTrue($cache->has_key("prova"), "La chiave prova non esiste!!"); $this->assertEquals("Hello!! ", $cache->get("prova"), "Il valore salvato non corrisponde!!"); $this->assertFalse($cache->has_key("12345"), "La chiave 12345 esiste!!"); $cache->set("12345", "Hello11!! "); $this->assertTrue($cache->has_key("12345"), "La chiave 12345 non esiste!!"); $this->assertEquals("Hello11!! ", $cache->get("12345"), "Il valore salvato non corrisponde!!"); $cache->set("prova", "New content for prova key"); $this->assertTrue($cache->has_key("prova"), "La chiave prova non esiste!!"); $this->assertEquals("New content for prova key", $cache->get("prova"), "Il valore salvato non corrisponde!!"); $cache->delete_key("12345"); $this->assertFalse($cache->has_key("12345"), "La chiave 12345 esiste!!"); $this->assertTrue($cache->has_key("prova"), "La chiave prova non esiste!!"); $cache->garbage_collect(); $this->assertFalse($cache->has_key("12345"), "La chiave 12345 esiste!!"); $this->assertTrue($cache->has_key("prova"), "La chiave prova non esiste!!"); $cache->set_entry_expire_time(1); $this->assertEquals(1, $cache->get_entry_expire_time()); sleep(5); $this->assertFalse($cache->has_key("12345"), "La chiave 12345 esiste!!"); $this->assertFalse($cache->has_key("prova"), "La chiave prova non esiste!!"); $cache->set_entry_expire_time(FlatDirCache::DEFAULT_ENTRY_EXPIRE_TIME); $cache->set("prova", "Hello!! "); $cache->set("12345", "Hello11!! "); $cache->clean_cache(); $this->assertFalse($cache->has_key("prova"), "La chiave prova non esiste!!"); $this->assertFalse($cache->has_key("12345"), "La chiave 12345 non esiste!!"); try { $cache->get("prova"); $this->fail(); } catch (IOException $ex) { } try { $cache->get("12345"); $this->fail(); } catch (IOException $ex) { } $cache->set_garbage_collection_interval(5); $this->assertEquals(5, $cache->get_garbage_collection_interval(), "L'intervallo di garbage collection non corrisponde!!'"); $v = "another content!\"£\$%&/()=?'ì^*é[]@#ù-_.:,;'"; $v2 = "" . $v; $cache->set("newkey", $v); $this->assertEquals($v2, $cache->get("newkey"), "Il valore nella cache non corrisponde!!"); $cache->delete_key("newkey"); $this->assertFalse($cache->has_key("newkey"), "La chiave newkey non è stata eliminata!!"); $f->delete(); $this->assertFalse($f->exists(), "La directory della cache non è stata eliminata!!"); }
/** * Execute the command. * * @return void */ public function handle() { $available_lang_dir = new Dir("/resources/lang/"); if ($available_lang_dir->exists()) { $this->info("Available languages :"); $this->info(""); $folds = $available_lang_dir->listFolders(); foreach ($folds as $f) { $this->info("[" . $f->getName() . "]"); } } else { $this->warn("Localization directory " . $available_lang_dir->getPath() . " does not exists!!"); } $hidden_lang_dir = new Dir("/storage/app/hidden_lang/"); $this->info(""); if ($hidden_lang_dir->exists()) { $this->info("Hidden languages :"); $this->info(""); $folds = $hidden_lang_dir->listFolders(); foreach ($folds as $f) { $this->info("[" . $f->getName() . "]"); } } else { $this->info("No hidden localizations found."); } }
/** * Execute the command. * * @return void */ public function handle() { $lang = $this->getNameArgument(); // $target = new Dir("/resources/lang/" . $lang); if ($target->exists()) { $hide_dir = new Dir("/storage/app/hidden_langs"); if (!$hide_dir->exists()) { $this->info("Hidden languages storage dir created."); $hide_dir->touch(); } $target->moveTo($hide_dir); $this->info("Language " . $lang . " hidden succesfully."); } else { $this->error("Language " . $lang . " not found."); } }
/** * Execute the command. * * @return void */ public function handle() { $lang = $this->getNameArgument(); // $target = new Dir("/storage/app/hidden_langs/" . $lang); if ($target->exists()) { $show_dir = new Dir("/resources/lang/"); $target->moveTo($show_dir); $this->info("Language " . $lang . " reenabled succesfully."); $check_dir_delete_if_empty = new Dir("/storage/app/hidden_langs"); if ($check_dir_delete_if_empty->isEmpty()) { $check_dir_delete_if_empty->delete(); $this->info("Hidden languages storage dir deleted (empty)."); } } else { $this->error("Language " . $lang . " not found."); } }
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); } }
function testDeleteRecursive() { $d = new Dir("/test/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(); $this->assertFalse($the_dir->exists(), "La directory non e' stata eliminata!!"); $this->assertTrue($d->isEmpty(), "Il contenuto della cartella non e' stato rimosso completamente!!"); }