dolibarr/test/phpunit
VIAL-GOUTEYRON Quentin ea54342891
NEW Drag and drop a file on the 23 remaining cards (#39473)
* FIX Drag and drop of a file reports a wrong error, or none at all

The error handler of dragAndDropFileUpload() had three defects that all end on
the user believing the file was attached when it was not.

 - The first assignment of the message was dead code, there was no return after
   the test on the http code 403, so a refusal was reported as a generic error.
 - The key ErrorUploadPermissionDenied it used exists in no language file, so
   the raw key was shown.
 - JSON.parse() was called with no try/catch on an answer that is not always a
   json, a fatal error of the endpoint or a request over post_max_size for
   example. The exception left the user on a page with no message at all.
 - An empty list of files was treated as a success, while it means the endpoint
   stored nothing.

The value of PHP_SELF is also escaped before it is written into the 6 generated
javascript strings. It holds the path info of the request on a server that
accepts it, so it is a user input. dol_escape_js() is called with the mode that
escapes a double quote by a double quote, the strings being delimited by double
quotes, and the sequence '</' is escaped too because the function does not do it
and the path info could otherwise close the script tag and open one of its own.

Adds the key ErrorOnAtLeastOneFileUpload to en_US, used when some files of a
batch failed and some did not.

* FIX getMultidirOutput returns a directory the Documents tab does not read

Four defects of the same function, all ending on a file stored where the user
will never see it, or written outside the documents directory.

 - The ref of the project of a task was only passed through dol_sanitizePathName(),
   which keeps a slash, a colon and the accented chars, while projet/tasks/document.php
   sanitizes it with dol_sanitizeFileName(). A project ref holding a slash even
   created an extra level of directory. Measured on real databases: 304 projects
   over 330 hold a slash on one of them, carrying 701 tasks over 824.
 - The same case calls $object->fetchProject() with no guard, while the signature
   of the function accepts an object that is not a CommonObject, and even a null
   when a module is given. Such a caller gets a fatal error where it expects the
   error string. No core caller is in that case today, an external module or a
   hook can be.
 - The entity of the object may have no declared directory, an object shared by
   another entity for example. The undefined index returned a relative path, so
   the caller read or wrote under the web root. The current entity is used
   instead, and the fallback is logged because the directory is then not the one
   of the entity of the object, which matters for a caller that deletes files.
 - When the current entity has no declared directory either, the fallback
   returned the sub directory alone, again a relative path. The same error than
   for a module that declares no directory at all is now returned.

Adds the sub directory of a partnership and of a stock transfer, which their own
document tabs already read.

* FIX getElementProperties answers wrong properties for 9 elements

A customer payment, a supplier payment, a various payment, a stock transfer and
the 4 objects of the hrm module had no properties at all, or wrong ones, so any
caller that resolves a class, a table or a document directory from an element
failed on them.

 - payment, payment_supplier and payment_various had no branch. The branch of a
   customer payment tests $elementType and not $element, because the rule on the
   elements named myobject_mysubobject rewrites $element to 'payment' for
   'payment_salary' too, which is stored somewhere else.
 - job, position, skill and evaluation answered a wrong table (hrm_job_user for
   a position, and so on) and no sub directory, while their document tabs read
   one named after the element.
 - stocktransfer answered an empty classname, because it is not the ucfirst() of
   the element, so a caller doing new $classname($db) ended on a fatal error.
 - The sub directory was concatenated even when the module is disabled and the
   directory is empty, which answered a path at the root of the file system.
 - A contact and a conference are stored into a sub directory their tab reads.

isModEnabled('invoice') is tested for a customer payment: there is no module
named 'compta', so testing it was always false, while $conf->compta->payment is
set unconditionally by Conf::setValues() and could not be used as a proxy.

* FIX Access refused to everyone on 11 objects of the core

restrictedArea() and checkUserAccessToObject() refuse the access to objects that
no permission and no rule can match, whatever the user, an administrator
included.

 - The hrm module declares no permission at its first level, only 'all', and the
   stocktransfer module only 'stocktransfer'. A check on the module itself
   therefore tests a permission that does not exist. The mapping is the same one
   as into User::hasRight().
 - The module of an event organization declares no permission at all, its whole
   permission block being commented out on purpose, and its cards check the
   parent project instead. The feature is mapped onto that project, with the two
   guards the card has: an external user is refused, and so is a conference with
   no parent project, whose id of 0 would otherwise grant an access with no check
   on the record at all.
 - The default rule of checkUserAccessToObject() builds its sql on the columns
   entity and fk_soc of the table. llx_asset, llx_paiement, llx_paiementfourn and
   llx_workstation_workstation have no fk_soc, and llx_hrm_job, llx_hrm_job_user
   and llx_hrm_skill have neither. The sql failed, so the access was refused to
   every user this rule applies to. These tables are now checked on their entity
   only, which is what the $check rule already does for the same class of tables,
   and the 3 tables of hrm can be checked on nothing at all. The rule is selected
   on the table and not on the element, because $object is an id and not an
   object for most of the callers, the cards of an asset and of a workstation
   included, which are broken today for any user without the permission to see
   all third parties.
 - An external user is refused explicitly on those tables: none of these objects
   is linked to a third party, so the default rule refused him through a link
   that does not exist, and the rules that replace it do not look at the third
   party of the user at all.

Measured on a vanilla instance with 5 profiles, an administrator, an internal
user with every right, one without the permission to see all third parties, one
that is not a sales representative of the third party of the object, and an
external user: the 11 objects go from refused to granted for the internal users
and stay refused for the external one, and the 26 other elements answer exactly
the same for the 5 profiles.

* FIX A file dropped on a card is lost, or reported as refused when it was stored

FileUpload stores the file into a directory that the "Attached files" tab of the
object never reads, so the user attaches a file that no screen will ever show,
and nothing is indexed in database to find it back. Measured on real databases:
216487 thirdparties over 216887 and 157852 products over 280319 are in that case
on the cards that already enable the drag and drop.

 - The directory of the object is now forged with get_exdir(), the way the tabs
   do: it always uses the id for a thirdparty, whose ref is a company name and is
   not unique, and it falls back on the id when the ref is empty. The sub
   directory of the module is read with getMultidirOutput(), which knows the
   elements that store their documents into one. That function does not return
   an empty string when it fails but a string starting with 'error-', so only an
   absolute path is accepted: writing into that string would create the files
   under the web root.
 - fetchObjectByElement() returns an object even when fetch() returned 0. The
   object was then not loaded, and the file was stored at the root of the
   directory of the module, out of any object. The constructor now throws, and
   the endpoint answers the error with the same json contract than a successful
   call so that the caller can show it, instead of a fatal error and an http 500.
 - An attachment of the same name was silently overwritten, dol_move_uploaded_file()
   being called with $allowoverwrite = 1 while the name was checked before the
   ref of the object was added as a prefix. The check is done again on the final
   name, and on the .noexe suffixed name too, which that function appends to an
   executable file.
 - An executable file was renamed with that .noexe suffix and then reported as an
   error, while it was correctly stored.
 - The endpoint called restrictedArea() with an empty feature when the element is
   unknown, and the loop of that function then takes no branch at all and grants
   the access with no check. It refuses before, with the same http code and the
   same message than a refusal, so that a user cannot tell an object that exists
   but is not allowed from an object that does not exist. The refusal of an
   external user on an object of another third party answered a message of its
   own, which allowed the same enumeration.

Comes with the tests of the path resolution, of the fallback of get_exdir(), of
the rejection of the error string of getMultidirOutput(), and of the file name
deduplication.

* FIX Remove the drop area from 13 cards where dropping a file is harmful

Two distinct groups, both of them removing a drop area that only produces a
result the user does not want.

7 pages have no "Attached files" tab at all, so a file dropped on them can be
reached by no screen: a fiscal year and its info page, an accounting model, a
webhook trigger history, an intracomm report, a bookcal calendar and its booking
list. Measured: 4 of them accepted the upload and wrote an orphan file, the
accounting model wrote it at the root of the directory of the module, out of any
object, and the 2 bookcal ones answered an http 500.

6 cards print their tabs inside their edit form, so the drop area covered that
form: a product, an expense report, a VAT payment, a social contribution, a loan
and a salary. Dropping a file there reloads the page, which discards what the
user is typing. A product and an expense report have a second call for the read
only view, so the drop area is only removed from the call of the edit branch;
the 4 others share a single call between both views, so the parameter is now
conditional.

* NEW Drag and drop a file on the 23 remaining cards

Every card of the core that owns an "Attached files" tab can now receive a file
by drag and drop, which was the case of 32 of them only. The 23 added here are
an asset, an event, a various payment, a customer payment, a contact, a donation,
a conference or booth, a shipment, a supplier payment, a leave request, an
evaluation, a job, a position, a skill, a knowledge record, a manufacturing
order, a partnership, a lot, a stock transfer, a task, a reception, a resource
and a workstation.

The tab bar of a leave request and of a resource is printed inside their edit
form, so the drop area is not enabled there: dropping a file reloads the page,
which would discard what the user is typing. The card of a supplier payment
prints its tab bar even when the object was not loaded, so the drop area is only
enabled when it is.

* FIX getMultidirOutput refuses an entity with no directory instead of falling back [skip-claudemd]

The previous revision of this PR fell back on the directory of the current
entity when the entity of the object had none, with a LOG_WARNING. On a
multicompany install that made a caller read, write and above all delete
files in the directory of another entity. Refuse instead: the function
already answers 'error-diroutput-not-defined-for-this-object' when the
module declares no directory at all, so the caller has one behaviour to
handle, not two.

The entity is cast to int, which is what the array index needs and what
silences the four PhanTypeMismatchDimFetchNullable this function reported.

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2026-08-19 02:46:21 +02:00
..
functional
.gitignore Ignore file to avoid commiting it 2025-10-18 11:56:07 +02:00
AbstractRestAPITest.php Debug v24 2026-06-21 15:20:14 +02:00
AccountancySystemTest.php
AccountingAccountTest.php exit code must be >= 0 (#35311) 2025-09-12 02:29:23 +02:00
ActionCommTest.php
AdherentTest.php CI 2026-05-22 12:17:17 +02:00
AdminLibTest.php Fix comparison on version to show the warning to upgrade database 2025-08-20 16:02:46 +02:00
AllTests.php NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517) 2026-08-19 02:35:04 +02:00
AssetModelTest.php
BankAccountTest.php
BarcodeTest.php
BlockedLogAndLNETest.php More robust phpunit 2026-01-29 11:25:33 +01:00
BOMTest.php
BonPrelevementTest.php FIX bon prelevement SEPA generation (#38998) 2026-07-04 13:27:58 +02:00
BonVirementTest.php FIX bon prelevement SEPA generation (#38998) 2026-07-04 13:27:58 +02:00
BookKeepingTest.php tests: add BookKeeping test (#34062) 2025-05-05 21:31:48 +02:00
BuildDocTest.php Fix CI 2026-03-02 15:15:44 +01:00
CategorieTest.php
CDavLibTest.php Revert "/imports/index.php wrongly shows access refused (#39379)" (#39386) 2026-08-04 22:23:57 +02:00
ChargeSocialesTest.php
CMailFileTest.php
CodingPhpTest.php Qual: Fix 'SqlInjection' notices (#39216) 2026-07-23 19:06:39 +02:00
CodingSqlTest.php Fix CI 2026-02-21 12:22:59 +01:00
CommandeFournisseurTest.php Clean code 2025-10-17 23:43:28 +02:00
CommandeTest.php NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517) 2026-08-19 02:35:04 +02:00
CommentTest.php NEW: Add phpunit test for Comment class (#39540) 2026-08-15 16:03:53 +02:00
CommonClassTest.class.php NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517) 2026-08-19 02:35:04 +02:00
CommonInvoiceTest.php Fix CI 2026-01-08 13:06:30 +01:00
CommonObjectTest.php FIX isInt() does not detect sized integer types (tinyint, bigint) (#39236) 2026-07-20 15:30:28 +02:00
CompanyBankAccountTest.php
CompanyLibTest.php
ContactTest.php CLOSE #29244 Feature to merge contacts (#39512) 2026-08-19 02:26:34 +02:00
ContratTest.php Fix contract update method. Add phpunit for TDD. 2025-03-07 16:02:18 +01:00
CoreTest.php
CronjobTest.php NEW: Add phpunit test for Cronjob class (#39541) 2026-08-15 18:22:45 +02:00
DateLibTest.php Automated merge from 22.0 to 23.0 by tool pullmerge.sh 2026-07-19 15:41:05 +02:00
DateLibTzFranceTest.php
DAVLibTest.php Revert "/imports/index.php wrongly shows access refused (#39379)" (#39386) 2026-08-04 22:23:57 +02:00
DiscountTest.php Merge branch '23.0' of git@github.com:Dolibarr/dolibarr.git into develop 2026-07-16 00:00:17 +02:00
DolDeprecationHandlerTest.php Update DolDeprecationHandlerTest 2025-02-19 15:53:56 +01:00
DoliDBTest.php Try to fix CI for pgsql 2025-12-22 03:45:20 +01:00
DolresourceTest.php NEW: Add phpunit test for Dolresource class (#39520) 2026-08-14 20:31:06 +02:00
DonTest.php NEW: Add phpunit tests for Don and PaymentDonation classes (#39539) 2026-08-19 01:40:33 +02:00
EmailCollectorTest.php Fix #39005 keep UTF-8 body extraction values (#39011) 2026-06-29 20:24:02 +02:00
EntrepotTest.php
EvalMathTest.php
ExampleTest.php
ExpeditionTest.php fix parameters (#35209) 2025-09-03 22:33:25 +02:00
ExpenseReportTest.php FIX Missing comma in ExpenseReportLine::fetch SQL (#38767) 2026-06-14 01:12:13 +02:00
ExportTest.php
ExtraFieldsTest.php FIX #30801 Filter a dependent select list of extrafields when the field is edited alone (#39488) 2026-08-15 03:04:31 +02:00
FactureFournisseurTest.php
FactureRecTest.php
FactureTest.php NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517) 2026-08-19 02:35:04 +02:00
FactureTestRounding.php
FichinterTest.php Fix intervention update sql error (#33916) 2025-04-18 20:01:58 +02:00
file_import_company_1.csv
file_pdf_with_js.pdf.jpg
FilesLibMoveDirTest.php
FilesLibTest.php FIX accounting export: enhance file metadata return and secure access checks (#39218) 2026-07-20 02:50:31 +02:00
FileUploadTest.php NEW Drag and drop a file on the 23 remaining cards (#39473) 2026-08-19 02:46:21 +02:00
FormAdminTest.php
FormTest.php fix: keep full product label searchable in combo (#39057) 2026-07-06 23:42:58 +02:00
Functions2LibTest.php
FunctionsBELibTest.php Execute phpunit for functionsbe in all tests 2025-08-26 05:27:02 +02:00
FunctionsLibDragDropTest.php NEW Drag and drop a file on the 23 remaining cards (#39473) 2026-08-19 02:46:21 +02:00
FunctionsLibTest.php NEW Drag and drop a file on the 23 remaining cards (#39473) 2026-08-19 02:46:21 +02:00
FunctionsNumToWordTest.php FIX: French amount in words (cent/vingt agreement, et, hyphens, mille/million, centimes) (#38945) 2026-06-22 14:34:52 +02:00
GetUrlLibTest.php Fix use of numeric hostname 2026-07-29 12:16:48 +02:00
HolidayTest.php
ImagesLibTest.php
imap_header.txt
imap_htmlmsg.txt Clean files 2026-01-07 19:01:54 +01:00
imap_plaintext.txt Clean files 2026-01-07 19:01:54 +01:00
img250x20.png
img250x50.jpg
imgsvgwithjs.svg
ImportTest.php
InventoryTest.php
JsonLibTest.php
KnowledgeRecordTest.php
LangTest.php fix french comments (#39019) 2026-06-30 12:25:04 +02:00
LesscTest.php
LinkTest.php NEW Link manage extrafields and phpunit test for the class (#39514) 2026-08-19 02:18:46 +02:00
LoanScheduleTest.php NEW: Add phpunit tests for LoanSchedule and PaymentLoan classes (#39537) 2026-08-19 01:37:51 +02:00
LoanTest.php
MarginsLibTest.php
ModuleBuilderLibTest.php NEW: ModuleBuilder - selectable object tabs (+ fixes for multi-object generation) (#38570) 2026-06-09 19:04:00 +02:00
ModuleBuilderShowOnComboboxTest.php FIX : ModuleBuilder apply showoncombobox to fields other than ref/code (#38904) 2026-06-21 23:30:54 +02:00
ModuleBuilderTemplateConventionsTest.php NEW: ModuleBuilder - consistent status labels and explicit trigger naming (#38883) 2026-08-17 21:41:18 +02:00
ModulesTest.php Try fix CI 2026-06-21 19:16:53 +02:00
MoTest.php NEW: Add phpunit test for Mo class (#39535) 2026-08-19 02:28:13 +02:00
MouvementStockTest.php FIX Stock balance truncated to int for fractional qty (#38806) 2026-06-15 14:18:44 +02:00
MultiCurrencyTest.php NEW: Add phpunit test for MultiCurrency class (#39534) 2026-08-15 16:03:41 +02:00
NamingContractTest.php don't take care of some french comments and fix false positive (#39007) 2026-06-29 19:28:28 +02:00
NumberingModulesTest.php Debug v23 2026-02-17 16:59:07 +01:00
ODFTest.php QUAL Add get_substitutionarray_each_var_object in phpunit 2025-02-06 12:04:41 +01:00
OpensurveysondageTest.php Add opensurveysondage phpunit test (#39522) 2026-08-14 14:57:48 +02:00
PaiementTest.php add new test (#39001) 2026-07-01 19:22:08 +02:00
PaymentDonationTest.php NEW: Add phpunit tests for Don and PaymentDonation classes (#39539) 2026-08-19 01:40:33 +02:00
PaymentLoanTest.php NEW: Add phpunit tests for LoanSchedule and PaymentLoan classes (#39537) 2026-08-19 01:37:51 +02:00
PaymentVATTest.php NEW: Add phpunit test for PaymentVAT class (#39544) 2026-08-15 18:21:48 +02:00
PaypalTest.php
PdfDocTest.php
PgsqlTest.php Try to fix CI for pgsql 2025-12-22 03:45:20 +01:00
phpunit.dtd
phpunittest.xml
PricesTest.php Qual: Fix french comments and improve detector (#39026) 2026-07-01 12:26:51 +02:00
ProductTest.php
ProfidLibTest.php FIX isValidTinForES() rejects almost every Spanish NIE starting with T (#39384) 2026-08-04 22:48:15 +02:00
ProjectTest.php
PropalCommandeFactureWorkflowTest.php NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517) 2026-08-19 02:35:04 +02:00
PropalTest.php NEW: Improve phpunit test coverage for Commande, Propal and Facture (#39517) 2026-08-19 02:35:04 +02:00
ReceptionTest.php
RemiseChequeTest.php NEW: Add phpunit test for RemiseCheque class (#39543) 2026-08-19 01:39:35 +02:00
RepositoryTest.php
RestAPIContactTest.php Fix travis 2025-03-24 21:42:16 +01:00
RestAPIDocumentTest.php Fix travis 2025-03-24 21:43:38 +01:00
RestAPIMoTest.php Fix travis 2025-03-24 21:44:57 +01:00
RestAPIUserTest.php Fix travis 2025-03-24 18:23:31 +01:00
ScriptsTest.php
SecurityGETPOSTTest.php Adapt phpunit to the new sanitization of restricthtml 2026-07-29 01:14:59 +02:00
SecurityLoginTest.php Code comment 2025-12-18 15:07:54 +01:00
SecurityTest.php Complete #39546 and #39547 2026-08-15 16:53:30 +02:00
SocieteTest.php FIX #37826 country_code must be an ISO code, not a label (#39191) 2026-07-16 13:56:33 +02:00
StripeTest.php Fix round in stripe amount 2026-01-21 21:00:37 +01:00
SupplierProposalTest.php phpunit more complete 2025-10-17 19:39:45 +02:00
TargetTest.php
test.php fix CI v22 (#34902) 2025-08-09 14:55:11 +02:00
testemailing.txt Clean files 2026-01-07 19:01:54 +01:00
testvirus.txt
textiso.txt Clean files 2026-01-07 19:01:54 +01:00
textutf8.txt Clean files 2026-01-07 19:01:54 +01:00
TicketTest.php
TtcRoundingTest.php FIX #37658 - Add unit tests for TTC unit price rounding and add fixes for others objects (proposals, orders, invoices and contracts) (#39055) 2026-08-11 19:48:40 +02:00
UserGroupTest.php
UserTest.php fetch greatest tms for user and fix user creation and modification (#35145) 2025-09-01 19:21:54 +02:00
UtilsTest.php Test 2026-06-27 14:30:17 +02:00
WebservicesInvoicesTest.php Better error message 2026-06-21 13:10:56 +02:00
WebservicesOrdersTest.php
WebservicesOtherTest.php
WebservicesProductsTest.php
WebservicesThirdpartyTest.php
WebservicesUserTest.php
WebsiteTest.php CI 2026-06-09 18:22:31 +02:00
WorkstationTest.php NEW: Add phpunit test for Workstation class (#39518) 2026-08-14 15:56:13 +02:00
XCalLibTest.php