/** * @dataProvider getDataForPostObjectTest */ public function testGetPostObjectData(array $options, array $expected) { $postObject = new PostObject($this->client, 'foo', $options); $postObject->prepareData(); $this->assertSame($expected['attributes'], $postObject->getFormAttributes()); $this->assertSame($expected['inputs'], $postObject->getFormInputs()); $this->assertSame($expected['policy'], $postObject->getJsonPolicy()); }
public function testPostObjectProducesCorrectParametersForPost() { $key = 'dummy.txt'; // Create the PostObject and fetch the data $post = new PostObject($this->client, $this->bucket); $post->prepareData(); $form = $post->getFormAttributes(); $data = $post->getFormInputs(); // Use Guzzle to simulate a browser POST upload to S3 $http = new Client(array('ssl.certificate_authority' => false)); /** @var $response \Guzzle\Http\Message\Response */ $response = $http->post($form['action'], null, $data)->addPostFiles(array('file' => __DIR__ . DIRECTORY_SEPARATOR . $key))->send(); // Verify that the response is as expected $this->assertEquals(204, $response->getStatusCode()); $this->assertEquals("https://{$this->bucket}.s3.amazonaws.com/{$key}", $response->getLocation()); // Delete the object $this->client->deleteObject(array('Bucket' => $this->bucket, 'Key' => $key)); }