Return specific code for duplicate
This commit is contained in:
parent
4690944216
commit
845fe95128
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user