From 3855732a0ee9d95fca3ea80d4c1cb78ef1a3cb3a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 Jun 2026 15:20:14 +0200 Subject: [PATCH] Debug v24 --- htdocs/core/class/commonobject.class.php | 22 ++++++++++----- htdocs/core/class/extrafields.class.php | 1 + htdocs/core/db/mysqli.class.php | 1 + htdocs/core/tpl/admin_extrafields_add.tpl.php | 6 ++--- .../core/tpl/admin_extrafields_edit.tpl.php | 6 ++--- test/phpunit/AbstractRestAPITest.php | 2 +- test/phpunit/AllTests.php | 27 ++++++++++--------- test/phpunit/CommonClassTest.class.php | 2 +- test/phpunit/SocieteTest.php | 2 +- 9 files changed, 40 insertions(+), 29 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d312cd98a16..dcef22e2cbd 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6968,6 +6968,13 @@ abstract class CommonObject $attributeUnique = $extrafields->attributes[$this->table_element]['unique'][$attributeKey]; $attrfieldcomputed = $extrafields->attributes[$this->table_element]['computed'][$attributeKey]; $attributeEmptyOnClone = $extrafields->attributes[$this->table_element]['emptyonclone'][$attributeKey]; + /* + $attributeEnabled = $extrafields->attributes[$this->table_element]['enabled'][$attributeKey]; + $enabled = 0; + if (!empty($extrafields->attributes[$this->table_element]['enabled'][$key])) { + $enabled = (int) dol_eval((string) $extrafields->attributes[$this->table_element]['enabled'][$key], 1, 1, '2'); + } + */ // If we clone, we have to clean unique extrafields to prevent duplicates. // If we clone, we have to clean extrafields having "empty on clone" option on. @@ -6985,7 +6992,7 @@ abstract class CommonObject } // Similar code than into insertExtraFields - if ($attributeRequired) { + if ($attributeRequired) { // If attribute is "Mandatory", then it is also in database as "Not null", so we must check even if attribute is not 'enabled'. $v = $this->array_options[$key]; if (ExtraFields::isEmptyValue($v, $attributeType)) { $langs->load("errors"); @@ -7441,15 +7448,16 @@ abstract class CommonObject $value = $this->array_options["options_".$key]; $attributeKey = $key; - $attributeType = $extrafields->attributes[$this->table_element]['type'][$key]; - $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$key]; - $attributeParam = $extrafields->attributes[$this->table_element]['param'][$key]; - $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$key]; + $attributeType = $extrafields->attributes[$this->table_element]['type'][$attributeKey]; + $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey]; + $attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey]; + $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$attributeKey]; $attributeUnique = $extrafields->attributes[$this->table_element]['unique'][$attributeKey]; - $attrfieldcomputed = $extrafields->attributes[$this->table_element]['computed'][$key]; + $attrfieldcomputed = $extrafields->attributes[$this->table_element]['computed'][$attributeKey]; + //$attributeEnabled = $extrafields->attributes[$this->table_element]['enabled'][$attributeKey]; // Similar code than into insertExtraFields - if ($attributeRequired) { + if ($attributeRequired) { // If attribute is "Mandatory", then it is also in database as "Not null", so we must check even if attribute is not 'enabled'. $mandatorypb = false; if ($attributeType == 'link' && $this->array_options["options_".$key] == '-1') { $mandatorypb = true; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 5cce1fe3374..826e19996d7 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -819,6 +819,7 @@ class ExtraFields $result = $this->update_label($attrname, $label, $type, $length, $elementtype, $unique, $required, $pos, $param, $alwayseditable, $perms, $list, $help, $default, $computed, $entity, $langfile, $enabled, $totalizable, $printable, $moreparams, $aiprompt, $emptyonclone, $showintooltip, $personal_data); } if ($result > 0) { + // Add or remove the unique index $sql = ''; if ($unique) { dol_syslog(get_class($this).'::update_unique', LOG_DEBUG); diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 23783ecc184..7a353fd2a35 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -1058,6 +1058,7 @@ class DoliDBMysqli extends DoliDB } } + //print $sql;exit; dol_syslog(get_class($this)."::DDLUpdateField ".$sql, LOG_DEBUG); if (!$this->query($sql)) { return -1; diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index 2e66235963a..54de7f07c8b 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -268,11 +268,11 @@ if (!getDolGlobalString('MAIN_STORE_COMPUTED_EXTRAFIELDS')) { echo $form->textwithpicto($langs->trans("AIPromptExtrafield"), $texthelp, 1, 'help', 'valignmiddle', 0, 3, 'abc');?> -trans("DefaultValue").' ('.$langs->trans("Database").')'; ?> +trans("DefaultValue").' ('.$langs->trans("Database").')'; ?> -trans("Unique"); ?>> +trans("Unique").' ('.$langs->trans("Database").')'; ?>> -trans("Mandatory"); ?>> +trans("Mandatory").' ('.$langs->trans("Database").')'; ?>> textwithpicto($langs->trans("AlwaysEditable"), $langs->trans("EditableWhenDraftOnly")); ?>> diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index b58283fb5a3..5e48800edad 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -345,13 +345,13 @@ if (!getDolGlobalString('MAIN_STORE_COMPUTED_EXTRAFIELDS')) { -trans("DefaultValue").' ('.$langs->trans("Database").')'; ?> +trans("DefaultValue").' ('.$langs->trans("Database").')'; ?> -trans("Unique"); ?>> +trans("Unique").' ('.$langs->trans("Database").')'; ?>> -trans("Mandatory"); ?>> +trans("Mandatory").' ('.$langs->trans("Database").')'; ?>> textwithpicto($langs->trans("AlwaysEditable"), $langs->trans("EditableWhenDraftOnly")); ?>> diff --git a/test/phpunit/AbstractRestAPITest.php b/test/phpunit/AbstractRestAPITest.php index 0218e62cc4d..dee7dc77479 100644 --- a/test/phpunit/AbstractRestAPITest.php +++ b/test/phpunit/AbstractRestAPITest.php @@ -99,7 +99,7 @@ abstract class AbstractRestAPITest extends CommonClassTest $this->assertNotNull($object, "$test Parsing of JSON result must not be null"); $this->assertNotEquals(500, (empty($object['error']['code']) ? 0 : $object['error']['code']), "$test Error".(empty($object['error']['message']) ? '' : ' '.$object['error']['message'])); - $this->assertEquals('200', $object['success']['code']); + $this->assertEquals('200', $object['success']['code'] ?? 0, "API call for setup failed"); $this->api_key = isset($object['success']['token']) ? $object['success']['token'] : null; diff --git a/test/phpunit/AllTests.php b/test/phpunit/AllTests.php index 135dbf63787..bc34478f39e 100644 --- a/test/phpunit/AllTests.php +++ b/test/phpunit/AllTests.php @@ -137,18 +137,6 @@ class AllTests require_once dirname(__FILE__).'/XCalLibTest.php'; $suite->addTestSuite('XCalLibTest'); - // Rules into source files content - require_once dirname(__FILE__).'/RepositoryTest.php'; - $suite->addTestSuite('RepositoryTest'); - require_once dirname(__FILE__).'/LangTest.php'; - $suite->addTestSuite('LangTest'); - require_once dirname(__FILE__).'/CodingSqlTest.php'; - $suite->addTestSuite('CodingSqlTest'); - require_once dirname(__FILE__).'/CodingPhpTest.php'; - $suite->addTestSuite('CodingPhpTest'); - require_once dirname(__FILE__).'/DoliDBTest.php'; - $suite->addTestSuite('DoliDBTest'); - require_once dirname(__FILE__).'/SecurityTest.php'; $suite->addTestSuite('SecurityTest'); require_once dirname(__FILE__).'/SecurityGETPOSTTest.php'; @@ -330,11 +318,24 @@ class AllTests require_once dirname(__FILE__).'/WebsiteTest.php'; $suite->addTestSuite('WebsiteTest'); - // At end because it's the longer + // --- At end because it's the longer + // Also enabling and disabling modules is changing the context and global variables that changes behaviour of previous tests require_once dirname(__FILE__).'/ModulesTest.php'; $suite->addTestSuite('ModulesTest'); + // Rules into source files content + require_once dirname(__FILE__).'/RepositoryTest.php'; + $suite->addTestSuite('RepositoryTest'); + require_once dirname(__FILE__).'/LangTest.php'; + $suite->addTestSuite('LangTest'); + require_once dirname(__FILE__).'/CodingSqlTest.php'; + $suite->addTestSuite('CodingSqlTest'); + require_once dirname(__FILE__).'/CodingPhpTest.php'; + $suite->addTestSuite('CodingPhpTest'); + require_once dirname(__FILE__).'/DoliDBTest.php'; + $suite->addTestSuite('DoliDBTest'); + return $suite; } } diff --git a/test/phpunit/CommonClassTest.class.php b/test/phpunit/CommonClassTest.class.php index 9267d1260f9..e2ca20ba1ab 100644 --- a/test/phpunit/CommonClassTest.class.php +++ b/test/phpunit/CommonClassTest.class.php @@ -428,7 +428,7 @@ abstract class CommonClassTest extends TestCase 'dav' => 'Dav', 'debugbar' => 'DebugBar', 'shipping' => 'Expedition', - 'deplacement' => 'Deplacement', // TODO Remove module + 'deplacement' => null, "documentgeneration" => 'DocumentGeneration', // TODO: fill in proper name 'don' => 'Don', 'dynamicprices' => 'DynamicPrices', diff --git a/test/phpunit/SocieteTest.php b/test/phpunit/SocieteTest.php index 9b627fa6d07..4f8a4e0fa72 100644 --- a/test/phpunit/SocieteTest.php +++ b/test/phpunit/SocieteTest.php @@ -174,7 +174,7 @@ class SocieteTest extends CommonClassTest $result = $localobject->update($localobject->id, $user); print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $this->assertLessThan($result, 0, __METHOD__." id=".$localobject->id." result=".$result); $result = $localobject->update_note($localobject->note_private, '_private'); print __METHOD__." id=".$localobject->id." result=".$result."\n";