dolibarr/test/phpunit/CommonClassTest.class.php

707 lines
22 KiB
PHP
Raw Normal View History

2024-02-16 22:26:32 +00:00
<?php
/* Copyright (C) 2018 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
FIX: CDavLib getSqlCalEvents broken after actioncomm_cdav table removal, Add CalDav tests (#39322) * # FIX: CDavLib getSqlCalEvents broken after actioncomm_cdav table removal # FIX: CDavLib getSqlCalEvents broken after actioncomm_cdav table removal, Add CalDav tests Add CalDav tests, which resulted in detecting Issue. ## Issue The `CDavLib::getSqlCalEvents()` method in `htdocs/dav/dav.class.php` has been generating broken SQL queries, causing the new `CDavLibTest::testGetFullCalendarObjects` test to fail. ## Root Cause The issue stems from the removal of the `actioncomm_cdav` table. The original code referenced: - `ac.sourceuid` field (from a non-existent `ac` alias) - `ac.uuidext` field (from the removed `actioncomm_cdav` table) - Used incorrect phone field names (`sp.phone`, `sp.phone_perso`, `sp.phone_mobile`) - Used incorrect country field `sp.fk_pays` instead of `sp.fk_country` - Missing JOIN for the `user` table (`sp` alias) ## Fixes Applied ### 1. SQL String Concatenation Upgraded to the use of `$this->db->prefix()` instead of `.MAIN_DB_PREFIX.` literal strings. ### 2. Phone Field Names Updated phone field names to match current Dolibarr schema: - `sp.phone` → `sp.office_phone as phone` - `sp.phone_perso` → `sp.personal_mobile as phone_perso` - `sp.phone_mobile` → `sp.user_mobile as phone_mobile` ### 3. Country Field Fixed the country JOIN to use the correct field: - `sp.fk_pays` → `sp.fk_country` - `s.fk_pays` remains unchanged (correct for societe table) ### 4. Removed Non-Existent Fields Removed `ac.sourceuid` and `a.sourceuid` from the SELECT clause as these fields do not exist in the `actioncomm` table. These were likely from the removed `actioncomm_cdav` table. ### 5. Added Missing JOINs Added proper JOIN for the user table: ```php LEFT JOIN ' . $this->db->prefix() . 'user as sp ON sp.rowid = a.fk_user_action ``` ### 6. OURI Parameter Handling Fixed the `$ouri` parameter handling to use `a.recurid` instead of the non-existent `ac.uuidext`: ```php // When both OID and OURI are provided $sql .= ' AND (a.id = ' . ((int) $oid) . ' OR a.recurid = \''. $this->db->escape($ouri) . '\')'; // When only OURI is provided } elseif ($ouri !== false) { $sql .= ' AND a.recurid = \''. $this->db->escape($ouri) . '\''; } ``` ## Test Cases Added Added test cases to `test/phpunit/CDavLibTest.php` to verify: 1. OID and OURI parameters together produce SQL with both `a.id =` and `a.recurid =` conditions 2. OURI parameter alone produces SQL with only `a.recurid =` condition (no `a.id =`) ## Regression Origin This regression dates back to when the `actioncomm_cdav` table was removed from Dolibarr. The code was not properly updated to handle the removal, leaving broken references to fields and tables that no longer exist. ## Files Modified - `htdocs/dav/dav.class.php` - Method `getSqlCalEvents()` (lines 69-111) - `test/phpunit/CDavLibTest.php` - Method `testGetSqlCalEvents()` (lines 123-138) ## Verification All CDavLibTest tests pass: - testCdavLibConstruct - testGetSqlCalEvents - testToVCalendar - testGetFullCalendarObjects * FIX: Phan type warnings and PHPUnit 7.x compatibility - Fix Phan type warnings in dav.class.php by casting $ouri to string before escape() - Add PHPUnit compatibility helper in CommonClassTest for assertMatchesRegularExpression which was introduced in PHPUnit 8.0, providing backward compatibility with PHPUnit 7.x Fixes: - PhanTypeMismatchArgument warnings for $ouri parameter - assertMatchesRegularExpression undefined method error in CI with PHPUnit < 8.0
2026-07-30 15:09:34 +00:00
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
NEW: Add phpunit test for Mo class (#39535) * NEW: Add phpunit test for Mo class Add a unit-level test for the Mo (manufacturing order) class, which had no direct test coverage yet (RestAPIMoTest.php only exercises the REST API layer over HTTP, and its most interesting part - produce/consume - is entirely commented out there). Covers create() (including the automatic "to produce" line it creates for the finished product), fetch, update, the draft -> validated -> canceled -> validated status workflow (validate/cancel/reopen, including the provisional ref being replaced on validate()), and delete. Uses a freshly created specimen Product for fk_product rather than a random real catalog product: Mo::create() rejects kit/BOM products unless ALLOW_USE_KITS_INTO_BOM_AND_MO is set, and a specimen product is guaranteed not to be one. The module is auto-activated in setUpBeforeClass() if not already enabled, following the same pattern as the other recently added tests (activation is real and persists after the test run, it is not undone by the rollback in tearDownAfterClass - see comment in setUpBeforeClass() for why). * FIX MoTest crash in the full test suite (stale $db) Same class of bug as StockTransferTest (see that commit for the full analysis): modMrp depends on modBom, which itself depends on modProduct, whose constructor queries the DB via Societe::useNPR(). If $db is stale/closed when this class's setUpBeforeClass() runs in the full suite (all classes in one continuous process), activating modMrp crashes on the dead connection the same way. Reconnect $db (and refresh $mysoc->db/$user->db, which stashed their own reference to the old connection at bootstrap) before calling activateModule(), same pattern as StockTransferTest. Verified the same way: closing $db and calling MoTest::setUpBeforeClass() directly reproduces the crash without this fix and is resolved with it. * FIX MoTest: resync $mysoc/$user->db unconditionally Same follow-up fix as StockTransferTest (see that commit for the full analysis): the previous defensive-reconnect only refreshed $mysoc->db/$user->db inside the branch where the global $db itself was detected stale. $mysoc/$user can diverge from a healthy $db independently (they stash their own ->db reference at bootstrap), so resync them unconditionally instead. Verified the same way: closing the original $db but reconnecting only the global $db variable (leaving $mysoc->db pointing at the closed one) reproduces the crash with the old code and is resolved with this fix. * NEW Centralize the stale-$db reconnect logic in CommonClassTest Same follow-up as StockTransferTest (#39542): the defensive reconnect-and-resync-$mysoc/$user logic was duplicated identically across 3 test classes. Extract it into a shared CommonClassTest::ensureDbIsConnected() helper so future test classes that activate a module depending on modProduct don't need to reimplement it, and so the fix can't drift between test files. MoTest::setUpBeforeClass() now just calls self::ensureDbIsConnected() before activateModule(). Re-verified the same way as before: closing the original $db but reconnecting only the global $db variable (leaving $mysoc->db pointing at the closed one) still reproduces the crash without this fix and is resolved with it. * Remove setUpBeforeClass from MoTest Removed setUpBeforeClass method to simplify test setup. * Update CommonClassTest.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2026-08-19 00:28:13 +00:00
* Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
2024-02-16 22:26:32 +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
* the Free Software Foundation; either version 3 of the License, or
* (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
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
*/
/**
* \file test/phpunit/CommonClassTest.php
2024-02-16 22:26:32 +00:00
* \ingroup test
* \brief PHPUnit test
* \remarks Class that extends all PHPunit tests. To share similar code between each test.
2024-02-16 22:26:32 +00:00
*/
2024-03-11 11:49:15 +00:00
// Workaround for false security issue with main.inc.php on Windows in tests:
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$_SERVER['PHP_SELF'] = "phpunit";
}
2024-02-16 22:26:32 +00:00
global $conf,$user,$langs,$db;
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
//require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
// Delete the log file to avoid problem of writing permission on it
@unlink(DOL_DATA_ROOT.'/dolibarr.log');
2024-02-16 22:26:32 +00:00
if (empty($user->id)) {
print "Load permissions for admin user nb 1\n";
$user->fetch(1);
$user->loadRights();
2024-02-16 22:26:32 +00:00
}
Qual: Improve test messages to help locate errors + php-cs-fixer on tests (#28272) * Qual: Apply php-cs-fixer before changes # Qual: Apply php-cs-fixer before changes Apply php-cs-fixer before changes to make real changes stand out in next commit. * Qual: Improve test messages to help locate errors. # Qual: Improve test messages to help locate errors. Included a description of the test in the failing assertions to help locate the error. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: Update spelling exception # Qual: Update spelling exception Formatting the code requires an update in the spelling exception list. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out.
2024-02-19 14:28:21 +00:00
$conf->global->MAIN_DISABLE_ALL_MAILS = 1;
2024-02-16 22:26:32 +00:00
use PHPUnit\Framework\TestCase;
2024-02-16 22:26:32 +00:00
/**
* Class for PHPUnit tests
*
* @backupGlobals disabled
* @backupStaticAttributes enabled
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
* @phan-file-suppress PhanUndeclaredClass
* @phan-file-suppress PhanUndeclaredExtendedClass
* @phan-file-suppress PhanUndeclaredMethod
2024-02-16 22:26:32 +00:00
*/
/** @phpstan-ignore class.notFound */
abstract class CommonClassTest extends TestCase
2024-02-16 22:26:32 +00:00
{
/** @var \Conf */
2024-02-16 22:26:32 +00:00
protected $savconf;
/** @var \User */
2024-02-16 22:26:32 +00:00
protected $savuser;
/** @var \Translate */
2024-02-16 22:26:32 +00:00
protected $savlangs;
/** @var \DoliDB */
2024-02-16 22:26:32 +00:00
protected $savdb;
/**
* Number of Dolibarr log lines to show in case of error
*
* @var integer
*/
2026-06-20 06:07:21 +00:00
public $nbLinesToShow = 50;
/**
* Log file from which to extract lines in case of failing test
*
* @var string
*/
public $logfile = DOL_DATA_ROOT.'/dolibarr.log';
/**
* Log file size before a test started (=in setUp() call)
*
* @var int
*/
public $logSizeAtSetup = 0;
2024-02-16 22:26:32 +00:00
/**
* Constructor
* We save global variables into local variables
*
* @param string $name Name
* @param array<mixed> $data Test data
* @param string $dataName Test data name.
2024-02-16 22:26:32 +00:00
*/
public function __construct($name = null, array $data = array(), $dataName = '')
2024-02-16 22:26:32 +00:00
{
parent::__construct($name, $data, $dataName);
2024-02-16 22:26:32 +00:00
//$this->sharedFixture
global $conf,$user,$langs,$db;
Qual: Improve test messages to help locate errors + php-cs-fixer on tests (#28272) * Qual: Apply php-cs-fixer before changes # Qual: Apply php-cs-fixer before changes Apply php-cs-fixer before changes to make real changes stand out in next commit. * Qual: Improve test messages to help locate errors. # Qual: Improve test messages to help locate errors. Included a description of the test in the failing assertions to help locate the error. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: Update spelling exception # Qual: Update spelling exception Formatting the code requires an update in the spelling exception list. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out.
2024-02-19 14:28:21 +00:00
$this->savconf = $conf;
$this->savuser = $user;
$this->savlangs = $langs;
$this->savdb = $db;
2024-02-16 22:26:32 +00:00
if ((int) getenv('PHPUNIT_DEBUG') > 0) {
2024-02-24 17:05:42 +00:00
print get_called_class()." db->type=".$db->type." user->id=".$user->id.PHP_EOL;
}
2024-02-16 22:26:32 +00:00
//print " - db ".$db->db;
}
/**
* setUpBeforeClass
*
* @return void
*/
public static function setUpBeforeClass(): void
{
global $conf,$user,$langs,$db;
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
if ((int) getenv('PHPUNIT_DEBUG') > 0) {
print get_called_class()."::".__FUNCTION__.PHP_EOL;
}
2024-02-16 22:26:32 +00:00
}
/**
* This method is called when a test fails
*
* @param Throwable $t Throwable object
* @return void
*/
protected function onNotSuccessfulTest(Throwable $t): void
{
2026-06-21 14:03:55 +00:00
global $db;
2024-02-16 22:26:32 +00:00
// Get the lines that were added since the start of the test
if (file_exists($this->logfile)) {
$filecontent = (string) @file_get_contents($this->logfile);
} else {
$filecontent = '';
}
$currentSize = strlen($filecontent);
if ($currentSize >= $this->logSizeAtSetup) {
$filecontent = substr($filecontent, $this->logSizeAtSetup);
}
$lines = preg_split("/\r?\n/", $filecontent, -1, PREG_SPLIT_NO_EMPTY);
// Determine the number of lines to show
2024-02-16 22:26:32 +00:00
$nbLinesToShow = $this->nbLinesToShow;
// @phan-suppress-next-line PhanUndeclaredClass
/** @phpstan-ignore comparison.alwaysFalse */
if (get_class($t) === 'PHPUnit\Framework\Error\Notice') {
$nbLinesToShow = 3;
}
2024-02-16 22:26:32 +00:00
// Determine test information to show
2024-02-16 22:26:32 +00:00
// @phan-suppress-next-line PhanUndeclaredMethod
// @phpstan-ignore method.notFound
$failedTestMethod = $this->getName(false);
$className = get_called_class();
// Get the test method's reflection
$reflectionMethod = new ReflectionMethod($className, $failedTestMethod);
// Get the test method's data set
// @phan-suppress-next-line PhanUndeclaredMethod
// @phpstan-ignore method.notFound
$argsText = $this->getDataSetAsString(true);
$totalLines = count($lines);
$first_line = max(0, $totalLines - $nbLinesToShow);
// Get the last line of the log
$last_lines = array_slice($lines, $first_line, $nbLinesToShow);
// Show log information
print PHP_EOL;
// Use GitHub Action compatible group output (:warning: arguments not encoded)
print "##[group]$className::$failedTestMethod failed - $argsText.".PHP_EOL;
// @phan-suppress-next-line PhanUndeclaredClassMethod
print "## ".get_class($t).": {$t->getMessage()}".PHP_EOL;
// Show some information about where it happened
// @phan-suppress-next-line PhanUndeclaredClassMethod
foreach ($t->getTrace() as $idx => $trace) {
if (isset($trace['file'], $trace['line']) // Only if we have a file name
&& !preg_match('/(?:\bphar\b|Framework)/', $trace['file']) // Only if it's not in phpunit
) {
print "## backtrace($idx): From {$trace['file']}:{$trace['line']}.".PHP_EOL;
}
}
if ($nbLinesToShow) {
2026-01-09 18:22:46 +00:00
print "\n";
2026-06-21 14:12:38 +00:00
print "########## We output the last ".$nbLinesToShow." lines of the file ".basename($this->logfile)." for the failed test ".$failedTestMethod." (file has ".$totalLines." lines) ".PHP_EOL;
$newLines = count($last_lines);
if ($newLines > 0) {
// Show partial log file contents when requested.
print "## Show last ".count($last_lines)." lines of dolibarr.log file -----".PHP_EOL;
foreach ($last_lines as $line) {
print $line.PHP_EOL;
}
2026-02-09 21:43:56 +00:00
print "########## end of dolibarr.log for $className::$failedTestMethod".PHP_EOL;
} else {
print "## No new lines in 'dolibarr.log' since start of this test.".PHP_EOL;
}
2024-02-16 22:26:32 +00:00
}
print "##[endgroup]".PHP_EOL;
2024-02-16 22:26:32 +00:00
// Print last line of file /var/log/apache2/travis_error_log (Unix only)
2026-06-21 14:03:55 +00:00
/* File travis_error_log seems not found on travis
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
$logFile = '/var/log/apache2/travis_error_log';
if (file_exists($logFile) && is_readable($logFile)) {
$lines = file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$lastFiveLines = array_slice($lines, -10);
print "\n";
echo "Last 10 lines of $logFile:\n";
foreach ($lastFiveLines as $line) {
echo $line . "\n";
}
} else {
2026-05-07 07:36:02 +00:00
echo "File $logFile does not exist or is not readable.\n";
2026-01-09 18:22:46 +00:00
}
}
2026-06-21 14:03:55 +00:00
*/
// Try to output DB info
print "\n";
print "########## We try to output some DB info".PHP_EOL;
$resql = $db->query("SHOW ENGINE INNODB STATUS");
if ($resql) {
$obj = $db->fetch_object($resql);
print $obj->Status.PHP_EOL;
} else {
print $db->lasterror().PHP_EOL;
}
print PHP_EOL;
2026-01-09 18:22:46 +00:00
/** @phpstan-ignore method.notFound */
2024-02-16 22:26:32 +00:00
parent::onNotSuccessfulTest($t);
}
/**
* Init phpunit tests
*
* @return void
*/
protected function setUp(): void
{
global $conf,$user,$langs,$db;
Qual: Improve test messages to help locate errors + php-cs-fixer on tests (#28272) * Qual: Apply php-cs-fixer before changes # Qual: Apply php-cs-fixer before changes Apply php-cs-fixer before changes to make real changes stand out in next commit. * Qual: Improve test messages to help locate errors. # Qual: Improve test messages to help locate errors. Included a description of the test in the failing assertions to help locate the error. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: Update spelling exception # Qual: Update spelling exception Formatting the code requires an update in the spelling exception list. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out. * Qual: php-cs-fixer on phpunit test file # Qual: php-cs-fixer on phpunit test file Apply php-cs-fixer on phpunit test files so that future manual changes stand out.
2024-02-19 14:28:21 +00:00
$conf = $this->savconf;
$user = $this->savuser;
$langs = $this->savlangs;
$db = $this->savdb;
2024-02-16 22:26:32 +00:00
// Record the filesize to determine which part of the log to show on error
if (file_exists($this->logfile)) {
$this->logSizeAtSetup = (int) filesize($this->logfile);
} else {
$this->logSizeAtSetup = 0;
}
if ((int) getenv('PHPUNIT_DEBUG') > 0) {
// @phpstan-ignore method.notFound
print get_called_class().'::'.$this->getName(false)."::".__FUNCTION__.PHP_EOL;
}
2024-02-16 22:26:32 +00:00
//print $db->getVersion()."\n";
}
/**
* End phpunit tests
*
* @return void
*/
protected function tearDown(): void
{
if ((int) getenv('PHPUNIT_DEBUG') > 0) {
// @phpstan-ignore method.notFound
print get_called_class().'::'.$this->getName(false)."::".__FUNCTION__.PHP_EOL;
}
2024-02-16 22:26:32 +00:00
}
/**
* tearDownAfterClass
*
* @return void
*/
public static function tearDownAfterClass(): void
{
global $db;
$db->rollback();
if ((int) getenv('PHPUNIT_DEBUG') > 0) {
print get_called_class()."::".__FUNCTION__.PHP_EOL;
}
2024-02-16 22:26:32 +00:00
}
/**
* Call method, even if protected.
*
* @param object $obj Object on which to call method
* @param string $name Method to call
* @param array<mixed> $args Arguments to provide in method call
* @return mixed Return value
*/
public static function callMethod($obj, $name, array $args = [])
{
$class = new \ReflectionClass($obj);
$method = $class->getMethod($name);
// If PHP is older then 8.1.0
if (PHP_VERSION_ID < 80100) {
$method->setAccessible(true);
}
return $method->invokeArgs($obj, $args);
}
/**
* Compare all public properties values of 2 objects
*
* @param Object $oA Object operand 1
* @param Object $oB Object operand 2
* @param boolean $ignoretype False will not report diff if type of value differs
* @param array<int|string> $fieldstoignorearray Array of fields to ignore in diff
* @return array<mixed> Array with differences
*/
public function objCompare($oA, $oB, $ignoretype = true, $fieldstoignorearray = array('id'))
{
$retAr = array();
if (get_class($oA) !== get_class($oB)) {
$retAr[] = "Supplied objects are not of same class.";
} else {
$oVarsA = get_object_vars($oA);
$oVarsB = get_object_vars($oB);
2026-01-29 10:25:33 +00:00
$aKeys = array_keys($oVarsA);
2026-01-29 10:25:33 +00:00
if (method_exists($oA, 'deprecatedProperties')) {
// Update exclusions
foreach (self::callMethod($oA, 'deprecatedProperties') as $deprecated => $new) {
if (in_array($deprecated, $fieldstoignorearray)) {
$fieldstoignorearray[] = $new;
}
}
}
foreach ($aKeys as $sKey) {
if (in_array($sKey, $fieldstoignorearray)) {
continue;
}
2026-01-29 10:25:33 +00:00
if (! $ignoretype && ($oVarsA[$sKey] !== $oVarsB[$sKey])) {
$retAr[] = get_class($oA).'::'.$sKey.' : '.(is_object($oVarsA[$sKey]) ? get_class($oVarsA[$sKey]) : json_encode($oVarsA[$sKey])).' <> '.(is_object($oVarsB[$sKey]) ? get_class($oVarsB[$sKey]) : json_encode($oVarsB[$sKey]));
}
if ($ignoretype && ($oVarsA[$sKey] != $oVarsB[$sKey])) {
$retAr[] = get_class($oA).'::'.$sKey.' : '.(is_object($oVarsA[$sKey]) ? get_class($oVarsA[$sKey]) : json_encode($oVarsA[$sKey])).' <> '.(is_object($oVarsB[$sKey]) ? get_class($oVarsB[$sKey]) : json_encode($oVarsB[$sKey]));
}
}
}
2026-01-29 10:25:33 +00:00
return $retAr;
}
/**
* Assert that the sum of the persisted line totals matches the object header totals.
* Catches bugs where update_price() forgets a line, or a total is not recalculated after a line change.
*
* @param CommonObject $localobject Object with a ->lines array of line objects having total_ht/total_tva/total_ttc
* @param string $message Extra message to show on failure
* @return void
*/
protected function assertLineTotalsMatchHeader($localobject, $message = '')
{
$sumht = 0.0;
$sumtva = 0.0;
$sumttc = 0.0;
foreach ($localobject->lines as $line) {
$sumht += (float) $line->total_ht;
$sumtva += (float) $line->total_tva;
$sumttc += (float) $line->total_ttc;
}
$this->assertEqualsWithDelta($sumht, (float) $localobject->total_ht, 0.01, 'total_ht does not match sum of lines. '.$message);
$this->assertEqualsWithDelta($sumtva, (float) $localobject->total_tva, 0.01, 'total_tva does not match sum of lines. '.$message);
$this->assertEqualsWithDelta($sumttc, (float) $localobject->total_ttc, 0.01, 'total_ttc does not match sum of lines. '.$message);
}
/**
* Compare $localobject against a freshly built specimen of the same class (with the same mutation applied)
* to detect fields unexpectedly changed by a lifecycle action such as update() or valid().
*
* @param object $localobject Object to check, already gone through create()/update()/valid()...
* @param callable $mutate Callback(object $specimen): void applying the same mutation that was applied to $localobject
* @param array<int|string> $fieldstoignorearray Fields to ignore in the comparison (passed to objCompare)
* @param array<mixed> $specimenparam Param array passed to initAsSpecimen()
* @return void
*/
protected function assertMatchesFreshSpecimen($localobject, callable $mutate, array $fieldstoignorearray, array $specimenparam = array())
{
global $db;
$class = get_class($localobject);
$newlocalobject = new $class($db);
$newlocalobject->initAsSpecimen($specimenparam);
$mutate($newlocalobject);
$clonedobject = clone $localobject;
unset($clonedobject->array_options);
$arraywithdiff = $this->objCompare($clonedobject, $newlocalobject, true, $fieldstoignorearray);
$this->assertEquals(array(), $arraywithdiff, 'Found differences '.var_export($arraywithdiff, true));
}
/**
* Map deprecated module names to new module names
*/
const DEPRECATED_MODULE_MAPPING = array(
'actioncomm' => 'agenda',
'adherent' => 'member',
'adherent_type' => 'member_type',
'banque' => 'bank',
'categorie' => 'category',
'commande' => 'order',
'contrat' => 'contract',
'entrepot' => 'stock',
2024-03-12 10:21:42 +00:00
'expedition' => 'shipping',
'facture' => 'invoice',
'fichinter' => 'intervention',
'product_fournisseur_price' => 'productsupplierprice',
'product_price' => 'productprice',
'projet' => 'project',
'propale' => 'propal',
'socpeople' => 'contact',
);
const EFFECTIVE_DEPRECATED_MODULE_MAPPING = array(
'adherent' => 'member',
'adherent_type' => 'member_type',
'banque' => 'bank',
'contrat' => 'contract',
'entrepot' => 'stock',
'ficheinter' => 'fichinter',
'projet' => 'project',
);
/**
* Map module names to the 'class' name (the class is: mod<CLASSNAME>)
* Value is null when the module is not internal to the default
* Dolibarr setup.
*/
const VALID_MODULE_MAPPING = array(
'accounting' => 'Accounting',
'agenda' => 'Agenda',
'ai' => 'Ai',
'anothermodule' => null, // Not used in code, used in translations.lang
'api' => 'Api',
'asset' => 'Asset',
'bank' => 'Banque',
'barcode' => 'Barcode',
'blockedlog' => 'BlockedLog',
'bom' => 'Bom',
'bookcal' => 'BookCal',
'bookmark' => 'Bookmark',
'cashdesk' => null,
'category' => 'Categorie',
'clicktodial' => 'ClickToDial',
2024-02-24 17:05:42 +00:00
'collab' => 'Collab', // TODO: fill in proper name
'comptabilite' => 'Comptabilite',
'contact' => null, // TODO: fill in proper class
'contract' => 'Contrat',
'cron' => 'Cron',
'datapolicy' => 'DataPolicy',
2024-02-24 17:05:42 +00:00
'dav' => 'Dav',
'debugbar' => 'DebugBar',
2024-03-12 10:21:42 +00:00
'shipping' => 'Expedition',
2026-06-21 13:20:14 +00:00
'deplacement' => null,
2024-02-24 17:05:42 +00:00
"documentgeneration" => 'DocumentGeneration', // TODO: fill in proper name
'don' => 'Don',
'dynamicprices' => 'DynamicPrices',
'ecm' => 'ECM',
'ecotax' => null, // TODO: External module ?
'emailcollector' => 'EmailCollector',
'eventorganization' => 'EventOrganization',
'expensereport' => 'ExpenseReport',
'export' => 'Export',
2024-02-24 17:05:42 +00:00
'externalrss' => 'ExternalRss', // TODO: fill in proper name
'fckeditor' => 'Fckeditor',
'fournisseur' => 'Fournisseur',
'ftp' => 'FTP',
2024-02-24 17:05:42 +00:00
'geoipmaxmind' => 'GeoIPMaxmind', // TODO: fill in proper name
'google' => null, // External ?
'gravatar' => 'Gravatar',
'holiday' => 'Holiday',
'hrm' => 'HRM',
'import' => 'Import',
'incoterm' => 'Incoterm',
'intervention' => 'Ficheinter',
'intracommreport' => 'Intracommreport',
'invoice' => 'Facture',
'knowledgemanagement' => 'KnowledgeManagement',
'label' => 'Label',
'ldap' => 'Ldap',
'loan' => 'Loan',
'mailing' => 'Mailing',
'mailman' => null, // Same module as mailmanspip -> MailmanSpip ??
'mailmanspip' => 'MailmanSpip',
'margin' => 'Margin',
'member' => 'Adherent',
'memcached' => null, // TODO: External module?
'modulebuilder' => 'ModuleBuilder',
'mrp' => 'Mrp',
'multicompany' => null, // Not provided by default, no module tests
'multicurrency' => 'MultiCurrency',
'mymodule' => null, // modMyModule - Name used in module builder (avoid false positives)
'notification' => 'Notification',
'numberwords' => null, // Not provided by default, no module tests
2024-02-24 17:05:42 +00:00
'oauth' => 'Oauth',
'openstreetmap' => null, // External module?
'opensurvey' => 'OpenSurvey',
'order' => 'Commande',
'partnership' => 'Partnership',
'paymentbybanktransfer' => 'PaymentByBankTransfer',
'paypal' => 'Paypal',
'paypalplus' => null,
'prelevement' => 'Prelevement',
2024-02-24 17:05:42 +00:00
'printing' => 'Printing', // TODO: set proper name
'product' => 'Product',
'productbatch' => 'ProductBatch',
'productprice' => null,
'productsupplierprice' => null,
'project' => 'Projet',
'propal' => 'Propale',
'quickmemo' => 'QuickMemo',
'receiptprinter' => 'ReceiptPrinter',
'reception' => 'Reception',
'recruitment' => 'Recruitment',
'resource' => 'Resource',
'salaries' => 'Salaries',
'service' => 'Service',
'socialnetworks' => 'SocialNetworks',
'societe' => 'Societe',
'stock' => 'Stock',
'stocktransfer' => 'StockTransfer',
'stripe' => 'Stripe',
NEW Subtotal module (#33502) * Changes to follow mvc logic * Reworked admin page and form to add lines * Reworked adding line logic * Adding options when editing subtotal lines * Fix translations * Fixed errors/displays and started pdf * Color for subtotals pdf lines * FIX display of subtotal totht * Added pdf azur for propal * Fix duplicate translation * Added subtotal support for facture pdf * Added subtotal support for commande pdf * Improve UI/translations * Restored old pdf * Info to warn user for unsupported pdf * Added title lines VAT rate and discount support This is meant for future feature wich is block mass changing vat rate and discount percentage * Working on block apply vat and discount * Added buttons for block actions * Handle editing vat and discount for subtotal lines * Editing vat and discount for subtotal lines bloc working * Added possibility to move by block * Updated adding and updating a subtotal line * Improved vat and discount block update * Improvement for block vat/discount and line edition Editing a title line edits the corresponding subtotal line * Improvement for moving by block * Bad tile or st line placement managing * Improved bad title or st line placement managing * Adding subtotal line improved Adding a subtotal line adds it right under its corresponding title * Improved deleting subtotal line Added possibility to choose if you want to delete the corresponding subtotal line when deleting a title line * Preventing too high level titles to be created * Create and update line errors managing * Improved bad title or st line placement managing * Improved st line creation * improve headers * fix bad block placement managing * fix adding st line not working if duplicates titles * fix translations * Fix block update * FIX special chars bug If special char like " ' " was used in title it could be converted to special char entity. * Prepare for pdf options Pdf options like page break befor title should be shown as a picto if activated on a subtotal line on a document * Added option managing * Improved subtotal options and PDF integration * Code refactor * Action name/Error managment/PDF refreshing When adding or updating a subtotal line * Reformat * Reworked subtotal options database managment * Changed access to special code * Remove unecessary call to php trait * Changed definition of subtotals special code constant * Reworked align on PDF * Removed unecessary function and improved error managment * Typo fix and removed treated todos * Post typo changed for to better match subtotals names * Disabled edit if status is not draft * Changed way subtotals options are stored * Added view managing when creating a document form an other * Improved creating document from an other Can check subtotals lines with table head checkbox and removed highlight class for better UI. * Make include of subtotals tpl more clear * Manage centered or justified case If user chose to center or justify, we don't change nothing * Improved pdf * Removed unecessary code block * optimisation * Code sniffer fix * Code sniffer fix * Code sniffer fix * Code sniffer fix * Code sniffer fix and added missing translation * Fix php code sniffer * Reload page when setup saved on subtotals admin page * Fix php code sniffer * pjan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * php warning fix * php warning fix * php phan fix * php phan fix * php phan fix * Fix bug admin page not loading because of const not defined * php phan fix * php phan fix * FIX subtotals admin page display * php phan fix * FIX php phan * Fix bugs and langs * Fix bug pdf align * Replace include by require * Add headers to avoid refreshing and adding unwanted lines * Fix phan * Add GETPOST check for security * Fix phan * Fix phan * Fix phan * Subtotal option when creating a document from another * Fix phan * Add field subtotal options for subtotal lines * Fix phan * Fix phan * Fix phan * Update to follow mvc * Fix php phan * Fix php phan * Fix phpstan/phan * Fix phpstan * Fix phpstan * Fix phpstan * Fix phpstan * Fix phpstan * Update to switch to extraparams * Update to switch to extraparams * Retrieve extraparams from db to objectline * Modified last things to switch to extraparams * Cleaning unnecessary code lines * Fix php-stan * Section subtotal in extraparams to differentiate if needed for further devs * Fix phan * Keep extraparams when creating from another object * Change default value to false when creating a subtotal line * Fix clone would not keep extraparams in new object * Fix dark subtotal line background color Fix when a subtotal background color is too dark and edit pencil or delete trash could not be seen * Fix typo * Fix typo * Added subtotals for facturerec * Fix precommit * Added extraparams when creating rec from fac and other way * Fix phan * Fix objectline null * Desactivating block vat / discount update for facturerec * reformating code * Added expeditions for subtotal * Save extraparams for shipping lines * Display of subtotals lines in shipments * Display when creating facture from shipments * Improve display of lines and invoice creation from shipments * Fix error if missing line rang * Deleted duplicate * Added deletion of subtotal line in shipping documents * Not including subtotal lines if there is no product line in between * Update get subtotal lines in shipment docs to disable * Delete possibility to edit subtotal lines in shipments * Handle pdf for shipment * Handle conf stock or shipment supporting services * Fix precommit * Fix duplicate name creating bug * Fix bug where id could be changed by the line id and would create bug * Deleted subtotal lines when STOCK_SUPPORTS_SERVICES is enabled and block would only have service lines * Disable shipments in admin modules Shimpements subtotals lines are only created from commands * Fixing phan and stan * Deleted unused template and phan fix * Fix phan * Fix phan * Fix phan * FIX: phan * Fix template bug If document was not in subtotal scope and would use a template used by subtotal it would create an error. * Fix php-stan * Fix bad display when modules and confs were activated * Fix php codesniffer * Excluding subtotal lines when mass updating * Fix shipments service lines exluded + showing subtotal line with specific configs * Fix line display with situation invoices + bug block line update * Added ODT managment This works with invoices but has not been tested with other documents * Fix bug when editing VAT/discount by block * Fix error raised when subtotal line added Subtotal line had no fk_product and raised the error but we want this line to have no fk product * Fix precommit * Added ODT template for documents that uses subtotals This template can be usefull to understand how to create an odt template using subtotals module * Fix phan * Fix phan * fix: buttons showing in bad document status * clean: unwanted commited files * add: table examples to use with subtotals on ODT templates * fix: Unwanted print of value when creating a document from another * feat: renaming for better understanding * feat: Improved templates for documents related to subtotals --------- Co-authored-by: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-05-10 00:44:31 +00:00
'subtotals' => 'Subtotals',
'supplier_invoice' => null, // Special case, uses invoice
'supplier_order' => null, // Special case, uses invoice
'supplier_proposal' => 'SupplierProposal',
'syslog' => 'Syslog',
'takepos' => 'TakePos',
'tax' => 'Tax',
'ticket' => 'Ticket',
'user' => 'User',
'variants' => 'Variants',
'webhook' => 'Webhook',
'webportal' => 'WebPortal',
'webservices' => 'WebServices',
'website' => 'Website',
'workflow' => 'Workflow',
'workstation' => 'Workstation',
'zapier' => 'Zapier',
);
2026-03-12 12:27:43 +00:00
/**
* Map module names to the 'class' name (the class is: mod<CLASSNAME>)
* Value is null when the module is not internal to the default
* Dolibarr setup.
*/
const OTHER_MODULE_MAPPING = array(
'captureserver' => 'CaptureServer'
);
/**
* Run php script (file) using the php binary used for running phpunit.
*
* The PHP executable may not be in the path, or refer to an uncontrolled
* version.
* This ensures that the php script is properly run on multiple platforms.
*
* @param string $phpScriptCommand The command and arguments are run by the php binary.
* @param array<string> $output The output returned by the command
* @param int $exitCode The exit code returned for the execution.
* @return false|string False on failure, else last line if the output from the command
*/
protected function runPhpScript(string $phpScriptCommand, &$output, &$exitCode)
{
$phpExecutable = PHP_BINARY;
// Build the command to execute the PHP script
$command = "$phpExecutable $phpScriptCommand";
// Execute the command
return exec($command, $output, $exitCode);
}
/**
* Assert that a directory does not exist without triggering deprecation
*
* @param string $directory The directory to test
* @param string $message The message to show if the directory exists
*
* @return void
*/
protected function assertDirectoryNotExistsCompat($directory, $message = '')
{
// @phan-suppress-next-line PhanUndeclaredClassReference, PhanUndeclaredClassMethod
$phpunitVersion = class_exists('\PHPUnit\Runner\Version') ? \PHPUnit\Runner\Version::id() : '9.0.0';
// Check if PHPUnit version is less than 9.0.0
if (version_compare($phpunitVersion, '9.0.0', '<')) {
// @phan-suppress-next-line PhanUndeclaredMethod
/** @phpstan-ignore method.notFound */
$this->assertDirectoryNotExists($directory, $message);
} else {
// @phan-suppress-next-line PhanUndeclaredMethod
/** @phpstan-ignore method.notFound */
$this->assertDirectoryDoesNotExist($directory, $message);
}
}
/**
* Assert that a file does not exist without triggering deprecation
*
* @param string $file The file to test
* @param string $message The message to show if the directory exists
*
* @return void
*/
protected function assertFileNotExistsCompat($file, $message = '')
{
// @phan-suppress-next-line PhanUndeclaredClassReference, PhanUndeclaredClassMethod
$phpunitVersion = class_exists('\PHPUnit\Runner\Version') ? \PHPUnit\Runner\Version::id() : '9.0.0';
// Check if PHPUnit version is less than 9.0.0
if (version_compare($phpunitVersion, '9.0.0', '<')) {
// @phan-suppress-next-line PhanUndeclaredMethod
$this->assertFileNotExists($file, $message);
} else {
// @phan-suppress-next-line PhanUndeclaredMethod
$this->assertFileDoesNotExist($file, $message);
}
}
/**
* Skip test if test is not running on "Unix"
*
* @param string $message Message to indicate which test requires "Unix"
*
* @return bool True if this is not *nix, and fake assert generated
*/
protected function fakeAssertIfNotUnix($message)
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
// @phan-suppress-next-line PhanUndeclaredMethod
// @phpstan-ignore method.notFound
$this->assertTrue(true, "Dummy test to not mark the test as risky");
// $this->markTestSkipped("PHPUNIT is running on windows. $message");
return true;
}
return false;
}
FIX: CDavLib getSqlCalEvents broken after actioncomm_cdav table removal, Add CalDav tests (#39322) * # FIX: CDavLib getSqlCalEvents broken after actioncomm_cdav table removal # FIX: CDavLib getSqlCalEvents broken after actioncomm_cdav table removal, Add CalDav tests Add CalDav tests, which resulted in detecting Issue. ## Issue The `CDavLib::getSqlCalEvents()` method in `htdocs/dav/dav.class.php` has been generating broken SQL queries, causing the new `CDavLibTest::testGetFullCalendarObjects` test to fail. ## Root Cause The issue stems from the removal of the `actioncomm_cdav` table. The original code referenced: - `ac.sourceuid` field (from a non-existent `ac` alias) - `ac.uuidext` field (from the removed `actioncomm_cdav` table) - Used incorrect phone field names (`sp.phone`, `sp.phone_perso`, `sp.phone_mobile`) - Used incorrect country field `sp.fk_pays` instead of `sp.fk_country` - Missing JOIN for the `user` table (`sp` alias) ## Fixes Applied ### 1. SQL String Concatenation Upgraded to the use of `$this->db->prefix()` instead of `.MAIN_DB_PREFIX.` literal strings. ### 2. Phone Field Names Updated phone field names to match current Dolibarr schema: - `sp.phone` → `sp.office_phone as phone` - `sp.phone_perso` → `sp.personal_mobile as phone_perso` - `sp.phone_mobile` → `sp.user_mobile as phone_mobile` ### 3. Country Field Fixed the country JOIN to use the correct field: - `sp.fk_pays` → `sp.fk_country` - `s.fk_pays` remains unchanged (correct for societe table) ### 4. Removed Non-Existent Fields Removed `ac.sourceuid` and `a.sourceuid` from the SELECT clause as these fields do not exist in the `actioncomm` table. These were likely from the removed `actioncomm_cdav` table. ### 5. Added Missing JOINs Added proper JOIN for the user table: ```php LEFT JOIN ' . $this->db->prefix() . 'user as sp ON sp.rowid = a.fk_user_action ``` ### 6. OURI Parameter Handling Fixed the `$ouri` parameter handling to use `a.recurid` instead of the non-existent `ac.uuidext`: ```php // When both OID and OURI are provided $sql .= ' AND (a.id = ' . ((int) $oid) . ' OR a.recurid = \''. $this->db->escape($ouri) . '\')'; // When only OURI is provided } elseif ($ouri !== false) { $sql .= ' AND a.recurid = \''. $this->db->escape($ouri) . '\''; } ``` ## Test Cases Added Added test cases to `test/phpunit/CDavLibTest.php` to verify: 1. OID and OURI parameters together produce SQL with both `a.id =` and `a.recurid =` conditions 2. OURI parameter alone produces SQL with only `a.recurid =` condition (no `a.id =`) ## Regression Origin This regression dates back to when the `actioncomm_cdav` table was removed from Dolibarr. The code was not properly updated to handle the removal, leaving broken references to fields and tables that no longer exist. ## Files Modified - `htdocs/dav/dav.class.php` - Method `getSqlCalEvents()` (lines 69-111) - `test/phpunit/CDavLibTest.php` - Method `testGetSqlCalEvents()` (lines 123-138) ## Verification All CDavLibTest tests pass: - testCdavLibConstruct - testGetSqlCalEvents - testToVCalendar - testGetFullCalendarObjects * FIX: Phan type warnings and PHPUnit 7.x compatibility - Fix Phan type warnings in dav.class.php by casting $ouri to string before escape() - Add PHPUnit compatibility helper in CommonClassTest for assertMatchesRegularExpression which was introduced in PHPUnit 8.0, providing backward compatibility with PHPUnit 7.x Fixes: - PhanTypeMismatchArgument warnings for $ouri parameter - assertMatchesRegularExpression undefined method error in CI with PHPUnit < 8.0
2026-07-30 15:09:34 +00:00
/**
* PHPUnit compatibility helper for assertMatchesRegularExpression
*
* assertMatchesRegularExpression was introduced in PHPUnit 8.0.
* This method provides backward compatibility with PHPUnit 7.x which only has assertRegExp.
*
* @param string $pattern Regular expression pattern
* @param string $string String to match against
* @param string $message Optional message
* @return void
*/
public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void
{
if (method_exists('PHPUnit\Framework\Assert', 'assertMatchesRegularExpression')) {
// PHPUnit 8.0+: call parent's method
PHPUnit\Framework\Assert::assertMatchesRegularExpression($pattern, $string, $message);
} else {
// PHPUnit 7.x and earlier: use assertRegExp
PHPUnit\Framework\Assert::assertRegExp($pattern, $string, $message);
}
}
2024-02-16 22:26:32 +00:00
}