コード例 #1
0
ファイル: FilePropsTest.php プロジェクト: mbcraft/piol
 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());
 }
コード例 #2
0
ファイル: StorageTest.php プロジェクト: mbcraft/piol
 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());
 }