diff --git a/classes/API/Google/Profanity.php b/classes/API/Google/Profanity.php index 0e61e59..f2b73e3 100644 --- a/classes/API/Google/Profanity.php +++ b/classes/API/Google/Profanity.php @@ -27,11 +27,12 @@ class API_Google_Profanity * * @usage API_Google_Profanity::check('fuck'); // returns true * @param string $word word to check + * @param string $endpoint the endpoint to call (helps testing) * @return boolean whether or not the word is profanity */ - public static function check($word) + public static function check($word, $endpoint = 'http://www.wdyl.com/profanity?q=') { - $response = json_decode(file_get_contents('http://www.wdyl.com/profanity?q=' . $word), true); + $response = json_decode(file_get_contents($endpoint . $word), true); if ($response == null || !isset($response['response']) || !in_array($response['response'], array('true', 'false'))) { diff --git a/tests/classes/API/Google/ProfanityTest.php b/tests/classes/API/Google/ProfanityTest.php index bcdfe12..aa9b7cc 100644 --- a/tests/classes/API/Google/ProfanityTest.php +++ b/tests/classes/API/Google/ProfanityTest.php @@ -24,6 +24,29 @@ class API_Google_ProfanityTest extends PHPUnit_Framework_TestCase ['cuntface', false], // Unsure why not... ]; } + + /** + * @expectedException Exception + * @expectedExceptionMessage Invalid response from API. + */ + public function testNullResponse() + { + $file = SITE_PATH . 'null-'; + + file_put_contents($file . 'test', null); + + API_Google_Profanity::check('test', $file); + } + + public function testMissingResponse() + { + + } + + public function testInvalidResponse() + { + + } } ?>