From 384d40ca01e3bfbc37ab8ef9af6c1ed6613f1575 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 17 Oct 2025 19:39:45 +0200 Subject: [PATCH] phpunit more complete --- htdocs/commande/class/commande.class.php | 6 +++++- htdocs/supplier_proposal/class/supplier_proposal.class.php | 4 ++-- test/phpunit/CommandeTest.php | 3 ++- test/phpunit/SupplierProposalTest.php | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 9619e16923c..5833b5119ba 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -4046,9 +4046,10 @@ class Commande extends CommonOrder * Used to build previews or test instances. * id must be 0 if object instance is a specimen. * + * @param array $param Array of options * @return int */ - public function initAsSpecimen() + public function initAsSpecimen($param = array()) { global $conf, $langs; @@ -4060,6 +4061,9 @@ class Commande extends CommonOrder $sql = "SELECT rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."product"; $sql .= " WHERE entity IN (".getEntity('product').")"; + if (array_key_exists('tosell', $param)) { + $sql .= " AND tosell = ".((int) $param['tosell']); + } $sql .= $this->db->plimit(100); $resql = $this->db->query($sql); diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 93d121371f3..400cddcc3ec 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -2406,8 +2406,8 @@ class SupplierProposal extends CommonObject $sql = "SELECT rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."product"; $sql .= " WHERE entity IN (".getEntity('product').")"; - if (array_key_exists('tosell', $param)) { - $sql .= " AND tosell = ".((int) $param['tosell']); + if (array_key_exists('tobuy', $param)) { + $sql .= " AND tobuy = ".((int) $param['tobuy']); } $sql .= $this->db->plimit(100); diff --git a/test/phpunit/CommandeTest.php b/test/phpunit/CommandeTest.php index b2dddb95951..0128cc418e9 100644 --- a/test/phpunit/CommandeTest.php +++ b/test/phpunit/CommandeTest.php @@ -87,7 +87,8 @@ class CommandeTest extends CommonClassTest $this->assertLessThan($socid, 0, $soc->errorsToString()); $localobject = new Commande($db); - $localobject->initAsSpecimen(); + $param = array('tosell' => 1); + $localobject->initAsSpecimen($param); $localobject->socid = $socid; $result = $localobject->create($user); diff --git a/test/phpunit/SupplierProposalTest.php b/test/phpunit/SupplierProposalTest.php index 21e143bd15c..1936fd464e3 100644 --- a/test/phpunit/SupplierProposalTest.php +++ b/test/phpunit/SupplierProposalTest.php @@ -105,7 +105,7 @@ class SupplierProposalTest extends CommonClassTest $db = $this->savdb; $localobject = new SupplierProposal($db); - $param = array('tosell' => 1); + $param = array('tobuy' => 1); $localobject->initAsSpecimen($param); $result = $localobject->create($user);