diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 7a7cc186a6d..fe00cf3a4cf 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -125,6 +125,7 @@ class Categorie * @return int -1 : erreur SQL * -2 : nouvel ID inconnu * -3 : categorie invalide + * -4 : category already exists */ function create($user='') { @@ -141,7 +142,7 @@ class Categorie { $this->error=$langs->trans("ImpossibleAddCat"); $this->error.=" : ".$langs->trans("CategoryExistsAtSameLevel"); - return -1; + return -4; } $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label, description,"; @@ -176,7 +177,7 @@ class Categorie if($this->add_fille() < 0) { $this->error=$langs->trans("ImpossibleAssociateCategory"); - return -1; + return -3; } } diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index 24693fdac20..f87a2c29d44 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -129,12 +129,16 @@ class CategorieTest extends PHPUnit_Framework_TestCase $localobject=new Categorie($this->savdb); $localobject->initAsSpecimen(); - $result=$localobject->create($user); + // We create category + $result=$localobject->create($user); $this->assertLessThan($result, 0); print __METHOD__." result=".$result."\n"; - // TODO Add test on error when creating duplicate + // We try to create same category again + $result=$localobject->create($user); + $this->assertLessThan($result, -4); + print __METHOD__." result=".$result."\n"; return $result;