Update http bestChoice to support the priority

Add unittests


git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5802 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-12-06 14:57:38 +00:00
parent 92ba3bb1c3
commit df20f6c372
2 changed files with 83 additions and 10 deletions

55
Tests/httpTest.php Normal file
View File

@@ -0,0 +1,55 @@
<?php
/** DomFramework - Tests
* @package domframework
* @author Dominique Fournier <dominique@fournier38.fr>
*/
/** Test the http.php file */
class httpTest extends PHPUnit_Framework_TestCase
{
/** bestChoice : exact existing entry
*/
public function testBestChoice1 ()
{
$http = new http ();
$res = $http->bestChoice (
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
array ("application/xml"), "text/html");
$this->assertSame ($res, "application/xml");
}
/** bestChoice : Generic catch.
* Use default value
*/
public function testBestChoice2 ()
{
$http = new http ();
$res = $http->bestChoice (
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
array ("text/plain"), "text/html");
$this->assertSame ($res, "text/html");
}
/** bestChoice : no solution : use the default value
*/
public function testBestChoice3 ()
{
$http = new http ();
$res = $http->bestChoice (
"text/html,application/xhtml+xml,application/xml;q=0.9",
array ("text/plain"), "text/html");
$this->assertSame ($res, "text/html");
}
/** bestChoice : invalid entry (end with comma). Continue without error and
* skip the bad choices
*/
public function testBestChoice4 ()
{
$http = new http ();
$res = $http->bestChoice (
"text/html,application/xhtml+xml,application/xml;q=0.9,",
array ("text/plain"), "text/html");
$this->assertSame ($res, "text/html");
}
}