Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

JGithubGists first cut (no comments)

  • Loading branch information...
commit ea6153b88c3fc5311b037d3cbdc94e0c9eb2bbec 1 parent 1a8f9cd
@ianmacl authored
View
4 libraries/joomla/client/github.php
@@ -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(
@@ -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) {
View
14 libraries/joomla/client/github/gists.php
@@ -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)
@@ -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;
@@ -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;
}
}
View
147 tests/suite/joomla/client/github/JGitHubGistsTest.php
@@ -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'
);
}
@@ -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'
);
}
@@ -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'
);
}
@@ -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'
);
}
@@ -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'
);
}
@@ -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'
);
}
@@ -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'
);
}
@@ -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.
Something went wrong with that request. Please try again.