Esempio n. 1
0
 /**
  * Test getAll() with directory path
  *
  * @return void
  */
 public function testGetAllWithDir()
 {
     $rootDir = '/' . uniqid('test_', true);
     $response = new Response(200, ['Content-Type' => 'application/json'], file_get_contents(__DIR__ . '/../../assets/DirectoryTest_getAll.json'));
     $mockedClient = $this->getMockBuilder('\\Seafile\\Client\\Http\\Client')->getMock();
     $mockedClient->method('getConfig')->willReturn('http://example.com/');
     $mockedClient->expects($this->once())->method('request')->with(self::equalTo('GET'), self::equalTo('http://example.com/repos/some-crazy-id/dir/'), self::equalTo(['query' => ['p' => $rootDir]]))->willReturn($response);
     /**
      * @var Client $mockedClient
      */
     $directoryResource = new Directory($mockedClient);
     $lib = new Library();
     $lib->id = 'some-crazy-id';
     $directoryResource->getAll($lib, $rootDir);
 }
Esempio n. 2
0
}
$libId = $cfg->testLibId;
// get specific library
$logger->log(Logger::INFO, "#################### Getting lib with ID " . $libId);
$lib = $libraryResource->getById($libId);
$lib->password = $cfg->testLibPassword;
// library is encrypted and thus we provide a password
if ($lib->encrypted) {
    $success = $libraryResource->decrypt($libId, ['query' => ['password' => $cfg->testLibPassword]]);
    $logger->log(Logger::INFO, "#################### Decrypting library " . $libId . ' was ' . ($success ? '' : 'un') . 'successful');
} else {
    $logger->log(Logger::INFO, "#################### Library is not encrypted: " . $libId);
}
// list library
$logger->log(Logger::INFO, "#################### Listing items of that library...");
$items = $directoryResource->getAll($lib);
$logger->log(Logger::INFO, sprintf("\nGot %d items", count($items)));
foreach ($items as $item) {
    printf("%s: %s (%d bytes)\n\n", $item->type, $item->name, $item->size);
}
$logger->log(Logger::INFO, "#################### Done listing items of that library.");
if (count($items) > 0) {
    // download first file
    $saveTo = './downloaded_' . $items[0]->name;
    if (file_exists($saveTo)) {
        unlink($saveTo);
    }
    switch ($items[0]->type) {
        case 'file':
            $logger->log(Logger::INFO, "#################### Downloading file '" . $items[0]->name . "' to '" . $saveTo);
            $downloadResponse = $fileResource->downloadFromDir($lib, $items[0], $saveTo, '/');