public function testAppendUri() { $this->assertEquals('a/b/c', Coder::appendUri('a', 'b', 'c')); $this->assertEquals('a/b/c/', Coder::appendUri('a', '/b/', '/c/')); $this->assertEquals('a/b/c/', Coder::appendUri('a/', '/b/', '/c/')); $this->assertEquals('a/b/foo/bar/c/', Coder::appendUri('a/', '/b/foo//bar//', '/c/')); $this->assertEquals('a/c/', Coder::appendUri('a/', '', '/c/')); $this->assertEquals('a/c/', Coder::appendUri('a/', null, '/c/')); $this->assertEquals('a/', Coder::appendUri('a/', null, null)); $this->assertEquals('/v1', Coder::appendUri('/v1', null, null)); $this->assertEquals('/v1', Coder::appendUri('/v1', '')); }
public function testReadRequestBodyFromString() { $grant_list = array(); $grant_list[] = array('grantee' => array(array('id' => 'a0a2fe988a774be08978736ae2a1668b'), array('id' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')), 'permission' => array('FULL_CONTROL')); $bucket = 'no-such-bucket-name'; // Prepare the request body $body = json_encode(array('accessControlList' => $grant_list)); $config = json_decode(__BOS_TEST_CONFIG, true); $client = new HttpClient($config); $path = Coder::appendUri(Bce::URL_PREFIX, $bucket); // Create the bucket $client->sendRequest(HttpMethod::PUT, $path, null, array(), array(), array($this, 'generateAuthorization'), null); // Set bucket acl $response = $client->sendRequest(HttpMethod::PUT, $path, $body, array(), array('acl' => ''), array($this, 'generateAuthorization'), null); $this->assertArrayHasKey('http_headers', $response); $this->assertArrayHasKey('body', $response); $this->assertArrayHasKey('x-bce-request-id', $response['http_headers']); $this->assertArrayHasKey('x-bce-debug-id', $response['http_headers']); $this->assertArrayHasKey('content-length', $response['http_headers']); $this->assertArrayHasKey('date', $response['http_headers']); $this->assertArrayHasKey('server', $response['http_headers']); $this->assertEquals(array(), $response['body']); // Delete the bucket $client->sendRequest(HttpMethod::DELETE, $path, null, array(), array(), array($this, 'generateAuthorization'), null); }
/** * @param mixed $config The http client config. * @param string $bucket_name The bucket name. * @param string $key The object path. * * @return string */ private function getPath($config, $bucket_name = null, $key = null) { return Coder::appendUri(Bce::URL_PREFIX, $bucket_name, $key); }