Skip to content

Commit

Permalink
JGithubGists first cut (no comments)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian MacLennan committed Nov 13, 2011
1 parent 1a8f9cd commit ea6153b
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 20 deletions.
4 changes: 2 additions & 2 deletions libraries/joomla/client/github.php
Expand Up @@ -71,7 +71,7 @@ public function __get($name)
}
}

public function sendRequest($url, $data = array(), $method = 'get', $options = array())
public function sendRequest($url, $method = 'get', $data = array(), $options = array())
{
// $this->http = new JHttp;
$curl_options = array(
Expand All @@ -82,7 +82,7 @@ public function sendRequest($url, $data = array(), $method = 'get', $options = a
CURLOPT_USERAGENT => 'JGithub',
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
CURLINFO_HEADER_OUT = true
CURLINFO_HEADER_OUT => true
);

switch ($method) {
Expand Down
14 changes: 7 additions & 7 deletions libraries/joomla/client/github/gists.php
Expand Up @@ -109,7 +109,7 @@ public function create($files, $public = false, $description = null)
$gist->description = $description;
}

return $this->connector->sendRequest('/gists', $gist, 'post')->body;
return $this->connector->sendRequest('/gists', 'post', $gist)->body;
}

public function edit($id, $files, $description = null)
Expand All @@ -121,22 +121,22 @@ public function edit($id, $files, $description = null)
$gist->description = $description;
}

return $this->connector->sendRequest('/gists/'.(int)$id, $gist, 'patch')->body;
return $this->connector->sendRequest('/gists/'.(int)$id, 'patch', $gist)->body;
}

public function star($id)
{
return $this->connector->sendRequest('/gists/'.(int)$id.'/star', null, 'put')->body;
return $this->connector->sendRequest('/gists/'.(int)$id.'/star', 'put')->body;
}

public function unstar($id)
{
return $this->connector->sendRequest('/gists/'.(int)$id.'/star', null, 'delete')->body;
return $this->connector->sendRequest('/gists/'.(int)$id.'/star', 'delete')->body;
}

public function isStarred($id)
{
$response = $this->connector->sendRequest('/gists/'.(int)$id.'/star', null);
$response = $this->connector->sendRequest('/gists/'.(int)$id.'/star');

if ($response->code == '204') {
return true;
Expand All @@ -147,11 +147,11 @@ public function isStarred($id)

public function fork($id)
{
return $this->connector->sendRequest('/gists/'.(int)$id.'/fork', null, 'post')->body;
return $this->connector->sendRequest('/gists/'.(int)$id.'/fork', 'put')->body;
}

public function delete($id)
{
return $this->connector->sendRequest('/gists/'.(int)$id, null, 'delete')->body;
return $this->connector->sendRequest('/gists/'.(int)$id, 'delete')->body;
}
}
147 changes: 136 additions & 11 deletions tests/suite/joomla/client/github/JGitHubGistsTest.php
Expand Up @@ -92,7 +92,7 @@ public function testGetAll()

$this->assertThat(
$gists->getAll(),
$this->equalTo($returnData),
$this->equalTo('Returned Data'),
'Get gists not called with the proper arguments'
);
}
Expand All @@ -117,7 +117,7 @@ public function testGetByUser()

$this->assertThat(
$gists->getByUser('testUser'),
$this->equalTo($returnData),
$this->equalTo('Returned Data'),
'Get gists by user not called with the proper arguments'
);
}
Expand All @@ -142,7 +142,7 @@ public function testGetPublic()

$this->assertThat(
$gists->getPublic(),
$this->equalTo($returnData),
$this->equalTo('Returned Data'),
'Get public gists not called with the proper arguments'
);
}
Expand All @@ -167,7 +167,7 @@ public function testGetStarred()

$this->assertThat(
$gists->getStarred(),
$this->equalTo($returnData),
$this->equalTo('Returned Data'),
'Get starred gists not called with the proper arguments'
);
}
Expand All @@ -192,7 +192,7 @@ public function testGet()

$this->assertThat(
$gists->get(54),
$this->equalTo($returnData),
$this->equalTo('Returned Data'),
'Get not called with the proper arguments'
);
}
Expand All @@ -218,12 +218,12 @@ public function testCreate()

