Example #1
0
 /**
  * Test remove()
  *
  * @return void
  */
 public function testRemove()
 {
     $getAllResponse = new Response(200, ['Content-Type' => 'application/json'], file_get_contents(__DIR__ . '/../../assets/LibraryTest_getAll.json'));
     $removeResponse = new Response(200, ['Content-Type' => 'text/plain']);
     $mockedClient = $this->getMockBuilder('\\Seafile\\Client\\Http\\Client')->getMock();
     $mockedClient->method('getConfig')->willReturn('http://example.com/');
     $expectUri = 'http://example.com/repos/some-crazy-id/';
     $expectParams = ['headers' => ['Accept' => "application/json"]];
     // @todo: Test more thoroughly. For example make sure request() gets called with POST twice (a, then b)
     $mockedClient->expects(self::any())->method('request')->with(self::logicalOr(self::equalTo('GET'), self::equalTo('DELETE')))->will(self::returnCallback(function ($method, $uri, $params) use($getAllResponse, $removeResponse, $expectUri, $expectParams) {
         if ($method === 'GET') {
             return $getAllResponse;
         }
         if ($expectUri === $uri && $expectParams === $params) {
             return $removeResponse;
         }
         return new Response(500);
     }));
     /**
      * @var Client $mockedClient
      */
     $libraryResource = new Library($mockedClient);
     $lib = new \Seafile\Client\Type\Library();
     $lib->id = 'some-crazy-id';
     self::assertTrue($libraryResource->remove($lib->id));
 }
Example #2
0
 *   "baseUri": "https://your.seafile-server.example.com",
 *   "testLibId": "ID of an encrypted library",
 *   "testLibPassword": "******"
 * }
 */
$cfgFile = getenv("HOME") . "/.seafile-php-sdk/cfg.json";
if (!is_readable($tokenFile)) {
    throw new Exception($tokenFile . ' is not readable or does not exist.');
}
if (!is_readable($cfgFile)) {
    throw new Exception($cfgFile . ' is not readable or does not exist.');
}
$token = json_decode(file_get_contents($tokenFile));
$cfg = json_decode(file_get_contents($cfgFile));
$client = new Client(['base_uri' => $cfg->baseUri, 'debug' => true, 'handler' => $stack, 'headers' => ['Content-Type' => 'application/json', 'Authorization' => 'Token ' . $token->token]]);
$libraryResource = new Library($client);
$directoryResource = new Directory($client);
$fileResource = new File($client);
// get all libraries available
$logger->log(Logger::INFO, "#################### Getting all libraries");
$libs = $libraryResource->getAll();
foreach ($libs as $lib) {
    printf("Name: %s, ID: %s, is encrypted: %s\n", $lib->name, $lib->id, $lib->encrypted ? 'YES' : 'NO');
}
$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) {
Example #3
0
 *   "baseUri": "https://your.seafile-server.example.com",
 *   "testLibId": "ID of an encrypted library",
 *   "testLibPassword": "******"
 * }
 */
$cfgFile = getenv("HOME") . "/.seafile-php-sdk/cfg.json";
if (!is_readable($tokenFile)) {
    throw new Exception($tokenFile . ' is not readable or does not exist.');
}
if (!is_readable($cfgFile)) {
    throw new Exception($cfgFile . ' is not readable or does not exist.');
}
$token = json_decode(file_get_contents($tokenFile));
$cfg = json_decode(file_get_contents($cfgFile));
$client = new Client(['base_uri' => $cfg->baseUri, 'debug' => true, 'handler' => $stack, 'headers' => ['Content-Type' => 'application/json', 'Authorization' => 'Token ' . $token->token]]);
$libraryResource = new Library($client);
$directoryResource = new Directory($client);
$fileResource = new File($client);
$starredFileResource = new StarredFile($client);
// get all starred files
$logger->log(Logger::INFO, "#################### Getting all starred files");
$dirItems = $starredFileResource->getAll();
if (!empty($dirItems)) {
    foreach ($dirItems as $dirItem) {
        var_dump($dirItem);
    }
    $logger->log(Logger::INFO, "#################### Unstarring files...");
    foreach ($dirItems as $dirItem) {
        $lib = $libraryResource->getById($dirItem->repo);
        $starredFileResource->unstar($lib, $dirItem);
    }