dolibarr/test/phpunit/BuildDocTest.php

428 lines
14 KiB
PHP
Raw Normal View History

2010-05-08 20:38:17 +02:00
<?php
2015-01-06 17:54:36 +01:00
/* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
2010-05-08 20:38:17 +02: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-08 20:38:17 +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-08 20:38:17 +02:00
*/
/**
2010-08-16 01:19:46 +02:00
* \file test/phpunit/BuildDocTest.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-08 20:38:17 +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/compta/facture/class/facture.class.php';
2012-02-15 13:41:05 +01:00
require_once dirname(__FILE__).'/../../htdocs/fourn/class/fournisseur.facture.class.php';
2010-10-13 16:57:08 +02:00
require_once dirname(__FILE__).'/../../htdocs/commande/class/commande.class.php';
2012-02-15 13:41:05 +01:00
require_once dirname(__FILE__).'/../../htdocs/fourn/class/fournisseur.commande.class.php';
2010-10-13 16:57:08 +02:00
require_once dirname(__FILE__).'/../../htdocs/comm/propal/class/propal.class.php';
2010-10-23 19:03:07 +02:00
require_once dirname(__FILE__).'/../../htdocs/fichinter/class/fichinter.class.php';
require_once dirname(__FILE__).'/../../htdocs/expedition/class/expedition.class.php';
2010-10-23 19:03:08 +02:00
require_once dirname(__FILE__).'/../../htdocs/projet/class/project.class.php';
require_once dirname(__FILE__).'/../../htdocs/projet/class/task.class.php';
2012-02-15 13:41:05 +01:00
require_once dirname(__FILE__).'/../../htdocs/fourn/class/fournisseur.product.class.php';
2011-10-24 12:59:44 +02:00
require_once dirname(__FILE__).'/../../htdocs/core/lib/pdf.lib.php';
require_once dirname(__FILE__).'/../../htdocs/core/modules/facture/doc/pdf_crabe.modules.php';
require_once dirname(__FILE__).'/../../htdocs/core/modules/propale/doc/pdf_azur.modules.php';
require_once dirname(__FILE__).'/../../htdocs/core/modules/commande/doc/pdf_einstein.modules.php';
require_once dirname(__FILE__).'/../../htdocs/core/modules/project/doc/pdf_baleine.modules.php';
2012-01-24 07:05:06 +01:00
require_once dirname(__FILE__).'/../../htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php';
2013-09-08 23:38:55 +02:00
require_once dirname(__FILE__).'/../../htdocs/core/modules/expedition/doc/pdf_merou.modules.php';
require_once dirname(__FILE__).'/../../htdocs/core/modules/expedition/doc/pdf_rouget.modules.php';
// Mother classes of pdf generators
require_once dirname(__FILE__).'/../../htdocs/core/modules/facture/modules_facture.php';
2012-02-15 13:41:05 +01:00
require_once dirname(__FILE__).'/../../htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php';
require_once dirname(__FILE__).'/../../htdocs/core/modules/commande/modules_commande.php';
2012-02-15 13:41:05 +01:00
require_once dirname(__FILE__).'/../../htdocs/core/modules/supplier_order/modules_commandefournisseur.php';
require_once dirname(__FILE__).'/../../htdocs/core/modules/propale/modules_propale.php';
require_once dirname(__FILE__).'/../../htdocs/core/modules/project/modules_project.php';
require_once dirname(__FILE__).'/../../htdocs/core/modules/fichinter/modules_fichinter.php';
require_once dirname(__FILE__).'/../../htdocs/core/modules/expedition/modules_expedition.php';
2010-05-08 20:38:17 +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-08 20:38:17 +02:00
}
2010-07-15 01:10:56 +02:00
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
2010-05-08 20:38:17 +02:00
/**
2011-09-23 14:21:00 +02:00
* Class for PHPUnit tests
*
2010-05-08 20:38:17 +02:00
* @backupGlobals disabled
* @backupStaticAttributes enabled
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
*/
class BuildDocTest 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 BuildDocTest
*/
function __construct()
2010-05-08 20:38:17 +02:00
{
2015-01-06 17:54:36 +01:00
//$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";
}
// Static methods
public static function setUpBeforeClass()
{
global $conf,$user,$langs,$db;
2010-12-13 12:27:41 +01:00
if (! $conf->facture->enabled) { print __METHOD__." invoice module not enabled\n"; die(); }
if (! $conf->commande->enabled) { print __METHOD__." order module not enabled\n"; die(); }
2012-03-22 08:33:44 +01:00
if (! $conf->propal->enabled) { print __METHOD__." propal module not enabled\n"; die(); }
2010-12-13 12:27:41 +01:00
if (! $conf->projet->enabled) { print __METHOD__." project module not enabled\n"; die(); }
if (! $conf->expedition->enabled) { print __METHOD__." shipment module not enabled\n"; die(); }
if (! $conf->ficheinter->enabled) { print __METHOD__." intervention module not enabled\n"; die(); }
if (! $conf->deplacement->enabled) { print __METHOD__." trip module not enabled\n"; die(); }
2010-12-13 12:27:41 +01:00
2015-01-06 17:54:36 +01:00
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
2010-05-08 20:38:17 +02:00
2015-01-06 17:54:36 +01:00
print __METHOD__."\n";
2010-05-08 20:38:17 +02:00
}
2015-01-06 17:54:36 +01:00
// tear down after class
2010-05-08 20:38:17 +02:00
public static function tearDownAfterClass()
{
2015-01-06 17:54:36 +01:00
global $conf,$user,$langs,$db;
$db->rollback();
2010-05-08 20:38:17 +02:00
2015-01-06 17:54:36 +01:00
print __METHOD__."\n";
2010-05-08 20:38:17 +02:00
}
2015-01-06 17:54:36 +01:00
/**
* Init phpunit tests
*
* @return void
*/
2010-05-08 20:38:17 +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-08 20:38:17 +02:00
2015-01-06 17:54:36 +01:00
print __METHOD__."\n";
2010-05-08 20:38:17 +02:00
}
2015-01-06 17:54:36 +01:00
/**
* End phpunit tests
*
* @return void
*/
2010-05-08 20:38:17 +02:00
protected function tearDown()
{
2015-01-06 17:54:36 +01:00
print __METHOD__."\n";
2010-05-08 20:38:17 +02:00
}
/**
2012-02-15 13:41:05 +01:00
* testFactureBuild
*
* @return int
2010-05-08 20:38:17 +02:00
*/
public function testFactureBuild()
{
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;
$conf->facture->dir_output.='/temp';
$localobjectcom=new Commande($this->savdb);
$localobjectcom->initAsSpecimen();
$localobject=new Facture($this->savdb);
$localobject->createFromOrder($localobjectcom);
$localobject->date_lim_reglement = dol_now() + 3600 * 24 *30;
// Crabe (english)
$localobject->modelpdf='crabe';
$result = $localobject->generateDocument($localobject->modelpdf, $langs);
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
// Crabe (japanese)
$newlangs1=new Translate("",$conf);
$newlangs1->setDefaultLang('ja_JP');
$localobject->modelpdf='crabe';
$result = $localobject->generateDocument($localobject->modelpdf, $newlangs1);
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
// Crabe (saudiarabia)
$newlangs2a=new Translate("",$conf);
$newlangs2a->setDefaultLang('sa_SA');
$localobject->modelpdf='crabe';
$result = $localobject->generateDocument($localobject->modelpdf, $newlangs2a);
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
// Crabe (english_saudiarabia)
$newlangs2b=new Translate("",$conf);
$newlangs2b->setDefaultLang('en_SA');
$localobject->modelpdf='crabe';
$result = $localobject->generateDocument($localobject->modelpdf, $newlangs2b);
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
// Crabe (greek)
$newlangs3=new Translate("",$conf);
$newlangs3->setDefaultLang('el_GR');
$localobject->modelpdf='crabe';
$result = $localobject->generateDocument($localobject->modelpdf, $newlangs3);
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
// Crabe (chinese)
$newlangs4=new Translate("",$conf);
$newlangs4->setDefaultLang('zh_CN');
$localobject->modelpdf='crabe';
$result = $localobject->generateDocument($localobject->modelpdf, $newlangs4);
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
// Crabe (russian)
$newlangs5=new Translate("",$conf);
$newlangs5->setDefaultLang('ru_RU');
$localobject->modelpdf='crabe';
$result = $localobject->generateDocument($localobject->modelpdf, $newlangs5);
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
return 0;
2010-05-08 20:38:17 +02:00
}
2010-10-13 16:57:08 +02:00
/**
2012-09-06 08:06:48 +02:00
* testFactureFournisseurBuild
2012-02-15 13:41:05 +01:00
*
* @return int
*/
public function testFactureFournisseurBuild()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$conf->fournisseur->facture->dir_output.='/temp';
$localobject=new FactureFournisseur($this->savdb);
$localobject->initAsSpecimen();
// Canelle
$localobject->modelpdf='canelle';
2015-01-06 17:54:36 +01:00
$result = $localobject->generateDocument($localobject->modelpdf, $langs);
2012-02-15 13:41:05 +01:00
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
return 0;
}
/**
* testCommandeBuild
*
* @return int
2010-10-13 16:57:08 +02:00
*/
public function testCommandeBuild()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$conf->commande->dir_output.='/temp';
$localobject=new Commande($this->savdb);
$localobject->initAsSpecimen();
// Einstein
$localobject->modelpdf='einstein';
2015-01-06 17:54:36 +01:00
$result = $localobject->generateDocument($localobject->modelpdf, $langs);
2010-10-13 16:57:08 +02:00
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
return 0;
}
2012-02-15 13:41:05 +01:00
/**
* testCommandeFournisseurBuild
2015-01-06 17:54:36 +01:00
*
* @return int
*/
2012-02-15 13:41:05 +01:00
public function testCommandeFournisseurBuild()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$conf->fournisseur->commande->dir_output.='/temp';
$localobject=new CommandeFournisseur($this->savdb);
$localobject->initAsSpecimen();
// Muscadet
$localobject->modelpdf='muscadet';
$result= $localobject->generateDocument($localobject->modelpdf, $langs);
2012-02-15 13:41:05 +01:00
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
return 0;
}
2010-10-13 16:57:08 +02:00
/**
2012-02-15 13:41:05 +01:00
* testPropalBuild
*
* @return int
2010-10-13 16:57:08 +02:00
*/
public function testPropalBuild()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
2012-03-22 08:33:44 +01:00
$conf->propal->dir_output.='/temp';
2010-10-13 16:57:08 +02:00
$localobject=new Propal($this->savdb);
$localobject->initAsSpecimen();
2012-09-06 08:06:48 +02:00
// Azur
2010-10-13 16:57:08 +02:00
$localobject->modelpdf='azur';
2015-01-06 17:54:36 +01:00
$result = $localobject->generateDocument($localobject->modelpdf, $langs);
2010-10-13 16:57:08 +02:00
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
2010-10-23 19:03:08 +02:00
return 0;
}
/**
2012-02-15 13:41:05 +01:00
* testProjectBuild
*
* @return int
2010-10-23 19:03:08 +02:00
*/
public function testProjectBuild()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
2012-09-19 13:30:59 +02:00
$conf->projet->dir_output.='/temp';
2010-10-23 19:03:08 +02:00
$localobject=new Project($this->savdb);
$localobject->initAsSpecimen();
2012-09-06 08:06:48 +02:00
// Baleine
2010-10-23 19:03:08 +02:00
$localobject->modelpdf='baleine';
2015-01-06 17:54:36 +01:00
$result = $localobject->generateDocument($localobject->modelpdf, $langs);
2010-10-23 19:03:08 +02:00
$this->assertLessThan($result, 0);
2010-10-13 16:57:08 +02:00
print __METHOD__." result=".$result."\n";
return 0;
}
2010-10-23 19:03:07 +02:00
/**
2012-02-15 13:41:05 +01:00
* testFichinterBuild
*
* @return int
2010-10-23 19:03:07 +02:00
*/
public function testFichinterBuild()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
2013-04-14 23:42:24 +02:00
$conf->ficheinter->dir_output.='/temp';
2010-10-23 19:03:07 +02:00
$localobject=new Fichinter($this->savdb);
$localobject->initAsSpecimen();
// Soleil
$localobject->modelpdf='soleil';
$result=fichinter_create($db, $localobject, $localobject->modelpdf, $langs);
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
return 0;
}
/**
2012-02-15 13:41:05 +01:00
* testExpeditionBuild
*
* @return int
2010-10-23 19:03:07 +02:00
*/
public function testExpeditionBuild()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$conf->expedition->dir_output.='/temp';
$localobject=new Expedition($this->savdb);
$localobject->initAsSpecimen();
2012-09-06 08:06:48 +02:00
// Merou
2010-10-23 19:03:07 +02:00
$localobject->modelpdf='merou';
$result= $localobject->generateDocument($localobject->modelpdf, $langs);
2010-10-23 19:03:07 +02:00
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
2012-09-06 08:06:48 +02:00
// Rouget
2010-10-23 19:03:07 +02:00
$localobject->modelpdf='rouget';
$result= $localobject->generateDocument($localobject->modelpdf, $langs);
2010-10-23 19:03:07 +02:00
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
return 0;
}
2010-05-08 20:38:17 +02:00
}