2010-05-05 18:08:42 +00:00
|
|
|
<?php
|
|
|
|
|
/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
2023-05-07 12:31:35 +00:00
|
|
|
* Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
|
2024-10-26 20:43:44 +00:00
|
|
|
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
|
2010-05-05 18:08:42 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
2013-01-16 14:36:08 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2010-05-05 18:08:42 +00:00
|
|
|
* (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
|
2019-09-23 19:55:30 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
* or see https://www.gnu.org/
|
2010-05-05 18:08:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2010-08-15 23:19:46 +00:00
|
|
|
* \file test/phpunit/CommonObjectTest.php
|
2015-01-06 16:54:36 +00:00
|
|
|
* \ingroup test
|
2010-10-03 18:53:40 +00:00
|
|
|
* \brief PHPUnit test
|
2015-01-06 16:54:36 +00:00
|
|
|
* \remarks To run this script as CLI: phpunit filename.php
|
2010-05-05 18:08:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
global $conf,$user,$langs,$db;
|
|
|
|
|
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
|
2014-05-01 17:57:53 +00:00
|
|
|
//require_once 'PHPUnit/Autoload.php';
|
2010-08-15 23:19:46 +00:00
|
|
|
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
|
|
|
|
|
require_once dirname(__FILE__).'/../../htdocs/commande/class/commande.class.php';
|
|
|
|
|
require_once dirname(__FILE__).'/../../htdocs/projet/class/project.class.php';
|
2024-02-16 22:26:32 +00:00
|
|
|
require_once dirname(__FILE__).'/CommonClassTest.class.php';
|
2010-05-05 18:08:42 +00:00
|
|
|
|
2015-01-06 16:54:36 +00:00
|
|
|
if (empty($user->id)) {
|
2021-01-14 14:09:08 +00:00
|
|
|
print "Load permissions for admin user nb 1\n";
|
|
|
|
|
$user->fetch(1);
|
2024-11-13 23:16:43 +00:00
|
|
|
$user->loadRights();
|
2010-05-05 18:08:42 +00:00
|
|
|
}
|
2024-02-19 14:28:21 +00:00
|
|
|
$conf->global->MAIN_DISABLE_ALL_MAILS = 1;
|
2010-05-05 18:08:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-09-23 12:21:00 +00:00
|
|
|
* Class for PHPUnit tests
|
2010-10-26 19:47:19 +00:00
|
|
|
*
|
2010-05-05 18:08:42 +00:00
|
|
|
* @backupGlobals disabled
|
|
|
|
|
* @backupStaticAttributes enabled
|
|
|
|
|
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
|
|
|
|
|
*/
|
2024-02-16 22:26:32 +00:00
|
|
|
class CommonObjectTest extends CommonClassTest
|
2010-05-05 18:08:42 +00:00
|
|
|
{
|
2021-01-14 14:09:08 +00:00
|
|
|
/**
|
|
|
|
|
* testFetchUser
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function testFetchUser()
|
|
|
|
|
{
|
|
|
|
|
global $conf,$user,$langs,$db;
|
2024-02-19 14:28:21 +00:00
|
|
|
$conf = $this->savconf;
|
|
|
|
|
$user = $this->savuser;
|
|
|
|
|
$langs = $this->savlangs;
|
|
|
|
|
$db = $this->savdb;
|
2021-01-14 14:09:08 +00:00
|
|
|
|
2024-02-19 14:28:21 +00:00
|
|
|
$localobject = new Commande($db);
|
2021-01-14 14:09:08 +00:00
|
|
|
$localobject->fetch(1);
|
|
|
|
|
|
2024-02-19 14:28:21 +00:00
|
|
|
$result = $localobject->fetch_user(1);
|
2021-01-14 14:09:08 +00:00
|
|
|
|
|
|
|
|
print __METHOD__." result=".$result."\n";
|
|
|
|
|
$this->assertLessThan($localobject->user->id, 0);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-02-17 14:34:19 +00:00
|
|
|
* testFetchProject
|
2021-01-14 14:09:08 +00:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2024-02-17 14:34:19 +00:00
|
|
|
public function testFetchProject()
|
2021-01-14 14:09:08 +00:00
|
|
|
{
|
|
|
|
|
global $conf,$user,$langs,$db;
|
2024-02-19 14:28:21 +00:00
|
|
|
$conf = $this->savconf;
|
|
|
|
|
$user = $this->savuser;
|
|
|
|
|
$langs = $this->savlangs;
|
|
|
|
|
$db = $this->savdb;
|
2021-01-14 14:09:08 +00:00
|
|
|
|
2024-02-19 14:28:21 +00:00
|
|
|
$localobject = new Commande($db);
|
2021-01-14 14:09:08 +00:00
|
|
|
$localobject->fetch(1);
|
2024-10-26 20:43:44 +00:00
|
|
|
$result = $localobject->fetchProject();
|
2021-01-14 14:09:08 +00:00
|
|
|
|
|
|
|
|
print __METHOD__." result=".$result."\n";
|
|
|
|
|
$this->assertLessThanOrEqual($result, 0);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* testFetchThirdParty
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function testFetchThirdParty()
|
|
|
|
|
{
|
|
|
|
|
global $conf,$user,$langs,$db;
|
2024-02-19 14:28:21 +00:00
|
|
|
$conf = $this->savconf;
|
|
|
|
|
$user = $this->savuser;
|
|
|
|
|
$langs = $this->savlangs;
|
|
|
|
|
$db = $this->savdb;
|
2021-01-14 14:09:08 +00:00
|
|
|
|
2024-02-19 14:28:21 +00:00
|
|
|
$localobject = new Commande($db);
|
2021-01-14 14:09:08 +00:00
|
|
|
$localobject->fetch(1);
|
|
|
|
|
|
2024-02-19 14:28:21 +00:00
|
|
|
$result = $localobject->fetch_thirdparty();
|
2021-01-14 14:09:08 +00:00
|
|
|
|
|
|
|
|
print __METHOD__." result=".$result."\n";
|
|
|
|
|
$this->assertLessThanOrEqual($result, 0);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2026-07-20 13:30:28 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* testIsInt
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function testIsInt()
|
|
|
|
|
{
|
|
|
|
|
global $conf,$user,$langs,$db;
|
|
|
|
|
$conf = $this->savconf;
|
|
|
|
|
$user = $this->savuser;
|
|
|
|
|
$langs = $this->savlangs;
|
|
|
|
|
$db = $this->savdb;
|
|
|
|
|
|
|
|
|
|
$localobject = new Commande($db);
|
|
|
|
|
|
|
|
|
|
// Integer types, with or without a size/unsigned suffix, must be detected.
|
|
|
|
|
$this->assertTrue($localobject->isInt(array('type' => 'int')), 'int');
|
|
|
|
|
$this->assertTrue($localobject->isInt(array('type' => 'int(11)')), 'int(11)');
|
|
|
|
|
$this->assertTrue($localobject->isInt(array('type' => 'integer')), 'integer');
|
|
|
|
|
$this->assertTrue($localobject->isInt(array('type' => 'tinyint(4)')), 'tinyint(4)');
|
|
|
|
|
$this->assertTrue($localobject->isInt(array('type' => 'smallint(6)')), 'smallint(6)');
|
|
|
|
|
$this->assertTrue($localobject->isInt(array('type' => 'bigint(20)')), 'bigint(20)');
|
|
|
|
|
// Dolibarr foreign-key column syntax "integer:Class:path" must keep being detected.
|
|
|
|
|
$this->assertTrue($localobject->isInt(array('type' => 'integer:User:user/class/user.class.php')), 'integer:User:...');
|
|
|
|
|
|
|
|
|
|
// Non-integer types must not be detected, including strings that merely contain "int".
|
|
|
|
|
$this->assertFalse($localobject->isInt(array('type' => 'varchar(255)')), 'varchar(255)');
|
|
|
|
|
$this->assertFalse($localobject->isInt(array('type' => 'double(24,8)')), 'double(24,8)');
|
|
|
|
|
$this->assertFalse($localobject->isInt(array('type' => 'date')), 'date');
|
|
|
|
|
$this->assertFalse($localobject->isInt(array('type' => 'sellist:llx_c_typent:libelle:id')), 'sellist:...');
|
|
|
|
|
|
|
|
|
|
print __METHOD__." OK\n";
|
|
|
|
|
}
|
2010-05-05 18:08:42 +00:00
|
|
|
}
|