feat: JSON API

This commit is contained in:
Pierre Rudloff 2018-03-20 12:02:21 +01:00
parent 618fb8416a
commit 74505cea57
4 changed files with 84 additions and 1 deletions

View file

@ -147,7 +147,7 @@ class FrontControllerTest extends TestCase
}
/**
* Assert that calling controller function with these parameters returns an HTTP redirect.
* Assert that calling controller function with these parameters returns an HTTP 500 error.
*
* @param string $request Controller function to call
* @param array $params Query parameters
@ -160,6 +160,20 @@ class FrontControllerTest extends TestCase
$this->assertTrue($this->getRequestResult($request, $params, $config)->isServerError());
}
/**
* Assert that calling controller function with these parameters returns an HTTP 400 error.
*
* @param string $request Controller function to call
* @param array $params Query parameters
* @param Config $config Custom config
*
* @return void
*/
private function assertRequestIsClientError($request, array $params = [], Config $config = null)
{
$this->assertTrue($this->getRequestResult($request, $params, $config)->isClientError());
}
/**
* Test the constructor.
*
@ -539,6 +553,36 @@ class FrontControllerTest extends TestCase
);
}
/**
* Test the json() function without the URL parameter.
*
* @return void
*/
public function testJsonWithoutUrl()
{
$this->assertRequestIsClientError('json');
}
/**
* Test the json() function.
*
* @return void
*/
public function testJson()
{
$this->assertRequestIsOk('json', ['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU']);
}
/**
* Test the json() function with an error.
*
* @return void
*/
public function testJsonWithError()
{
$this->assertRequestIsServerError('json', ['url' => 'http://example.com/foo']);
}
/**
* Test the locale() function.
*