dolibarr/test
Frédéric FRANCE a0b0e44278
NEW Link manage extrafields and phpunit test for the class (#39514)
* NEW: Add extrafields support to Link class

Link now declares isextrafieldmanaged and wires fetch_optionals()/
insertExtraFields()/deleteExtraFields() into fetch(), fetchAll(),
create(), update() and delete(), matching the llx_links_extrafields
table added previously.

* FIX: Several bugs in Link class review

- create(): wrong duplicate-record error message (copy-pasted from
  Societe, referenced undefined $this->name) replaced by the generic
  ErrorDuplicateField, consistent with update().
- create()/update(): missing "NoURL" translation key replaced by the
  standard ErrorFieldRequired pattern.
- fetch(): guard against running an unfiltered query (no rowid, no
  hashforshare) that could silently return an arbitrary link; a caller
  in actions_linkedfiles.inc.php could hit this when 'linkid' was
  missing from the request.
- actions_linkedfiles.inc.php: check fetch() result with `> 0` instead
  of a truthy test, since -1 (error) is truthy in PHP.
- delete(): add User type hint (consistent with create()/update()) and
  a $notrigger parameter to optionally skip the LINK_DELETE trigger.
- update(): fix copy-pasted docblock ("third party" -> "link").

* NEW: Add PHPUnit test for Link class

Covers create/fetch/update/fetchAll/count/delete, plus regression
tests for the two bugs fixed in the previous commit: create() rejects
an empty url, and fetch() rejects a call with neither rowid nor
hashforshare instead of returning an arbitrary record.

* FIX Phan false positive on $object in actions_linkedfiles.inc.php

Phan's ambient type inference for the loosely-typed global $object in
this shared include file was picking up CommonSocialNetworks (an
unrelated trait, not even a class), reported as undeclared
->id/->entity/->addThumbs()/->delThumbs() in a real CI Phan run on
this branch, once this file was analyzed on its own via the
changed-files file-list (this file has no prior baseline entry, so it
was apparently never previously exercised in isolation like this).

Force $object's type explicitly to CommonObject via the same
@phan-var-force string-literal idiom this file already uses for
$upload_dir/$upload_dirold/$confirm/$forceFullTextIndexation -
CommonObject genuinely declares addThumbs()/delThumbs(), which
resolves those two errors outright. $id/$entity remain reported as
PhanUndeclaredProperty (CommonObject itself does not declare them,
only its concrete subclasses do at runtime) - baseline-suppress that
for this file the same way it is already suppressed for the sibling
shared-include files actions_addupdatedelete.inc.php,
actions_massactions.inc.php and actions_sendmails.inc.php, which have
the exact same $object typing situation.
2026-08-19 02:18:46 +02:00
..
acceptance
assets/xsd FIX bon prelevement SEPA generation (#38998) 2026-07-04 13:27:58 +02:00
awbot Clean files 2026-01-07 19:01:54 +01:00
hurl NEW API endpoint for getting product price logs (#38420) 2026-05-25 02:41:33 +02:00
manual Debug v24 2026-02-18 23:03:16 +01:00
other Doc 2026-06-02 23:40:29 +02:00
phpunit NEW Link manage extrafields and phpunit test for the class (#39514) 2026-08-19 02:18:46 +02:00
selenium Clean files 2026-01-07 19:01:54 +01:00
soapui Clean files 2026-01-07 19:01:54 +01:00
sqlmap Clean files 2026-01-07 19:01:54 +01:00
.gitignore
bootstrap.php
README Clean files 2026-01-07 19:01:54 +01:00

README (English)
--------------------------------
This directory contains unit tests and docs for Dolibarr quality analysis.


- PHPUnit          -  https://phpunit.de
- PHP_CodeSniffer  -  https://pear.php.net/package/PHP_CodeSniffer/
- PHP Depend       -  https://pdepend.org/


PHPUNIT
-------
To use make phpunit analysis, you must:

* Install PHPUnit
If using Eclipse, you must also add an entry as external tool for phpunit program with:
-Name:      PHPUnit
-Location:  Linux:   /usr/bin/php
            Windows: C:\Program Files (x86)\wamp\bin\php\php5.2.8\php.exe
-Workspace: ${workspace_loc}
-Arguments: Linux:   /usr/bin/phpunit ${resource_path}
            Windows: "C:\Program Files (x86)\PHPUnit-3.4.9\phpunit.php" ${resource_path}
If not using Eclipse, to install PHPUnit manually:
> sudo apt-get remove phpunit
> sudo apt-get upgrade pear
> sudo pear channel-discover pear.phpunit.de
> sudo pear channel-discover pear.symfony-project.com
> sudo pear channel-discover components.ez.no
> sudo pear update-channels
> sudo pear upgrade-all
> sudo pear install --alldeps phpunit/PHPUnit


* Run Unit tests:
> cd test/phpunit
> phpunit MyFileTest.php
If using Eclipse, select the test and click on menu "Run external tools and choose PHPUnit".

* Example to run phpunit 7.0 from composer using php version 8.0:
> cd ~/tmp
> composer -i phpunit
> cd test/phpunit
> /usr/bin/php8.0 ~/tmp/htdocs/includes/phpunit/phpunit/phpunit MyFileTest.php


* Generate a report of Unit tests code coverage done by one tested class:
> cd test
> phpunit -d memory_limit=-1 -d max_input_time=1800 -d max_execution_time=1800 --configuration ./phpunit/phpunittest.xml --coverage-html ./report ./report/logs/phpunit.xml phpunit/MyClassTest.php
Note that xdebug must be installed for this feature to work.

* Generate a report of Unit tests code coverage done by all Dolibarr unit test classes:
Increase your PHP memory (memory_limit and suhosin.memory_limit in php.ini) to 4G. You can check setup with "php -i | grep memory". Note: Version 3.5 need 1.5G
> cd test
> phpunit -d suhosin.memory_limit=4G -d memory_limit=-1 -d max_input_time=0 -d max_execution_time=0 --configuration ./phpunit/phpunittest.xml --coverage-html ./report phpunit/AllTests.php

If there is a timeout before end, try this:
> cd test
> php -d suhosin.memory_limit=4G -d memory_limit=-1 -d max_input_time=0 -d max_execution_time=0 /usr/bin/phpunit -d suhosin.memory_limit=4G -d memory_limit=-1 -d max_input_time=0 -d max_execution_time=0 --configuration ./phpunit/phpunittest.xml --coverage-html ./report phpunit/AllTests.php
ou
> php -d suhosin.memory_limit=4G -d memory_limit=-1 -d max_input_time=0 -d max_execution_time=0 /usr/bin/phpunit -d suhosin.memory_limit=4G -d memory_limit=-1 -d max_input_time=0 -d max_execution_time=0 --configuration ./phpunit/phpunittest.xml --coverage-php ./report/codecoverage.php phpunit/AllTests.php
puis
> sudo renice -10 idprocessphp



PHP-CODESNIFFER
---------------
* Install phpcs

* Launch PHP-Codesniffer:
> cd dev
> /usr/bin/php5 -c ./codesniffer/php.ini /usr/bin/phpcs --report=xml --standard=./codesniffer ../htdocs/test.php



PHPDEPEND
---------
* Install pdepend

* Launch PDepend analysis:
> cd test
> pdepend --debug -d memory_limit=-1 --configuration=./phpunit/phpunittest.xml --phpunit-xml=./report/logs/pdepend.xml --summary-xml=./report/logs/summary.xml --jdepend-chart=./report/logs/jdepend.svg --overview-pyramid=./report/logs/pyramid.svg --ignore=custom,custom2,adodbtime,artichow,ckeditor,efc_xfss,fckeditor,fpdf,geoip,magpierss,nusoap,odtphp,php_writeexcel,smarty,smtps,tcpdf,vcard ../htdocs

* To clean pdepend cache files
> rm -fr ~/.pdepend/*