2010-04-25 14:19:58 +00:00
|
|
|
<?php
|
2024-11-13 20:21:15 +00:00
|
|
|
/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517)
* NEW: Improve phpunit test coverage for Commande, Propal and Facture
Add line CRUD (addline/updateline/deleteLine) and total-consistency
assertions, reuse the specimen-invariant regression check (previously
only in FactureTest) across all three, and add a new integration test
covering the full Propal -> Commande -> Facture conversion chain
(thirdparty, notes, totals and object_linked propagation).
Two shared assertions were added to CommonClassTest for this:
assertLineTotalsMatchHeader() and assertMatchesFreshSpecimen().
* Update commande.class.php
* FIX PropalCommandeFactureWorkflowTest reads wrong invoice after createFromOrder
Facture::createFromOrder() returns a status flag (1/-1), not the new
invoice id, unlike Commande::createFromProposal(). The test was doing
fetch($result) with $result==1, which happened to no-op locally (no
invoice with rowid=1) but fetched an unrelated invoice in CI, causing
a spurious thirdparty mismatch. Use $facture->id, already set by
create() inside createFromOrder(), like every other caller of this
method does.
2026-08-19 00:35:04 +00:00
|
|
|
* Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
|
2024-11-13 20:21:15 +00:00
|
|
|
* Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
|
|
|
|
|
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
2010-04-25 14:19:58 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 14:36:08 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2010-04-25 14:19:58 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-09-23 19:55:30 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
* or see https://www.gnu.org/
|
2010-04-25 14:19:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2010-08-15 23:19:46 +00:00
|
|
|
* \file test/phpunit/FactureTest.php
|
2015-01-06 16:54:36 +00:00
|
|
|
* \ingroup test
|
2010-10-03 18:53:40 +00:00
|
|
|
* \brief PHPUnit test
|
2015-01-06 16:54:36 +00:00
|
|
|
* \remarks To run this script as CLI: phpunit filename.php
|
2010-04-25 14:19:58 +00:00
|
|
|
*/
|
2010-04-27 08:36:14 +00:00
|
|
|
|
2010-04-26 23:20:14 +00:00
|
|
|
global $conf,$user,$langs,$db;
|
2010-04-25 14:19:58 +00:00
|
|
|
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
|
2014-05-01 22:08:19 +00:00
|
|
|
//require_once 'PHPUnit/Autoload.php';
|
2010-08-15 23:19:46 +00:00
|
|
|
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
|
|
|
|
|
require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture.class.php';
|
2026-01-29 10:25:33 +00:00
|
|
|
require_once dirname(__FILE__).'/../../htdocs/core/modules/modBlockedLog.class.php';
|
2024-02-16 22:26:32 +00:00
|
|
|
require_once dirname(__FILE__).'/CommonClassTest.class.php';
|
2010-04-25 14:19:58 +00:00
|
|
|
|
2015-01-06 16:54:36 +00:00
|
|
|
if (empty($user->id)) {
|
2021-01-14 14:09:08 +00:00
|
|
|
print "Load permissions for admin user nb 1\n";
|
|
|
|
|
$user->fetch(1);
|
2024-11-13 20:21:15 +00:00
|
|
|
$user->loadRights();
|
2010-04-26 23:52:51 +00:00
|
|
|
}
|
2024-02-19 14:28:21 +00:00
|
|
|
$conf->global->MAIN_DISABLE_ALL_MAILS = 1;
|
2010-04-26 23:20:14 +00:00
|
|
|
|
|
|
|
|
|
2010-04-25 14:19:58 +00:00
|
|
|
/**
|
2011-09-23 12:21:00 +00:00
|
|
|
* Class for PHPUnit tests
|
2010-10-26 19:47:19 +00:00
|
|
|
*
|
2010-04-26 23:52:51 +00:00
|
|
|
* @backupGlobals disabled
|
2010-04-25 14:19:58 +00:00
|
|
|
* @backupStaticAttributes enabled
|
2010-04-26 23:52:51 +00:00
|
|
|
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
|
2010-04-25 14:19:58 +00:00
|
|
|
*/
|
2024-02-16 22:26:32 +00:00
|
|
|
class FactureTest extends CommonClassTest
|
2010-04-25 14:19:58 +00:00
|
|
|
{
|
2021-01-14 14:09:08 +00:00
|
|
|
/**
|
|
|
|
|
* setUpBeforeClass
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2022-09-21 15:55:04 +00:00
|
|
|
public static function setUpBeforeClass(): void
|
2021-01-14 14:09:08 +00:00
|
|
|
{
|
2026-01-15 15:05:06 +00:00
|
|
|
self::assertTrue(isModEnabled('invoice'), " module customer invoice must be enabled");
|
2024-03-05 00:12:28 +00:00
|
|
|
self::assertFalse(isModEnabled('ecotaxdeee'), " module ecotaxdeee must not be enabled");
|
2024-03-03 16:08:57 +00:00
|
|
|
parent::setUpBeforeClass();
|
2026-01-29 10:25:33 +00:00
|
|
|
|
|
|
|
|
// We disable module blocked log to avoid interference with tests
|
|
|
|
|
global $db;
|
|
|
|
|
$blockedlogmodule = new modBlockedLog($db);
|
|
|
|
|
$blockedlogmodule->remove();
|
2021-01-14 14:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* testFactureCreate
|
|
|
|
|
*
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function testFactureCreate()
|
|
|
|
|
{
|
|
|
|
|
global $conf,$user,$langs,$db;
|
2024-02-19 14:28:21 +00:00
|
|
|
$conf = $this->savconf;
|
|
|
|
|
$user = $this->savuser;
|
|
|
|
|
$langs = $this->savlangs;
|
|
|
|
|
$db = $this->savdb;
|
2021-01-14 14:09:08 +00:00
|
|
|
|
2024-02-19 14:28:21 +00:00
|
|
|
$localobject = new Facture($db);
|
2021-01-14 14:09:08 +00:00
|
|
|
$localobject->initAsSpecimen();
|
2024-02-19 14:28:21 +00:00
|
|
|
$result = $localobject->create($user);
|
2021-01-14 14:09:08 +00:00
|
|
|
$this->assertLessThan($result, 0);
|
|
|
|
|
print __METHOD__." result=".$result."\n";
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* testFactureFetch
|
|
|
|
|
*
|
|
|
|
|
* @param int $id Id invoice
|
|
|
|
|
* @return int
|
|
|
|
|
*
|
|
|
|
|
* @depends testFactureCreate
|
|
|
|
|
* The depends says test is run only if previous is ok
|
|
|
|
|
*/
|
|
|
|
|
public function testFactureFetch($id)
|
|
|
|
|
{
|
|
|
|
|
global $conf,$user,$langs,$db;
|
2024-02-19 14:28:21 +00:00
|
|
|
$conf = $this->savconf;
|
|
|
|
|
$user = $this->savuser;
|
|
|
|
|
$langs = $this->savlangs;
|
|
|
|
|
$db = $this->savdb;
|
2021-01-14 14:09:08 +00:00
|
|
|
|
2024-02-19 14:28:21 +00:00
|
|
|
$localobject = new Facture($db);
|
|
|
|
|
$result = $localobject->fetch($id);
|
2021-01-14 14:09:08 +00:00
|
|
|
|
|
|
|
|
$this->assertLessThan($result, 0);
|
|
|
|
|
print __METHOD__." id=".$id." result=".$result."\n";
|
NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517)
* NEW: Improve phpunit test coverage for Commande, Propal and Facture
Add line CRUD (addline/updateline/deleteLine) and total-consistency
assertions, reuse the specimen-invariant regression check (previously
only in FactureTest) across all three, and add a new integration test
covering the full Propal -> Commande -> Facture conversion chain
(thirdparty, notes, totals and object_linked propagation).
Two shared assertions were added to CommonClassTest for this:
assertLineTotalsMatchHeader() and assertMatchesFreshSpecimen().
* Update commande.class.php
* FIX PropalCommandeFactureWorkflowTest reads wrong invoice after createFromOrder
Facture::createFromOrder() returns a status flag (1/-1), not the new
invoice id, unlike Commande::createFromProposal(). The test was doing
fetch($result) with $result==1, which happened to no-op locally (no
invoice with rowid=1) but fetched an unrelated invoice in CI, causing
a spurious thirdparty mismatch. Use $facture->id, already set by
create() inside createFromOrder(), like every other caller of this
method does.
2026-08-19 00:35:04 +00:00
|
|
|
|
|
|
|
|
// Specimen lines are built from real products picked at random (see Facture::initAsSpecimen), so the
|
|
|
|
|
// exact line count is not stable (a kit/BOM product can expand into extra lines) - only check totals coherence.
|
|
|
|
|
$this->assertNotEmpty($localobject->lines);
|
|
|
|
|
$this->assertLineTotalsMatchHeader($localobject, 'after fetch');
|
|
|
|
|
|
2021-01-14 14:09:08 +00:00
|
|
|
return $localobject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* testFactureFetch
|
|
|
|
|
*
|
2021-02-10 07:47:22 +00:00
|
|
|
* @param Facture $localobject Invoice
|
2021-01-14 14:09:08 +00:00
|
|
|
* @return int
|
|
|
|
|
*
|
|
|
|
|
* @depends testFactureFetch
|
|
|
|
|
* The depends says test is run only if previous is ok
|
|
|
|
|
*/
|
|
|
|
|
public function testFactureUpdate($localobject)
|
|
|
|
|
{
|
|
|
|
|
global $conf,$user,$langs,$db;
|
2024-02-19 14:28:21 +00:00
|
|
|
$conf = $this->savconf;
|
|
|
|
|
$user = $this->savuser;
|
|
|
|
|
$langs = $this->savlangs;
|
|
|
|
|
$db = $this->savdb;
|
2021-01-14 14:09:08 +00:00
|
|
|
|
|
|
|
|
$this->changeProperties($localobject);
|
2024-02-19 14:28:21 +00:00
|
|
|
$result = $localobject->update($user);
|
2021-01-14 14:09:08 +00:00
|
|
|
|
|
|
|
|
print __METHOD__." id=".$localobject->id." result=".$result."\n";
|
|
|
|
|
$this->assertLessThan($result, 0);
|
|
|
|
|
return $localobject;
|
|
|
|
|
}
|
|
|
|
|
|
NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517)
* NEW: Improve phpunit test coverage for Commande, Propal and Facture
Add line CRUD (addline/updateline/deleteLine) and total-consistency
assertions, reuse the specimen-invariant regression check (previously
only in FactureTest) across all three, and add a new integration test
covering the full Propal -> Commande -> Facture conversion chain
(thirdparty, notes, totals and object_linked propagation).
Two shared assertions were added to CommonClassTest for this:
assertLineTotalsMatchHeader() and assertMatchesFreshSpecimen().
* Update commande.class.php
* FIX PropalCommandeFactureWorkflowTest reads wrong invoice after createFromOrder
Facture::createFromOrder() returns a status flag (1/-1), not the new
invoice id, unlike Commande::createFromProposal(). The test was doing
fetch($result) with $result==1, which happened to no-op locally (no
invoice with rowid=1) but fetched an unrelated invoice in CI, causing
a spurious thirdparty mismatch. Use $facture->id, already set by
create() inside createFromOrder(), like every other caller of this
method does.
2026-08-19 00:35:04 +00:00
|
|
|
/**
|
|
|
|
|
* testFactureAddLine
|
|
|
|
|
*
|
|
|
|
|
* @param Facture $localobject Invoice
|
|
|
|
|
* @return array{0:Facture,1:int} Invoice and id of the line added
|
|
|
|
|
*
|
|
|
|
|
* @depends testFactureUpdate
|
|
|
|
|
* The depends says test is run only if previous is ok
|
|
|
|
|
*/
|
|
|
|
|
public function testFactureAddLine($localobject)
|
|
|
|
|
{
|
|
|
|
|
global $conf,$user,$langs,$db;
|
|
|
|
|
$conf = $this->savconf;
|
|
|
|
|
$user = $this->savuser;
|
|
|
|
|
$langs = $this->savlangs;
|
|
|
|
|
$db = $this->savdb;
|
|
|
|
|
|
|
|
|
|
$localobject->fetch_thirdparty();
|
|
|
|
|
$beforelinecount = count($localobject->lines);
|
|
|
|
|
$beforetotalht = (float) $localobject->total_ht;
|
|
|
|
|
|
|
|
|
|
$lineid = $localobject->addline('PHPUnit addline test', 100, 2, 20); // 2 x 100 HT at 20% VAT = 200 HT / 40 VAT / 240 TTC
|
|
|
|
|
|
|
|
|
|
print __METHOD__." id=".$localobject->id." lineid=".$lineid."\n";
|
|
|
|
|
$this->assertGreaterThan(0, $lineid, $localobject->errorsToString());
|
|
|
|
|
|
|
|
|
|
$localobject->fetch($localobject->id);
|
|
|
|
|
$this->assertCount($beforelinecount + 1, $localobject->lines);
|
|
|
|
|
$this->assertEqualsWithDelta($beforetotalht + 200, (float) $localobject->total_ht, 0.01, 'total_ht not updated after addline');
|
|
|
|
|
$this->assertLineTotalsMatchHeader($localobject, 'after addline');
|
|
|
|
|
|
|
|
|
|
return array($localobject, $lineid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* testFactureUpdateLine
|
|
|
|
|
*
|
|
|
|
|
* @param array{0:Facture,1:int} $params Invoice and id of the line to update
|
|
|
|
|
* @return array{0:Facture,1:int} Invoice and id of the line updated
|
|
|
|
|
*
|
|
|
|
|
* @depends testFactureAddLine
|
|
|
|
|
* The depends says test is run only if previous is ok
|
|
|
|
|
*/
|
|
|
|
|
public function testFactureUpdateLine($params)
|
|
|
|
|
{
|
|
|
|
|
global $conf,$user,$langs,$db;
|
|
|
|
|
$conf = $this->savconf;
|
|
|
|
|
$user = $this->savuser;
|
|
|
|
|
$langs = $this->savlangs;
|
|
|
|
|
$db = $this->savdb;
|
|
|
|
|
|
|
|
|
|
list($localobject, $lineid) = $params;
|
|
|
|
|
$beforelinecount = count($localobject->lines);
|
|
|
|
|
$beforetotalht = (float) $localobject->total_ht;
|
|
|
|
|
|
|
|
|
|
$result = $localobject->updateline($lineid, 'PHPUnit addline test', 100, 3, 0, '', '', 20); // qty 2 -> 3, so +100 HT / +20 VAT / +120 TTC
|
|
|
|
|
|
|
|
|
|
print __METHOD__." id=".$localobject->id." lineid=".$lineid." result=".$result."\n";
|
|
|
|
|
$this->assertGreaterThan(0, $result, $localobject->errorsToString());
|
|
|
|
|
|
|
|
|
|
$localobject->fetch($localobject->id);
|
|
|
|
|
$this->assertCount($beforelinecount, $localobject->lines);
|
|
|
|
|
$this->assertEqualsWithDelta($beforetotalht + 100, (float) $localobject->total_ht, 0.01, 'total_ht not updated after updateline');
|
|
|
|
|
$this->assertLineTotalsMatchHeader($localobject, 'after updateline');
|
|
|
|
|
|
|
|
|
|
return array($localobject, $lineid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* testFactureDeleteLine
|
|
|
|
|
*
|
|
|
|
|
* @param array{0:Facture,1:int} $params Invoice and id of the line to delete
|
|
|
|
|
* @return Facture
|
|
|
|
|
*
|
|
|
|
|
* @depends testFactureUpdateLine
|
|
|
|
|
* The depends says test is run only if previous is ok
|
|
|
|
|
*/
|
|
|
|
|
public function testFactureDeleteLine($params)
|
|
|
|
|
{
|
|
|
|
|
global $conf,$user,$langs,$db;
|
|
|
|
|
$conf = $this->savconf;
|
|
|
|
|
$user = $this->savuser;
|
|
|
|
|
$langs = $this->savlangs;
|
|
|
|
|
$db = $this->savdb;
|
|
|
|
|
|
|
|
|
|
list($localobject, $lineid) = $params;
|
|
|
|
|
$beforelinecount = count($localobject->lines);
|
|
|
|
|
$beforetotalht = (float) $localobject->total_ht;
|
|
|
|
|
|
|
|
|
|
$result = $localobject->deleteLine($lineid);
|
|
|
|
|
|
|
|
|
|
print __METHOD__." id=".$localobject->id." lineid=".$lineid." result=".$result."\n";
|
|
|
|
|
$this->assertGreaterThan(0, $result, $localobject->errorsToString());
|
|
|
|
|
|
|
|
|
|
$localobject->fetch($localobject->id);
|
|
|
|
|
// Back to the original specimen lines, with the same totals
|
|
|
|
|
$this->assertCount($beforelinecount - 1, $localobject->lines);
|
|
|
|
|
$this->assertEqualsWithDelta($beforetotalht - 300, (float) $localobject->total_ht, 0.01, 'total_ht not updated after deleteLine');
|
|
|
|
|
$this->assertLineTotalsMatchHeader($localobject, 'after deleteLine');
|
|
|
|
|
|
|
|
|
|
return $localobject;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-14 14:09:08 +00:00
|
|
|
/**
|
|
|
|
|
* testFactureValid
|
|
|
|
|
*
|
2021-02-10 07:47:22 +00:00
|
|
|
* @param Facture $localobject Invoice
|
NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517)
* NEW: Improve phpunit test coverage for Commande, Propal and Facture
Add line CRUD (addline/updateline/deleteLine) and total-consistency
assertions, reuse the specimen-invariant regression check (previously
only in FactureTest) across all three, and add a new integration test
covering the full Propal -> Commande -> Facture conversion chain
(thirdparty, notes, totals and object_linked propagation).
Two shared assertions were added to CommonClassTest for this:
assertLineTotalsMatchHeader() and assertMatchesFreshSpecimen().
* Update commande.class.php
* FIX PropalCommandeFactureWorkflowTest reads wrong invoice after createFromOrder
Facture::createFromOrder() returns a status flag (1/-1), not the new
invoice id, unlike Commande::createFromProposal(). The test was doing
fetch($result) with $result==1, which happened to no-op locally (no
invoice with rowid=1) but fetched an unrelated invoice in CI, causing
a spurious thirdparty mismatch. Use $facture->id, already set by
create() inside createFromOrder(), like every other caller of this
method does.
2026-08-19 00:35:04 +00:00
|
|
|
* @return Facture
|
2021-01-14 14:09:08 +00:00
|
|
|
*
|
NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517)
* NEW: Improve phpunit test coverage for Commande, Propal and Facture
Add line CRUD (addline/updateline/deleteLine) and total-consistency
assertions, reuse the specimen-invariant regression check (previously
only in FactureTest) across all three, and add a new integration test
covering the full Propal -> Commande -> Facture conversion chain
(thirdparty, notes, totals and object_linked propagation).
Two shared assertions were added to CommonClassTest for this:
assertLineTotalsMatchHeader() and assertMatchesFreshSpecimen().
* Update commande.class.php
* FIX PropalCommandeFactureWorkflowTest reads wrong invoice after createFromOrder
Facture::createFromOrder() returns a status flag (1/-1), not the new
invoice id, unlike Commande::createFromProposal(). The test was doing
fetch($result) with $result==1, which happened to no-op locally (no
invoice with rowid=1) but fetched an unrelated invoice in CI, causing
a spurious thirdparty mismatch. Use $facture->id, already set by
create() inside createFromOrder(), like every other caller of this
method does.
2026-08-19 00:35:04 +00:00
|
|
|
* @depends testFactureDeleteLine
|
2021-01-14 14:09:08 +00:00
|
|
|
* The depends says test is run only if previous is ok
|
|
|
|
|
*/
|
|
|
|
|
public function testFactureValid($localobject)
|
|
|
|
|
{
|
|
|
|
|
global $conf,$user,$langs,$db;
|
2024-02-19 14:28:21 +00:00
|
|
|
$conf = $this->savconf;
|
|
|
|
|
$user = $this->savuser;
|
|
|
|
|
$langs = $this->savlangs;
|
|
|
|
|
$db = $this->savdb;
|
2021-01-14 14:09:08 +00:00
|
|
|
|
2026-01-29 10:25:33 +00:00
|
|
|
// Force to default setup
|
|
|
|
|
$conf->global->FAC_FORCE_DATE_VALIDATION = 0;
|
|
|
|
|
$conf->global->INVOICE_CHECK_POSTERIOR_DATE = 0;
|
|
|
|
|
|
2024-02-19 14:28:21 +00:00
|
|
|
$result = $localobject->validate($user);
|
2021-01-14 14:09:08 +00:00
|
|
|
print __METHOD__." id=".$localobject->id." result=".$result."\n";
|
|
|
|
|
|
|
|
|
|
$this->assertLessThan($result, 0);
|
|
|
|
|
|
NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517)
* NEW: Improve phpunit test coverage for Commande, Propal and Facture
Add line CRUD (addline/updateline/deleteLine) and total-consistency
assertions, reuse the specimen-invariant regression check (previously
only in FactureTest) across all three, and add a new integration test
covering the full Propal -> Commande -> Facture conversion chain
(thirdparty, notes, totals and object_linked propagation).
Two shared assertions were added to CommonClassTest for this:
assertLineTotalsMatchHeader() and assertMatchesFreshSpecimen().
* Update commande.class.php
* FIX PropalCommandeFactureWorkflowTest reads wrong invoice after createFromOrder
Facture::createFromOrder() returns a status flag (1/-1), not the new
invoice id, unlike Commande::createFromProposal(). The test was doing
fetch($result) with $result==1, which happened to no-op locally (no
invoice with rowid=1) but fetched an unrelated invoice in CI, causing
a spurious thirdparty mismatch. Use $facture->id, already set by
create() inside createFromOrder(), like every other caller of this
method does.
2026-08-19 00:35:04 +00:00
|
|
|
// Test everything is still the same as a freshly built specimen with the same mutation applied
|
|
|
|
|
// (catches unwanted field changes introduced by update()/validate())
|
|
|
|
|
$this->assertMatchesFreshSpecimen(
|
2018-05-27 13:04:12 +00:00
|
|
|
$localobject,
|
NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517)
* NEW: Improve phpunit test coverage for Commande, Propal and Facture
Add line CRUD (addline/updateline/deleteLine) and total-consistency
assertions, reuse the specimen-invariant regression check (previously
only in FactureTest) across all three, and add a new integration test
covering the full Propal -> Commande -> Facture conversion chain
(thirdparty, notes, totals and object_linked propagation).
Two shared assertions were added to CommonClassTest for this:
assertLineTotalsMatchHeader() and assertMatchesFreshSpecimen().
* Update commande.class.php
* FIX PropalCommandeFactureWorkflowTest reads wrong invoice after createFromOrder
Facture::createFromOrder() returns a status flag (1/-1), not the new
invoice id, unlike Commande::createFromProposal(). The test was doing
fetch($result) with $result==1, which happened to no-op locally (no
invoice with rowid=1) but fetched an unrelated invoice in CI, causing
a spurious thirdparty mismatch. Use $facture->id, already set by
create() inside createFromOrder(), like every other caller of this
method does.
2026-08-19 00:35:04 +00:00
|
|
|
function ($specimen) {
|
|
|
|
|
$this->changeProperties($specimen);
|
|
|
|
|
},
|
2018-05-27 13:04:12 +00:00
|
|
|
array(
|
NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517)
* NEW: Improve phpunit test coverage for Commande, Propal and Facture
Add line CRUD (addline/updateline/deleteLine) and total-consistency
assertions, reuse the specimen-invariant regression check (previously
only in FactureTest) across all three, and add a new integration test
covering the full Propal -> Commande -> Facture conversion chain
(thirdparty, notes, totals and object_linked propagation).
Two shared assertions were added to CommonClassTest for this:
assertLineTotalsMatchHeader() and assertMatchesFreshSpecimen().
* Update commande.class.php
* FIX PropalCommandeFactureWorkflowTest reads wrong invoice after createFromOrder
Facture::createFromOrder() returns a status flag (1/-1), not the new
invoice id, unlike Commande::createFromProposal(). The test was doing
fetch($result) with $result==1, which happened to no-op locally (no
invoice with rowid=1) but fetched an unrelated invoice in CI, causing
a spurious thirdparty mismatch. Use $facture->id, already set by
create() inside createFromOrder(), like every other caller of this
method does.
2026-08-19 00:35:04 +00:00
|
|
|
'newref', 'oldcopy', 'oldref', 'id', 'lines', 'line', 'client', 'thirdparty', 'brouillon', 'fk_user_author', 'fk_user_modif', 'user_modification_id', 'date_creation', 'date_validation', 'datem', 'date_modification',
|
|
|
|
|
'ref', 'statut', 'status', 'paye', 'ref', 'actiontypecode', 'actionmsg2', 'actionmsg', 'mode_reglement', 'cond_reglement',
|
2020-12-13 12:34:21 +00:00
|
|
|
'cond_reglement_doc', 'modelpdf',
|
NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517)
* NEW: Improve phpunit test coverage for Commande, Propal and Facture
Add line CRUD (addline/updateline/deleteLine) and total-consistency
assertions, reuse the specimen-invariant regression check (previously
only in FactureTest) across all three, and add a new integration test
covering the full Propal -> Commande -> Facture conversion chain
(thirdparty, notes, totals and object_linked propagation).
Two shared assertions were added to CommonClassTest for this:
assertLineTotalsMatchHeader() and assertMatchesFreshSpecimen().
* Update commande.class.php
* FIX PropalCommandeFactureWorkflowTest reads wrong invoice after createFromOrder
Facture::createFromOrder() returns a status flag (1/-1), not the new
invoice id, unlike Commande::createFromProposal(). The test was doing
fetch($result) with $result==1, which happened to no-op locally (no
invoice with rowid=1) but fetched an unrelated invoice in CI, causing
a spurious thirdparty mismatch. Use $facture->id, already set by
create() inside createFromOrder(), like every other caller of this
method does.
2026-08-19 00:35:04 +00:00
|
|
|
// Totals are ignored here: specimen lines reference random real products, and a kit/BOM product can
|
|
|
|
|
// expand into extra lines with a different amount - total correctness is checked by assertLineTotalsMatchHeader() instead.
|
|
|
|
|
'total_ht', 'total_tva', 'total_ttc',
|
|
|
|
|
'multicurrency_total_ht', 'multicurrency_total_tva', 'multicurrency_total_ttc', 'fk_multicurrency', 'multicurrency_code', 'multicurrency_tx',
|
|
|
|
|
'retained_warranty', 'retained_warranty_date_limit', 'retained_warranty_fk_cond_reglement', 'specimen', 'situation_cycle_ref', 'situation_counter', 'situation_final',
|
|
|
|
|
'trackid', 'user_creat', 'user_valid', 'note'
|
2018-05-27 13:04:12 +00:00
|
|
|
)
|
|
|
|
|
);
|
2026-01-29 10:25:33 +00:00
|
|
|
|
2021-01-14 14:09:08 +00:00
|
|
|
return $localobject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* testFactureOther
|
|
|
|
|
*
|
2021-02-10 07:47:22 +00:00
|
|
|
* @param Facture $localobject Invoice
|
2021-01-14 14:09:08 +00:00
|
|
|
* @return int
|
|
|
|
|
*
|
|
|
|
|
* @depends testFactureValid
|
|
|
|
|
* The depends says test is run only if previous is ok
|
|
|
|
|
*/
|
|
|
|
|
public function testFactureOther($localobject)
|
|
|
|
|
{
|
|
|
|
|
global $conf,$user,$langs,$db;
|
2024-02-19 14:28:21 +00:00
|
|
|
$conf = $this->savconf;
|
|
|
|
|
$user = $this->savuser;
|
|
|
|
|
$langs = $this->savlangs;
|
|
|
|
|
$db = $this->savdb;
|
2021-01-14 14:09:08 +00:00
|
|
|
|
|
|
|
|
$localobject->info($localobject->id);
|
|
|
|
|
print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n";
|
|
|
|
|
$this->assertNotEquals($localobject->date_creation, '');
|
|
|
|
|
|
2024-02-19 14:28:21 +00:00
|
|
|
$result = $localobject->demande_prelevement($user);
|
2021-01-14 14:09:08 +00:00
|
|
|
print __METHOD__." result=".$result."\n";
|
|
|
|
|
$this->assertLessThan($result, 0);
|
|
|
|
|
|
|
|
|
|
return $localobject->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* testFactureDelete
|
|
|
|
|
*
|
|
|
|
|
* @param int $id Id of invoice
|
|
|
|
|
* @return int
|
|
|
|
|
*
|
|
|
|
|
* @depends testFactureOther
|
|
|
|
|
* The depends says test is run only if previous is ok
|
|
|
|
|
*/
|
|
|
|
|
public function testFactureDelete($id)
|
|
|
|
|
{
|
|
|
|
|
global $conf,$user,$langs,$db;
|
2024-02-19 14:28:21 +00:00
|
|
|
$conf = $this->savconf;
|
|
|
|
|
$user = $this->savuser;
|
|
|
|
|
$langs = $this->savlangs;
|
|
|
|
|
$db = $this->savdb;
|
2021-01-14 14:09:08 +00:00
|
|
|
|
|
|
|
|
// Force default setup
|
|
|
|
|
unset($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED);
|
|
|
|
|
unset($conf->global->INVOICE_CAN_NEVER_BE_REMOVED);
|
|
|
|
|
|
2024-02-19 14:28:21 +00:00
|
|
|
$localobject = new Facture($db);
|
|
|
|
|
$result = $localobject->fetch($id);
|
2021-01-14 14:09:08 +00:00
|
|
|
|
|
|
|
|
// Create another invoice and validate it after $localobject
|
2024-02-19 14:28:21 +00:00
|
|
|
$localobject2 = new Facture($db);
|
|
|
|
|
$result = $localobject2->initAsSpecimen();
|
|
|
|
|
$result = $localobject2->create($user);
|
|
|
|
|
$result = $localobject2->validate($user);
|
2017-10-03 20:52:57 +00:00
|
|
|
print 'Invoice $localobject ref = '.$localobject->ref."\n";
|
2021-01-14 14:09:08 +00:00
|
|
|
print 'Invoice $localobject2 created with ref = '.$localobject2->ref."\n";
|
|
|
|
|
|
|
|
|
|
$conf->global->INVOICE_CAN_NEVER_BE_REMOVED = 1;
|
|
|
|
|
|
2024-02-19 14:28:21 +00:00
|
|
|
$result = $localobject2->delete($user); // Deletion is KO, option INVOICE_CAN_NEVER_BE_REMOVED is on
|
2021-01-14 14:09:08 +00:00
|
|
|
print __METHOD__." id=".$localobject2->id." ref=".$localobject2->ref." result=".$result."\n";
|
|
|
|
|
$this->assertEquals(0, $result, 'Deletion should fail, option INVOICE_CAN_NEVER_BE_REMOVED is on');
|
|
|
|
|
|
|
|
|
|
unset($conf->global->INVOICE_CAN_NEVER_BE_REMOVED);
|
|
|
|
|
|
2024-02-19 14:28:21 +00:00
|
|
|
$result = $localobject->delete($user); // Deletion is KO, it is not last invoice
|
2021-01-14 14:09:08 +00:00
|
|
|
print __METHOD__." id=".$localobject->id." ref=".$localobject->ref." result=".$result."\n";
|
|
|
|
|
$this->assertEquals(0, $result, 'Deletion should fail, it is not last invoice');
|
|
|
|
|
|
2026-01-29 10:25:33 +00:00
|
|
|
var_dump($localobject2->is_erasable());
|
|
|
|
|
|
2024-02-19 14:28:21 +00:00
|
|
|
$result = $localobject2->delete($user); // Deletion is OK, it is last invoice
|
2021-01-14 14:09:08 +00:00
|
|
|
print __METHOD__." id=".$localobject2->id." ref=".$localobject2->ref." result=".$result."\n";
|
|
|
|
|
$this->assertGreaterThan(0, $result, 'Deletion should work, it is last invoice');
|
|
|
|
|
|
2024-02-19 14:28:21 +00:00
|
|
|
$result = $localobject->delete($user); // Deletion is KO, it is not last invoice
|
2021-01-14 14:09:08 +00:00
|
|
|
print __METHOD__." id=".$localobject->id." ref=".$localobject->ref." result=".$result."\n";
|
|
|
|
|
$this->assertGreaterThan(0, $result, 'Deletion should work, it is again last invoice');
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Edit an object to test updates
|
|
|
|
|
*
|
2021-02-10 07:47:22 +00:00
|
|
|
* @param Facture $localobject Object Facture
|
2021-01-14 14:09:08 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function changeProperties(&$localobject)
|
|
|
|
|
{
|
2024-02-19 14:28:21 +00:00
|
|
|
$localobject->note_private = 'New note';
|
2021-01-14 14:09:08 +00:00
|
|
|
//$localobject->note='New note after update';
|
|
|
|
|
}
|
2010-04-25 14:19:58 +00:00
|
|
|
}
|