Esempio n. 1
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());
 }
Esempio n. 2
0
 function testRandomRename()
 {
     $d = new Dir("/test/more_dir_tests/");
     $subdir = $d->newRandomSubdir();
     $old_name = $subdir->getFullName();
     $this->assertEquals($old_name, $subdir->getName(), "Il nome non coincide con quello appena ottenuto!!");
     $this->assertEquals($old_name, $subdir->getFullName(), "Il nome non coincide con quello appena ottenuto!!");
     $subdir->randomRename();
     $this->assertFalse($subdir->exists(), "L'oggetto ha aggiornato il suo percorso!!");
     $this->assertTrue($d->hasOnlyOneSubdir(), "La directory non risulta avere una sola sottocartella!!");
     $this->assertEquals($old_name, $subdir->getName(), "Il nome non è stato cambiato!!");
     $this->assertEquals($old_name, $subdir->getFullName(), "Il nome non è stato cambiato!!");
     $subdir2 = $d->getUniqueSubdir();
     $subdir2->delete();
     $this->assertFalse($d->hasOnlyOneSubdir(), "La directory rinominata non è stata eliminata!!");
 }