From abadd2b803482c21d6b7897ae7305e377e7c2d79 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 6 Dec 2020 19:33:43 +0100 Subject: [PATCH] Clean phpunit --- htdocs/product/class/product.class.php | 18 +++++----- test/phpunit/ProductTest.php | 50 +++----------------------- 2 files changed, 13 insertions(+), 55 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index dfb5a7e042a..740a2633a80 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -915,8 +915,8 @@ class Product extends CommonObject $this->db->begin(); - // Check name is required and codes are ok or unique. - // If error, this->errors[] is filled + $result = 0; + // Check name is required and codes are ok or unique. If error, this->errors[] is filled if ($action != 'add') { $result = $this->verify(); // We don't check when update called during a create because verify was already done } @@ -2186,14 +2186,14 @@ class Product extends CommonObject if ($resql) { $result = $this->db->fetch_array($resql); - $this->multiprices[$i] = $result["price"]; - $this->multiprices_ttc[$i] = $result["price_ttc"]; - $this->multiprices_min[$i] = $result["price_min"]; - $this->multiprices_min_ttc[$i] = $result["price_min_ttc"]; - $this->multiprices_base_type[$i] = $result["price_base_type"]; + $this->multiprices[$i] = $result ? $result["price"] : null; + $this->multiprices_ttc[$i] = $result ? $result["price_ttc"] : null; + $this->multiprices_min[$i] = $result ? $result["price_min"] : null; + $this->multiprices_min_ttc[$i] = $result ? $result["price_min_ttc"] : null; + $this->multiprices_base_type[$i] = $result ? $result["price_base_type"] : null; // Next two fields are used only if PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL is on - $this->multiprices_tva_tx[$i] = $result["tva_tx"]; // TODO Add ' ('.$result['default_vat_code'].')' - $this->multiprices_recuperableonly[$i] = $result["recuperableonly"]; + $this->multiprices_tva_tx[$i] = $result ? $result["tva_tx"].($result ? ' ('.$result['default_vat_code'].')' : '') : null; + $this->multiprices_recuperableonly[$i] = $result ? $result["recuperableonly"] : null; // Price by quantity /* diff --git a/test/phpunit/ProductTest.php b/test/phpunit/ProductTest.php index 650d8a93e37..e574d3e1d20 100644 --- a/test/phpunit/ProductTest.php +++ b/test/phpunit/ProductTest.php @@ -147,7 +147,7 @@ class ProductTest extends PHPUnit\Framework\TestCase $result=$localobject->create($user); print __METHOD__." result=".$result."\n"; - $this->assertLessThanOrEqual($result, 0); + $this->assertLessThanOrEqual($result, 0, "Creation of product"); return $result; } @@ -177,31 +177,6 @@ class ProductTest extends PHPUnit\Framework\TestCase return $localobject; } - /** - * testProductGetArboEachProd - * - * @return void - */ - public function testProductGetArboEachProd() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; - - /* - $localobject=new Product($db); - $localobject->fetch(208); - $localobject->get_sousproduits_arbo(); - $localobject->get_arbo_each_prod(); - - var_dump($localobject->res); print (json_encode($localobject->res)); exit; - */ - - return; - } - /** * testProductUpdate * @@ -219,7 +194,8 @@ class ProductTest extends PHPUnit\Framework\TestCase $langs=$this->savlangs; $db=$this->savdb; - $localobject->note='New note after update'; + $localobject->note_public = 'New public note after update'; + $localobject->note_private = 'New private note after update'; $result=$localobject->update($localobject->id, $user); print __METHOD__." id=".$localobject->id." result=".$result."\n"; $this->assertLessThan($result, 0); @@ -244,6 +220,7 @@ class ProductTest extends PHPUnit\Framework\TestCase $langs=$this->savlangs; $db=$this->savdb; + $this->assertEquals(0, 0); return $localobject->id; } @@ -274,23 +251,4 @@ class ProductTest extends PHPUnit\Framework\TestCase return $result; } - - /** - * testProductStatic - * - * @return void - */ - public function testProductStatic() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; - - $localobject=new Product($db); - - - return; - } }