From fd0889cebbbf62a89412e77f77716133624f1e1e Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Tue, 25 Mar 2025 22:31:49 +0100 Subject: [PATCH] Test --- ...ce_95_modWebhook_WebhookTriggers.class.php | 13 ++++++++--- test/phpunit/AllTests.php | 1 + test/phpunit/ModulesTest.php | 22 ++++++++++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/htdocs/core/triggers/interface_95_modWebhook_WebhookTriggers.class.php b/htdocs/core/triggers/interface_95_modWebhook_WebhookTriggers.class.php index c786ccce5d0..4d8d161ec66 100644 --- a/htdocs/core/triggers/interface_95_modWebhook_WebhookTriggers.class.php +++ b/htdocs/core/triggers/interface_95_modWebhook_WebhookTriggers.class.php @@ -46,7 +46,9 @@ class InterfaceWebhookTriggers extends DolibarrTriggers */ public function __construct($db) { - parent::__construct($db); + $this->db = $db; + + $this->name = preg_replace('/^Interface/i', '', get_class($this)); $this->family = "demo"; $this->description = "Webhook triggers."; $this->version = self::VERSIONS['dev']; @@ -76,7 +78,7 @@ class InterfaceWebhookTriggers extends DolibarrTriggers $nbPosts = 0; $errors = 0; $static_object = new Target($this->db); - $target_url = $static_object->fetchAll(); + $target_url = $static_object->fetchAll(); // TODO Replace this with a search with filter on $action trigger to avoid to filter later. if (is_numeric($target_url) && $target_url < 0) { dol_syslog("Error Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); @@ -91,7 +93,12 @@ class InterfaceWebhookTriggers extends DolibarrTriggers $sendmanualtriggers = (!empty($object->context['sendmanualtriggers']) ? $object->context['sendmanualtriggers'] : ""); foreach ($target_url as $key => $tmpobject) { - $actionarray = explode(",", $tmpobject->trigger_codes); + // Set list of all triggers for this targetinto $actionarray + $actionarraytmp = explode(",", $tmpobject->trigger_codes); + $actionarray = array(); + foreach ($actionarraytmp as $val) { + $actionarray = trim($val); + } // Test on Target status $testontargetstatus = ($tmpobject->status == Target::STATUS_AUTOMATIC_TRIGGER || ($tmpobject->status == Target::STATUS_MANUAL_TRIGGER && !empty($sendmanualtriggers))); diff --git a/test/phpunit/AllTests.php b/test/phpunit/AllTests.php index 47c5f0a7e2a..8565326d49a 100644 --- a/test/phpunit/AllTests.php +++ b/test/phpunit/AllTests.php @@ -308,6 +308,7 @@ class AllTests $suite->addTestSuite('WebsiteTest'); // At end because it's the longer + // Also enabling and disabling modules is changing the context and global variables that changes behaviour of previous tests require_once dirname(__FILE__).'/ModulesTest.php'; $suite->addTestSuite('ModulesTest'); diff --git a/test/phpunit/ModulesTest.php b/test/phpunit/ModulesTest.php index d1cb7a94c8b..3a7bbb35654 100644 --- a/test/phpunit/ModulesTest.php +++ b/test/phpunit/ModulesTest.php @@ -51,6 +51,26 @@ use PHPUnit\Framework\TestCase; */ class ModulesTest extends CommonClassTest // TestCase //CommonClassTest { + /** + * setUpBeforeClass + * + * @return void + */ + public static function setUpBeforeClass(): void + { + global $conf,$user,$langs,$db; + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + + if ((int) getenv('PHPUNIT_DEBUG') > 0) { + print get_called_class()."::".__FUNCTION__.PHP_EOL; + } + + $infotable = $db->DDLListTablesFull($db->database_name); + print "List of existing tables before running test ModulesTest\n"; + print var_export($infotable, true)."\n"; + } + + /** * Return list of modules for which to test initialisation * @@ -90,7 +110,7 @@ class ModulesTest extends CommonClassTest // TestCase //CommonClassTest $mod = new $class($db); $result = $mod->remove(); - print __METHOD__." test remove for module ".$modlabel.", result=".$result."\n"; + print __METHOD__." test remove for module ".$modlabel.", result=".$result."\n"; $result = $mod->init(); print __METHOD__." test init for module ".$modlabel.", result=".$result."\n";