Permalink
Browse files

Added some unit tests.

  • Loading branch information...
1 parent d5d79a1 commit 50ed6ab1a091a045c1d26fdfdd4202325d9b0eed @ezarko committed Jul 12, 2012
Showing with 31 additions and 1 deletion.
  1. +1 −0 coderwall2.info
  2. +3 −1 coderwall2.module
  3. +27 −0 coderwall2.test
View
@@ -2,3 +2,4 @@ name = Coderwall2
description = The Coderwall module provides integration with the Coderwall service, allowing you to display Coderwall achievements on your site.
package = Other
core = 7.x
+files[] = coderwall2.test
View
@@ -160,7 +160,9 @@ function theme_badges($variables) {
function _coderwall2_get_data($username) {
$url = "http://coderwall.com/$username.json?source=jqcw";
$response = drupal_http_request($url);
- return json_decode($response->data, TRUE);
+ if ($response->code == 200) {
+ return json_decode($response->data, TRUE);
+ }
}
function _coderwall2_logo() {
View
@@ -0,0 +1,27 @@
+<?php
+class CoderwallTestCase extends DrupalUnitTestCase {
+ public static function getInfo() {
+ // Note: getInfo() strings should not be translated.
+ return array(
+ 'name' => 'Coderwall unit tests',
+ 'description' => 'Test that Coderwall works properly.',
+ 'group' => 'Coderwall',
+ );
+ }
+
+ function testAPI() {
+ $result = _coderwall2_get_data(NULL);
+ $this->assertNull($result);
+
+ $result = _coderwall2_get_data('');
+ $this->assertNull($result);
+
+ $result = _coderwall2_get_data('dmnsdklcvsdkj');
+ $this->assertNull($result);
+
+ $result = _coderwall2_get_data('ezarko');
+ $this->assertNotNull($result);
+ $this->assertEqual($result['username'], 'ezarko');
+ }
+}
+?>

0 comments on commit 50ed6ab

Please sign in to comment.