rest : rewrite to support the bestChoice of the user, and to be tested

rest : add tests


git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5803 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-12-06 15:51:40 +00:00
parent df20f6c372
commit 66495ee503
2 changed files with 109 additions and 16 deletions

60
Tests/restTest.php Normal file
View File

@@ -0,0 +1,60 @@
<?php
/** DomFramework
* @package domframework
* @author Dominique Fournier <dominique@fournier38.fr>
*/
/** Test the domframework REST part */
class restTest extends PHPUnit_Framework_TestCase
{
/** No param, JSON by default
*/
public function testChooseType1 ()
{
$rest = new \rest ();
$res = $rest->chooseType ();
$this->assertSame ($res, "json");
}
/** If limited allowedTypes, return the first one as default
*/
public function testChooseType2 ()
{
$rest = new \rest ();
$rest->allowedtypes = array ("xml", "csv");
$res = $rest->chooseType ();
$this->assertSame ($res, "xml");
}
/** Choose by the user specification : exact match
*/
public function testChooseType3 ()
{
$rest = new \rest ();
$_SERVER["HTTP_ACCEPT"] = "text/html,application/xml;q=0.9,*/*;q=0.8";
$res = $rest->chooseType ();
$this->assertSame ($res, "xml");
}
/** Choose by the user specification : generic match
*/
public function testChooseType4 ()
{
$rest = new \rest ();
$_SERVER["HTTP_ACCEPT"] = "text/html;q=0.9,*/*;q=0.8";
$res = $rest->chooseType ();
$this->assertSame ($res, "json");
}
/** Choose by the user specification : generic match with limited allowed
* types
*/
public function testChooseType5 ()
{
$rest = new \rest ();
$rest->allowedtypes = array ("xml", "csv");
$_SERVER["HTTP_ACCEPT"] = "text/html;q=0.9,*/*;q=0.8";
$res = $rest->chooseType ();
$this->assertSame ($res, "xml");
}
}