mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-12 19:02:35 +01:00
WIP PSR2
This commit is contained in:
@@ -18,9 +18,9 @@
|
||||
|
||||
/**
|
||||
* \file test/phpunit/CategorieTest.php
|
||||
* \ingroup test
|
||||
* \ingroup test
|
||||
* \brief PHPUnit test
|
||||
* \remarks To run this script as CLI: phpunit filename.php
|
||||
* \remarks To run this script as CLI: phpunit filename.php
|
||||
*/
|
||||
|
||||
global $conf,$user,$langs,$db;
|
||||
@@ -30,11 +30,10 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
|
||||
require_once dirname(__FILE__).'/../../htdocs/categories/class/categorie.class.php';
|
||||
require_once dirname(__FILE__).'/../../htdocs/product/class/product.class.php';
|
||||
|
||||
if (empty($user->id))
|
||||
{
|
||||
print "Load permissions for admin user nb 1\n";
|
||||
$user->fetch(1);
|
||||
$user->getrights();
|
||||
if (empty($user->id)) {
|
||||
print "Load permissions for admin user nb 1\n";
|
||||
$user->fetch(1);
|
||||
$user->getrights();
|
||||
}
|
||||
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
@@ -48,70 +47,72 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
*/
|
||||
class CategorieTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $savconf;
|
||||
protected $savuser;
|
||||
protected $savlangs;
|
||||
protected $savdb;
|
||||
protected $savconf;
|
||||
protected $savuser;
|
||||
protected $savlangs;
|
||||
protected $savdb;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* We save global variables into local variables
|
||||
*
|
||||
* @return CategorieTest
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
//$this->sharedFixture
|
||||
global $conf,$user,$langs,$db;
|
||||
$this->savconf=$conf;
|
||||
$this->savuser=$user;
|
||||
$this->savlangs=$langs;
|
||||
$this->savdb=$db;
|
||||
|
||||
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
|
||||
//print " - db ".$db->db;
|
||||
print "\n";
|
||||
}
|
||||
|
||||
// Static methods
|
||||
public static function setUpBeforeClass()
|
||||
/**
|
||||
* Constructor
|
||||
* We save global variables into local variables
|
||||
*
|
||||
* @return CategorieTest
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
|
||||
//$this->sharedFixture
|
||||
global $conf,$user,$langs,$db;
|
||||
$this->savconf=$conf;
|
||||
$this->savuser=$user;
|
||||
$this->savlangs=$langs;
|
||||
$this->savdb=$db;
|
||||
|
||||
print __METHOD__."\n";
|
||||
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
|
||||
//print " - db ".$db->db;
|
||||
print "\n";
|
||||
}
|
||||
|
||||
// Static methods
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
|
||||
|
||||
print __METHOD__."\n";
|
||||
}
|
||||
|
||||
// tear down after class
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$db->rollback();
|
||||
global $conf,$user,$langs,$db;
|
||||
$db->rollback();
|
||||
|
||||
print __METHOD__."\n";
|
||||
print __METHOD__."\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Init phpunit tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
/**
|
||||
* Init phpunit tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
print __METHOD__."\n";
|
||||
print __METHOD__."\n";
|
||||
}
|
||||
/**
|
||||
* End phpunit tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
/**
|
||||
* End phpunit tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
print __METHOD__."\n";
|
||||
print __METHOD__."\n";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,145 +122,145 @@ class CategorieTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testCategorieCreate()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
|
||||
// We create a category
|
||||
$localobject=new Categorie($this->savdb);
|
||||
$localobject->initAsSpecimen();
|
||||
// We create a category
|
||||
$localobject=new Categorie($this->savdb);
|
||||
$localobject->initAsSpecimen();
|
||||
|
||||
// Check it does not exist (return 0)
|
||||
$resultCheck=$localobject->already_exists();
|
||||
print __METHOD__." resultCheck=".$resultCheck."\n";
|
||||
$this->assertEquals(0, $resultCheck);
|
||||
// Check it does not exist (return 0)
|
||||
$resultCheck=$localobject->already_exists();
|
||||
print __METHOD__." resultCheck=".$resultCheck."\n";
|
||||
$this->assertEquals(0, $resultCheck);
|
||||
|
||||
// Create
|
||||
$resultFirstCreate=$localobject->create($user);
|
||||
print __METHOD__." resultFirstCreate=".$resultFirstCreate."\n";
|
||||
$this->assertGreaterThan(0, $resultFirstCreate);
|
||||
// Create
|
||||
$resultFirstCreate=$localobject->create($user);
|
||||
print __METHOD__." resultFirstCreate=".$resultFirstCreate."\n";
|
||||
$this->assertGreaterThan(0, $resultFirstCreate);
|
||||
|
||||
// We try to create another one with same ref
|
||||
$localobject2=new Categorie($this->savdb);
|
||||
$localobject2->initAsSpecimen();
|
||||
// We try to create another one with same ref
|
||||
$localobject2=new Categorie($this->savdb);
|
||||
$localobject2->initAsSpecimen();
|
||||
|
||||
// Check it does exist (return 1)
|
||||
$resultCheck=$localobject2->already_exists();
|
||||
print __METHOD__." resultCheck=".$resultCheck."\n";
|
||||
$this->assertGreaterThan(0, $resultCheck);
|
||||
// Check it does exist (return 1)
|
||||
$resultCheck=$localobject2->already_exists();
|
||||
print __METHOD__." resultCheck=".$resultCheck."\n";
|
||||
$this->assertGreaterThan(0, $resultCheck);
|
||||
|
||||
$resultSecondCreate=$localobject2->create($user);
|
||||
print __METHOD__." result=".$resultSecondCreate."\n";
|
||||
$this->assertEquals(-4, $resultSecondCreate);
|
||||
$resultSecondCreate=$localobject2->create($user);
|
||||
print __METHOD__." result=".$resultSecondCreate."\n";
|
||||
$this->assertEquals(-4, $resultSecondCreate);
|
||||
|
||||
return $resultFirstCreate;
|
||||
return $resultFirstCreate;
|
||||
}
|
||||
|
||||
/**
|
||||
* testCategorieProduct
|
||||
*
|
||||
* @param int $id Id of category
|
||||
* @return int
|
||||
* @param int $id Id of category
|
||||
* @return int
|
||||
*
|
||||
* @depends testCategorieCreate
|
||||
* @depends testCategorieCreate
|
||||
* The depends says test is run only if previous is ok
|
||||
*/
|
||||
public function testCategorieProduct($id)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$localobjecttmp=new Categorie($this->savdb);
|
||||
$localobjecttmp->initAsSpecimen();
|
||||
$localobjecttmp->label='Specimen Category for product';
|
||||
$localobjecttmp->type=0; // product category
|
||||
$catid=$localobjecttmp->create($user);
|
||||
$localobjecttmp=new Categorie($this->savdb);
|
||||
$localobjecttmp->initAsSpecimen();
|
||||
$localobjecttmp->label='Specimen Category for product';
|
||||
$localobjecttmp->type=0; // product category
|
||||
$catid=$localobjecttmp->create($user);
|
||||
|
||||
print __METHOD__." catid=".$catid."\n";
|
||||
$this->assertGreaterThan(0, $catid);
|
||||
|
||||
// Try to create product linked to category
|
||||
$localobject2=new Product($this->savdb);
|
||||
$localobject2->initAsSpecimen();
|
||||
$localobject2->ref.='-CATEG';
|
||||
$localobject2->tva_npr=1;
|
||||
$result=$localobject2->create($user);
|
||||
$cat = new Categorie($this->savdb);
|
||||
$cat->id = $catid;
|
||||
$result=$cat->add_type($localobject2,"product");
|
||||
$localobject2=new Product($this->savdb);
|
||||
$localobject2->initAsSpecimen();
|
||||
$localobject2->ref.='-CATEG';
|
||||
$localobject2->tva_npr=1;
|
||||
$result=$localobject2->create($user);
|
||||
$cat = new Categorie($this->savdb);
|
||||
$cat->id = $catid;
|
||||
$result=$cat->add_type($localobject2,"product");
|
||||
|
||||
print __METHOD__." result=".$result."\n";
|
||||
$this->assertGreaterThan(0, $result);
|
||||
print __METHOD__." result=".$result."\n";
|
||||
$this->assertGreaterThan(0, $result);
|
||||
|
||||
// Get list of categories for product
|
||||
$localcateg=new Categorie($this->savdb);
|
||||
$listofcateg=$localcateg->containing($localobject2->id, 'product', 'label');
|
||||
$this->assertTrue(in_array('Specimen Category for product',$listofcateg), 'Categ not found linked to product when it should');
|
||||
// Get list of categories for product
|
||||
$localcateg=new Categorie($this->savdb);
|
||||
$listofcateg=$localcateg->containing($localobject2->id, 'product', 'label');
|
||||
$this->assertTrue(in_array('Specimen Category for product',$listofcateg), 'Categ not found linked to product when it should');
|
||||
|
||||
return $id;
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* testCategorieFetch
|
||||
*
|
||||
* @param int $id Id of category
|
||||
* @return int
|
||||
* @param int $id Id of category
|
||||
* @return int
|
||||
*
|
||||
* @depends testCategorieProduct
|
||||
* @depends testCategorieProduct
|
||||
* The depends says test is run only if previous is ok
|
||||
*/
|
||||
public function testCategorieFetch($id)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$localobject=new Categorie($this->savdb);
|
||||
$result=$localobject->fetch($id);
|
||||
$localobject=new Categorie($this->savdb);
|
||||
$result=$localobject->fetch($id);
|
||||
|
||||
print __METHOD__." id=".$id." result=".$result."\n";
|
||||
$this->assertGreaterThan(0, $result);
|
||||
return $localobject;
|
||||
print __METHOD__." id=".$id." result=".$result."\n";
|
||||
$this->assertGreaterThan(0, $result);
|
||||
return $localobject;
|
||||
}
|
||||
|
||||
/**
|
||||
* testCategorieUpdate
|
||||
*
|
||||
* @param Category $localobject Category
|
||||
* @return int
|
||||
* @param Category $localobject Category
|
||||
* @return int
|
||||
|
||||
* @depends testCategorieFetch
|
||||
* @depends testCategorieFetch
|
||||
* The depends says test is run only if previous is ok
|
||||
*/
|
||||
public function testCategorieUpdate($localobject)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$localobject->note='New note after update';
|
||||
$result=$localobject->update($user);
|
||||
$localobject->note='New note after update';
|
||||
$result=$localobject->update($user);
|
||||
|
||||
print __METHOD__." id=".$localobject->id." result=".$result."\n";
|
||||
$this->assertGreaterThan(0, $result);
|
||||
return $localobject;
|
||||
print __METHOD__." id=".$localobject->id." result=".$result."\n";
|
||||
$this->assertGreaterThan(0, $result);
|
||||
return $localobject;
|
||||
}
|
||||
|
||||
/**
|
||||
* testCategorieOther
|
||||
*
|
||||
* @param Category $localobject Category
|
||||
* @return int
|
||||
* @param Category $localobject Category
|
||||
* @return int
|
||||
*
|
||||
* @depends testCategorieUpdate
|
||||
* The depends says test is run only if previous is ok
|
||||
@@ -289,50 +290,50 @@ class CategorieTest extends PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* testCategorieDelete
|
||||
*
|
||||
* @param int $id Id of category
|
||||
* @return int
|
||||
* @param int $id Id of category
|
||||
* @return int
|
||||
*
|
||||
* @depends testCategorieOther
|
||||
* The depends says test is run only if previous is ok
|
||||
*/
|
||||
public function testCategorieDelete($id)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$localobject=new Categorie($this->savdb);
|
||||
$result=$localobject->fetch($id);
|
||||
$result=$localobject->delete($user);
|
||||
$localobject=new Categorie($this->savdb);
|
||||
$result=$localobject->fetch($id);
|
||||
$result=$localobject->delete($user);
|
||||
|
||||
print __METHOD__." id=".$id." result=".$result."\n";
|
||||
$this->assertGreaterThan(0, $result);
|
||||
return $result;
|
||||
print __METHOD__." id=".$id." result=".$result."\n";
|
||||
$this->assertGreaterThan(0, $result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* testCategorieStatic
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*
|
||||
* @depends testCategorieDelete
|
||||
*/
|
||||
public function testCategorieStatic()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$localobject=new Categorie($this->savdb);
|
||||
$localobject=new Categorie($this->savdb);
|
||||
$retarray=$localobject->get_full_arbo(3);
|
||||
|
||||
print __METHOD__." retarray size=".count($retarray)."\n";
|
||||
$this->assertTrue(is_array($retarray));
|
||||
return $retarray;
|
||||
print __METHOD__." retarray size=".count($retarray)."\n";
|
||||
$this->assertTrue(is_array($retarray));
|
||||
return $retarray;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user