Example #1
0
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
require_once '../fts/utils.php';
/* steal fts utils ;) */
require_once 'lib/StorageClient/StorageClient.class.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'testUtils.php';
/* generate some random names in order to be reasonably sure they don't exist yet */
$fileName = 'demoFileName.txt';
$otherFileName = 'otherDemoFileName.txt';
$dirName = 'demoDirectory';
$otherDirName = 'otherDemoDirectory';
// $dbg = TRUE;
$dbg = FALSE;
$storageProvider = array('displayName' => 'Test Server', 'apiUrl' => 'http://localhost/filetrader/fts', 'consumerKey' => '12345', 'consumerSecret' => '54321');
$sc = new StorageClient($storageProvider);
$sc->performDecode(TRUE);
handleResponse("ping " . $storageProvider['apiUrl'], $dbg, $sc->call("pingServer"));
handleNegativeResponse("mkdir {$dirName}/{$otherDirName}", $dbg, $sc->call("createDirectory", array('relativePath' => "{$dirName}/{$otherDirName}"), "POST"));
handleResponse("mkdir {$dirName}", $dbg, $sc->call("createDirectory", array('relativePath' => $dirName), "POST"));
handleResponse("mkdir {$dirName}/{$otherDirName}", $dbg, $sc->call("createDirectory", array('relativePath' => "{$dirName}/{$otherDirName}"), "POST"));
handleNegativeResponse("mkdir {$dirName}/{$otherDirName}/.test", $dbg, $sc->call("createDirectory", array('relativePath' => "{$dirName}/{$otherDirName}/.test"), "POST"));
handleNegativeResponse("mkdir ../test", $dbg, $sc->call("createDirectory", array('relativePath' => "../test"), "POST"));
handleNegativeResponse("setdesc {$fileName}", $dbg, $sc->call('setDescription', array('relativePath' => $fileName, 'fileDescription' => 'Hello World'), "POST"));
handleNegativeResponse("getdesc {$fileName}", $dbg, $sc->call('getDescription', array('relativePath' => $fileName), "POST"));
/* upload a file, use random name, but actually send COPYING as it is
 * there anyway... */
$r = handleResponse("utoken {$fileName}", $dbg, $sc->call("getUploadToken", array('relativePath' => $fileName, 'fileSize' => filesize("COPYING")), "POST"));
handleResponse("ufile {$fileName}", $dbg, uploadFile($r->uploadLocation, "COPYING", 1024));
handleResponse("setdesc {$fileName}", $dbg, $sc->call('setDescription', array('relativePath' => $fileName, 'fileDescription' => "'Hello World'"), "POST"));
$d = handleResponse("getdesc {$fileName}", $dbg, $sc->call('getDescription', array('relativePath' => $fileName), "POST"));
if ($d->fileDescription !== "'Hello World'") {