$connector->expects($this->once())
->method('sendRequest')
->with('/gists', $gist, 'post')
->with('/gists', 'post', $gist)
->will($this->returnValue($returnData));

$this->assertThat(
$gists->create(array('file1.txt' => 'This is a file'), true, 'My Gist Rocks'),
$this->equalTo($returnData),
$this->equalTo('Returned Data'),
'Create not called with the proper arguments'
);
}
Expand All @@ -248,12 +248,12 @@ public function testEdit()

$connector->expects($this->once())
->method('sendRequest')
->with('/gists/65', $gist, 'patch')
->with('/gists/65', 'patch', $gist)
->will($this->returnValue($returnData));

$this->assertThat(
$gists->edit(65, array('file1.txt' => 'This is a file'), true, 'My Gist Rocks More'),
$this->equalTo($returnData),
$this->equalTo('Returned Data'),
'Edit not called with the proper arguments'
);
}
Expand All @@ -273,14 +273,139 @@ public function testStar()

$connector->expects($this->once())
->method('sendRequest')
->with('/gists/65/star', null, 'put')
->with('/gists/65/star', 'put')
->will($this->returnValue($returnData));

$this->assertThat(
$gists->star(65),
$this->equalTo($returnData),
$this->equalTo(''),
'star not called with the proper arguments'
);
}

/**
* Tests the unstar method
*/
public function testUnstar()
{
$connector = $this->getMock('sendRequest', array('sendRequest'));

$gists = new JGithubGists($connector);

$returnData = new stdClass;
$returnData->code = 204;
$returnData->body = '';

$connector->expects($this->once())
->method('sendRequest')
->with('/gists/65/star', 'delete')
->will($this->returnValue($returnData));

$this->assertThat(
$gists->unstar(65),
$this->equalTo(''),
'unstar not called with the proper arguments'
);
}

/**
* Tests the isStarred method when the gist is starred
*/
public function testIsStarredTrue()
{
$connector = $this->getMock('sendRequest', array('sendRequest'));

$gists = new JGithubGists($connector);

$returnData = new stdClass;
$returnData->code = 204;
$returnData->body = '';

$connector->expects($this->once())
->method('sendRequest')
->with('/gists/65/star')
->will($this->returnValue($returnData));

$this->assertThat(
$gists->isStarred(65),
$this->equalTo(true),
'isStarred not called with the proper arguments'
);
}

/**
* Tests the isStarred method when the gist is not starred
*/
public function testIsStarredFalse()
{
$connector = $this->getMock('sendRequest', array('sendRequest'));

$gists = new JGithubGists($connector);

$returnData = new stdClass;
$returnData->code = 404;
$returnData->body = '';

$connector->expects($this->once())
->method('sendRequest')
->with('/gists/65/star')
->will($this->returnValue($returnData));

$this->assertThat(
$gists->isStarred(65),
$this->equalTo(false),
'isStarred not called with the proper arguments'
);
}

/**
* Tests the fork method
*/
public function testFork()
{
$connector = $this->getMock('sendRequest', array('sendRequest'));

$gists = new JGithubGists($connector);

$returnData = new stdClass;
$returnData->code = 201;
$returnData->body = 'Response Body';

$connector->expects($this->once())
->method('sendRequest')
->with('/gists/65/fork', 'put')
->will($this->returnValue($returnData));

$this->assertThat(
$gists->fork(65),
$this->equalTo('Response Body'),
'fork not called with the proper arguments'
);
}

/**
* Tests the delete method
*/
public function testDelete()
{
$connector = $this->getMock('sendRequest', array('sendRequest'));

$gists = new JGithubGists($connector);

$returnData = new stdClass;
$returnData->code = 204;
$returnData->body = '';

$connector->expects($this->once())
->method('sendRequest')
->with('/gists/65', 'delete')
->will($this->returnValue($returnData));

$this->assertThat(
$gists->delete(65),
$this->equalTo(''),
'delete not called with the proper arguments'
);
}

}

0 comments on commit ea6153b

Please sign in to comment.