dolibarr/test/phpunit/CommonObjectTest.php

120 lines
3.1 KiB
PHP
Raw Normal View History

2010-05-05 18:08:42 +00:00
<?php
/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
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
* 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
//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);
$user->getrights();
2010-05-05 18:08:42 +00:00
}
2010-07-14 23:10:56 +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-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;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new Commande($db);
2021-01-14 14:09:08 +00:00
$localobject->fetch(1);
$result=$localobject->fetch_user(1);
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;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new Commande($db);
2021-01-14 14:09:08 +00:00
$localobject->fetch(1);
$result=$localobject->fetch_projet();
print __METHOD__." result=".$result."\n";
$this->assertLessThanOrEqual($result, 0);
return $result;
}
/**
* testFetchThirdParty
*
* @return void
*/
public function testFetchThirdParty()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new Commande($db);
2021-01-14 14:09:08 +00:00
$localobject->fetch(1);
$result=$localobject->fetch_thirdparty();
print __METHOD__." result=".$result."\n";
$this->assertLessThanOrEqual($result, 0);
return $result;
}
2010-05-05 18:08:42 +00:00
}