Skip to content

Commit

Permalink
Fix file upload and update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Poitrey committed Apr 15, 2010
1 parent cc8a3b8 commit a758876
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
1 change: 1 addition & 0 deletions .fixtures
Submodule .fixtures added at a4a127
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule ".fixtures"]
path = .fixtures
url = git://github.com/dailymotion/cloudkey-fixtures.git
11 changes: 3 additions & 8 deletions CloudKey.php
Expand Up @@ -77,25 +77,20 @@ class CloudKey_File extends CloudKey_Api
{
public function upload_file($file)
{
$result = parent::upload($args);

if ($args === null || !is_array($args) || !isset($args['file']))
{
return $result;
}
$result = parent::upload();

$ch = curl_init();

curl_setopt_array($ch, array
(
CURLOPT_URL => $url,
CURLOPT_URL => $result->url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_CONNECTTIMEOUT => $this->connect_timeout,
CURLOPT_TIMEOUT => $this->response_timeout,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => array('file' => '@' . $args['file']),
CURLOPT_POSTFIELDS => array('file' => '@' . $file),
));

if ($this->proxy !== null)
Expand Down
48 changes: 32 additions & 16 deletions test.php
Expand Up @@ -21,6 +21,8 @@ public static function suite()
$suite->addTestSuite('CloudKey_UserTest');
$suite->addTestSuite('CloudKey_FileTest');
$suite->addTestSuite('CloudKey_MediaTest');
$suite->addTestSuite('CloudKey_MediaMetaTest');
$suite->addTestSuite('CloudKey_MediaAssetTest');
return $suite;
}
}
Expand Down Expand Up @@ -123,7 +125,12 @@ protected function setUp()
$this->markTestSkipped('Missing test configuration');
return;
}
$this->cloudkey = new CloudKey($username, $password);
if (!is_file('.fixtures/video.3gp'))
{
$this->markTestSkipped('Missing fixtures, please do `git submodule init; git submodule update\'');
return;
}
$this->cloudkey = new CloudKey($username, $password, null, 'localhost:8888');
$this->cloudkey->media->reset();
}

Expand Down Expand Up @@ -159,12 +166,15 @@ public function testUploadFile()
$this->assertObjectHasAttribute('size', $media);
$this->assertObjectHasAttribute('name', $media);
$this->assertObjectHasAttribute('url', $media);
$this->assertEquals($media->size, 92545);
$this->assertObjectHasAttribute('hash', $media);
$this->assertObjectHasAttribute('seal', $media);
$this->assertEquals($media->size, filesize('.fixtures/video.3gp'));
$this->assertEquals($media->name, 'video');
$this->assertEquals($media->hash, sha1_file('.fixtures/video.3gp'));
}
}

class CloudKey_MediaTest extends PHPUnit_Framework_TestCase
class CloudKey_MediaTestBase extends PHPUnit_Framework_TestCase
{
protected
$cloudkey = null;
Expand All @@ -188,11 +198,10 @@ public function tearDown()
$this->cloudkey->media->reset();
}
}
}

//
// MEDIA CRUD
//

class CloudKey_MediaTest extends CloudKey_MediaTestBase
{
public function testCreate()
{
$res = $this->cloudkey->media->create();
Expand Down Expand Up @@ -254,11 +263,10 @@ public function testDeleteInvalidMediaId()
{
$this->cloudkey->media->delete(array('id' => 'b87186c84e1b015a0000000'));
}
}

//
// META
//

class CloudKey_MediaMetaTest extends CloudKey_MediaTestBase
{
public function testSetMeta()
{
$media = $this->cloudkey->media->create();
Expand Down Expand Up @@ -382,10 +390,18 @@ public function testRemoveMetaNotFound()
$media = $this->cloudkey->media->create();
$this->cloudkey->media->remove_meta(array('id' => $media->id, 'key' => 'mykey'));
}
}

//
// ASSETS
//

// TODO
class CloudKey_MediaAssetTest extends CloudKey_MediaTestBase
{
public function testSetAsset()
{
$file = $this->cloudkey->file->upload_file('.fixtures/video.3gp');
$media = $this->cloudkey->media->create();
$res = $this->cloudkey->media->set_asset(array('id' => $media->id, 'preset' => 'source', 'url' => $file->url));
$this->assertNull($res);
$res = $this->cloudkey->media->get_asset(array('id' => $media->id, 'preset' => 'source'));
$this->assertObjectHasAttribute('status', $res);
$this->assertEquals($res->status, 'ready');
}
}

0 comments on commit a758876

Please sign in to comment.