Exemple #1
0
        default:
            $logger->log(Logger::INFO, "#################### Not downloading '" . $items[0]->name . "' because it's not a file.");
            break;
    }
}
// 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 = tempnam('.', 'Seafile-PHP-SDK_Test_Upload_');
rename($newFilename, $newFilename . '.txt');
$newFilename .= '.txt';
file_put_contents($newFilename, 'Hello World: ' . date('Y-m-d H:i:s'));
$logger->log(Logger::INFO, "#################### Uploading file " . $newFilename);
$response = $fileResource->upload($lib, $newFilename, '/');
// get file info
$logger->log(Logger::INFO, "#################### Getting file details on " . $newFilename);
$result = $fileResource->getFileDetail($lib, '/' . basename($newFilename));
// Update file
$logger->log(Logger::INFO, "#################### Power napping 10s before updating the file...");
sleep(10);
file_put_contents($newFilename, ' - UPDATED!', FILE_APPEND);
$response = $fileResource->update($lib, $newFilename, '/');
$result = unlink($newFilename);
// Create dir structure
$logger->log(Logger::INFO, "#################### Recursively create directory structure...");
$parentDir = '/';
// Create directory within this folder
$directory = 'a/b/c/d/e/f/g/h/i';
// directory structure
$recursive = true;
// recursive will create parentDir if not already existing
$success = $directoryResource->create($lib, $directory, $parentDir, $recursive);
print PHP_EOL . 'Done' . PHP_EOL;
 /**
  * Test create() recursively
  *
  * @return void
  */
 public function testCreateRecursive()
 {
     $getAllResponse = new Response(200, ['Content-Type' => 'application/json'], file_get_contents(__DIR__ . '/../../assets/DirectoryTest_getAll.json'));
     $mkdirResponse = new Response(201, ['Content-Type' => 'text/plain']);
     $mockedClient = $this->getMockBuilder('\\Seafile\\Http\\Client')->getMock();
     $mockedClient->method('getConfig')->willReturn('http://example.com/');
     // @todo: Test more thoroughly. For example make sure request() gets called with POST twice (a, then b)
     $mockedClient->expects($this->any())->method('request')->with($this->logicalOr($this->equalTo('GET'), $this->equalTo('POST')))->will($this->returnCallback(function ($method) use($getAllResponse, $mkdirResponse) {
         if ($method === 'GET') {
             return $getAllResponse;
         }
         return $mkdirResponse;
     }));
     /**
      * @var Client $mockedClient
      */
     $directoryResource = new Directory($mockedClient);
     $lib = new \Seafile\Type\Library();
     $lib->id = 'some-crazy-id';
     $this->assertTrue($directoryResource->create($lib, 'a/b', '/', true));
 }