dolibarr/test/phpunit/CommonObjectTest.php

189 lines
4.7 KiB
PHP
Raw Normal View History

2010-05-05 20:08:42 +02:00
<?php
/* Copyright (C) 2010 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
2010-05-05 20:08:42 +02: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
2011-12-17 21:58:44 +01:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
2010-05-05 20:08:42 +02:00
*/
/**
2010-08-16 01:19:46 +02:00
* \file test/phpunit/CommonObjectTest.php
2015-01-06 17:54:36 +01:00
* \ingroup test
2010-10-03 20:53:40 +02:00
* \brief PHPUnit test
2015-01-06 17:54:36 +01:00
* \remarks To run this script as CLI: phpunit filename.php
2010-05-05 20:08:42 +02: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-16 01:19:46 +02: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';
2010-05-05 20:08:42 +02:00
2015-01-06 17:54:36 +01:00
if (empty($user->id)) {
print "Load permissions for admin user nb 1\n";
$user->fetch(1);
$user->getrights();
2010-05-05 20:08:42 +02:00
}
2010-07-15 01:10:56 +02:00
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
2010-05-05 20:08:42 +02:00
/**
2011-09-23 14:21:00 +02:00
* Class for PHPUnit tests
*
2010-05-05 20:08:42 +02:00
* @backupGlobals disabled
* @backupStaticAttributes enabled
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
*/
class CommonObjectTest extends PHPUnit_Framework_TestCase
{
2015-01-06 17:54:36 +01:00
protected $savconf;
protected $savuser;
protected $savlangs;
protected $savdb;
/**
* Constructor
* We save global variables into local variables
*
* @return CommonObjectTest
*/
function __construct()
{
2018-09-02 14:10:06 +02:00
parent::__construct();
//$this->sharedFixture
2015-01-06 17:54:36 +01:00
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";
}
// Static methods
public static function setUpBeforeClass()
2010-05-05 20:08:42 +02:00
{
2015-01-06 17:54:36 +01:00
global $conf,$user,$langs,$db;
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
2010-05-05 20:08:42 +02:00
2015-01-06 17:54:36 +01:00
print __METHOD__."\n";
2010-05-05 20:08:42 +02:00
}
2015-01-06 17:54:36 +01:00
// tear down after class
2010-05-05 20:08:42 +02:00
public static function tearDownAfterClass()
{
2015-01-06 17:54:36 +01:00
global $conf,$user,$langs,$db;
$db->rollback();
2010-05-05 20:08:42 +02:00
2015-01-06 17:54:36 +01:00
print __METHOD__."\n";
2010-05-05 20:08:42 +02:00
}
2015-01-06 17:54:36 +01:00
/**
* Init phpunit tests
*
* @return void
*/
2010-05-05 20:08:42 +02:00
protected function setUp()
{
2015-01-06 17:54:36 +01:00
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
2010-05-05 20:08:42 +02:00
2015-01-06 17:54:36 +01:00
print __METHOD__."\n";
2010-05-05 20:08:42 +02:00
}
2015-01-06 17:54:36 +01:00
/**
* End phpunit tests
*
* @return void
*/
2010-05-05 20:08:42 +02:00
protected function tearDown()
{
2015-01-06 17:54:36 +01:00
print __METHOD__."\n";
2010-05-05 20:08:42 +02:00
}
/**
2015-01-06 17:54:36 +01:00
* testFetchUser
2010-05-05 20:08:42 +02:00
*
2015-01-06 17:54:36 +01:00
* @return void
2010-05-05 20:08:42 +02:00
*/
public function testFetchUser()
{
2015-01-06 17:54:36 +01:00
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
2010-05-05 20:08:42 +02:00
2015-01-06 17:54:36 +01:00
$localobject=new Commande($this->savdb);
$localobject->fetch(1);
2010-05-05 20:08:42 +02:00
2015-01-06 17:54:36 +01:00
$result=$localobject->fetch_user(1);
2010-05-05 20:08:42 +02:00
2015-01-06 17:54:36 +01:00
print __METHOD__." result=".$result."\n";
$this->assertLessThan($localobject->user->id, 0);
return $result;
2010-05-05 20:08:42 +02:00
}
/**
2015-01-06 17:54:36 +01:00
* testFetchProjet
2010-05-05 20:08:42 +02:00
*
2015-01-06 17:54:36 +01:00
* @return void
2010-05-05 20:08:42 +02:00
*/
public function testFetchProjet()
{
2015-01-06 17:54:36 +01:00
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new Commande($this->savdb);
$localobject->fetch(1);
$result=$localobject->fetch_projet();
print __METHOD__." result=".$result."\n";
2019-01-27 13:07:22 +01:00
$this->assertLessThanOrEqual($result, 0);
2015-01-06 17:54:36 +01:00
return $result;
2010-05-05 20:08:42 +02:00
}
/**
2015-01-06 17:54:36 +01:00
* testFetchThirdParty
2010-05-05 20:08:42 +02:00
*
2015-01-06 17:54:36 +01:00
* @return void
2010-05-05 20:08:42 +02:00
*/
2011-11-23 15:08:03 +01:00
public function testFetchThirdParty()
2010-05-05 20:08:42 +02:00
{
2015-01-06 17:54:36 +01:00
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
2010-05-05 20:08:42 +02:00
2015-01-06 17:54:36 +01:00
$localobject=new Commande($this->savdb);
$localobject->fetch(1);
2010-05-05 20:08:42 +02:00
2015-01-06 17:54:36 +01:00
$result=$localobject->fetch_thirdparty();
2010-05-05 20:08:42 +02:00
2015-01-06 17:54:36 +01:00
print __METHOD__." result=".$result."\n";
2019-01-27 13:07:22 +01:00
$this->assertLessThanOrEqual($result, 0);
2015-01-06 17:54:36 +01:00
return $result;
2010-05-05 20:08:42 +02:00
}
}