forked from Wavyzz/dolibarr
Clean code. Add a phpunit test to avoid duplicate jquery.
This commit is contained in:
@@ -641,11 +641,11 @@ if ($mode == 'common' || $mode == 'commonkanban') {
|
|||||||
// We discard showing according to filters
|
// We discard showing according to filters
|
||||||
if ($search_keyword) {
|
if ($search_keyword) {
|
||||||
$qualified = 0;
|
$qualified = 0;
|
||||||
if (preg_match('/'.preg_quote($search_keyword).'/i', $modulename)
|
if (preg_match('/'.preg_quote($search_keyword, '/').'/i', $modulename)
|
||||||
|| preg_match('/'.preg_quote($search_keyword).'/i', $moduletechnicalname)
|
|| preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduletechnicalname)
|
||||||
|| preg_match('/'.preg_quote($search_keyword).'/i', $moduledesc)
|
|| ($moduledesc && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduledesc))
|
||||||
|| preg_match('/'.preg_quote($search_keyword).'/i', $moduledesclong)
|
|| ($moduledesclong && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduledesclong))
|
||||||
|| preg_match('/'.preg_quote($search_keyword).'/i', $moduleauthor)
|
|| ($moduleauthor && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduleauthor))
|
||||||
) {
|
) {
|
||||||
$qualified = 1;
|
$qualified = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,9 +55,9 @@ class DolibarrDebugBar extends DebugBar
|
|||||||
public function getRenderer()
|
public function getRenderer()
|
||||||
{
|
{
|
||||||
$renderer = parent::getJavascriptRenderer(DOL_URL_ROOT.'/includes/maximebf/debugbar/src/DebugBar/Resources');
|
$renderer = parent::getJavascriptRenderer(DOL_URL_ROOT.'/includes/maximebf/debugbar/src/DebugBar/Resources');
|
||||||
//$renderer->disableVendor('jquery');
|
$renderer->disableVendor('jquery'); // We already have jquery loaded globally by the main.inc.php
|
||||||
$renderer->disableVendor('fontawesome');
|
$renderer->disableVendor('fontawesome'); // We already have fontawesome loaded globally by the main.inc.php
|
||||||
$renderer->disableVendor('highlightjs');
|
$renderer->disableVendor('highlightjs'); // We don't need this
|
||||||
return $renderer;
|
return $renderer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 434 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
@@ -1,125 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
github.com style (c) Vasily Polovnyov <vast@whiteants.net>
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs {
|
|
||||||
display: block; padding: 0.5em;
|
|
||||||
color: #333;
|
|
||||||
background: #f8f8f8
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-comment,
|
|
||||||
div.phpdebugbar .hljs-template_comment,
|
|
||||||
div.phpdebugbar .diff .hljs-header,
|
|
||||||
div.phpdebugbar .hljs-javadoc {
|
|
||||||
color: #998;
|
|
||||||
font-style: italic
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-keyword,
|
|
||||||
div.phpdebugbar .css .rule .hljs-keyword,
|
|
||||||
div.phpdebugbar .hljs-winutils,
|
|
||||||
div.phpdebugbar .javascript .hljs-title,
|
|
||||||
div.phpdebugbar .nginx .hljs-title,
|
|
||||||
div.phpdebugbar .hljs-subst,
|
|
||||||
div.phpdebugbar .hljs-request,
|
|
||||||
div.phpdebugbar .hljs-status {
|
|
||||||
color: #333;
|
|
||||||
font-weight: bold
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-number,
|
|
||||||
div.phpdebugbar .hljs-hexcolor,
|
|
||||||
div.phpdebugbar .ruby .hljs-constant {
|
|
||||||
color: #099;
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-string,
|
|
||||||
div.phpdebugbar .hljs-tag .hljs-value,
|
|
||||||
div.phpdebugbar .hljs-phpdoc,
|
|
||||||
div.phpdebugbar .tex .hljs-formula {
|
|
||||||
color: #d14
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-title,
|
|
||||||
div.phpdebugbar .hljs-id,
|
|
||||||
div.phpdebugbar .coffeescript .hljs-params,
|
|
||||||
div.phpdebugbar .scss .hljs-preprocessor {
|
|
||||||
color: #900;
|
|
||||||
font-weight: bold
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .javascript .hljs-title,
|
|
||||||
div.phpdebugbar .lisp .hljs-title,
|
|
||||||
div.phpdebugbar .clojure .hljs-title,
|
|
||||||
div.phpdebugbar .hljs-subst {
|
|
||||||
font-weight: normal
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-class .hljs-title,
|
|
||||||
div.phpdebugbar .haskell .hljs-type,
|
|
||||||
div.phpdebugbar .vhdl .hljs-literal,
|
|
||||||
div.phpdebugbar .tex .hljs-command {
|
|
||||||
color: #458;
|
|
||||||
font-weight: bold
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-tag,
|
|
||||||
div.phpdebugbar .hljs-tag .hljs-title,
|
|
||||||
div.phpdebugbar .hljs-rules .hljs-property,
|
|
||||||
div.phpdebugbar .django .hljs-tag .hljs-keyword {
|
|
||||||
color: #000080;
|
|
||||||
font-weight: normal
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-attribute,
|
|
||||||
div.phpdebugbar .hljs-variable,
|
|
||||||
div.phpdebugbar .lisp .hljs-body {
|
|
||||||
color: #008080
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-regexp {
|
|
||||||
color: #009926
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-symbol,
|
|
||||||
div.phpdebugbar .ruby .hljs-symbol .hljs-string,
|
|
||||||
div.phpdebugbar .lisp .hljs-keyword,
|
|
||||||
div.phpdebugbar .tex .hljs-special,
|
|
||||||
div.phpdebugbar .hljs-prompt {
|
|
||||||
color: #990073
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-built_in,
|
|
||||||
div.phpdebugbar .lisp .hljs-title,
|
|
||||||
div.phpdebugbar .clojure .hljs-built_in {
|
|
||||||
color: #0086b3
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-preprocessor,
|
|
||||||
div.phpdebugbar .hljs-pragma,
|
|
||||||
div.phpdebugbar .hljs-pi,
|
|
||||||
div.phpdebugbar .hljs-doctype,
|
|
||||||
div.phpdebugbar .hljs-shebang,
|
|
||||||
div.phpdebugbar .hljs-cdata {
|
|
||||||
color: #999;
|
|
||||||
font-weight: bold
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-deletion {
|
|
||||||
background: #fdd
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-addition {
|
|
||||||
background: #dfd
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .diff .hljs-change {
|
|
||||||
background: #0086b3
|
|
||||||
}
|
|
||||||
|
|
||||||
div.phpdebugbar .hljs-chunk {
|
|
||||||
color: #aaa
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -104,6 +104,8 @@ class AllTests
|
|||||||
$suite->addTestSuite('XCalLibTest');
|
$suite->addTestSuite('XCalLibTest');
|
||||||
|
|
||||||
// Rules into source files content
|
// Rules into source files content
|
||||||
|
require_once dirname(__FILE__).'/RepositoryTest.php';
|
||||||
|
$suite->addTestSuite('RepositoryTest');
|
||||||
require_once dirname(__FILE__).'/LangTest.php';
|
require_once dirname(__FILE__).'/LangTest.php';
|
||||||
$suite->addTestSuite('LangTest');
|
$suite->addTestSuite('LangTest');
|
||||||
require_once dirname(__FILE__).'/CodingSqlTest.php';
|
require_once dirname(__FILE__).'/CodingSqlTest.php';
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ class CodingPhpTest extends PHPUnit\Framework\TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testSql
|
* testPHP
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -171,8 +171,7 @@ class CodingPhpTest extends PHPUnit\Framework\TestCase
|
|||||||
$db=$this->savdb;
|
$db=$this->savdb;
|
||||||
|
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
$filesarray = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, '\.php', null, 'fullname', SORT_ASC, 0, 0, '', 1);
|
$filesarray = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, '\.php', null, 'fullname', SORT_ASC, 0, 1, '', 1);
|
||||||
//$filesarray = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, '\.php', null, 'fullname');
|
|
||||||
|
|
||||||
foreach ($filesarray as $key => $file) {
|
foreach ($filesarray as $key => $file) {
|
||||||
if (preg_match('/\/htdocs\/includes\//', $file['fullname'])) {
|
if (preg_match('/\/htdocs\/includes\//', $file['fullname'])) {
|
||||||
|
|||||||
@@ -469,25 +469,6 @@ class FilesLibTest extends PHPUnit\Framework\TestCase
|
|||||||
$this->assertGreaterThanOrEqual(1, $result, "Pb with dol_compress_dir of ".$dirout." into ".$conf->admin->dir_temp.'/testdir.zip');
|
$this->assertGreaterThanOrEqual(1, $result, "Pb with dol_compress_dir of ".$dirout." into ".$conf->admin->dir_temp.'/testdir.zip');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* testDolDirList
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @depends testDolCompressUnCompress
|
|
||||||
* The depends says test is run only if previous is ok
|
|
||||||
*/
|
|
||||||
public function testDolDirList()
|
|
||||||
{
|
|
||||||
global $conf,$user,$langs,$db;
|
|
||||||
|
|
||||||
// Scan dir to guaruante we on't have library jquery twice (we accept exception of duplicte into ckeditor because all dir is removed for debian package, so there is no duplicate).
|
|
||||||
$founddirs=dol_dir_list(DOL_DOCUMENT_ROOT.'/includes/', 'files', 1, '^jquery\.js', array('ckeditor'));
|
|
||||||
print __METHOD__." count(founddirs)=".count($founddirs)."\n";
|
|
||||||
$this->assertEquals(1, count($founddirs));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testDolCheckSecureAccessDocument
|
* testDolCheckSecureAccessDocument
|
||||||
*
|
*
|
||||||
|
|||||||
214
test/phpunit/RepositoryTest.php
Normal file
214
test/phpunit/RepositoryTest.php
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
<?php
|
||||||
|
/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* 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/RepositoryTest.php
|
||||||
|
* \ingroup test
|
||||||
|
* \brief PHPUnit test
|
||||||
|
* \remarks To run this script as CLI: phpunit filename.php
|
||||||
|
*/
|
||||||
|
|
||||||
|
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';
|
||||||
|
require_once dirname(__FILE__).'/../../htdocs/core/lib/files.lib.php';
|
||||||
|
|
||||||
|
if (! defined('NOREQUIREUSER')) {
|
||||||
|
define('NOREQUIREUSER', '1');
|
||||||
|
}
|
||||||
|
if (! defined('NOREQUIREDB')) {
|
||||||
|
define('NOREQUIREDB', '1');
|
||||||
|
}
|
||||||
|
if (! defined('NOREQUIRESOC')) {
|
||||||
|
define('NOREQUIRESOC', '1');
|
||||||
|
}
|
||||||
|
if (! defined('NOREQUIRETRAN')) {
|
||||||
|
define('NOREQUIRETRAN', '1');
|
||||||
|
}
|
||||||
|
if (! defined('NOCSRFCHECK')) {
|
||||||
|
define('NOCSRFCHECK', '1');
|
||||||
|
}
|
||||||
|
if (! defined('NOTOKENRENEWAL')) {
|
||||||
|
define('NOTOKENRENEWAL', '1');
|
||||||
|
}
|
||||||
|
if (! defined('NOREQUIREMENU')) {
|
||||||
|
define('NOREQUIREMENU', '1'); // If there is no menu to show
|
||||||
|
}
|
||||||
|
if (! defined('NOREQUIREHTML')) {
|
||||||
|
define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
|
||||||
|
}
|
||||||
|
if (! defined('NOREQUIREAJAX')) {
|
||||||
|
define('NOREQUIREAJAX', '1');
|
||||||
|
}
|
||||||
|
if (! defined("NOLOGIN")) {
|
||||||
|
define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($user->id)) {
|
||||||
|
print "Load permissions for admin user nb 1\n";
|
||||||
|
$user->fetch(1);
|
||||||
|
$user->getrights();
|
||||||
|
}
|
||||||
|
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for PHPUnit tests
|
||||||
|
*
|
||||||
|
* @backupGlobals disabled
|
||||||
|
* @backupStaticAttributes enabled
|
||||||
|
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
|
||||||
|
*/
|
||||||
|
class CodingPhpTest extends PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
protected $savconf;
|
||||||
|
protected $savuser;
|
||||||
|
protected $savlangs;
|
||||||
|
protected $savdb;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* We save global variables into local variables
|
||||||
|
*
|
||||||
|
* @return SecurityTest
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
//$this->sharedFixture
|
||||||
|
global $conf,$user,$langs,$db;
|
||||||
|
$this->savconf=$conf;
|
||||||
|
$this->savuser=$user;
|
||||||
|
$this->savlangs=$langs;
|
||||||
|
$this->savdb=$db;
|
||||||
|
|
||||||
|
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
|
||||||
|
//print " - db ".$db->db;
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
|
||||||
|
print __METHOD__."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tearDownAfterClass
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function tearDownAfterClass(): void
|
||||||
|
{
|
||||||
|
global $conf,$user,$langs,$db;
|
||||||
|
$db->rollback();
|
||||||
|
|
||||||
|
print __METHOD__."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init phpunit tests
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
global $conf,$user,$langs,$db;
|
||||||
|
$conf=$this->savconf;
|
||||||
|
$user=$this->savuser;
|
||||||
|
$langs=$this->savlangs;
|
||||||
|
$db=$this->savdb;
|
||||||
|
|
||||||
|
print __METHOD__."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End phpunit tests
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
print __METHOD__."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testJqueryOnce
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* The depends says test is run only if previous is ok
|
||||||
|
*/
|
||||||
|
public function testJqueryOnce()
|
||||||
|
{
|
||||||
|
global $conf,$user,$langs,$db;
|
||||||
|
|
||||||
|
// Scan dir to guarante we don't have library jquery twice
|
||||||
|
$founddirs=dol_dir_list(DOL_DOCUMENT_ROOT.'/includes/', 'files', 1, '^jquery\.js', array('ckeditor'));
|
||||||
|
print __METHOD__." count(founddirs)=".count($founddirs)."\n";
|
||||||
|
$this->assertEquals(1, count($founddirs), 'We found jquery lib (jquery.js) twice');
|
||||||
|
|
||||||
|
// Scan dir to guarante we don't have library jquery twice
|
||||||
|
$founddirs=dol_dir_list(DOL_DOCUMENT_ROOT.'/includes/', 'files', 1, '^jquery\.min\.js', array('ckeditor'));
|
||||||
|
print __METHOD__." count(founddirs)=".count($founddirs)."\n";
|
||||||
|
$this->assertEquals(1, count($founddirs), 'We found jquery lib (jquery.min.js) twice');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testRepository
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function testRepository()
|
||||||
|
{
|
||||||
|
global $conf,$user,$langs,$db;
|
||||||
|
$conf=$this->savconf;
|
||||||
|
$user=$this->savuser;
|
||||||
|
$langs=$this->savlangs;
|
||||||
|
$db=$this->savdb;
|
||||||
|
|
||||||
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
|
$filesarray = dol_dir_list(DOL_DOCUMENT_ROOT, 'directories', 1, '', array('\/custom\/'), 'fullname', SORT_ASC, 0, 1, '', 1);
|
||||||
|
//$filesarray = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, '\.php', null, 'fullname');
|
||||||
|
|
||||||
|
$ok = true;
|
||||||
|
foreach ($filesarray as $key => $file) {
|
||||||
|
if (preg_match('/\/vendor\//', $file['fullname'])) {
|
||||||
|
if (!preg_match('/php-imap/', $file['fullname'])) { // we accept 'vendor' dir for php-imap (not find how to do it easily without)
|
||||||
|
print "Found a vendor dir into ".$file['fullname']."\n";
|
||||||
|
$ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertTrue($ok, 'Pb in list of files of repository');
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user