/** * Test remove() and removeByEmail * * @dataProvider dataProviderRemove * * @param array $data DataProvider data * * @return void */ public function testRemove(array $data) { $baseUri = 'https://example.com/'; $accountType = new AccountType(); $accountType->email = $data['email']; $mockedClient = $this->getMock('\\Seafile\\Client\\Http\\Client', ['delete', 'getConfig']); $mockedClient->expects(self::any())->method('delete')->with($baseUri . 'accounts/' . $accountType->email . '/')->willReturn(new Response(200)); $mockedClient->expects(self::any())->method('getConfig')->with('base_uri')->willReturn($baseUri); /** * @var Client $mockedClient */ $accountResource = new Account($mockedClient); self::assertSame($data['result'], $accountResource->remove($accountType)); // test removeByEmail() in one go self::assertSame($data['result'], $accountResource->removeByEmail($accountType->email)); }
* "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]]); $accountResource = new Account($client); // get API user info $logger->log(Logger::INFO, "#################### Getting API user info"); $accountType = $accountResource->getInfo(); foreach ((array) $accountType as $key => $value) { $logger->log(Logger::INFO, $key . ': ' . $value); } // get all users $logger->log(Logger::INFO, "#################### Get all users"); $accountTypes = $accountResource->getAll(); foreach ($accountTypes as $accountType) { $logger->log(Logger::INFO, $accountType->email); } // create random account $logger->log(Logger::INFO, "#################### Create random account"); $newAccountType = (new AccountType())->fromArray(['email' => uniqid('test-', true) . '@example.com', 'password' => md5(uniqid('t.gif', true)), 'name' => 'Hugh Jazz', 'note' => 'I will not waste chalk', 'storage' => 100000000, 'institution' => 'Duff Beer Inc.']);