Skip to content

Commit

Permalink
Track Resource download feature and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
njasm committed Apr 5, 2015
1 parent 7f954d4 commit fb08f69
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Soundcloud/Resource/Track.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

class Track extends AbstractResource
{

public function download($download = true)
{
$this->isNewLogicalException(true, "Resource is new.");

$trackID = $this->get('id');
return $this->sc->download($trackID, $download);
}

public function save()
{

Expand Down
22 changes: 22 additions & 0 deletions tests/Resource/TrackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class TrackTest extends \PHPUnit_Framework_TestCase
{
use \Njasm\Soundcloud\Tests\MocksTrait, \Njasm\Soundcloud\Tests\ReflectionsTrait;

/** @var Track */
protected $track;

Expand Down Expand Up @@ -42,6 +44,26 @@ public function testUnserialize()
$this->assertFalse($this->track->isNew());
}

public function testDownloadNewResource()
{
$this->setExpectedException('\LogicException');
$this->track->download();
}

public function testDownload()
{
$data = 'BIG_TRACK_DATA';
$response = $this->getResponseMock('bodyRaw', function() use ($data) { return $data; });
$request = $this->getRequestMock($response);
$factory = $this->getFactoryMock($request, $response);
$reflectedFactory = $this->reflectProperty(Soundcloud::instance(), 'factory');
$reflectedFactory->setValue(Soundcloud::instance(), $factory);

$this->track->set('id', 1);
$response = $this->track->download();
$this->assertEquals("BIG_TRACK_DATA", $response->bodyRaw());
}

public function testSaveUpdateDelete()
{
$this->assertNull($this->track->save());
Expand Down

0 comments on commit fb08f69

Please sign in to comment.