CodingPhpTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <?php
  2. /* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. * or see https://www.gnu.org/
  17. */
  18. /**
  19. * \file test/phpunit/CodingPhpTest.php
  20. * \ingroup test
  21. * \brief PHPUnit test
  22. * \remarks To run this script as CLI: phpunit filename.php
  23. */
  24. global $conf,$user,$langs,$db;
  25. //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
  26. //require_once 'PHPUnit/Autoload.php';
  27. require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
  28. require_once dirname(__FILE__).'/../../htdocs/core/lib/security.lib.php';
  29. require_once dirname(__FILE__).'/../../htdocs/core/lib/security2.lib.php';
  30. if (! defined('NOREQUIREUSER')) {
  31. define('NOREQUIREUSER', '1');
  32. }
  33. if (! defined('NOREQUIREDB')) {
  34. define('NOREQUIREDB', '1');
  35. }
  36. if (! defined('NOREQUIRESOC')) {
  37. define('NOREQUIRESOC', '1');
  38. }
  39. if (! defined('NOREQUIRETRAN')) {
  40. define('NOREQUIRETRAN', '1');
  41. }
  42. if (! defined('NOCSRFCHECK')) {
  43. define('NOCSRFCHECK', '1');
  44. }
  45. if (! defined('NOTOKENRENEWAL')) {
  46. define('NOTOKENRENEWAL', '1');
  47. }
  48. if (! defined('NOREQUIREMENU')) {
  49. define('NOREQUIREMENU', '1'); // If there is no menu to show
  50. }
  51. if (! defined('NOREQUIREHTML')) {
  52. define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
  53. }
  54. if (! defined('NOREQUIREAJAX')) {
  55. define('NOREQUIREAJAX', '1');
  56. }
  57. if (! defined("NOLOGIN")) {
  58. define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
  59. }
  60. if (empty($user->id)) {
  61. print "Load permissions for admin user nb 1\n";
  62. $user->fetch(1);
  63. $user->getrights();
  64. }
  65. $conf->global->MAIN_DISABLE_ALL_MAILS=1;
  66. /**
  67. * Class for PHPUnit tests
  68. *
  69. * @backupGlobals disabled
  70. * @backupStaticAttributes enabled
  71. * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
  72. */
  73. class CodingPhpTest extends PHPUnit\Framework\TestCase
  74. {
  75. protected $savconf;
  76. protected $savuser;
  77. protected $savlangs;
  78. protected $savdb;
  79. /**
  80. * Constructor
  81. * We save global variables into local variables
  82. *
  83. * @return SecurityTest
  84. */
  85. public function __construct()
  86. {
  87. parent::__construct();
  88. //$this->sharedFixture
  89. global $conf,$user,$langs,$db;
  90. $this->savconf=$conf;
  91. $this->savuser=$user;
  92. $this->savlangs=$langs;
  93. $this->savdb=$db;
  94. print __METHOD__." db->type=".$db->type." user->id=".$user->id;
  95. //print " - db ".$db->db;
  96. print "\n";
  97. }
  98. /**
  99. * setUpBeforeClass
  100. *
  101. * @return void
  102. */
  103. public static function setUpBeforeClass()
  104. {
  105. global $conf,$user,$langs,$db;
  106. $db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
  107. print __METHOD__."\n";
  108. }
  109. /**
  110. * tearDownAfterClass
  111. *
  112. * @return void
  113. */
  114. public static function tearDownAfterClass()
  115. {
  116. global $conf,$user,$langs,$db;
  117. $db->rollback();
  118. print __METHOD__."\n";
  119. }
  120. /**
  121. * Init phpunit tests
  122. *
  123. * @return void
  124. */
  125. protected function setUp()
  126. {
  127. global $conf,$user,$langs,$db;
  128. $conf=$this->savconf;
  129. $user=$this->savuser;
  130. $langs=$this->savlangs;
  131. $db=$this->savdb;
  132. print __METHOD__."\n";
  133. }
  134. /**
  135. * End phpunit tests
  136. *
  137. * @return void
  138. */
  139. protected function tearDown()
  140. {
  141. print __METHOD__."\n";
  142. }
  143. /**
  144. * testSql
  145. *
  146. * @return string
  147. */
  148. public function testPHP()
  149. {
  150. global $conf,$user,$langs,$db;
  151. $conf=$this->savconf;
  152. $user=$this->savuser;
  153. $langs=$this->savlangs;
  154. $db=$this->savdb;
  155. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  156. $filesarray = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, '\.php', null, 'fullname', SORT_ASC, 0, 0, '', 1);
  157. //$filesarray = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, '\.php', null, 'fullname');
  158. foreach ($filesarray as $key => $file) {
  159. if (preg_match('/\/htdocs\/includes\//', $file['fullname'])) {
  160. continue;
  161. }
  162. if (preg_match('/\/htdocs\/custom\//', $file['fullname'])) {
  163. continue;
  164. }
  165. if (preg_match('/\/htdocs\/dolimed/', $file['fullname'])) {
  166. continue;
  167. }
  168. if (preg_match('/\/htdocs\/nltechno/', $file['fullname'])) {
  169. continue;
  170. }
  171. if (preg_match('/\/htdocs\/teclib/', $file['fullname'])) {
  172. continue;
  173. }
  174. print 'Check php file '.$file['fullname']."\n";
  175. $filecontent=file_get_contents($file['fullname']);
  176. if (preg_match('/\.class\.php/', $file['relativename'])
  177. || preg_match('/boxes\/box_/', $file['relativename'])
  178. || preg_match('/modules\/.*\/doc\/(doc|pdf)_/', $file['relativename'])
  179. || preg_match('/modules\/(import|mailings|printing)\//', $file['relativename'])
  180. || in_array($file['name'], array('modules_boxes.php', 'rapport.pdf.php', 'TraceableDB.php'))) {
  181. if (! in_array($file['name'], array(
  182. 'api.class.php',
  183. 'commonobject.class.php',
  184. 'conf.class.php',
  185. 'html.form.class.php',
  186. 'html.formmail.class.php',
  187. 'translate.class.php',
  188. 'utils.class.php',
  189. 'modules_product.class.php',
  190. 'modules_societe.class.php',
  191. 'TraceableDB.php',
  192. 'multicurrency.class.php',
  193. 'productbatch.class.php',
  194. 'reception.class.php',
  195. ))) {
  196. // Must not find $db->
  197. $ok=true;
  198. $matches=array();
  199. // Check string $db-> inside a class.php file (it should be $this->db-> into such classes)
  200. preg_match_all('/'.preg_quote('$db->', '/').'/', $filecontent, $matches, PREG_SET_ORDER);
  201. foreach ($matches as $key => $val) {
  202. $ok=false;
  203. break;
  204. }
  205. //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
  206. $this->assertTrue($ok, 'Found string $db-> into a .class.php file in '.$file['relativename'].'. Inside a .class file, you should use $this->db-> instead.');
  207. //exit;
  208. }
  209. } else {
  210. if (! in_array($file['name'], array(
  211. 'extrafieldsinexport.inc.php',
  212. 'DolQueryCollector.php'
  213. ))) {
  214. // Must must not found $this->db->
  215. $ok=true;
  216. $matches=array();
  217. // Check string $this->db-> into a non class.php file (it shoud be $db-> into such classes)
  218. preg_match_all('/'.preg_quote('$this->db->', '/').'/', $filecontent, $matches, PREG_SET_ORDER);
  219. foreach ($matches as $key => $val) {
  220. $ok=false;
  221. break;
  222. }
  223. //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
  224. $this->assertTrue($ok, 'Found string $this->db-> in '.$file['relativename']);
  225. //exit;
  226. }
  227. }
  228. $ok=true;
  229. $matches=array();
  230. preg_match_all('/'.preg_quote('get_class($this)."::".__METHOD__', '/').'/', $filecontent, $matches, PREG_SET_ORDER);
  231. foreach ($matches as $key => $val) {
  232. $ok=false;
  233. break;
  234. }
  235. //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
  236. $this->assertTrue($ok, 'Found string get_class($this)."::".__METHOD__ that must be replaced with __METHOD__ only in '.$file['relativename']);
  237. //exit;
  238. // Check string $this->db->idate without quotes
  239. $ok=true;
  240. $matches=array();
  241. preg_match_all('/(..)\s*\.\s*\$this->db->idate\(/', $filecontent, $matches, PREG_SET_ORDER);
  242. foreach ($matches as $key => $val) {
  243. if ($val[1] != '\'"' && $val[1] != '\'\'') {
  244. $ok=false;
  245. break;
  246. }
  247. //if ($reg[0] != 'db') $ok=false;
  248. }
  249. //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
  250. $this->assertTrue($ok, 'Found a $this->db->idate to forge a sql request without quotes around this date field '.$file['relativename']);
  251. //exit;
  252. // Check sql string DELETE|OR|AND|WHERE|INSERT ... yyy = ".$xxx
  253. // with xxx that is not 'thi' (for $this->db->sanitize) and 'db-' (for $db->sanitize). It means we forget a ' if string, or an (int) if int, when forging sql request.
  254. $ok=true;
  255. $matches=array();
  256. preg_match_all('/(DELETE|OR|AND|WHERE|INSERT)\s.*([^\s][^\s][^\s])\s*=\s*(\'|")\s*\.\s*\$(...)/', $filecontent, $matches, PREG_SET_ORDER);
  257. foreach ($matches as $key => $val) {
  258. if ($val[2] == 'ity' && $val[4] == 'con') { // exclude entity = ".$conf->entity
  259. continue;
  260. }
  261. if ($val[2] == 'ame' && $val[4] == 'db-' && preg_match('/WHERE name/', $val[0])) { // exclude name = ".$db->encrypt(
  262. continue;
  263. }
  264. if ($val[2] == 'ame' && $val[4] == 'thi' && preg_match('/WHERE name/', $val[0])) { // exclude name = ".$this->db->encrypt(
  265. continue;
  266. }
  267. var_dump($matches);
  268. $ok=false;
  269. break;
  270. }
  271. //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
  272. $this->assertTrue($ok, 'Found non quoted or not casted var into sql request '.$file['relativename'].' - Bad.');
  273. //exit;
  274. // Check that forged sql string is using ' instead of " as string PHP quotes
  275. $ok=true;
  276. $matches=array();
  277. preg_match_all('/\$sql \.= \'\s*VALUES.*\$/', $filecontent, $matches, PREG_SET_ORDER);
  278. foreach ($matches as $key => $val) {
  279. //if ($val[1] != '\'"' && $val[1] != '\'\'') {
  280. var_dump($matches);
  281. $ok=false;
  282. break;
  283. //}
  284. //if ($reg[0] != 'db') $ok=false;
  285. }
  286. //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
  287. $this->assertTrue($ok, 'Found a forged SQL string that mix on same line the use of \' for PHP string and PHP variables into file '.$file['relativename'].' Use " to forge PHP string like this: $sql = "SELET ".$myvar...');
  288. //exit;
  289. // Check that forged sql string is using ' instead of " as string PHP quotes
  290. $ok=true;
  291. $matches=array();
  292. preg_match_all('/\$sql \.?= \'SELECT.*\$/', $filecontent, $matches, PREG_SET_ORDER);
  293. foreach ($matches as $key => $val) {
  294. var_dump($matches);
  295. $ok=false;
  296. break;
  297. }
  298. $this->assertTrue($ok, 'Found a forged SQL string that mix on same line the use of \' for PHP string and PHP variables into file '.$file['relativename'].' Use " to forge PHP string like this: $sql = "SELET ".$myvar...');
  299. // Check sql string VALUES ... , ".$xxx
  300. // with xxx that is not 'db-' (for $db->escape). It means we forget a ' if string, or an (int) if int, when forging sql request.
  301. $ok=true;
  302. $matches=array();
  303. preg_match_all('/(VALUES).*,\s*"\s*\.\s*\$(...)/', $filecontent, $matches, PREG_SET_ORDER);
  304. foreach ($matches as $key => $val) {
  305. if ($val[1] == 'VALUES' && $val[2] == 'db-') { // exclude $db->escape(
  306. continue;
  307. }
  308. if ($val[1] == 'VALUES' && $val[2] == 'thi' && preg_match('/this->db->encrypt/', $val[0])) { // exclude ".$this->db->encrypt(
  309. continue;
  310. }
  311. var_dump($matches);
  312. $ok=false;
  313. break;
  314. }
  315. //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
  316. $this->assertTrue($ok, 'Found non quoted or not casted var into sql request '.$file['relativename'].' - Bad.');
  317. //exit;
  318. // Check '".$xxx non escaped
  319. // Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request.
  320. $ok=true;
  321. $matches=array();
  322. preg_match_all('/=\s*\'"\s*\.\s*\$this->(....)/', $filecontent, $matches, PREG_SET_ORDER);
  323. foreach ($matches as $key => $val) {
  324. if ($val[1] != 'db->' && $val[1] != 'esca') {
  325. $ok=false;
  326. break;
  327. }
  328. }
  329. //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
  330. $this->assertTrue($ok, 'Found non escaped string in building of a sql request (case 1) in '.$file['relativename'].' - Bad.');
  331. // Check string sql|set|WHERE|...'".$yyy->xxx with xxx that is not 'escape', 'idate', .... It means we forget a db->escape when forging sql request.
  332. $ok=true;
  333. $matches=array();
  334. preg_match_all('/(sql|SET|WHERE|INSERT|VALUES|LIKE).+\s*\'"\s*\.\s*\$(.......)/', $filecontent, $matches, PREG_SET_ORDER);
  335. foreach ($matches as $key => $val) {
  336. if (! in_array($val[2], array('this->d', 'this->e', 'db->esc', 'dbs->es', 'mydb->e', 'dbsessi', 'db->ida', 'escaped', 'exclude', 'include'))) {
  337. $ok=false; // This will generate error
  338. break;
  339. }
  340. //if ($reg[0] != 'db') $ok=false;
  341. }
  342. //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
  343. $this->assertTrue($ok, 'Found non escaped string in building of a sql request (case 2) in '.$file['relativename'].': '.$val[0].' - Bad.');
  344. //exit;
  345. // Check string sql|set...'.$yyy->xxx with xxx that is not 'escape', 'idate', .... It means we forget a db->escape when forging sql request.
  346. $ok=true;
  347. $matches=array();
  348. preg_match_all('/(\$sql|SET\s|WHERE\s|INSERT\s|VALUES\s|VALUES\().+\s*\'\s*\.\s*\$(.........)/', $filecontent, $matches, PREG_SET_ORDER);
  349. foreach ($matches as $key => $val) {
  350. if (! in_array($val[2], array('this->db-', 'db->sanit', 'conf->ent', 'key : \'\')', 'key])."\')', 'excludefi', 'regexstri', ''))) {
  351. $ok=false;
  352. var_dump($matches);
  353. break;
  354. }
  355. //if ($reg[0] != 'db') $ok=false;
  356. }
  357. //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
  358. $this->assertTrue($ok, 'Found non escaped string in building of a sql request (case 3) in '.$file['relativename'].': '.$val[0].' - Bad.');
  359. //exit;
  360. // Checks with IN
  361. // Check string ' IN (".xxx' or ' IN (\'.xxx' with xxx that is not '$this->db->sanitize' and not '$db->sanitize'. It means we forget a db->sanitize when forging sql request.
  362. $ok=true;
  363. $matches=array();
  364. preg_match_all('/\s+IN\s*\([\'"]\s*\.\s*(.........)/i', $filecontent, $matches, PREG_SET_ORDER);
  365. foreach ($matches as $key => $val) {
  366. //var_dump($val);
  367. if (!in_array($val[1], array('$db->sani', '$this->db', 'getEntity', 'WON\',\'L', 'self::STA', 'Commande:', 'CommandeF', 'Entrepot:', 'Facture::', 'FactureFo', 'ExpenseRe', 'Societe::', 'Ticket::S'))) {
  368. $ok=false;
  369. break;
  370. }
  371. //if ($reg[0] != 'db') $ok=false;
  372. }
  373. //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
  374. $this->assertTrue($ok, 'Found non sanitized string in building of a IN or NOT IN sql request '.$file['relativename'].' - Bad.');
  375. //exit;
  376. // Check string ' IN (\'".xxx' with xxx that is not '$this->db->sanitize' and not '$db->sanitize'. It means we forget a db->sanitize when forging sql request.
  377. $ok=true;
  378. $matches=array();
  379. preg_match_all('/\s+IN\s*\(\'"\s*\.\s*(.........)/i', $filecontent, $matches, PREG_SET_ORDER);
  380. foreach ($matches as $key => $val) {
  381. //var_dump($val);
  382. if (!in_array($val[1], array('$db->sani', '$this->db', 'getEntity', 'WON\',\'L', 'self::STA', 'Commande:', 'CommandeF', 'Entrepot:', 'Facture::', 'FactureFo', 'ExpenseRe', 'Societe::', 'Ticket::S'))) {
  383. $ok=false;
  384. break;
  385. }
  386. //if ($reg[0] != 'db') $ok=false;
  387. }
  388. //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
  389. $this->assertTrue($ok, 'Found non sanitized string in building of a IN or NOT IN sql request '.$file['relativename'].' - Bad.');
  390. //exit;
  391. // Test that output of $_SERVER\[\'QUERY_STRING\'\] is escaped.
  392. $ok=true;
  393. $matches=array();
  394. preg_match_all('/(..............)\$_SERVER\[\'QUERY_STRING\'\]/', $filecontent, $matches, PREG_SET_ORDER);
  395. foreach ($matches as $key => $val) {
  396. if ($val[1] != 'scape_htmltag(' && $val[1] != 'ing_nohtmltag(' && $val[1] != 'dol_escape_js(') {
  397. $ok=false;
  398. break;
  399. }
  400. }
  401. $this->assertTrue($ok, 'Found a $_SERVER[\'QUERY_STRING\'] without dol_escape_htmltag neither dol_string_nohtmltag around it, in file '.$file['relativename'].'. Bad.');
  402. // Check GETPOST(... 'none');
  403. $ok=true;
  404. $matches=array();
  405. preg_match_all('/GETPOST\s*\(([^\)]+),\s*["\']none["\']/i', $filecontent, $matches, PREG_SET_ORDER);
  406. foreach ($matches as $key => $val) {
  407. var_dump($val);
  408. if (!in_array($val[1], array(
  409. "'replacestring'", "'htmlheader'", "'WEBSITE_HTML_HEADER'", "'WEBSITE_CSS_INLINE'", "'WEBSITE_JS_INLINE'", "'WEBSITE_MANIFEST_JSON'", "'PAGE_CONTENT'", "'WEBSITE_README'",
  410. "'search_status'", '"mysqldump"', '"postgresqldump"', "'db_pass_root'", "'db_pass'", '"pass"', '"pass1"', '"pass2"', '"password"', "'password'", '"MAIN_MAIL_SMTPS_PW"'))) {
  411. $ok=false;
  412. break;
  413. }
  414. //if ($reg[0] != 'db') $ok=false;
  415. }
  416. //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n";
  417. $this->assertTrue($ok, 'Found a GETPOST that use \'none\' as a parameter in file '.$file['relativename'].' and param is not an allowed parameter for using none - Bad.');
  418. //exit;
  419. // Test that first param of print_liste_field_titre is a translation key and not the translated value
  420. $ok=true;
  421. $matches=array();
  422. // Check string ='print_liste_field_titre\(\$langs'.
  423. preg_match_all('/print_liste_field_titre\(\$langs/', $filecontent, $matches, PREG_SET_ORDER);
  424. foreach ($matches as $key => $val) {
  425. $ok=false;
  426. break;
  427. }
  428. $this->assertTrue($ok, 'Found a use of print_liste_field_titre with first parameter that is a translated value instead of just the translation key in file '.$file['relativename'].'. Bad.');
  429. // Test we don't have <br />
  430. $ok=true;
  431. $matches=array();
  432. preg_match_all('/<br\s+\/>/', $filecontent, $matches, PREG_SET_ORDER);
  433. foreach ($matches as $key => $val) {
  434. if ($file['name'] != 'functions.lib.php') {
  435. $ok=false;
  436. break;
  437. }
  438. }
  439. $this->assertTrue($ok, 'Found a tag <br /> that is for xml in file '.$file['relativename'].'. You must use html syntax <br> instead.');
  440. // Test we don't have name="token" value="'.$_SESSION['newtoken'], we must use name="token" value="'.newToken() instead.
  441. $ok=true;
  442. $matches=array();
  443. preg_match_all('/name="token" value="\'\s*\.\s*\$_SESSION/', $filecontent, $matches, PREG_SET_ORDER);
  444. foreach ($matches as $key => $val) {
  445. if ($file['name'] != 'excludefile.php') {
  446. $ok=false;
  447. break;
  448. }
  449. }
  450. $this->assertTrue($ok, 'Found a forbidden string sequence into '.$file['relativename'].' : name="token" value="\'.$_SESSION[..., you must use a newToken() instead of $_SESSION[\'newtoken\'].');
  451. // Test we don't have @var array(
  452. $ok=true;
  453. $matches=array();
  454. preg_match_all('/preg_grep\(.*\$/', $filecontent, $matches, PREG_SET_ORDER);
  455. foreach ($matches as $key => $val) {
  456. if (strpos($val[0], 'preg_quote') === false) {
  457. $ok=false;
  458. break;
  459. }
  460. }
  461. $this->assertTrue($ok, 'Found a preg_grep with a param that is a $var but without preg_quote in file '.$file['relativename'].'.');
  462. // Test we don't have @var array(
  463. $ok=true;
  464. $matches=array();
  465. preg_match_all('/@var\s+array\(/', $filecontent, $matches, PREG_SET_ORDER);
  466. foreach ($matches as $key => $val) {
  467. $ok=false;
  468. break;
  469. }
  470. $this->assertTrue($ok, 'Found a declaration @var array() instead of @var array in file '.$file['relativename'].'.');
  471. // Test we don't have CURDATE()
  472. $ok=true;
  473. $matches=array();
  474. preg_match_all('/CURDATE\(\)/', $filecontent, $matches, PREG_SET_ORDER);
  475. foreach ($matches as $key => $val) {
  476. $ok=false;
  477. break;
  478. }
  479. $this->assertTrue($ok, 'Found a CURDATE\(\) into code. Do not use this SQL method in file '.$file['relativename'].'. You must use the PHP function dol_now() instead.');
  480. }
  481. return;
  482. }
  483. }