From e24a8b45052b2a92ea7ca3ab26f46a22aeed0a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 20 May 2015 16:43:44 +0200 Subject: [PATCH 01/18] Closed bug #2843 Wrong SQL table called --- htdocs/categories/class/categorie.class.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 96949371bae..4ebf6126deb 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -472,7 +472,7 @@ class Categorie extends CommonObject * Link an object to the category * * @param Object $obj Object to link to category - * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact') + * @param string $type Type of category ('societe', 'member', 'customer', 'supplier', 'product', 'contact') * @return int 1 : OK, -1 : erreur SQL, -2 : id not defined, -3 : Already linked */ function add_type($obj,$type) @@ -488,9 +488,20 @@ class Categorie extends CommonObject if ($type == 'customer') $type='societe'; if ($type == 'supplier') $type='fournisseur'; - $column_name=$type; - if ($type=='contact') $column_name='socpeople'; - if ($type=='fournisseur') $column_name='societe'; + /** + * llx_categorie_contact => fk_socpeople + * llx_categorie_fournisseur, llx_categorie_societe => fk_soc + * llx_categorie_member => fk_member + * llx_categorie_product => fk_product + * llx_categories_extrafields => fk_object + */ + if ($type == 'contact') { + $column_name = 'socpeople'; + } elseif ($type == 'supplier' || ($type == 'societe')) { + $column_name = 'soc'; + } else { + $column_name = 'type'; + } $this->db->begin(); From 9ebae9520a72805b88aa91898d0081ccdc56b6b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 20 May 2015 16:46:12 +0200 Subject: [PATCH 02/18] Extrafields does not form part of this class --- htdocs/categories/class/categorie.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 4ebf6126deb..b5e46cc475a 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -493,7 +493,6 @@ class Categorie extends CommonObject * llx_categorie_fournisseur, llx_categorie_societe => fk_soc * llx_categorie_member => fk_member * llx_categorie_product => fk_product - * llx_categories_extrafields => fk_object */ if ($type == 'contact') { $column_name = 'socpeople'; From ba68598ec75814dfa57133f593a01f1558d08fd9 Mon Sep 17 00:00:00 2001 From: abb Date: Sat, 23 May 2015 15:06:18 +0100 Subject: [PATCH 03/18] added new trigger for supplier invoice unvalidation in Agenda --- htdocs/core/modules/modAgenda.class.php | 2 ++ .../interface_50_modAgenda_ActionsAuto.class.php | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/htdocs/core/modules/modAgenda.class.php b/htdocs/core/modules/modAgenda.class.php index 73a8390c9e6..c6492ab5161 100644 --- a/htdocs/core/modules/modAgenda.class.php +++ b/htdocs/core/modules/modAgenda.class.php @@ -6,6 +6,7 @@ * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2009-2011 Regis Houssin * Copyright (C) 2013 Cedric Gross + * Copyright (C) 2015 Bahfir Abbes * * 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 @@ -90,6 +91,7 @@ class modAgenda extends DolibarrModules $this->const[12] = array("MAIN_AGENDA_ACTIONAUTO_SHIPPING_VALIDATE","chaine","1"); $this->const[13] = array("MAIN_AGENDA_ACTIONAUTO_SHIPPING_SENTBYMAIL","chaine","1"); $this->const[14] = array("MAIN_AGENDA_ACTIONAUTO_BILL_UNVALIDATE","chaine","1"); + $this->const[15] = array("MAIN_AGENDA_ACTIONAUTO_BILL_SUPPLIER_UNVALIDATE","chaine","1"); // New pages on tabs // ----------------- diff --git a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php index 46a6cd0daa6..8a77bf86b4f 100644 --- a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php +++ b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2011-2014 Juanjo Menent * Copyright (C) 2013 Cedric GROSS * Copyright (C) 2014 Marcos García + * Copyright (C) 2015 Bahfir Abbes * * 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 @@ -493,6 +494,18 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + $object->sendtoid=0; + } + elseif ($action == 'BILL_SUPPLIER_UNVALIDATE') + { + $langs->load("other"); + $langs->load("bills"); + + $object->actiontypecode='AC_OTH_AUTO'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + $object->sendtoid=0; } elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') From 4e48f245073e4e1bda18690d48dffb42ea0d8302 Mon Sep 17 00:00:00 2001 From: abb Date: Sat, 23 May 2015 15:12:24 +0100 Subject: [PATCH 04/18] added new trigger for supplier invoice unvalidation "BILL_SUPPLIER_UNVALIDATE" in Database --- htdocs/install/mysql/data/llx_c_action_trigger.sql | 2 ++ htdocs/install/mysql/migration/3.7.0-3.8.0.sql | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/data/llx_c_action_trigger.sql b/htdocs/install/mysql/data/llx_c_action_trigger.sql index 1dde6d5d37c..408c7a36ff6 100644 --- a/htdocs/install/mysql/data/llx_c_action_trigger.sql +++ b/htdocs/install/mysql/data/llx_c_action_trigger.sql @@ -8,6 +8,7 @@ -- Copyright (C) 2010-2013 Juanjo Menent -- Copyright (C) 2013 Cedric Gross -- Copyright (C) 2014 Raphaël Doursenaud +-- Copyright (C) 2015 Bahfir Abbes -- -- 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 @@ -74,3 +75,4 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_CREATE','Task created','Executed when a project task is created','project',35); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_MODIFY','Task modified','Executed when a project task is modified','project',36); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_DELETE','Task deleted','Executed when a project task is deleted','project',37); +insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILL_SUPPLIER_UNVALIDATE', 'Supplier invoice unvalidated', 'Executed when a supplier invoice status is set back to draft', 'invoice_supplier',15); diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index aabca14f5a1..c44fa88c49c 100755 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -644,4 +644,5 @@ ALTER TABLE llx_actioncomm ADD COLUMN recurdateend datetime; ALTER TABLE llx_stcomm ADD COLUMN picto varchar(128); - +-- New trigger for Supplier invoice unvalidation +INSERT INTO llx_c_action_trigger (code, label, description, elementtype, rang) VALUES ('BILL_SUPPLIER_UNVALIDATE','Supplier invoice unvalidated','Executed when a supplier invoice status is set back to draft','invoice_supplier',15); From 879c82ee0a736ec4f3686537e560f6f0b50726f9 Mon Sep 17 00:00:00 2001 From: abb Date: Sat, 23 May 2015 15:27:12 +0100 Subject: [PATCH 05/18] added new trigger for supplier invoice unvalidation "BILL_SUPPLIER_UNVALIDATE" in trigger demo file --- htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN index 8da8c6e3e00..99a8a152384 100644 --- a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN +++ b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN @@ -2,6 +2,7 @@ /* Copyright (C) 2005-2014 Laurent Destailleur * Copyright (C) 2005-2014 Regis Houssin * Copyright (C) 2014 Marcos García + * Copyright (C) 2015 Bahfir Abbes * * 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 @@ -197,6 +198,7 @@ class InterfaceDemo extends DolibarrTriggers case 'BILL_SUPPLIER_PAYED': case 'BILL_SUPPLIER_UNPAYED': case 'BILL_SUPPLIER_VALIDATE': + case 'BILL_SUPPLIER_UNVALIDATE': case 'LINEBILL_SUPPLIER_CREATE': case 'LINEBILL_SUPPLIER_UPDATE': case 'LINEBILL_SUPPLIER_DELETE': From ebf2edf019057b73e7a816d1fdc64478f4749236 Mon Sep 17 00:00:00 2001 From: abb Date: Sat, 23 May 2015 15:35:19 +0100 Subject: [PATCH 06/18] added new trigger for supplier invoice unvalidation "BILL_SUPPLIER_UNVALIDATE" in set_draft class function --- htdocs/fourn/class/fournisseur.facture.class.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 994ddb28310..1cfbe941d9a 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -8,6 +8,7 @@ * Copyright (C) 2013 Philippe Grand * Copyright (C) 2013 Florian Henry * Copyright (C) 2014-2015 Marcos García + * Copyright (C) 2015 Bahfir Abbes * * 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 @@ -1073,7 +1074,14 @@ class FactureFournisseur extends CommonInvoice } } } - + // Triggers call + if (! $error && empty($notrigger)) + { + // Call trigger + $result=$this->call_trigger('BILL_SUPPLIER_VALIDATE',$user); + if ($result < 0) $error++; + // End call triggers + } if ($error == 0) { $this->db->commit(); From c018858e91b6cf28ac0e027602d030cdd5829445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Sat, 23 May 2015 20:43:01 +0200 Subject: [PATCH 07/18] Deprecation of the mysql driver Fix #2886 --- htdocs/core/db/mysql.class.php | 2 ++ htdocs/install/fileconf.php | 5 +++-- htdocs/langs/en_US/install.lang | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/htdocs/core/db/mysql.class.php b/htdocs/core/db/mysql.class.php index 30a7780afdf..bca6d0798b8 100644 --- a/htdocs/core/db/mysql.class.php +++ b/htdocs/core/db/mysql.class.php @@ -28,6 +28,8 @@ require_once DOL_DOCUMENT_ROOT .'/core/db/DoliDB.class.php'; /** * Class to manage Dolibarr database access for a MySQL database using the mysql extension + * + * @deprecated Use DoliDBMysqli */ class DoliDBMysql extends DoliDB { diff --git a/htdocs/install/fileconf.php b/htdocs/install/fileconf.php index 97a52ff6c34..04f8a3caf4c 100644 --- a/htdocs/install/fileconf.php +++ b/htdocs/install/fileconf.php @@ -328,8 +328,9 @@ if (! empty($force_install_message)) $option.='>'; $option.=$type.'   '; if ($note) $option.=' '.$note; - // Experimental - if ($type=='mssql') $option.=' '.$langs->trans("Experimental"); + // Deprecated and experimental + if ($type=='mysql') $option.=' ' . $langs->trans("Deprecated"); + elseif ($type=='mssql') $option.=' '.$langs->trans("Experimental"); elseif ($type=='sqlite') $option.=' '.$langs->trans("Experimental"); elseif ($type=='sqlite3') $option.=' '.$langs->trans("Experimental"); // No available diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang index 7de123d5ea3..0c61ce35e2e 100644 --- a/htdocs/langs/en_US/install.lang +++ b/htdocs/langs/en_US/install.lang @@ -64,6 +64,7 @@ DatabaseSuperUserAccess=Database server - Superuser access CheckToCreateDatabase=Check box if database does not exist and must be created.
In this case, you must fill the login/password for superuser account at the bottom of this page. CheckToCreateUser=Check box if database owner does not exist and must be created.
In this case, you must choose its login and password and also fill the login/password for the superuser account at the bottom of this page. If this box is unchecked, owner database and its passwords must exists. Experimental=(experimental) +Deprecated=(deprecated) DatabaseRootLoginDescription=Login of the user allowed to create new databases or new users, mandatory if your database or its owner does not already exists. KeepEmptyIfNoPassword=Leave empty if user has no password (avoid this) SaveConfigurationFile=Save values @@ -211,4 +212,4 @@ MigrationCategorieAssociation=Migration of categories MigrationEvents=Migration of events to add event owner into assignement table ShowNotAvailableOptions=Show not available options -HideNotAvailableOptions=Hide not available options \ No newline at end of file +HideNotAvailableOptions=Hide not available options From 8627f2f19b5551beb1de040e0c7f4f7ba7487e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Mon, 25 May 2015 14:01:15 +0200 Subject: [PATCH 08/18] Removed innecesary test --- htdocs/categories/class/categorie.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index b5e46cc475a..67d821578dd 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -472,7 +472,7 @@ class Categorie extends CommonObject * Link an object to the category * * @param Object $obj Object to link to category - * @param string $type Type of category ('societe', 'member', 'customer', 'supplier', 'product', 'contact') + * @param string $type Type of category ('societe', 'member', 'product', 'contact', 'fournisseur) * @return int 1 : OK, -1 : erreur SQL, -2 : id not defined, -3 : Already linked */ function add_type($obj,$type) @@ -485,8 +485,8 @@ class Categorie extends CommonObject // For backward compatibility if ($type == 'company') $type='societe'; - if ($type == 'customer') $type='societe'; - if ($type == 'supplier') $type='fournisseur'; + elseif ($type == 'customer') $type='societe'; + elseif ($type == 'supplier') $type='fournisseur'; /** * llx_categorie_contact => fk_socpeople @@ -496,7 +496,7 @@ class Categorie extends CommonObject */ if ($type == 'contact') { $column_name = 'socpeople'; - } elseif ($type == 'supplier' || ($type == 'societe')) { + } elseif ($type == 'fournisseur' || ($type == 'societe')) { $column_name = 'soc'; } else { $column_name = 'type'; From d1c7c9489e017adc33ae07d96b3c2c5421598fae Mon Sep 17 00:00:00 2001 From: Steve Braun Date: Mon, 25 May 2015 14:56:37 +0200 Subject: [PATCH 09/18] fixes #2847 --- htdocs/core/lib/functions2.lib.php | 46 ++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 1a1fd706e0a..e06577cf8f5 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -637,10 +637,21 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m //$date=dol_mktime(12, 0, 0, 1, 1, 1900); //$date=dol_stringtotime('20130101'); + $hasglobalcounter=false; // Extract value for mask counter, mask raz and mask offset - if (! preg_match('/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i',$mask,$reg)) return 'ErrorBadMask'; - $masktri=$reg[1].(! empty($reg[2])?$reg[2]:'').(! empty($reg[3])?$reg[3]:''); - $maskcounter=$reg[1]; + if (preg_match('/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i',$mask,$reg)) + { + $masktri=$reg[1].(! empty($reg[2])?$reg[2]:'').(! empty($reg[3])?$reg[3]:''); + $maskcounter=$reg[1]; + $hasglobalcounter=true; + } + else + { + // setting some defaults so the rest of the code won't fail if there is a third party counter + $masktri='00000'; + $maskcounter='00000'; + } + $maskraz=-1; $maskoffset=0; $resetEveryMonth=false; @@ -659,6 +670,12 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m if (dol_strlen($maskrefclient_maskcounter) > 0 && dol_strlen($maskrefclient_maskcounter) < 3) return 'ErrorCounterMustHaveMoreThan3Digits'; } else $maskrefclient=''; + + // fail if there is neither a global nor a third party counter + if (! $hasglobalcounter && ($maskrefclient_maskcounter == '')) + { + return 'ErrorBadMask'; + } // Extract value for third party type if (preg_match('/\{(t+)\}/i',$mask,$regType)) @@ -993,10 +1010,21 @@ function check_value($mask,$value) { $result=0; + $hasglobalcounter=false; // Extract value for mask counter, mask raz and mask offset - if (! preg_match('/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i',$mask,$reg)) return 'ErrorBadMask'; - $masktri=$reg[1].(isset($reg[2])?$reg[2]:'').(isset($reg[3])?$reg[3]:''); - $maskcounter=$reg[1]; + if (preg_match('/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i',$mask,$reg)) + { + $masktri=$reg[1].(isset($reg[2])?$reg[2]:'').(isset($reg[3])?$reg[3]:''); + $maskcounter=$reg[1]; + $hasglobalcounter=true; + } + else + { + // setting some defaults so the rest of the code won't fail if there is a third party counter + $masktri='00000'; + $maskcounter='00000'; + } + $maskraz=-1; $maskoffset=0; if (dol_strlen($maskcounter) < 3) return 'ErrorCounterMustHaveMoreThan3Digits'; @@ -1015,6 +1043,12 @@ function check_value($mask,$value) } else $maskrefclient=''; + // fail if there is neither a global nor a third party counter + if (! $hasglobalcounter && ($maskrefclient_maskcounter == '')) + { + return 'ErrorBadMask'; + } + $maskwithonlyymcode=$mask; $maskwithonlyymcode=preg_replace('/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i',$maskcounter,$maskwithonlyymcode); $maskwithonlyymcode=preg_replace('/\{dd\}/i','dd',$maskwithonlyymcode); From c0346bcba43a94e4e26b7962fe9355e886cdbe1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Mon, 25 May 2015 14:59:34 +0200 Subject: [PATCH 10/18] Fixed typo --- htdocs/categories/class/categorie.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 67d821578dd..cd248d45744 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -499,7 +499,7 @@ class Categorie extends CommonObject } elseif ($type == 'fournisseur' || ($type == 'societe')) { $column_name = 'soc'; } else { - $column_name = 'type'; + $column_name = $type; } $this->db->begin(); From a30d4d4be6b9bc8a2462b71c0752e2cc5a69f831 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Mon, 25 May 2015 18:14:49 +0200 Subject: [PATCH 11/18] Tabs collector better identification Tabs collector goes wrong with 2 tabs in the same page (like projet and task), so we use picto name to identify the 2 tabscollect We need to substract the @ if the tabs is from a module... eg : factory@factory --- htdocs/core/lib/functions.lib.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 63ab76dcb2f..8b6dfa38657 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -789,14 +789,15 @@ function dol_get_fiche_head($links=array(), $active='0', $title='', $notab=0, $p if ($displaytab > $limittoshow) { - $out.='
'; + $tabsname=str_replace ("@", "", $picto); + $out.='
'; $out.=''.$langs->trans("More").'...'; - $out.='
'.$outmore.'
'; + $out.='
'.$outmore.'
'; $out.="
\n"; $out.=""; } From 278d447e45f1f7863c7c2c943411c0cc8e191116 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Wed, 27 May 2015 15:42:34 +0200 Subject: [PATCH 12/18] Use Constant for status --- htdocs/webservices/server_invoice.php | 51 ++++++++++++++------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index 336917a8c60..d358847c0b6 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -557,25 +557,25 @@ function createInvoice($authentication,$invoice) if (! $error) { - $newobject=new Facture($db); - $newobject->socid=$invoice['thirdparty_id']; - $newobject->type=$invoice['type']; - $newobject->ref_ext=$invoice['ref_ext']; - $newobject->date=dol_stringtotime($invoice['date'],'dayrfc'); - $newobject->note_private=$invoice['note_private']; - $newobject->note_public=$invoice['note_public']; - $newobject->statut= Facture::STATUS_DRAFT; // We start with status draft - $newobject->fk_project=$invoice['project_id']; - $newobject->date_creation=$now; + $new_invoice=new Facture($db); + $new_invoice->socid=$invoice['thirdparty_id']; + $new_invoice->type=$invoice['type']; + $new_invoice->ref_ext=$invoice['ref_ext']; + $new_invoice->date=dol_stringtotime($invoice['date'],'dayrfc'); + $new_invoice->note_private=$invoice['note_private']; + $new_invoice->note_public=$invoice['note_public']; + $new_invoice->statut= Facture::STATUS_DRAFT; // We start with status draft + $new_invoice->fk_project=$invoice['project_id']; + $new_invoice->date_creation=$now; //take mode_reglement and cond_reglement from thirdparty $soc = new Societe($db); - $res=$soc->fetch($newobject->socid); + $res=$soc->fetch($new_invoice->socid); if ($res > 0) { - $newobject->mode_reglement_id = ! empty($invoice['payment_mode_id'])?$invoice['payment_mode_id']:$soc->mode_reglement_id; - $newobject->cond_reglement_id = $soc->cond_reglement_id; + $new_invoice->mode_reglement_id = ! empty($invoice['payment_mode_id'])?$invoice['payment_mode_id']:$soc->mode_reglement_id; + $new_invoice->cond_reglement_id = $soc->cond_reglement_id; } - else $newobject->mode_reglement_id = $invoice['payment_mode_id']; + else $new_invoice->mode_reglement_id = $invoice['payment_mode_id']; // Trick because nusoap does not store data with same structure if there is one or several lines $arrayoflines=array(); @@ -598,22 +598,22 @@ function createInvoice($authentication,$invoice) $newline->date_start=dol_stringtotime($line['date_start']); $newline->date_end=dol_stringtotime($line['date_end']); $newline->fk_product=$line['product_id']; - $newobject->lines[]=$newline; + $new_invoice->lines[]=$newline; } //var_dump($newobject->date_lim_reglement); exit; //var_dump($invoice['lines'][0]['type']); $db->begin(); - $result=$newobject->create($fuser,0,dol_stringtotime($invoice['date_due'],'dayrfc')); + $result=$new_invoice->create($fuser,0,dol_stringtotime($invoice['date_due'],'dayrfc')); if ($result < 0) { $error++; } - if ($invoice['status'] == 1) // We want invoice to have status validated + if (!$error && $invoice['status'] == Facture::STATUS_VALIDATED) // We want invoice to have status validated { - $result=$newobject->validate($fuser); + $result=$new_invoice->validate($fuser); if ($result < 0) { $error++; @@ -623,15 +623,16 @@ function createInvoice($authentication,$invoice) if (! $error) { $db->commit(); - $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newobject->id, - 'ref'=>$newobject->ref,'ref_ext'=>$newobject->ref_ext); + $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$new_invoice->id, + 'ref'=>$new_invoice->ref,'ref_ext'=>$new_invoice->ref_ext); } else { $db->rollback(); $error++; $errorcode='KO'; - $errorlabel=$newobject->error; + $errorlabel=$new_invoice->error; + dol_syslog("Function: createInvoice error while creating".$errorlabel); } } @@ -781,8 +782,8 @@ function updateInvoice($authentication,$invoice) if (isset($invoice['status'])) { - if ($invoice['status'] == 0) $result=$object->set_draft($fuser); - if ($invoice['status'] == 1) + if ($invoice['status'] == Facture::STATUS_DRAFT) $result=$object->set_draft($fuser); + if ($invoice['status'] == Facture::STATUS_VALIDATED) { $result=$object->validate($fuser); @@ -793,11 +794,11 @@ function updateInvoice($authentication,$invoice) $order->generateDocument($invoice->modelpdf, $outputlangs); } } - if ($invoice['status'] == 2) + if ($invoice['status'] == Facture::STATUS_CLOSED) { $result = $object->set_paid($fuser,$invoice->close_code,$invoice->close_note); } - if ($invoice['status'] == 3) $result=$object->set_canceled($fuser,$invoice->close_code,$invoice->close_note); + if ($invoice['status'] == Facture::STATUS_ABANDONED) $result=$object->set_canceled($fuser,$invoice->close_code,$invoice->close_note); } } From 336b8c49b31637e073d8ce39f3c70437e4ae2747 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Wed, 27 May 2015 15:42:46 +0200 Subject: [PATCH 13/18] update test --- test/phpunit/WebservicesInvoicesTest.php | 190 +++++++++++++---------- 1 file changed, 106 insertions(+), 84 deletions(-) diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index a295dbdc64e..4731c8f7651 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -53,7 +53,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase protected $savuser; protected $savlangs; protected $savdb; - + /** * Constructor * We save global variables into local variables @@ -79,6 +79,23 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase { global $conf,$user,$langs,$db; $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + + // create a third_party, needed to create an invoice + $societe=new Societe($db); + $societe->ref=''; + $societe->name='name'; + $societe->ref_ext='209'; + $societe->status=1; + $societe->client=1; + $societe->fournisseur=0; + $societe->date_creation=$now; + $societe->tva_assuj=0; + $societe->particulier=0; + + $societe->create($user); + + print __METHOD__." societe created id=".$societe->id."\n"; + print __METHOD__."\n"; } @@ -102,10 +119,9 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - - // create a third_party, needed to create an invoice - + print __METHOD__."\n"; + } /** @@ -136,6 +152,11 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $WS_METHOD = 'createInvoice'; $ns='http://www.dolibarr.org/ns/'; + // load societe first + $societe=new Societe($db); + $societe->fetch('', '', '209'); + print __METHOD__." societe loaded id=".$societe->id."\n"; + // Set the WebService URL print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; $soapclient = new nusoap_client($WS_DOL_URL); @@ -144,48 +165,49 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $soapclient->soap_defencoding='UTF-8'; $soapclient->decodeUTF8(false); } + $body = array ( - ["id"] => NULL, - ["ref"]=> NULL, - ["ref_ext"]=> "165", - ["thirdparty_id"]=> "209", - ["fk_user_author"] => NULL, - ["fk_user_valid"] => NULL, - ["date"]=> "2015-04-19 20:16:53", - ["date_due"]=> "", - ["date_creation"]=> "", - ["date_validation"]=> "", - ["date_modification"]=> "", - ["type"]=> "", - ["total_net"]=> "36.30", - ["total_vat"]=> "6.00", - ["total"]=> "42.30", - ["payment_mode_id"]=> 50, - ["note_private"]=> "Synchronised from Prestashop", - ["note_public"]=> "", - ["status"]=> "1", - ["close_code"]=> NULL , - ["close_note"]=> NULL, - ["project_id"]=> NULL, - ["lines"] => array( - ["id"] => NULL, - ["type"]=> 0, - ["desc"]=> "Horloge Vinyle Serge", - ["vat_rate"]=> 20, - ["qty"]=> "1", - ["unitprice"]=> "30.000000", - ["total_net"]=> "30.000000", - ["total_vat"]=> "6.00", - ["total"]=> "36.000000", - ["date_start"]=> "", - ["date_end"]=> "", - ["payment_mode_id"]=> "", - ["product_id"]=> "", - ["product_ref"]=> "", - ["product_label"]=> "", - ["product_desc"]=> "" ) - ); + "id" => NULL, + "ref" => NULL, + "ref_ext" => "165", + "thirdparty_id" => $societe->id, + "fk_user_author" => NULL, + "fk_user_valid" => NULL, + "date" => "2015-04-19 20:16:53", + "date_due" => "", + "date_creation" => "", + "date_validation" => "", + "date_modification" => "", + "type" => "", + "total_net" => "36.30", + "total_vat" => "6.00", + "total" => "42.30", + "payment_mode_id" => 50, + "note_private" => "Synchronised from Prestashop", + "note_public" => "", + "status" => "1", + "close_code" => NULL , + "close_note" => NULL, + "project_id" => NULL, + "lines" => array( + "id" => NULL, + "type" => 0, + "desc" => "Horloge Vinyle Serge", + "vat_rate" => 20, + "qty" => "1", + "unitprice" => "30.000000", + "total_net" => "30.000000", + "total_vat" => "6.00", + "total" => "36.000000", + "date_start" => "", + "date_end" => "", + "payment_mode_id" => "", + "product_id" => "", + "product_ref" => "", + "product_label" => "", + "product_desc" => "" ) + ); // Call the WebService method and store its result in $result. $authentication=array( @@ -218,7 +240,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase print "\n"; } - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_label']."\n"; $this->assertEquals('OK',$result['result']['result_code']); $this->assertEquals('165', $result['ref_ext']); @@ -319,45 +341,45 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase // update status to 2 $body = array ( - ["id"] => NULL, - ["ref"]=> NULL, - ["ref_ext"]=> "165", - ["thirdparty_id"]=> "209", - ["fk_user_author"] => NULL, - ["fk_user_valid"] => NULL, - ["date"]=> "2015-04-19 20:16:53", - ["date_due"]=> "", - ["date_creation"]=> "", - ["date_validation"]=> "", - ["date_modification"]=> "", - ["type"]=> "", - ["total_net"]=> "36.30", - ["total_vat"]=> "6.00", - ["total"]=> "42.30", - ["payment_mode_id"]=> 50, - ["note_private"]=> "Synchronised from Prestashop", - ["note_public"]=> "", - ["status"]=> "2", - ["close_code"]=> NULL , - ["close_note"]=> NULL, - ["project_id"]=> NULL, - ["lines"] => array( - ["id"] => NULL, - ["type"]=> 0, - ["desc"]=> "Horloge Vinyle Serge", - ["vat_rate"]=> 20, - ["qty"]=> "1", - ["unitprice"]=> "30.000000", - ["total_net"]=> "30.000000", - ["total_vat"]=> "6.00", - ["total"]=> "36.000000", - ["date_start"]=> "", - ["date_end"]=> "", - ["payment_mode_id"]=> "", - ["product_id"]=> "", - ["product_ref"]=> "", - ["product_label"]=> "", - ["product_desc"]=> "" ) + "id" => NULL, + "ref" => NULL, + "ref_ext" => "165", + "thirdparty_id" => "209", + "fk_user_author" => NULL, + "fk_user_valid" => NULL, + "date" => "2015-04-19 20:16:53", + "date_due" => "", + "date_creation" => "", + "date_validation" => "", + "date_modification" => "", + "type" => "", + "total_net" => "36.30", + "total_vat" => "6.00", + "total" => "42.30", + "payment_mode_id" => 50, + "note_private" => "Synchronised from Prestashop", + "note_public" => "", + "status" => "2", + "close_code" => NULL , + "close_note" => NULL, + "project_id" => NULL, + "lines" => array( + "id" => NULL, + "type" => 0, + "desc" => "Horloge Vinyle Serge", + "vat_rate" => 20, + "qty" => "1", + "unitprice" => "30.000000", + "total_net" => "30.000000", + "total_vat" => "6.00", + "total" => "36.000000", + "date_start" => "", + "date_end" => "", + "payment_mode_id" => "", + "product_id" => "", + "product_ref" => "", + "product_label" => "", + "product_desc" => "" ) ); // Call the WebService method and store its result in $result. From 33d5299a22dfd7506899d6648ae29bf810f3701c Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Thu, 28 May 2015 15:40:38 +0200 Subject: [PATCH 14/18] add deleteThirdParty api call + add tests --- test/phpunit/WebservicesThirdpartyTest.php | 258 +++++++++++++++++++-- 1 file changed, 237 insertions(+), 21 deletions(-) diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 0c99d7d362a..71c90b3f636 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -52,6 +52,13 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase protected $savuser; protected $savlangs; protected $savdb; + protected $soapclient; + + private $WS_DOL_URL; + private $ns='http://www.dolibarr.org/ns/'; + + + /** * Constructor @@ -67,6 +74,16 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $this->savuser=$user; $this->savlangs=$langs; $this->savdb=$db; + + $this->WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; + + // Set the WebService URL + print __METHOD__." create nusoap_client for URL=".$this->WS_DOL_URL."\n"; + $this->soapclient = new nusoap_client($this->WS_DOL_URL); + if ($this->soapclient) { + $this->soapclient->soap_defencoding='UTF-8'; + $this->soapclient->decodeUTF8(false); + } print __METHOD__." db->type=".$db->type." user->id=".$user->id; //print " - db ".$db->db; @@ -117,31 +134,113 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase print __METHOD__."\n"; } - /** - * testWSThirdpartygetThirdParty + * testWSThirdpartycreateThirdParty * * @return int */ - public function testWSThirdpartygetThirdParty() + public function testWSThirdpartycreateThirdParty() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $WS_METHOD = 'createThirdParty'; + + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + $body = array ( + "id" => NULL, + "ref" => "name", + "ref_ext" => "12", + "fk_user_author" => NULL, + "status" => NULL, + "client" => 1, + "supplier" => 0, + "customer_code" => "", + "supplier_code" => "", + "customer_code_accountancy" => "", + "supplier_code_accountancy" => "", + "date_creation" => "", // dateTime + "date_modification" => "", // dateTime + "note_private" => "", + "note_public" => "", + "address" => "", + "zip" => "", + "town" => "", + "province_id" => "", + "country_id" => "", + "country_code" => "", + "country" => "", + "phone" => "", + "fax" => "", + "email" => "", + "url" => "", + "profid1" => "", + "profid2" => "", + "profid3" => "", + "profid4" => "", + "profid5" => "", + "profid6" => "", + "capital" => "", + "vat_used" => "", + "vat_number" => "" + ); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication, 'thirdparty'=>$body); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$thid->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + if (! $result || ! empty($result['faultstring'])) { + //var_dump($soapclient); + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals('name',$result['ref']); + + return $result; + } + + /** + * testWSThirdpartygetThirdPartyById + * + * Use id to retrieve thirdparty + * @depends testWSThirdpartycreateThirdParty + * + * @return int + */ + public function testWSThirdpartygetThirdPartyById($result) { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; + $id = $result['id']; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; $WS_METHOD = 'getThirdParty'; - $ns='http://www.dolibarr.org/ns/'; - - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } // Call the WebService method and store its result in $result. $authentication=array( @@ -151,30 +250,147 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase 'password'=>'admin', 'entity'=>''); - // Test URL $result=''; - $parameters = array('authentication'=>$authentication, 'id'=>1); + $parameters = array('authentication'=>$authentication, 'id'=>$id); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; } if (! $result || ! empty($result['faultstring'])) { //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_code']."\n"; $this->assertEquals('OK',$result['result']['result_code']); - + $this->assertEquals($id, $result['thirdparty']['id']); + $this->assertEquals('name', $result['thirdparty']['ref']); + $this->assertEquals('12', $result['thirdparty']['ref_ext']); + $this->assertEquals('0', $result['thirdparty']['status']); + $this->assertEquals('1', $result['thirdparty']['client']); + $this->assertEquals('0', $result['thirdparty']['supplier']); + + return $result; } + + /** + * testWSThirdpartygetThirdPartyByRefExt + * + * Use ref_ext to retrieve thirdparty + * + * @depends testWSThirdpartycreateThirdParty + * @return int + */ + public function testWSThirdpartygetThirdPartyByRefExt($result) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + $id = $result['id']; + + $WS_METHOD = 'getThirdParty'; + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication, 'id'=>'', 'ref'=>'', 'ref_ext'=>'12'); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + print $this->soapclient->response; + if (! $result || ! empty($result['faultstring'])) { + //var_dump($soapclient); + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals($id, $result['thirdparty']['id']); + $this->assertEquals('name', $result['thirdparty']['ref']); + $this->assertEquals('12', $result['thirdparty']['ref_ext']); + $this->assertEquals('0', $result['thirdparty']['status']); + $this->assertEquals('1', $result['thirdparty']['client']); + $this->assertEquals('0', $result['thirdparty']['supplier']); + + + return $result; + } + + /** + * testWSThirdpartydeleteThirdParty + * + * @depends testWSThirdpartycreateThirdParty + * + * @return int + */ + public function testWSThirdpartydeleteThirdPartyById($result) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + $id = $result['id']; + + $WS_METHOD = 'deleteThirdParty'; + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + $result=''; + $parameters = array('authentication'=>$authentication, 'id'=>$id, 'ref'=>'', 'ref_ext'=>''); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + //if (! $result || ! empty($result['faultstring'])) { + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + //} + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + + return $result; + } } From 05a7ab158b51a05dbb38ac7b02abf0d2c1df9891 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Thu, 28 May 2015 15:40:38 +0200 Subject: [PATCH 15/18] add deleteThirdParty api call + add tests --- htdocs/webservices/server_thirdparty.php | 106 +++++++++ test/phpunit/WebservicesThirdpartyTest.php | 258 +++++++++++++++++++-- 2 files changed, 343 insertions(+), 21 deletions(-) diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index c7ca5911d62..542e2980c45 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -258,8 +258,31 @@ $server->register( 'WS to get list of thirdparties id and ref' ); +// Register WSDL +$server->register( + 'deleteThirdParty', + // Entry values + array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'), + // Exit values + array('result'=>'tns:result','id'=>'xsd:string'), + $ns, + $ns.'#deleteThirdParty', + $styledoc, + $styleuse, + 'WS to delete a thirdparty from its id, ref or ref_ext' +); + // Full methods code +/** + * Get a thirdparty + * + * @param array $authentication Array of authentication information + * @param string $id internal id + * @param string $ref internal reference + * @param string $ref_ext external reference + * @return array Array result + */ function getThirdParty($authentication,$id='',$ref='',$ref_ext='') { global $db,$conf,$langs; @@ -728,5 +751,88 @@ function getListOfThirdParties($authentication,$filterthirdparty) return $objectresp; } +/** + * Delete a thirdparty + * + * @param array $authentication Array of authentication information + * @param string $id internal id + * @param string $ref internal reference + * @param string $ref_ext external reference + * @return array Array result + */ +function deleteThirdParty($authentication,$id='',$ref='',$ref_ext='') +{ + global $db,$conf,$langs; + + dol_syslog("Function: deleteThirdParty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); + + if ($authentication['entity']) $conf->entity=$authentication['entity']; + + // Init and check authentication + $objectresp=array(); + $errorcode='';$errorlabel=''; + $error=0; + $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); + // Check parameters + if (! $error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) + { + dol_syslog("Function: deleteThirdParty checkparam"); + $error++; + $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both."; + } + dol_syslog("Function: deleteThirdParty 1"); + + if (! $error) + { + $fuser->getrights(); + + if ($fuser->rights->societe->lire && $fuser->rights->societe->supprimer) + { + $thirdparty=new Societe($db); + $result=$thirdparty->fetch($id,$ref,$ref_ext); + + if ($result > 0) + { + $db->begin(); + + $result=$thirdparty->delete($thirdparty->id, $fuser); + + if ($result > 0) + { + $db->commit(); + + $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>'')); + } + else + { + $db->rollback(); + $error++; + $errorcode='KO'; + $errorlabel=$thirdparty->error; + dol_syslog("Function: deleteThirdParty cant delete"); + } + } + else + { + $error++; + $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext; + + } + } + else + { + $error++; + $errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request'; + } + } + + if ($error) + { + $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); + } + + return $objectresp; +} + // Return the results. $server->service(file_get_contents("php://input")); diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 0c99d7d362a..71c90b3f636 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -52,6 +52,13 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase protected $savuser; protected $savlangs; protected $savdb; + protected $soapclient; + + private $WS_DOL_URL; + private $ns='http://www.dolibarr.org/ns/'; + + + /** * Constructor @@ -67,6 +74,16 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $this->savuser=$user; $this->savlangs=$langs; $this->savdb=$db; + + $this->WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; + + // Set the WebService URL + print __METHOD__." create nusoap_client for URL=".$this->WS_DOL_URL."\n"; + $this->soapclient = new nusoap_client($this->WS_DOL_URL); + if ($this->soapclient) { + $this->soapclient->soap_defencoding='UTF-8'; + $this->soapclient->decodeUTF8(false); + } print __METHOD__." db->type=".$db->type." user->id=".$user->id; //print " - db ".$db->db; @@ -117,31 +134,113 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase print __METHOD__."\n"; } - /** - * testWSThirdpartygetThirdParty + * testWSThirdpartycreateThirdParty * * @return int */ - public function testWSThirdpartygetThirdParty() + public function testWSThirdpartycreateThirdParty() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $WS_METHOD = 'createThirdParty'; + + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + $body = array ( + "id" => NULL, + "ref" => "name", + "ref_ext" => "12", + "fk_user_author" => NULL, + "status" => NULL, + "client" => 1, + "supplier" => 0, + "customer_code" => "", + "supplier_code" => "", + "customer_code_accountancy" => "", + "supplier_code_accountancy" => "", + "date_creation" => "", // dateTime + "date_modification" => "", // dateTime + "note_private" => "", + "note_public" => "", + "address" => "", + "zip" => "", + "town" => "", + "province_id" => "", + "country_id" => "", + "country_code" => "", + "country" => "", + "phone" => "", + "fax" => "", + "email" => "", + "url" => "", + "profid1" => "", + "profid2" => "", + "profid3" => "", + "profid4" => "", + "profid5" => "", + "profid6" => "", + "capital" => "", + "vat_used" => "", + "vat_number" => "" + ); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication, 'thirdparty'=>$body); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$thid->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + if (! $result || ! empty($result['faultstring'])) { + //var_dump($soapclient); + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals('name',$result['ref']); + + return $result; + } + + /** + * testWSThirdpartygetThirdPartyById + * + * Use id to retrieve thirdparty + * @depends testWSThirdpartycreateThirdParty + * + * @return int + */ + public function testWSThirdpartygetThirdPartyById($result) { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; + $id = $result['id']; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; $WS_METHOD = 'getThirdParty'; - $ns='http://www.dolibarr.org/ns/'; - - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } // Call the WebService method and store its result in $result. $authentication=array( @@ -151,30 +250,147 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase 'password'=>'admin', 'entity'=>''); - // Test URL $result=''; - $parameters = array('authentication'=>$authentication, 'id'=>1); + $parameters = array('authentication'=>$authentication, 'id'=>$id); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; } if (! $result || ! empty($result['faultstring'])) { //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_code']."\n"; $this->assertEquals('OK',$result['result']['result_code']); - + $this->assertEquals($id, $result['thirdparty']['id']); + $this->assertEquals('name', $result['thirdparty']['ref']); + $this->assertEquals('12', $result['thirdparty']['ref_ext']); + $this->assertEquals('0', $result['thirdparty']['status']); + $this->assertEquals('1', $result['thirdparty']['client']); + $this->assertEquals('0', $result['thirdparty']['supplier']); + + return $result; } + + /** + * testWSThirdpartygetThirdPartyByRefExt + * + * Use ref_ext to retrieve thirdparty + * + * @depends testWSThirdpartycreateThirdParty + * @return int + */ + public function testWSThirdpartygetThirdPartyByRefExt($result) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + $id = $result['id']; + + $WS_METHOD = 'getThirdParty'; + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication, 'id'=>'', 'ref'=>'', 'ref_ext'=>'12'); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + print $this->soapclient->response; + if (! $result || ! empty($result['faultstring'])) { + //var_dump($soapclient); + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals($id, $result['thirdparty']['id']); + $this->assertEquals('name', $result['thirdparty']['ref']); + $this->assertEquals('12', $result['thirdparty']['ref_ext']); + $this->assertEquals('0', $result['thirdparty']['status']); + $this->assertEquals('1', $result['thirdparty']['client']); + $this->assertEquals('0', $result['thirdparty']['supplier']); + + + return $result; + } + + /** + * testWSThirdpartydeleteThirdParty + * + * @depends testWSThirdpartycreateThirdParty + * + * @return int + */ + public function testWSThirdpartydeleteThirdPartyById($result) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + $id = $result['id']; + + $WS_METHOD = 'deleteThirdParty'; + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + $result=''; + $parameters = array('authentication'=>$authentication, 'id'=>$id, 'ref'=>'', 'ref_ext'=>''); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + //if (! $result || ! empty($result['faultstring'])) { + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + //} + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + + return $result; + } } From 3003b41a88c6ba4853646a63484280caeb6a3df7 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Thu, 28 May 2015 16:57:28 +0200 Subject: [PATCH 16/18] add test for invoices API --- htdocs/webservices/server_invoice.php | 14 +- test/phpunit/WebservicesInvoicesTest.php | 212 +++++++++++------------ 2 files changed, 108 insertions(+), 118 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index d358847c0b6..4a495607a29 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -751,8 +751,8 @@ function updateInvoice($authentication,$invoice) { global $db,$conf,$langs; - dol_syslog("Function: updateInvoice login=".$authentication['login']." id=".$invoice->id. - ", ref=".$invoice->ref.", ref_ext=".$invoice->ref_ext); + dol_syslog("Function: updateInvoice login=".$authentication['login']." id=".$invoice['id']. + ", ref=".$invoice['ref'].", ref_ext=".$invoice['ref_ext']); if ($authentication['entity']) $conf->entity=$authentication['entity']; @@ -782,10 +782,13 @@ function updateInvoice($authentication,$invoice) if (isset($invoice['status'])) { - if ($invoice['status'] == Facture::STATUS_DRAFT) $result=$object->set_draft($fuser); + if ($invoice['status'] == Facture::STATUS_DRAFT) + { + $result = $object->set_draft($fuser); + } if ($invoice['status'] == Facture::STATUS_VALIDATED) { - $result=$object->validate($fuser); + $result = $object->validate($fuser); if ($result >= 0) { @@ -798,7 +801,8 @@ function updateInvoice($authentication,$invoice) { $result = $object->set_paid($fuser,$invoice->close_code,$invoice->close_note); } - if ($invoice['status'] == Facture::STATUS_ABANDONED) $result=$object->set_canceled($fuser,$invoice->close_code,$invoice->close_note); + if ($invoice['status'] == Facture::STATUS_ABANDONED) + $result = $object->set_canceled($fuser,$invoice->close_code,$invoice->close_note); } } diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index 4731c8f7651..bbcf6d0b136 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -53,6 +53,10 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase protected $savuser; protected $savlangs; protected $savdb; + protected $soapclient; + protected $socid; + + protected $ns = 'http://www.dolibarr.org/ns/'; /** * Constructor @@ -68,17 +72,17 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $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; - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; + + + // Set the WebService URL + print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; + $this->soapclient = new nusoap_client($WS_DOL_URL); + if ($this->soapclient) + { + $this->soapclient->soap_defencoding='UTF-8'; + $this->soapclient->decodeUTF8(false); + } // create a third_party, needed to create an invoice $societe=new Societe($db); @@ -94,8 +98,20 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $societe->create($user); - print __METHOD__." societe created id=".$societe->id."\n"; + $this->socid = $societe->id; + print __METHOD__." societe created id=".$societe->id."\n"; + + 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; + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. print __METHOD__."\n"; } @@ -148,23 +164,12 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $langs=$this->savlangs; $db=$this->savdb; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; $WS_METHOD = 'createInvoice'; - $ns='http://www.dolibarr.org/ns/'; // load societe first $societe=new Societe($db); $societe->fetch('', '', '209'); print __METHOD__." societe loaded id=".$societe->id."\n"; - - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) - { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } $body = array ( @@ -191,11 +196,11 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase "close_note" => NULL, "project_id" => NULL, "lines" => array( - "id" => NULL, + array("id" => NULL, "type" => 0, "desc" => "Horloge Vinyle Serge", "vat_rate" => 20, - "qty" => "1", + "qty" => 1, "unitprice" => "30.000000", "total_net" => "30.000000", "total_vat" => "6.00", @@ -206,7 +211,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase "product_id" => "", "product_ref" => "", "product_label" => "", - "product_desc" => "" ) + "product_desc" => "" )) ); // Call the WebService method and store its result in $result. @@ -222,7 +227,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication,'invoice'=>$body); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { @@ -232,15 +237,15 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase if (! $result || ! empty($result['faultstring'])) { //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - print __METHOD__." result=".$result['result']['result_label']."\n"; + print __METHOD__." result=".$result['result']['result_code']."\n"; $this->assertEquals('OK',$result['result']['result_code']); $this->assertEquals('165', $result['ref_ext']); @@ -249,11 +254,13 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase } /** - * testWSInvoicesGetInvoice - * + * testWSInvoicesGetInvoiceByRefExt + * + * Retrieve an invoice using ref_ext + * @depends testWSInvoicesCreateInvoice * @return int */ - public function testWSInvoicesGetInvoice() + public function testWSInvoicesGetInvoiceByRefExt($result) { global $conf,$user,$langs,$db; $conf=$this->savconf; @@ -261,18 +268,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $langs=$this->savlangs; $db=$this->savdb; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; $WS_METHOD = 'getInvoice'; - $ns='http://www.dolibarr.org/ns/'; - - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) - { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } // Call the WebService method and store its result in $result. $authentication=array( @@ -287,7 +283,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication,'id'=>NULL,'ref'=>NULL,'ref_ext'=>165); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { @@ -296,29 +292,30 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase } if (! $result || ! empty($result['faultstring'])) { - //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_code']."\n"; $this->assertEquals('OK',$result['result']['result_code']); - $this->assertEquals('165', $result['result']['invoice']->ref_ext); + $this->assertEquals('165', $result['invoice']['ref_ext']); return $result; } /** - * testWSInvoicesUpdateInvoice + * testWSInvoicesUpdateInvoiceByRefExt + * + * Update an invoice using ref_ext + * @depends testWSInvoicesCreateInvoice * * @return int */ - public function testWSInvoicesUpdateInvoice() + public function testWSInvoicesUpdateInvoiceByRefExt($result) { global $conf,$user,$langs,$db; $conf=$this->savconf; @@ -326,61 +323,51 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $langs=$this->savlangs; $db=$this->savdb; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; $WS_METHOD = 'updateInvoice'; - $ns='http://www.dolibarr.org/ns/'; - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) - { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } - // update status to 2 - $body = array ( - "id" => NULL, - "ref" => NULL, - "ref_ext" => "165", - "thirdparty_id" => "209", - "fk_user_author" => NULL, - "fk_user_valid" => NULL, - "date" => "2015-04-19 20:16:53", - "date_due" => "", - "date_creation" => "", - "date_validation" => "", - "date_modification" => "", - "type" => "", - "total_net" => "36.30", + $body = array ( + "id" => NULL, + "ref" => NULL, + "ref_ext" => "165", + "thirdparty_id" => "209", + "fk_user_author" => NULL, + "fk_user_valid" => NULL, + "date" => "2015-04-19 20:16:53", + "date_due" => "", + "date_creation" => "", + "date_validation" => "", + "date_modification" => "", + "type" => "", + "total_net" => "36.30", + "total_vat" => "6.00", + "total" => "42.30", + "payment_mode_id" => 50, + "note_private" => "Synchronised from Prestashop", + "note_public" => "", + "status" => "2", + "close_code" => NULL , + "close_note" => NULL, + "project_id" => NULL, + "lines" => array( + array( + "id" => NULL, + "type" => 0, + "desc" => "Horloge Vinyle Serge", + "vat_rate" => 20, + "qty" => "1", + "unitprice" => "30.000000", + "total_net" => "30.000000", "total_vat" => "6.00", - "total" => "42.30", - "payment_mode_id" => 50, - "note_private" => "Synchronised from Prestashop", - "note_public" => "", - "status" => "2", - "close_code" => NULL , - "close_note" => NULL, - "project_id" => NULL, - "lines" => array( - "id" => NULL, - "type" => 0, - "desc" => "Horloge Vinyle Serge", - "vat_rate" => 20, - "qty" => "1", - "unitprice" => "30.000000", - "total_net" => "30.000000", - "total_vat" => "6.00", - "total" => "36.000000", - "date_start" => "", - "date_end" => "", - "payment_mode_id" => "", - "product_id" => "", - "product_ref" => "", - "product_label" => "", - "product_desc" => "" ) - ); + "total" => "36.000000", + "date_start" => "", + "date_end" => "", + "payment_mode_id" => "", + "product_id" => "", + "product_ref" => "", + "product_label" => "", + "product_desc" => "" )) + ); // Call the WebService method and store its result in $result. $authentication=array( @@ -395,7 +382,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication,'invoice'=>$body); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { @@ -404,18 +391,17 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase } if (! $result || ! empty($result['faultstring'])) { - //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_code'].$result['result']['result_label']."\n"; $this->assertEquals('OK',$result['result']['result_code']); - $this->assertEquals('2', $result['result']['invoice']->status); + $this->assertEquals('165', $result['ref_ext']); return $result; From 0c66c9745e4c52ad0c7e6b5dd0930639ac7e4dec Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 1 Jun 2015 13:04:33 +0200 Subject: [PATCH 17/18] fix travis error --- test/phpunit/WebservicesInvoicesTest.php | 4 ++-- test/phpunit/WebservicesThirdpartyTest.php | 24 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index bbcf6d0b136..12d5ae2011c 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -258,7 +258,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * * Retrieve an invoice using ref_ext * @depends testWSInvoicesCreateInvoice - * @return int + * @return array Invoice */ public function testWSInvoicesGetInvoiceByRefExt($result) { @@ -313,7 +313,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * Update an invoice using ref_ext * @depends testWSInvoicesCreateInvoice * - * @return int + * @return array Invoice */ public function testWSInvoicesUpdateInvoiceByRefExt($result) { diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 71c90b3f636..6ae126b7e70 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -54,8 +54,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase protected $savdb; protected $soapclient; - private $WS_DOL_URL; - private $ns='http://www.dolibarr.org/ns/'; + private $_WS_DOL_URL; + private $_ns='http://www.dolibarr.org/ns/'; @@ -75,11 +75,11 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $this->savlangs=$langs; $this->savdb=$db; - $this->WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; + $this->_WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$this->WS_DOL_URL."\n"; - $this->soapclient = new nusoap_client($this->WS_DOL_URL); + print __METHOD__." create nusoap_client for URL=".$this->_WS_DOL_URL."\n"; + $this->soapclient = new nusoap_client($this->_WS_DOL_URL); if ($this->soapclient) { $this->soapclient->soap_defencoding='UTF-8'; $this->soapclient->decodeUTF8(false); @@ -137,7 +137,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase /** * testWSThirdpartycreateThirdParty * - * @return int + * @return array thirdparty created */ public function testWSThirdpartycreateThirdParty() { @@ -229,7 +229,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * Use id to retrieve thirdparty * @depends testWSThirdpartycreateThirdParty * - * @return int + * @return array thirpdarty updated */ public function testWSThirdpartygetThirdPartyById($result) { @@ -254,7 +254,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication, 'id'=>$id); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->_ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; @@ -288,7 +288,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * Use ref_ext to retrieve thirdparty * * @depends testWSThirdpartycreateThirdParty - * @return int + * @return array thirdparty */ public function testWSThirdpartygetThirdPartyByRefExt($result) { @@ -314,7 +314,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication, 'id'=>'', 'ref'=>'', 'ref_ext'=>'12'); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->_ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; @@ -348,7 +348,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * * @depends testWSThirdpartycreateThirdParty * - * @return int + * @return array thirdparty */ public function testWSThirdpartydeleteThirdPartyById($result) { @@ -373,7 +373,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication, 'id'=>$id, 'ref'=>'', 'ref_ext'=>''); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->_ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; From 3099e2acc4168f37d46c0b04b6906b90f559a2fe Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 1 Jun 2015 14:15:09 +0200 Subject: [PATCH 18/18] fix travis issues again --- test/phpunit/WebservicesInvoicesTest.php | 5 ++++- test/phpunit/WebservicesThirdpartyTest.php | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index 12d5ae2011c..ff8a9a30e73 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -258,6 +258,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * * Retrieve an invoice using ref_ext * @depends testWSInvoicesCreateInvoice + * + * @param result invoice created by create method * @return array Invoice */ public function testWSInvoicesGetInvoiceByRefExt($result) @@ -312,7 +314,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * * Update an invoice using ref_ext * @depends testWSInvoicesCreateInvoice - * + * + * @param result invoice created by create method * @return array Invoice */ public function testWSInvoicesUpdateInvoiceByRefExt($result) diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 6ae126b7e70..2bf3f3fe094 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -228,7 +228,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * * Use id to retrieve thirdparty * @depends testWSThirdpartycreateThirdParty - * + * + * @param result thirdparty created by create method * @return array thirpdarty updated */ public function testWSThirdpartygetThirdPartyById($result) @@ -288,6 +289,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * Use ref_ext to retrieve thirdparty * * @depends testWSThirdpartycreateThirdParty + * + * @param result thirdparty created by create method * @return array thirdparty */ public function testWSThirdpartygetThirdPartyByRefExt($result) @@ -348,6 +351,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * * @depends testWSThirdpartycreateThirdParty * + * @param result thirdparty created by create method * @return array thirdparty */ public function testWSThirdpartydeleteThirdPartyById($result)