dolibarr/test/phpunit/CommandeTest.php

306 lines
7.9 KiB
PHP
Raw Normal View History

2010-04-27 01:20:14 +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-04-27 01:20:14 +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
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
2010-04-27 01:20:14 +02:00
*/
/**
2010-08-16 01:19:46 +02:00
* \file test/phpunit/CommandeTest.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-04-27 01:20:14 +02:00
*/
2010-04-27 10:36:14 +02:00
2010-04-27 01:20:14 +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';
2010-04-27 01:20:14 +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-04-27 01:52:51 +02:00
}
2010-07-15 01:10:56 +02:00
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
2010-04-27 01:20:14 +02:00
/**
2011-09-23 14:21:00 +02:00
* Class for PHPUnit tests
*
2010-04-27 01:52:51 +02:00
* @backupGlobals disabled
2010-04-27 01:20:14 +02:00
* @backupStaticAttributes enabled
2010-04-27 01:52:51 +02:00
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
2010-04-27 01:20:14 +02:00
*/
2019-07-05 21:28:27 +02:00
class CommandeTest extends PHPUnit\Framework\TestCase
2010-04-27 01:20:14 +02:00
{
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 CommandeTest
*/
2019-02-25 00:56:48 +01:00
public function __construct()
2015-01-06 17:54:36 +01:00
{
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";
}
2020-05-03 22:47:43 +02:00
/**
* setUpBeforeClass
*
* @return void
*/
2015-01-06 17:54:36 +01:00
public static function setUpBeforeClass()
2010-04-27 01:20:14 +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-04-27 01:20:14 +02:00
2015-03-17 00:35:17 +01:00
if (empty($conf->commande->enabled)) { print __METHOD__." module customer order must be enabled.\n"; die(); }
2015-01-06 17:54:36 +01:00
print __METHOD__."\n";
2010-04-27 01:20:14 +02:00
}
2015-01-06 17:54:36 +01:00
2020-05-03 22:47:43 +02:00
/**
* tearDownAfterClass
*
* @return void
*/
2010-04-27 01:20:14 +02:00
public static function tearDownAfterClass()
{
2015-01-06 17:54:36 +01:00
global $conf,$user,$langs,$db;
$db->rollback();
2010-04-27 01:20:14 +02:00
2015-01-06 17:54:36 +01:00
print __METHOD__."\n";
2010-04-27 01:20:14 +02:00
}
2015-01-06 17:54:36 +01:00
/**
* Init phpunit tests
*
* @return void
*/
2010-04-27 01:20:14 +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;
print __METHOD__."\n";
//print $db->getVersion()."\n";
2010-04-27 01:20:14 +02:00
}
2015-01-06 17:54:36 +01:00
/**
* End phpunit tests
*
* @return void
*/
2010-04-27 01:20:14 +02:00
protected function tearDown()
{
2015-01-06 17:54:36 +01:00
print __METHOD__."\n";
2010-04-27 01:20:14 +02:00
}
/**
2012-02-17 16:02:35 +01:00
* testCommandeCreate
*
2015-01-06 17:54:36 +01:00
* @return void
2010-04-27 01:20:14 +02:00
*/
public function testCommandeCreate()
{
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->initAsSpecimen();
$result=$localobject->create($user);
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
return $result;
2010-04-27 01:20:14 +02:00
}
/**
2012-02-17 16:02:35 +01:00
* testCommandeFetch
*
2015-01-06 17:54:36 +01:00
* @param int $id Id order
* @return Commande
*
2010-04-27 01:20:14 +02:00
* @depends testCommandeCreate
* The depends says test is run only if previous is ok
*/
public function testCommandeFetch($id)
{
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);
$result=$localobject->fetch($id);
$this->assertLessThan($result, 0);
print __METHOD__." id=".$id." result=".$result."\n";
return $localobject;
2010-04-27 01:20:14 +02:00
}
2017-12-01 15:39:18 +01:00
/**
* testCommandeUpdate
*
* @param Object $localobject Commande
* @return Commande
*
* @depends testCommandeFetch
* The depends says test is run only if previous is ok
*/
2018-05-18 09:25:59 +02:00
public function testCommandeUpdate($localobject)
2017-12-01 15:39:18 +01:00
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject->note_private='New note private after update';
$result=$localobject->update($user);
$this->assertLessThan($result, 0);
print __METHOD__." id=".$id." result=".$result."\n";
return $localobject;
}
2010-04-27 01:20:14 +02:00
/**
2012-02-17 16:02:35 +01:00
* testCommandeValid
*
2015-01-06 17:54:36 +01:00
* @param Object $localobject Order
2017-12-01 15:39:18 +01:00
* @return Commande
*
2018-05-18 09:25:59 +02:00
* @depends testCommandeUpdate
2010-04-27 01:20:14 +02:00
* The depends says test is run only if previous is ok
*/
public function testCommandeValid($localobject)
{
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-04-27 01:20:14 +02:00
2015-01-06 17:54:36 +01:00
$result=$localobject->valid($user);
2010-04-27 01:52:51 +02:00
2015-01-06 17:54:36 +01:00
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertLessThan($result, 0);
return $localobject;
2010-04-27 01:20:14 +02:00
}
/**
2012-02-17 16:02:35 +01:00
* testCommandeCancel
*
2015-01-06 17:54:36 +01:00
* @param Object $localobject Order
2017-12-01 15:39:18 +01:00
* @return Commande
*
2015-01-06 17:54:36 +01:00
* @depends testCommandeValid
2010-04-27 01:20:14 +02:00
* The depends says test is run only if previous is ok
*/
2010-05-17 14:48:55 +02:00
public function testCommandeCancel($localobject)
{
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-17 14:48:55 +02:00
2015-01-06 17:54:36 +01:00
$result=$localobject->cancel();
2010-05-17 14:48:55 +02:00
2015-01-06 17:54:36 +01:00
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertLessThan($result, 0);
return $localobject;
2010-10-13 21:01:22 +02:00
}
/**
2012-02-17 16:02:35 +01:00
* testCommandeOther
*
2015-01-06 17:54:36 +01:00
* @param Object $localobject Order
2017-12-01 15:39:18 +01:00
* @return int Order id
*
2010-10-13 21:01:22 +02:00
* @depends testCommandeCancel
* The depends says test is run only if previous is ok
*/
public function testCommandeOther($localobject)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
/*$result=$localobject->setstatus(0);
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertLessThan($result, 0);
*/
$localobject->info($localobject->id);
print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n";
$this->assertNotEquals($localobject->date_creation, '');
return $localobject->id;
2010-05-17 14:48:55 +02:00
}
/**
2012-02-17 16:02:35 +01:00
* testCommandeDelete
*
2015-01-06 17:54:36 +01:00
* @param int $id Id of order
* @return void
*
2015-01-06 17:54:36 +01:00
* @depends testCommandeOther
2010-05-17 14:48:55 +02:00
* The depends says test is run only if previous is ok
*/
2010-04-27 01:20:14 +02:00
public function testCommandeDelete($id)
{
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);
$result=$localobject->fetch($id);
$result=$localobject->delete($user);
print __METHOD__." id=".$id." result=".$result."\n";
$this->assertLessThan($result, 0);
return $result;
2010-04-27 01:20:14 +02:00
}
}