示例#1
0
 /**
  * Test create()
  *
  * @dataProvider dataProviderCreate
  *
  * @param array $data Test data
  *
  * @return void
  */
 public function testCreate(array $data)
 {
     $headers = ['Content-Type' => 'text/plain'];
     if (!empty($data['Location'])) {
         $headers['Location'] = $data['Location'];
     }
     $createResponse = new Response($data['createResponseCode'], $headers);
     $mockedClient = $this->getMockBuilder('\\Seafile\\Client\\Http\\Client')->getMock();
     $mockedClient->expects(self::any())->method('request')->with('PUT')->willReturn($createResponse);
     /**
      * @var Client $mockedClient
      */
     $sharedLinkResource = new SharedLink($mockedClient);
     $sharedLinkType = new SharedLinkType();
     $sharedLinkType->url = 'https://seafile.example.com/f/abc/';
     $libraryType = new LibraryType();
     $libraryType->id = 'decaf-deadbeef-dad';
     if (is_null($data['returnType'])) {
         self::assertNull($sharedLinkResource->create($libraryType, '/abc', 123, SharedLinkType::SHARE_TYPE_DOWNLOAD, 'pa55word'));
     } else {
         self::assertInstanceOf($data['returnType'], $sharedLinkResource->create($libraryType, '/abc', 123, SharedLinkType::SHARE_TYPE_DOWNLOAD, 'pa55word'));
     }
 }
示例#2
0
 * }
 */
$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);
$sharedLinkResource = new SharedLink($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
$success = $libraryResource->decrypt($libId, ['query' => ['password' => $cfg->testLibPassword]]);
// upload a Hello World file and random file name (note: this seems not to work at this time when you are not logged into the Seafile web frontend).
$newFilename = './Seafile-PHP-SDK_Test_Upload.txt';