Debug emailcollector
This commit is contained in:
parent
f48b2812a3
commit
a0b594fbdc
@ -482,13 +482,13 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
||||||
|
|
||||||
// Filters
|
// Filters
|
||||||
print '<div class="div-table-responsive">';
|
print '<div class="div-table-responsive-no-min">';
|
||||||
print '<table class="border centpercent tableforfield">';
|
print '<table id="tablelineoffilters" class="noborder margintable noshadow">';
|
||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre nodrag nodrop">';
|
||||||
print '<td>'.$form->textwithpicto($langs->trans("Filters"), $langs->trans("EmailCollectorFilterDesc")).'</td><td></td><td></td>';
|
print '<td>'.$form->textwithpicto($langs->trans("Filters"), $langs->trans("EmailCollectorFilterDesc")).'</td><td></td><td></td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
// Add filter
|
// Add filter
|
||||||
print '<tr class="oddeven">';
|
print '<tr class="oddeven nodrag nodrop">';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
$arrayoftypes = array(
|
$arrayoftypes = array(
|
||||||
'from'=>array('label'=>'MailFrom', 'data-placeholder'=>$langs->trans('SearchString')),
|
'from'=>array('label'=>'MailFrom', 'data-placeholder'=>$langs->trans('SearchString')),
|
||||||
@ -518,7 +518,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
'isnotanswer'=>array('label'=>'IsNotAnAnswer', 'data-noparam'=>1),
|
'isnotanswer'=>array('label'=>'IsNotAnAnswer', 'data-noparam'=>1),
|
||||||
'isanswer'=>array('label'=>'IsAnAnswer', 'data-noparam'=>1)
|
'isanswer'=>array('label'=>'IsAnAnswer', 'data-noparam'=>1)
|
||||||
);
|
);
|
||||||
print $form->selectarray('filtertype', $arrayoftypes, '', 1, 0, 0, '', 1, 0, 0, '', 'maxwidth500', 1, '', 2);
|
print $form->selectarray('filtertype', $arrayoftypes, '', 1, 0, 0, '', 1, 0, 0, '', 'maxwidth300', 1, '', 2);
|
||||||
|
|
||||||
print "\n";
|
print "\n";
|
||||||
print '<script>';
|
print '<script>';
|
||||||
@ -542,7 +542,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
print '</td><td>';
|
print '</td><td>';
|
||||||
print '<input type="text" name="rulevalue" id="rulevalue">';
|
print '<input type="text" name="rulevalue" id="rulevalue">';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td class="right"><input type="submit" name="addfilter" id="addfilter" class="flat button" value="'.$langs->trans("Add").'"></td>';
|
print '<td class="right"><input type="submit" name="addfilter" id="addfilter" class="flat button small" value="'.$langs->trans("Add").'"></td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
// List filters
|
// List filters
|
||||||
foreach ($object->filters as $rulefilter) {
|
foreach ($object->filters as $rulefilter) {
|
||||||
@ -568,12 +568,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
|
|
||||||
// Operations
|
// Operations
|
||||||
print '<div class="div-table-responsive">';
|
print '<div class="div-table-responsive">';
|
||||||
print '<table id="tablelines" class="noborder noshadow tableforfield">';
|
print '<table id="tablelines" class="noborder margintable noshadow">';
|
||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre nodrag nodrop">';
|
||||||
print '<td>'.$form->textwithpicto($langs->trans("EmailcollectorOperations"), $langs->trans("EmailcollectorOperationsDesc")).'</td><td></td><td></td><td></td>';
|
print '<td>'.$form->textwithpicto($langs->trans("EmailcollectorOperations"), $langs->trans("EmailcollectorOperationsDesc")).'</td><td></td><td></td><td></td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
// Add operation
|
// Add operation
|
||||||
print '<tr class="oddeven">';
|
print '<tr class="oddeven nodrag nodrop">';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
$arrayoftypes = array(
|
$arrayoftypes = array(
|
||||||
'loadthirdparty'=>$langs->trans('LoadThirdPartyFromName', $langs->transnoentities("ThirdPartyName")),
|
'loadthirdparty'=>$langs->trans('LoadThirdPartyFromName', $langs->transnoentities("ThirdPartyName")),
|
||||||
@ -609,7 +609,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
$htmltext = $langs->transnoentitiesnoconv("OperationParamDesc");
|
$htmltext = $langs->transnoentitiesnoconv("OperationParamDesc");
|
||||||
print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'operationparamtt');
|
print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'operationparamtt');
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td class="right"><input type="submit" name="addoperation" id="addoperation" class="flat button" value="'.$langs->trans("Add").'"></td>';
|
print '<td class="right"><input type="submit" name="addoperation" id="addoperation" class="flat button small" value="'.$langs->trans("Add").'"></td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
// List operations
|
// List operations
|
||||||
$nboflines = count($object->actions);
|
$nboflines = count($object->actions);
|
||||||
@ -630,12 +630,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
print $form->textwithpicto('', $langs->transnoentitiesnoconv('EmailCollectorLoadThirdPartyHelp'));
|
print $form->textwithpicto('', $langs->transnoentitiesnoconv('EmailCollectorLoadThirdPartyHelp'));
|
||||||
}
|
}
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td class="wordbreak">';
|
print '<td class="wordbreak minwidth300">';
|
||||||
if ($action == 'editoperation' && $ruleaction['id'] == $operationid) {
|
if ($action == 'editoperation' && $ruleaction['id'] == $operationid) {
|
||||||
print '<input type="text" class="quatrevingtquinzepercent" name="operationparam2" value="'.$ruleaction['actionparam'].'"><br>';
|
print '<input type="text" class="quatrevingtquinzepercent" name="operationparam2" value="'.$ruleaction['actionparam'].'"><br>';
|
||||||
print '<input type="hidden" name="rowidoperation2" value="'.$ruleaction['id'].'"><br>';
|
print '<input type="hidden" name="rowidoperation2" value="'.$ruleaction['id'].'">';
|
||||||
print '<input type="submit" class="button button-save" name="saveoperation2" value="'.$langs->trans("Save").'">';
|
print '<input type="submit" class="button small button-save" name="saveoperation2" value="'.$langs->trans("Save").'">';
|
||||||
print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
|
print '<input type="submit" class="button small button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
|
||||||
} else {
|
} else {
|
||||||
print $ruleaction['actionparam'];
|
print $ruleaction['actionparam'];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5835,7 +5835,8 @@ abstract class CommonObject
|
|||||||
$mandatorypb = true;
|
$mandatorypb = true;
|
||||||
}
|
}
|
||||||
if ($mandatorypb) {
|
if ($mandatorypb) {
|
||||||
dol_syslog("Mandatory extra field ".$key." is empty");
|
$langs->load("errors");
|
||||||
|
dol_syslog("Mandatory field '".$key."' is empty during create and set to required into definition of extrafields");
|
||||||
$this->errors[] = $langs->trans('ErrorFieldRequired', $attributeLabel);
|
$this->errors[] = $langs->trans('ErrorFieldRequired', $attributeLabel);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -6201,7 +6202,8 @@ abstract class CommonObject
|
|||||||
$mandatorypb = true;
|
$mandatorypb = true;
|
||||||
}
|
}
|
||||||
if ($mandatorypb) {
|
if ($mandatorypb) {
|
||||||
dol_syslog("Mandatory extra field options_".$key." is empty");
|
$langs->load("errors");
|
||||||
|
dol_syslog("Mandatory field 'options_".$key."' is empty during update and set to required into definition of extrafields");
|
||||||
$this->errors[] = $langs->trans('ErrorFieldRequired', $attributeLabel);
|
$this->errors[] = $langs->trans('ErrorFieldRequired', $attributeLabel);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -8380,12 +8382,14 @@ abstract class CommonObject
|
|||||||
|
|
||||||
if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && (!isset($values[$key]) || $values[$key] === 'NULL') && is_null($this->fields[$key]['default'])) {
|
if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && (!isset($values[$key]) || $values[$key] === 'NULL') && is_null($this->fields[$key]['default'])) {
|
||||||
$error++;
|
$error++;
|
||||||
|
$langs->load("errors");
|
||||||
|
dol_syslog("Mandatory field '".$key."' is empty and required into ->fields definition of class");
|
||||||
$this->errors[] = $langs->trans("ErrorFieldRequired", $this->fields[$key]['label']);
|
$this->errors[] = $langs->trans("ErrorFieldRequired", $this->fields[$key]['label']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If value is null and there is a default value for field
|
// If value is null and there is a default value for field
|
||||||
if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && (!isset($values[$key]) || $values[$key] === 'NULL') && !is_null($this->fields[$key]['default'])) {
|
if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && (!isset($values[$key]) || $values[$key] === 'NULL') && !is_null($this->fields[$key]['default'])) {
|
||||||
$values[$key] = $this->fields[$key]['default'];
|
$values[$key] = $this->quote($this->fields[$key]['default'], $this->fields[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If field is an implicit foreign key field
|
// If field is an implicit foreign key field
|
||||||
|
|||||||
@ -204,7 +204,7 @@ class Translate
|
|||||||
dol_print_error('', get_class($this)."::Load ErrorWrongParameters");
|
dol_print_error('', get_class($this)."::Load ErrorWrongParameters");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ($this->defaultlang == 'none_NONE') {
|
if ($this->defaultlang === 'none_NONE') {
|
||||||
return 0; // Special language code to not translate keys
|
return 0; // Special language code to not translate keys
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -274,7 +274,7 @@ class EmailCollector extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($this->filters) && count($this->filters)) {
|
if (is_array($this->actions) && count($this->actions)) {
|
||||||
$emailcollectoroperation = new EmailCollectorAction($this->db);
|
$emailcollectoroperation = new EmailCollectorAction($this->db);
|
||||||
|
|
||||||
foreach ($this->actions as $operation) {
|
foreach ($this->actions as $operation) {
|
||||||
@ -653,6 +653,9 @@ class EmailCollector extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function initAsSpecimen()
|
public function initAsSpecimen()
|
||||||
{
|
{
|
||||||
|
$this->host = 'localhost';
|
||||||
|
$this->login = 'alogin';
|
||||||
|
|
||||||
$this->initAsSpecimenCommon();
|
$this->initAsSpecimenCommon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -941,6 +941,10 @@ class MyObject extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function initAsSpecimen()
|
public function initAsSpecimen()
|
||||||
{
|
{
|
||||||
|
// Set here init that are not commonf fields
|
||||||
|
// $this->property1 = ...
|
||||||
|
// $this->property2 = ...
|
||||||
|
|
||||||
$this->initAsSpecimenCommon();
|
$this->initAsSpecimenCommon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -256,6 +256,10 @@ class AllTests
|
|||||||
require_once dirname(__FILE__).'/StripeTest.php';
|
require_once dirname(__FILE__).'/StripeTest.php';
|
||||||
$suite->addTestSuite('StripeTest');
|
$suite->addTestSuite('StripeTest');
|
||||||
|
|
||||||
|
// Email collector
|
||||||
|
require_once dirname(__FILE__).'/EmailCollectorTest.php';
|
||||||
|
$suite->addTestSuite('EmailCollectorTest');
|
||||||
|
|
||||||
return $suite;
|
return $suite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
235
test/phpunit/EmailCollector.php
Normal file
235
test/phpunit/EmailCollector.php
Normal file
@ -0,0 +1,235 @@
|
|||||||
|
<?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
|
||||||
|
* (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
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
* or see https://www.gnu.org/
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file test/phpunit/EmailCollectorTest.php
|
||||||
|
* \ingroup test
|
||||||
|
* \brief PHPUnit test
|
||||||
|
* \remarks To run this script as CLI: phpunit filename.php
|
||||||
|
*/
|
||||||
|
|
||||||
|
global $conf,$user,$langs,$db;
|
||||||
|
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
|
||||||
|
//require_once 'PHPUnit/Autoload.php';
|
||||||
|
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
|
||||||
|
require_once dirname(__FILE__).'/../../htdocs/emailcollector/class/emailcollector.class.php';
|
||||||
|
|
||||||
|
if (empty($user->id)) {
|
||||||
|
print "Load permissions for admin user nb 1\n";
|
||||||
|
$user->fetch(1);
|
||||||
|
$user->getrights();
|
||||||
|
}
|
||||||
|
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for PHPUnit tests
|
||||||
|
*
|
||||||
|
* @backupGlobals disabled
|
||||||
|
* @backupStaticAttributes enabled
|
||||||
|
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
|
||||||
|
*/
|
||||||
|
class EmailCollectorTest extends PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
protected $savconf;
|
||||||
|
protected $savuser;
|
||||||
|
protected $savlangs;
|
||||||
|
protected $savdb;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* We save global variables into local variables
|
||||||
|
*
|
||||||
|
* @return ExpenseReportTest
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
//$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";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setUpBeforeClass
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tearDownAfterClass
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function tearDownAfterClass()
|
||||||
|
{
|
||||||
|
global $conf,$user,$langs,$db;
|
||||||
|
$db->rollback();
|
||||||
|
|
||||||
|
print __METHOD__."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init phpunit tests
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
global $conf,$user,$langs,$db;
|
||||||
|
$conf=$this->savconf;
|
||||||
|
$user=$this->savuser;
|
||||||
|
$langs=$this->savlangs;
|
||||||
|
$db=$this->savdb;
|
||||||
|
|
||||||
|
print __METHOD__."\n";
|
||||||
|
//print $db->getVersion()."\n";
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* End phpunit tests
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function tearDown()
|
||||||
|
{
|
||||||
|
print __METHOD__."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testEmailCollectorCreate
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testEmailCollectorCreate()
|
||||||
|
{
|
||||||
|
global $conf,$user,$langs,$db;
|
||||||
|
$conf=$this->savconf;
|
||||||
|
$user=$this->savuser;
|
||||||
|
$langs=$this->savlangs;
|
||||||
|
$db=$this->savdb;
|
||||||
|
|
||||||
|
$langs->load("main");
|
||||||
|
|
||||||
|
// Create supplier order with a too low quantity
|
||||||
|
$localobject=new EmailCollector($db);
|
||||||
|
$localobject->initAsSpecimen(); // Init a specimen with lines
|
||||||
|
|
||||||
|
$this->filters = array();
|
||||||
|
|
||||||
|
$this->actions = array();
|
||||||
|
|
||||||
|
$result=$localobject->create($user);
|
||||||
|
print __METHOD__." result=".$result."\n";
|
||||||
|
$this->assertGreaterThan(0, $result, "Error on test EmailCollector create: ".$localobject->error.' '.join(',', $localobject->errors));
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testEmailCollectorFetch
|
||||||
|
*
|
||||||
|
* @param int $id Id of supplier order
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @depends testEmailCollectorCreate
|
||||||
|
* The depends says test is run only if previous is ok
|
||||||
|
*/
|
||||||
|
public function testEmailCollectorFetch($id)
|
||||||
|
{
|
||||||
|
global $conf,$user,$langs,$db;
|
||||||
|
$conf=$this->savconf;
|
||||||
|
$user=$this->savuser;
|
||||||
|
$langs=$this->savlangs;
|
||||||
|
$db=$this->savdb;
|
||||||
|
|
||||||
|
$localobject=new EmailCollector($this->savdb);
|
||||||
|
$result=$localobject->fetch($id);
|
||||||
|
|
||||||
|
print __METHOD__." id=".$id." result=".$result."\n";
|
||||||
|
$this->assertLessThan($result, 0);
|
||||||
|
return $localobject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testEmailCollectorOther
|
||||||
|
*
|
||||||
|
* @param EmailCollector $localobject EmailCollector
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @depends testEmailCollectorFetch
|
||||||
|
* The depends says test is run only if previous is ok
|
||||||
|
*/
|
||||||
|
public function testEmailCollectorCollect($localobject)
|
||||||
|
{
|
||||||
|
global $conf,$user,$langs,$db;
|
||||||
|
$conf=$this->savconf;
|
||||||
|
$user=$this->savuser;
|
||||||
|
$langs=$this->savlangs;
|
||||||
|
$db=$this->savdb;
|
||||||
|
|
||||||
|
$result=$localobject->getConnectStringIMAP();
|
||||||
|
print __METHOD__." id=".$localobject->id." result=".$result."\n";
|
||||||
|
$this->assertEquals('{localhost:993/service=imap/ssl/novalidate-cert}', $result, 'Error in getConnectStringIMAP '.$localobject->error);
|
||||||
|
|
||||||
|
return $localobject->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testEmailCollectorDelete
|
||||||
|
*
|
||||||
|
* @param int $id Id of order
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @depends testEmailCollectorCollect
|
||||||
|
* The depends says test is run only if previous is ok
|
||||||
|
*/
|
||||||
|
public function testEmailCollectorDelete($id)
|
||||||
|
{
|
||||||
|
global $conf,$user,$langs,$db;
|
||||||
|
$conf=$this->savconf;
|
||||||
|
$user=$this->savuser;
|
||||||
|
$langs=$this->savlangs;
|
||||||
|
$db=$this->savdb;
|
||||||
|
|
||||||
|
$localobject=new EmailCollector($this->savdb);
|
||||||
|
$result=$localobject->fetch($id);
|
||||||
|
$result=$localobject->delete($user);
|
||||||
|
|
||||||
|
print __METHOD__." id=".$id." result=".$result."\n";
|
||||||
|
$this->assertGreaterThan(0, $result);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user