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:
parent
abe73f66a4
commit
5d7f3a0e5a
2 changed files with 26 additions and 2 deletions
|
@ -27,11 +27,12 @@ class API_Google_Profanity
|
||||||
*
|
*
|
||||||
* @usage API_Google_Profanity::check('fuck'); // returns true
|
* @usage API_Google_Profanity::check('fuck'); // returns true
|
||||||
* @param string $word word to check
|
* @param string $word word to check
|
||||||
|
* @param string $endpoint the endpoint to call (helps testing)
|
||||||
* @return boolean whether or not the word is profanity
|
* @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')))
|
if ($response == null || !isset($response['response']) || !in_array($response['response'], array('true', 'false')))
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,29 @@ class API_Google_ProfanityTest extends PHPUnit_Framework_TestCase
|
||||||
['cuntface', false], // Unsure why not...
|
['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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue