Added an injectable endpoint

Allows for injecting endpoints to simulate poor responses while still testing
the responses from the actual endpoint.
This commit is contained in:
Joshua Sherman 2014-01-11 19:07:29 -05:00
parent abe73f66a4
commit 5d7f3a0e5a
2 changed files with 26 additions and 2 deletions

View file

@ -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')))
{