From 99b6de1c7ef7309e39602a4256d2f445fdd0251f Mon Sep 17 00:00:00 2001 From: mambax7 Date: Tue, 7 Mar 2023 02:05:26 -0500 Subject: [PATCH 01/12] initial --- htdocs/tests/Unit/.htaccess | 1 + htdocs/tests/Unit/bootstrap.php | 43 ++++++++++++++ htdocs/tests/Unit/class/testClass.xml | 39 ++++++++++++ htdocs/tests/Unit/common_phpunit.php | 30 ++++++++++ htdocs/tests/Unit/init_new.php | 42 +++++++++++++ .../Unit/kernel/XoopsBlockHandlerTest.php | 33 +++++++++++ htdocs/tests/Unit/kernel/XoopsBlockTest.php | 25 ++++++++ .../Unit/kernel/XoopsConfigHandlerTest.php | 33 +++++++++++ .../kernel/XoopsConfigItemHandlerTest.php | 34 +++++++++++ .../tests/Unit/kernel/XoopsConfigItemTest.php | 25 ++++++++ .../kernel/XoopsConfigOptionHandlerTest.php | 29 +++++++++ .../Unit/kernel/XoopsConfigOptionTest.php | 25 ++++++++ .../Unit/kernel/XoopsGroupHandlerTest.php | 27 +++++++++ .../Unit/kernel/XoopsGroupPermHandlerTest.php | 27 +++++++++ .../tests/Unit/kernel/XoopsGroupPermTest.php | 25 ++++++++ htdocs/tests/Unit/kernel/XoopsGroupTest.php | 25 ++++++++ .../Unit/kernel/XoopsMemberHandlerTest.php | 33 +++++++++++ .../Unit/kernel/XoopsModuleHandlerTest.php | 33 +++++++++++ htdocs/tests/Unit/kernel/XoopsModuleTest.php | 25 ++++++++ .../Unit/kernel/XoopsObjectHandlerTest.php | 45 ++++++++++++++ htdocs/tests/Unit/kernel/XoopsObjectTest.php | 28 +++++++++ .../Unit/kernel/XoopsOnlineHandlerTest.php | 35 +++++++++++ .../XoopsPersistableObjectHandlerTest.php | 59 +++++++++++++++++++ .../kernel/XoopsPrivmessageHandlerTest.php | 33 +++++++++++ .../Unit/kernel/XoopsPrivmessageTest.php | 25 ++++++++ .../Unit/kernel/XoopsTplFileHandlerTest.php | 33 +++++++++++ htdocs/tests/Unit/kernel/XoopsTplFileTest.php | 25 ++++++++ .../Unit/kernel/XoopsTplSetHandlerTest.php | 33 +++++++++++ htdocs/tests/Unit/kernel/XoopsTplSetTest.php | 25 ++++++++ .../Unit/kernel/XoopsUserHandlerTest.php | 33 +++++++++++ htdocs/tests/Unit/kernel/XoopsUserTest.php | 25 ++++++++ htdocs/tests/Unit/kernel/testKernel.xml | 38 ++++++++++++ htdocs/tests/Unit/testKernel.xml | 38 ++++++++++++ 33 files changed, 1029 insertions(+) create mode 100644 htdocs/tests/Unit/.htaccess create mode 100644 htdocs/tests/Unit/bootstrap.php create mode 100644 htdocs/tests/Unit/class/testClass.xml create mode 100644 htdocs/tests/Unit/common_phpunit.php create mode 100644 htdocs/tests/Unit/init_new.php create mode 100644 htdocs/tests/Unit/kernel/XoopsBlockHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsBlockTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsConfigHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsConfigItemHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsConfigItemTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsConfigOptionHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsConfigOptionTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsGroupHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsGroupPermHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsGroupPermTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsGroupTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsMemberHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsModuleHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsModuleTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsObjectHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsObjectTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsOnlineHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsPersistableObjectHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsPrivmessageHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsPrivmessageTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsTplFileHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsTplFileTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsTplSetHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsTplSetTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsUserHandlerTest.php create mode 100644 htdocs/tests/Unit/kernel/XoopsUserTest.php create mode 100644 htdocs/tests/Unit/kernel/testKernel.xml create mode 100644 htdocs/tests/Unit/testKernel.xml diff --git a/htdocs/tests/Unit/.htaccess b/htdocs/tests/Unit/.htaccess new file mode 100644 index 000000000..3418e55a6 --- /dev/null +++ b/htdocs/tests/Unit/.htaccess @@ -0,0 +1 @@ +deny from all \ No newline at end of file diff --git a/htdocs/tests/Unit/bootstrap.php b/htdocs/tests/Unit/bootstrap.php new file mode 100644 index 000000000..88f110315 --- /dev/null +++ b/htdocs/tests/Unit/bootstrap.php @@ -0,0 +1,43 @@ += 5.3.0'; + die(1); +} + +define('CLI', true); + +ini_set('memory_limit', -1); + +while (ob_get_level()) { + ob_end_flush(); +} + + +/* + + +*/ diff --git a/htdocs/tests/Unit/class/testClass.xml b/htdocs/tests/Unit/class/testClass.xml new file mode 100644 index 000000000..8e4955780 --- /dev/null +++ b/htdocs/tests/Unit/class/testClass.xml @@ -0,0 +1,39 @@ + + + + + class + + + + + + slow + + + + + + ../htdocs/class + + + + + + + + diff --git a/htdocs/tests/Unit/common_phpunit.php b/htdocs/tests/Unit/common_phpunit.php new file mode 100644 index 000000000..9d353d0fc --- /dev/null +++ b/htdocs/tests/Unit/common_phpunit.php @@ -0,0 +1,30 @@ + initializing $_SERVER values +if (empty($_SERVER['HTTP_HOST'])) { + $_SERVER['HTTP_HOST'] = 'localhost'; + $_SERVER['HTTP_CONNECTION'] = 'keep-alive'; + $_SERVER['HTTP_ACCEPT'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'; + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1496.0 Safari/537.36'; + $_SERVER['HTTP_REFERER'] = 'http://localhost/xoops/'; + $_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip,deflate,sdch'; + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4'; + $_SERVER['SERVER_SIGNATURE'] = ''; + $_SERVER['SERVER_SOFTWARE'] = 'Apache/2.2.3 (Win32) PHP/7.4.0'; + $_SERVER['SERVER_NAME'] = 'localhost'; + $_SERVER['SERVER_ADDR'] = '127.0.0.1'; + $_SERVER['SERVER_PORT'] = '80'; + $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; + $_SERVER['REMOTE_PORT'] = '58644'; + $_SERVER['GATEWAY_INTERFACE'] = 'CGI/1.1'; + $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['QUERY_STRING'] = ''; + $_SERVER['REQUEST_URI'] = '/XoopsCore/tests/xoops_lib/XoopsTest.php'; +} diff --git a/htdocs/tests/Unit/init_new.php b/htdocs/tests/Unit/init_new.php new file mode 100644 index 000000000..cc03beaa4 --- /dev/null +++ b/htdocs/tests/Unit/init_new.php @@ -0,0 +1,42 @@ + initializing $_SERVER values +if (empty($_SERVER['HTTP_HOST'])) { + define('IS_PHPUNIT', true); +} + +if (defined('IS_PHPUNIT')) { + require_once __DIR__ . '/common_phpunit.php'; +} else { + // Avoid check proxy to define constant XOOPS_DB_PROXY + // because it implies a readonly database connection + $_SERVER['REQUEST_METHOD'] = 'POST'; + define('XOOPS_XMLRPC', 0); +} + +define('XOOPS_TU_ROOT_PATH', realpath(dirname(__DIR__, 2))); + +// echo 'XOOPS_TU_ROOT_PATH = ' . XOOPS_TU_ROOT_PATH. "\n"; + +//temporary patch, we still need mainfile until we have a config file +$xoopsOption['nocommon'] = true; // don't include common.php file +require_once(XOOPS_TU_ROOT_PATH . '/mainfile.php'); +//require_once(XOOPS_TU_ROOT_PATH . '/class/XoopsBaseConfig.php'); + +//\XoopsBaseConfig::bootstrapTransition(); +// +//\Xoops\Locale::loadLocale(); diff --git a/htdocs/tests/Unit/kernel/XoopsBlockHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsBlockHandlerTest.php new file mode 100644 index 000000000..ba67596e1 --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsBlockHandlerTest.php @@ -0,0 +1,33 @@ +conn = XoopsDatabaseFactory::getDatabaseConnection(); + } + + public function test___construct() + { + $instance = new \XoopsBlockHandler($this->conn); + $this->assertInstanceOf(\XoopsBlockHandler::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsBlockTest.php b/htdocs/tests/Unit/kernel/XoopsBlockTest.php new file mode 100644 index 000000000..747b577c2 --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsBlockTest.php @@ -0,0 +1,25 @@ +assertInstanceOf(\XoopsBlock::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsConfigHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsConfigHandlerTest.php new file mode 100644 index 000000000..675f452bc --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsConfigHandlerTest.php @@ -0,0 +1,33 @@ +conn = XoopsDatabaseFactory::getDatabaseConnection(); + } + + public function test___construct() + { + $instance = new \XoopsConfigHandler($this->conn); + $this->assertInstanceOf(\XoopsConfigHandler::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsConfigItemHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsConfigItemHandlerTest.php new file mode 100644 index 000000000..6a0a41f50 --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsConfigItemHandlerTest.php @@ -0,0 +1,34 @@ +conn = XoopsDatabaseFactory::getDatabaseConnection(); + } + + public function test___construct() + { + $instance = new \XoopsConfigItemHandler($this->conn); + $this->assertInstanceOf(\XoopsConfigItemHandler::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsConfigItemTest.php b/htdocs/tests/Unit/kernel/XoopsConfigItemTest.php new file mode 100644 index 000000000..8cdb4113a --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsConfigItemTest.php @@ -0,0 +1,25 @@ +assertInstanceOf(\XoopsConfigItem::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsConfigOptionHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsConfigOptionHandlerTest.php new file mode 100644 index 000000000..1fc7f2783 --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsConfigOptionHandlerTest.php @@ -0,0 +1,29 @@ +conn = XoopsDatabaseFactory::getDatabaseConnection(); + } + + public function test___construct() + { + $instance = new \XoopsConfigOptionHandler($this->conn); + $this->assertInstanceOf(\XoopsConfigOptionHandler::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsConfigOptionTest.php b/htdocs/tests/Unit/kernel/XoopsConfigOptionTest.php new file mode 100644 index 000000000..90fb6477b --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsConfigOptionTest.php @@ -0,0 +1,25 @@ +assertInstanceOf(\XoopsConfigOption::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsGroupHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsGroupHandlerTest.php new file mode 100644 index 000000000..c45679a2a --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsGroupHandlerTest.php @@ -0,0 +1,27 @@ +conn = XoopsDatabaseFactory::getDatabaseConnection(); + } + + public function test___construct() + { + $instance = new \XoopsGroupHandler($this->conn); + $this->assertInstanceOf(\XoopsGroupHandler::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsGroupPermHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsGroupPermHandlerTest.php new file mode 100644 index 000000000..c6509520a --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsGroupPermHandlerTest.php @@ -0,0 +1,27 @@ +conn = XoopsDatabaseFactory::getDatabaseConnection(); + } + + public function test___construct() + { + $instance = new \XoopsGroupPermHandler($this->conn); + $this->assertInstanceOf(\XoopsGroupPermHandler::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsGroupPermTest.php b/htdocs/tests/Unit/kernel/XoopsGroupPermTest.php new file mode 100644 index 000000000..991850fc4 --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsGroupPermTest.php @@ -0,0 +1,25 @@ +assertInstanceOf(\XoopsGroupPerm::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsGroupTest.php b/htdocs/tests/Unit/kernel/XoopsGroupTest.php new file mode 100644 index 000000000..22931a4f2 --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsGroupTest.php @@ -0,0 +1,25 @@ +assertInstanceOf(\XoopsGroup::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsMemberHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsMemberHandlerTest.php new file mode 100644 index 000000000..fc3dec10d --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsMemberHandlerTest.php @@ -0,0 +1,33 @@ +conn = XoopsDatabaseFactory::getDatabaseConnection(); + } + + public function test___construct() + { + $instance = new \XoopsMemberHandler($this->conn); + $this->assertInstanceOf(\XoopsMemberHandler::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsModuleHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsModuleHandlerTest.php new file mode 100644 index 000000000..d1b86a661 --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsModuleHandlerTest.php @@ -0,0 +1,33 @@ +conn = XoopsDatabaseFactory::getDatabaseConnection(); + } + + public function test___construct() + { + $instance = new \XoopsModuleHandler($this->conn); + $this->assertInstanceOf(\XoopsModuleHandler::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsModuleTest.php b/htdocs/tests/Unit/kernel/XoopsModuleTest.php new file mode 100644 index 000000000..04e16f449 --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsModuleTest.php @@ -0,0 +1,25 @@ +assertInstanceOf(\XoopsModule::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsObjectHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsObjectHandlerTest.php new file mode 100644 index 000000000..a9cdb92bf --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsObjectHandlerTest.php @@ -0,0 +1,45 @@ +myClass, $item); + } catch (ReflectionException $e) { + } + $this->assertTrue($prop->isPublic()); + } + } + + public function test___construct() + { + $conn = \XoopsDatabaseFactory::getDatabaseConnection(); + $instance = new $this->myClass($conn); + $this->assertInstanceOf($this->myClass, $instance); + $this->assertInstanceOf(\XoopsObjectHandler::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsObjectTest.php b/htdocs/tests/Unit/kernel/XoopsObjectTest.php new file mode 100644 index 000000000..5c3d48623 --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsObjectTest.php @@ -0,0 +1,28 @@ +myClass(); + $this->assertInstanceOf($this->myClass, $instance); + $this->assertInstanceOf(\XoopsObject::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsOnlineHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsOnlineHandlerTest.php new file mode 100644 index 000000000..405bc783c --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsOnlineHandlerTest.php @@ -0,0 +1,35 @@ +conn = $onlineHandler->db(); + $this->conn = $db; + } + + public function test___construct() + { + $instance = new \XoopsOnlineHandler($this->conn); + $this->assertInstanceOf(\XoopsOnlineHandler::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsPersistableObjectHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsPersistableObjectHandlerTest.php new file mode 100644 index 000000000..91f11ab9f --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsPersistableObjectHandlerTest.php @@ -0,0 +1,59 @@ +myclass, $item); + } catch (ReflectionException $e) { + } + $this->assertTrue($prop->isPublic()); + } + } + + public function test___construct() + { + $conn = \XoopsDatabaseFactory::getDatabaseConnection(); + $table = 'table'; + $className = 'className'; + $keyName = 'keyName'; + $identifierName = 'identifierName'; + $instance = new $this->myclass($conn, $table, $className, $keyName, $identifierName); + $this->assertInstanceOf($this->myclass, $instance); + $this->assertInstanceOf(\XoopsPersistableObjectHandler::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsPrivmessageHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsPrivmessageHandlerTest.php new file mode 100644 index 000000000..40cbfc12c --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsPrivmessageHandlerTest.php @@ -0,0 +1,33 @@ +conn = XoopsDatabaseFactory::getDatabaseConnection(); + } + + public function test___construct() + { + $instance = new \XoopsPrivmessageHandler($this->conn); + $this->assertInstanceOf(\XoopsPrivmessageHandler::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsPrivmessageTest.php b/htdocs/tests/Unit/kernel/XoopsPrivmessageTest.php new file mode 100644 index 000000000..e0562eeb1 --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsPrivmessageTest.php @@ -0,0 +1,25 @@ +assertInstanceOf(\XoopsPrivmessage::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsTplFileHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsTplFileHandlerTest.php new file mode 100644 index 000000000..78ad3240e --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsTplFileHandlerTest.php @@ -0,0 +1,33 @@ +conn = XoopsDatabaseFactory::getDatabaseConnection(); + } + + public function test___construct() + { + $instance = new \XoopsTplfileHandler($this->conn); + $this->assertInstanceOf('\XoopsTplFileHandler', $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsTplFileTest.php b/htdocs/tests/Unit/kernel/XoopsTplFileTest.php new file mode 100644 index 000000000..c43ff8e58 --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsTplFileTest.php @@ -0,0 +1,25 @@ +assertInstanceOf('\XoopsTplFile', $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsTplSetHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsTplSetHandlerTest.php new file mode 100644 index 000000000..5ad054833 --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsTplSetHandlerTest.php @@ -0,0 +1,33 @@ +conn = XoopsDatabaseFactory::getDatabaseConnection(); + } + + public function test___construct() + { + $instance = new \XoopsTplsetHandler($this->conn); + $this->assertInstanceOf('\XoopsTplSetHandler', $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsTplSetTest.php b/htdocs/tests/Unit/kernel/XoopsTplSetTest.php new file mode 100644 index 000000000..41f3b0dee --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsTplSetTest.php @@ -0,0 +1,25 @@ +assertInstanceOf('\XoopsTplSet', $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsUserHandlerTest.php b/htdocs/tests/Unit/kernel/XoopsUserHandlerTest.php new file mode 100644 index 000000000..1dc4d4779 --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsUserHandlerTest.php @@ -0,0 +1,33 @@ +conn = XoopsDatabaseFactory::getDatabaseConnection(); + } + + public function test___construct() + { + $instance = new \XoopsUserHandler($this->conn); + $this->assertInstanceOf(\XoopsUserHandler::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/XoopsUserTest.php b/htdocs/tests/Unit/kernel/XoopsUserTest.php new file mode 100644 index 000000000..fb2f4a05f --- /dev/null +++ b/htdocs/tests/Unit/kernel/XoopsUserTest.php @@ -0,0 +1,25 @@ +assertInstanceOf(\XoopsUser::class, $instance); + } +} diff --git a/htdocs/tests/Unit/kernel/testKernel.xml b/htdocs/tests/Unit/kernel/testKernel.xml new file mode 100644 index 000000000..b0ab6d5d3 --- /dev/null +++ b/htdocs/tests/Unit/kernel/testKernel.xml @@ -0,0 +1,38 @@ + + + + + kernel + + + + + + slow + + + + + + ../htdocs/kernel + + + + + + + diff --git a/htdocs/tests/Unit/testKernel.xml b/htdocs/tests/Unit/testKernel.xml new file mode 100644 index 000000000..b0ab6d5d3 --- /dev/null +++ b/htdocs/tests/Unit/testKernel.xml @@ -0,0 +1,38 @@ + + + + + kernel + + + + + + slow + + + + + + ../htdocs/kernel + + + + + + + From b51adb24af47ab56e9bbb9e614fa834f835a738a Mon Sep 17 00:00:00 2001 From: mambax7 Date: Tue, 7 Mar 2023 02:08:28 -0500 Subject: [PATCH 02/12] fix for conflict with PhpUnit --- htdocs/kernel/config.php | 5 ++--- htdocs/kernel/member.php | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/htdocs/kernel/config.php b/htdocs/kernel/config.php index 57a3e3704..52eafd21d 100644 --- a/htdocs/kernel/config.php +++ b/htdocs/kernel/config.php @@ -17,9 +17,8 @@ */ defined('XOOPS_ROOT_PATH') || exit('Restricted access'); -require_once $GLOBALS['xoops']->path('kernel/configoption.php'); -require_once $GLOBALS['xoops']->path('kernel/configitem.php'); - +require_once __DIR__ . '/configoption.php'; +require_once __DIR__ . '/configitem.php'; /** * XOOPS configuration handling class. * This class acts as an interface for handling general configurations of XOOPS diff --git a/htdocs/kernel/member.php b/htdocs/kernel/member.php index 5c6c7260d..b0f07f704 100644 --- a/htdocs/kernel/member.php +++ b/htdocs/kernel/member.php @@ -17,8 +17,8 @@ */ defined('XOOPS_ROOT_PATH') || exit('Restricted access'); -require_once $GLOBALS['xoops']->path('kernel/user.php'); -require_once $GLOBALS['xoops']->path('kernel/group.php'); +require_once __DIR__ . '/user.php'; +require_once __DIR__ . '/group.php'; /** * XOOPS member handler class. From b8ce94885487a8f8059978f828c818e23da6bb88 Mon Sep 17 00:00:00 2001 From: mambax7 Date: Tue, 7 Mar 2023 02:18:36 -0500 Subject: [PATCH 03/12] duplicate testKernel.xml --- htdocs/tests/Unit/testKernel.xml | 38 -------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 htdocs/tests/Unit/testKernel.xml diff --git a/htdocs/tests/Unit/testKernel.xml b/htdocs/tests/Unit/testKernel.xml deleted file mode 100644 index b0ab6d5d3..000000000 --- a/htdocs/tests/Unit/testKernel.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - kernel - - - - - - slow - - - - - - ../htdocs/kernel - - - - - - - From 9570b72defcbc199e57f201ed9d25c3cfb327866 Mon Sep 17 00:00:00 2001 From: mambax7 Date: Thu, 9 Mar 2023 05:08:53 -0500 Subject: [PATCH 04/12] Xmf tests --- .../Unit/class/libraries/Xmf/AssertTest.php | 477 ++++++++++++++++++ .../libraries/Xmf/Database/MigrateTest.php | 102 ++++ .../libraries/Xmf/Database/TableLoadTest.php | 74 +++ .../libraries/Xmf/Database/TablesTest.php | 383 ++++++++++++++ .../Unit/class/libraries/Xmf/DebugTest.php | 91 ++++ .../class/libraries/Xmf/FilterInputTest.php | 120 +++++ .../class/libraries/Xmf/HighlighterTest.php | 51 ++ .../class/libraries/Xmf/IPAddressTest.php | 106 ++++ .../libraries/Xmf/Jwt/JsonWebTokenTest.php | 85 ++++ .../libraries/Xmf/Jwt/JsonWebTokenTest0.php | 85 ++++ .../libraries/Xmf/Jwt/KeyFactoryTest.php | 65 +++ .../libraries/Xmf/Jwt/TokenFactoryTest.php | 71 +++ .../libraries/Xmf/Jwt/TokenReaderTest.php | 87 ++++ .../libraries/Xmf/Key/ArrayStorageTest.php | 74 +++ .../class/libraries/Xmf/Key/BasicTest.php | 85 ++++ .../libraries/Xmf/Key/FileStorageTest.php | 77 +++ .../libraries/Xmf/Key/KeyAbstractTest.php | 58 +++ .../Xmf/Key/StorageInterfaceTest.php | 43 ++ .../Unit/class/libraries/Xmf/LanguageTest.php | 57 +++ .../Unit/class/libraries/Xmf/MetagenTest.php | 221 ++++++++ .../class/libraries/Xmf/Module/AdminTest.php | 196 +++++++ .../Xmf/Module/Helper/AbstractHelperTest.php | 58 +++ .../libraries/Xmf/Module/Helper/CacheTest.php | 83 +++ .../Xmf/Module/Helper/GenericHelperTest.php | 155 ++++++ .../Xmf/Module/Helper/PermissionTest.php | 107 ++++ .../Xmf/Module/Helper/SessionTest.php | 75 +++ .../class/libraries/Xmf/Module/HelperTest.php | 53 ++ .../Unit/class/libraries/Xmf/RandomTest.php | 58 +++ .../Unit/class/libraries/Xmf/RequestTest.php | 242 +++++++++ .../class/libraries/Xmf/StopWordsTest.php | 53 ++ .../Unit/class/libraries/Xmf/UuidTest.php | 104 ++++ .../Unit/class/libraries/Xmf/YamlTest.php | 112 ++++ 32 files changed, 3708 insertions(+) create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/AssertTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Database/MigrateTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Database/TableLoadTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Database/TablesTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/DebugTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/FilterInputTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/HighlighterTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/IPAddressTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Jwt/JsonWebTokenTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Jwt/JsonWebTokenTest0.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Jwt/KeyFactoryTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Jwt/TokenFactoryTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Jwt/TokenReaderTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Key/ArrayStorageTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Key/BasicTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Key/FileStorageTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Key/KeyAbstractTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Key/StorageInterfaceTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/LanguageTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/MetagenTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Module/AdminTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/AbstractHelperTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/CacheTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/GenericHelperTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/PermissionTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/SessionTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/Module/HelperTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/RandomTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/RequestTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/StopWordsTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/UuidTest.php create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/YamlTest.php diff --git a/htdocs/tests/Unit/class/libraries/Xmf/AssertTest.php b/htdocs/tests/Unit/class/libraries/Xmf/AssertTest.php new file mode 100644 index 000000000..7e630fa11 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/AssertTest.php @@ -0,0 +1,477 @@ + + * + * The MIT License (MIT) + * + * Copyright (c) 2014 Bernhard Schussek + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +use ArrayIterator; +use Exception; +use Error; +use LogicException; +use RuntimeException; +use stdClass; +use Xmf\Assert; + +/** + * @since 1.0 + * + * @author Bernhard Schussek + */ +class AssertTest extends TestCase +{ + private static $resource; + + public static function getResource() + { + if (!static::$resource) { + static::$resource = fopen(__FILE__, 'r'); + } + + return static::$resource; + } + + public static function tearDownAfterClass(): void + { + @fclose(self::$resource); + } + + public function getTests(): array + { + $resource = self::getResource(); + + return [ + ['string', ['value'], true], + ['string', [''], true], + ['string', [1234], false], + ['stringNotEmpty', ['value'], true], + ['stringNotEmpty', [''], false], + ['stringNotEmpty', [1234], false], + ['integer', [123], true], + ['integer', ['123'], false], + ['integer', [1.0], false], + ['integer', [1.23], false], + ['integerish', [1.0], true], + ['integerish', [1.23], false], + ['integerish', [123], true], + ['integerish', ['123'], true], + ['float', [1.0], true], + ['float', [1.23], true], + ['float', [123], false], + ['float', ['123'], false], + ['numeric', [1.0], true], + ['numeric', [1.23], true], + ['numeric', [123], true], + ['numeric', ['123'], true], + ['numeric', ['foo'], false], + ['boolean', [true], true], + ['boolean', [false], true], + ['boolean', [1], false], + ['boolean', ['1'], false], + ['scalar', ['1'], true], + ['scalar', [123], true], + ['scalar', [true], true], + ['scalar', [null], false], + ['scalar', [[]], false], + ['scalar', [new stdClass()], false], + ['object', [new stdClass()], true], + ['object', [new RuntimeException()], true], + ['object', [null], false], + ['object', [true], false], + ['object', [1], false], + ['object', [[]], false], + ['resource', [$resource], true], + ['resource', [$resource, 'stream'], true], + ['resource', [$resource, 'other'], false], + ['resource', [1], false], + ['isCallable', ['strlen'], true], + ['isCallable', [[$this, 'getTests']], true], + ['isCallable', [static function () { }], true], + ['isCallable', [1234], false], + ['isCallable', ['foobar'], false], + ['isArray', [[]], true], + ['isArray', [[1, 2, 3]], true], + ['isArray', [new ArrayIterator([])], false], + ['isArray', [123], false], + ['isArray', [new stdClass()], false], + ['isTraversable', [[]], true], + ['isTraversable', [[1, 2, 3]], true], + ['isTraversable', [new ArrayIterator([])], true], + ['isTraversable', [123], false], + ['isTraversable', [new stdClass()], false], + ['isInstanceOf', [new stdClass(), 'stdClass'], true], + ['isInstanceOf', [new Exception(), 'stdClass'], false], + ['isInstanceOf', [123, 'stdClass'], false], + ['isInstanceOf', [[], 'stdClass'], false], + ['notInstanceOf', [new stdClass(), 'stdClass'], false], + ['notInstanceOf', [new Exception(), 'stdClass'], true], + ['notInstanceOf', [123, 'stdClass'], true], + ['notInstanceOf', [[], 'stdClass'], true], + ['true', [true], true], + ['true', [false], false], + ['true', [1], false], + ['true', [null], false], + ['false', [false], true], + ['false', [true], false], + ['false', [1], false], + ['false', [0], false], + ['false', [null], false], + ['null', [null], true], + ['null', [false], false], + ['null', [0], false], + ['notNull', [false], true], + ['notNull', [0], true], + ['notNull', [null], false], + ['isEmpty', [null], true], + ['isEmpty', [false], true], + ['isEmpty', [0], true], + ['isEmpty', [''], true], + ['isEmpty', [1], false], + ['isEmpty', ['a'], false], + ['notEmpty', [1], true], + ['notEmpty', ['a'], true], + ['notEmpty', [null], false], + ['notEmpty', [false], false], + ['notEmpty', [0], false], + ['notEmpty', [''], false], + ['eq', [1, 1], true], + ['eq', [1, '1'], true], + ['eq', [1, true], true], + ['eq', [1, 0], false], + ['notEq', [1, 0], true], + ['notEq', [1, 1], false], + ['notEq', [1, '1'], false], + ['notEq', [1, true], false], + ['same', [1, 1], true], + ['same', [1, '1'], false], + ['same', [1, true], false], + ['same', [1, 0], false], + ['notSame', [1, 0], true], + ['notSame', [1, 1], false], + ['notSame', [1, '1'], true], + ['notSame', [1, true], true], + ['greaterThan', [1, 0], true], + ['greaterThan', [0, 0], false], + ['greaterThanEq', [2, 1], true], + ['greaterThanEq', [1, 1], true], + ['greaterThanEq', [0, 1], false], + ['lessThan', [0, 1], true], + ['lessThan', [1, 1], false], + ['lessThanEq', [0, 1], true], + ['lessThanEq', [1, 1], true], + ['lessThanEq', [2, 1], false], + ['range', [1, 1, 2], true], + ['range', [2, 1, 2], true], + ['range', [0, 1, 2], false], + ['range', [3, 1, 2], false], + ['oneOf', [1, [1, 2, 3]], true], + ['oneOf', [1, ['1', '2', '3']], false], + ['contains', ['abcd', 'ab'], true], + ['contains', ['abcd', 'bc'], true], + ['contains', ['abcd', 'cd'], true], + ['contains', ['abcd', 'de'], false], + ['contains', ['', 'de'], false], + ['startsWith', ['abcd', 'ab'], true], + ['startsWith', ['abcd', 'bc'], false], + ['startsWith', ['', 'bc'], false], + ['startsWithLetter', ['abcd'], true], + ['startsWithLetter', ['1abcd'], false], + ['startsWithLetter', [''], false], + ['endsWith', ['abcd', 'cd'], true], + ['endsWith', ['abcd', 'bc'], false], + ['endsWith', ['', 'bc'], false], + ['regex', ['abcd', '~^ab~'], true], + ['regex', ['abcd', '~^bc~'], false], + ['regex', ['', '~^bc~'], false], + ['alpha', ['abcd'], true], + ['alpha', ['ab1cd'], false], + ['alpha', [''], false], + ['digits', ['1234'], true], + ['digits', ['12a34'], false], + ['digits', [''], false], + ['alnum', ['ab12'], true], + ['alnum', ['ab12$'], false], + ['alnum', [''], false], + ['lower', ['abcd'], true], + ['lower', ['abCd'], false], + ['lower', ['ab_d'], false], + ['lower', [''], false], + ['upper', ['ABCD'], true], + ['upper', ['ABcD'], false], + ['upper', ['AB_D'], false], + ['upper', [''], false], + ['length', ['abcd', 4], true], + ['length', ['abc', 4], false], + ['length', ['abcde', 4], false], + ['length', ['äbcd', 4], true, true], + ['length', ['äbc', 4], false, true], + ['length', ['äbcde', 4], false, true], + ['minLength', ['abcd', 4], true], + ['minLength', ['abcde', 4], true], + ['minLength', ['abc', 4], false], + ['minLength', ['äbcd', 4], true, true], + ['minLength', ['äbcde', 4], true, true], + ['minLength', ['äbc', 4], false, true], + ['maxLength', ['abcd', 4], true], + ['maxLength', ['abc', 4], true], + ['maxLength', ['abcde', 4], false], + ['maxLength', ['äbcd', 4], true, true], + ['maxLength', ['äbc', 4], true, true], + ['maxLength', ['äbcde', 4], false, true], + ['lengthBetween', ['abcd', 3, 5], true], + ['lengthBetween', ['abc', 3, 5], true], + ['lengthBetween', ['abcde', 3, 5], true], + ['lengthBetween', ['ab', 3, 5], false], + ['lengthBetween', ['abcdef', 3, 5], false], + ['lengthBetween', ['äbcd', 3, 5], true, true], + ['lengthBetween', ['äbc', 3, 5], true, true], + ['lengthBetween', ['äbcde', 3, 5], true, true], + ['lengthBetween', ['äb', 3, 5], false, true], + ['lengthBetween', ['äbcdef', 3, 5], false, true], + ['fileExists', [__FILE__], true], + ['fileExists', [__DIR__], true], + ['fileExists', [__DIR__ . '/foobar'], false], + ['file', [__FILE__], true], + ['file', [__DIR__], false], + ['file', [__DIR__ . '/foobar'], false], + ['directory', [__DIR__], true], + ['directory', [__FILE__], false], + ['directory', [__DIR__ . '/foobar'], false], + // no tests for readable()/writable() for now + ['classExists', [__CLASS__], true], + ['classExists', [__NAMESPACE__ . '\Foobar'], false], + ['subclassOf', [__CLASS__, TestCase::class], true], + ['subclassOf', [__CLASS__, 'stdClass'], false], + ['implementsInterface', ['ArrayIterator', 'Traversable'], true], + ['implementsInterface', [__CLASS__, 'Traversable'], false], + ['propertyExists', [(object)['property' => 0], 'property'], true], + ['propertyExists', [(object)['property' => null], 'property'], true], + ['propertyExists', [(object)['property' => null], 'foo'], false], + ['propertyNotExists', [(object)['property' => 0], 'property'], false], + ['propertyNotExists', [(object)['property' => null], 'property'], false], + ['propertyNotExists', [(object)['property' => null], 'foo'], true], + ['methodExists', ['RuntimeException', 'getMessage'], true], + ['methodExists', [new RuntimeException(), 'getMessage'], true], + ['methodExists', ['stdClass', 'getMessage'], false], + ['methodExists', [new stdClass(), 'getMessage'], false], + ['methodExists', [null, 'getMessage'], false], + ['methodExists', [true, 'getMessage'], false], + ['methodExists', [1, 'getMessage'], false], + ['methodNotExists', ['RuntimeException', 'getMessage'], false], + ['methodNotExists', [new RuntimeException(), 'getMessage'], false], + ['methodNotExists', ['stdClass', 'getMessage'], true], + ['methodNotExists', [new stdClass(), 'getMessage'], true], + ['methodNotExists', [null, 'getMessage'], true], + ['methodNotExists', [true, 'getMessage'], true], + ['methodNotExists', [1, 'getMessage'], true], + ['keyExists', [['key' => 0], 'key'], true], + ['keyExists', [['key' => null], 'key'], true], + ['keyExists', [['key' => null], 'foo'], false], + ['keyNotExists', [['key' => 0], 'key'], false], + ['keyNotExists', [['key' => null], 'key'], false], + ['keyNotExists', [['key' => null], 'foo'], true], + ['count', [[0, 1, 2], 3], true], + ['count', [[0, 1, 2], 2], false], + ['uuid', ['00000000-0000-0000-0000-000000000000'], true], + ['uuid', ['ff6f8cb0-c57d-21e1-9b21-0800200c9a66'], true], + ['uuid', ['ff6f8cb0-c57d-11e1-9b21-0800200c9a66'], true], + ['uuid', ['ff6f8cb0-c57d-31e1-9b21-0800200c9a66'], true], + ['uuid', ['ff6f8cb0-c57d-41e1-9b21-0800200c9a66'], true], + ['uuid', ['ff6f8cb0-c57d-51e1-9b21-0800200c9a66'], true], + ['uuid', ['FF6F8CB0-C57D-11E1-9B21-0800200C9A66'], true], + ['uuid', ['zf6f8cb0-c57d-11e1-9b21-0800200c9a66'], false], + ['uuid', ['af6f8cb0c57d11e19b210800200c9a66'], false], + ['uuid', ['ff6f8cb0-c57da-51e1-9b21-0800200c9a66'], false], + ['uuid', ['af6f8cb-c57d-11e1-9b21-0800200c9a66'], false], + ['uuid', ['3f6f8cb0-c57d-11e1-9b21-0800200c9a6'], false], + ['throws', [function () { throw new LogicException('test'); }, 'LogicException'], true], + ['throws', [function () { throw new LogicException('test'); }, 'IllogicException'], false], + ['throws', [function () { throw new Exception('test'); }], true], + //array('throws', array(function() { trigger_error('test'); }, 'Throwable'), true, false, 70000), + ['throws', [function () { trigger_error('test'); }, 'Unthrowable'], false, false, 70000], + ['throws', [function () { throw new Error(); }, 'Throwable'], true, true, 70000], + ]; + } + + public function getMethods(): array + { + $methods = []; + + foreach ($this->getTests() as $params) { + $methods[$params[0]] = [$params[0]]; + } + + return array_values($methods); + } + + /** + * @dataProvider getTests + */ + public function testAssert($method, $args, $success, $multibyte = false, $minVersion = null) + { + if ($minVersion && PHP_VERSION_ID < $minVersion) { + $this->markTestSkipped(sprintf('This test requires php %s or upper.', $minVersion)); + + return; + } + if ($multibyte && !function_exists('mb_strlen')) { + $this->markTestSkipped('The function mb_strlen() is not available'); + + return; + } + + if (!$success) { + $this->expectException(\InvalidArgumentException::class); + } + + call_user_func_array([Assert::class, $method], $args); + self::assertTrue(true, 'Return type ensures this assertion is never reached on failure'); + } + + /** + * @dataProvider getTests + */ + public function testNullOr($method, $args, $success, $multibyte = false, $minVersion = null) + { + if ($minVersion && PHP_VERSION_ID < $minVersion) { + $this->markTestSkipped(sprintf('This test requires php %s or upper.', $minVersion)); + + return; + } + if ($multibyte && !function_exists('mb_strlen')) { + $this->markTestSkipped('The function mb_strlen() is not available'); + + return; + } + + if (!$success && null !== reset($args)) { + $this->expectException(\InvalidArgumentException::class); + } + + call_user_func_array([Assert::class, 'nullOr' . ucfirst($method)], $args); + self::assertTrue(true, 'Return type ensures this assertion is never reached on failure'); + } + + /** + * @dataProvider getMethods + */ + public function testNullOrAcceptsNull($method) + { + call_user_func([Assert::class, 'nullOr' . ucfirst($method)], null); + self::assertTrue(true, 'Return type ensures this assertion is never reached on failure'); + } + + /** + * @dataProvider getTests + */ + public function testAllArray($method, $args, $success, $multibyte = false, $minVersion = null) + { + if ($minVersion && PHP_VERSION_ID < $minVersion) { + $this->markTestSkipped(sprintf('This test requires php %s or upper.', $minVersion)); + + return; + } + if ($multibyte && !function_exists('mb_strlen')) { + $this->markTestSkipped('The function mb_strlen() is not available'); + + return; + } + + if (!$success) { + $this->expectException(\InvalidArgumentException::class); + } + + $arg = array_shift($args); + array_unshift($args, [$arg]); + + call_user_func_array([Assert::class, 'all' . ucfirst($method)], $args); + self::assertTrue(true, 'Return type ensures this assertion is never reached on failure'); + } + + /** + * @dataProvider getTests + */ + public function testAllTraversable($method, $args, $success, $multibyte = false, $minVersion = null) + { + if ($minVersion && PHP_VERSION_ID < $minVersion) { + $this->markTestSkipped(sprintf('This test requires php %s or upper.', $minVersion)); + + return; + } + if ($multibyte && !function_exists('mb_strlen')) { + $this->markTestSkipped('The function mb_strlen() is not available'); + + return; + } + + if (!$success) { + $this->expectException(\InvalidArgumentException::class); + } + + $arg = array_shift($args); + array_unshift($args, new ArrayIterator([$arg])); + + call_user_func_array([Assert::class, 'all' . ucfirst($method)], $args); + self::assertTrue(true, 'Return type ensures this assertion is never reached on failure'); + } + + public function getStringConversions(): array + { + return [ + ['integer', ['foobar'], 'Expected an integer. Got: string'], + ['string', [1], 'Expected a string. Got: integer'], + ['string', [true], 'Expected a string. Got: boolean'], + ['string', [null], 'Expected a string. Got: NULL'], + ['string', [[]], 'Expected a string. Got: array'], + ['string', [new stdClass()], 'Expected a string. Got: stdClass'], + ['string', [self::getResource()], 'Expected a string. Got: resource'], + + ['eq', ['1', '2'], 'Expected a value equal to "2". Got: "1"'], + ['eq', [1, 2], 'Expected a value equal to 2. Got: 1'], + ['eq', [true, false], 'Expected a value equal to false. Got: true'], + ['eq', [true, null], 'Expected a value equal to null. Got: true'], + ['eq', [null, true], 'Expected a value equal to true. Got: null'], + ['eq', [[1], [2]], 'Expected a value equal to array. Got: array'], + ['eq', [new ArrayIterator([]), new stdClass()], 'Expected a value equal to stdClass. Got: ArrayIterator'], + ['eq', [1, self::getResource()], 'Expected a value equal to resource. Got: 1'], + ]; + } + + /** + * @dataProvider getStringConversions + */ + public function testConvertValuesToStrings($method, $args, $exceptionMessage) + { + $this->expectException(\InvalidArgumentException::class, $exceptionMessage); + + call_user_func_array([Assert::class, $method], $args); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Database/MigrateTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Database/MigrateTest.php new file mode 100644 index 000000000..710d956d5 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Database/MigrateTest.php @@ -0,0 +1,102 @@ +object = new Migrate('profile'); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testContracts() + { + $this->assertInstanceOf(Migrate::class, $this->object); + } + + public function testSaveCurrentSchema() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testGetCurrentSchema() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testGetTargetDefinitions() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testSynchronizeSchema() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testGetSynchronizeDDL() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testGetLastError() + { + $actual = $this->object->getLastError(); + $this->assertNull($actual); + } + + public function testGetLastErrNo() + { + $actual = $this->object->getLastErrNo(); + $this->assertNull($actual); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Database/TableLoadTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Database/TableLoadTest.php new file mode 100644 index 000000000..2b065e3ca --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Database/TableLoadTest.php @@ -0,0 +1,74 @@ +object = new TableLoad(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testLoadTableFromArray() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testLoadTableFromYamlFile() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testTruncateTable() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testRowCount() + { + $actual = $this->object->countRows('users'); + $this->assertIsInt($actual); + $this->assertTrue($actual >= 1); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Database/TablesTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Database/TablesTest.php new file mode 100644 index 000000000..4141f6d72 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Database/TablesTest.php @@ -0,0 +1,383 @@ +logger(); +//$xoops->events(); +//$psr4loader = new \Xoops\Core\Psr4ClassLoader(); +//$psr4loader->register(); +//$xoops->events() +// ->triggerEvent('core.include.common.psr4loader', $psr4loader); +//$xoops->events() +// ->triggerEvent('core.include.common.classmaps'); + +class TablesTest extends TestCase +{ + /** + * @var Tables + */ + protected $object; + /** + * @var string + */ + protected $prefix; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp(): void + { + $this->object = new Tables(); + $this->prefix = \XoopsDatabaseFactory::getDatabaseConnection()->prefix(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + protected function prefix($table) + { + return $this->prefix . '_' . $table; + } + + public function testName() + { + $tableName = 'users'; + $actual = $this->object->useTable($tableName); + $this->assertTrue($actual); + + $tables = $this->object->dumpTables(); + $this->assertArrayHasKey($tableName, $tables); + $this->assertEquals($this->prefix($tableName), $tables[$tableName]['name']); + } + + public function testAddColumn() + { + $tableName = 'users'; + $actual = $this->object->useTable($tableName); + $this->assertTrue($actual); + + $columnName = 'not_real_column'; + $columnAttr = 'int NOT NULL'; + + $this->object->addColumn($tableName, $columnName, $columnAttr); + $queue = $this->object->dumpQueue(); + $expected = "ALTER TABLE `{$this->prefix}_{$tableName}` ADD COLUMN `{$columnName}` {$columnAttr}"; + $this->assertEquals($expected, $queue[0]); + } + + public function testAddPrimaryKey() + { + $tableName = 'users'; + $actual = $this->object->useTable($tableName); + $this->assertTrue($actual); + + $columnName = 'uid'; + + $this->object->addPrimaryKey($tableName, $columnName); + $queue = $this->object->dumpQueue(); + //var_dump($queue); + $expected = "ALTER TABLE `{$this->prefix}_{$tableName}` ADD PRIMARY KEY(`{$columnName}`)"; + $this->assertEquals($expected, $queue[0]); + } + + public function testAddTable() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testUseTable() + { + $actual = $this->object->useTable('users'); + $this->assertTrue($actual); + + $actual = $this->object->useTable('system_nosuch_table'); + $this->assertFalse($actual); + } + + public function testGetColumnAttributes() + { + $tableName = 'users'; + $actual = $this->object->useTable($tableName); + $this->assertTrue($actual); + + $columnName = 'uid'; + + $actual = $this->object->getColumnAttributes($tableName, $columnName); + + $this->assertNotFalse(stristr($actual, 'mediumint(8)')); + $this->assertNotFalse(stristr($actual, 'unsigned')); + $this->assertNotFalse(stristr($actual, 'NOT NULL')); + $this->assertNotFalse(stristr($actual, 'auto_increment')); + } + + public function testGetTableIndexes() + { + $tableName = 'users'; + $this->object->useTable($tableName); + $actual = $this->object->getTableIndexes($tableName); + $this->assertIsArray($actual); + $this->assertArrayHasKey('PRIMARY', $actual); + + $actual = $this->object->getTableIndexes('system_bogus_table_name'); + $this->assertFalse($actual); + } + + public function testAlterColumn() + { + $tableName = 'users'; + $actual = $this->object->useTable($tableName); + $this->assertTrue($actual); + + $columnName = 'pass'; + $newColumnName = 'password'; + $attributes = 'varchar(255) NOT NULL DEFAULT \'\''; + + $this->object->alterColumn($tableName, $columnName, $attributes, $newColumnName); + $queue = $this->object->dumpQueue(); + //var_dump($queue); + $expected = "ALTER TABLE `{$this->prefix}_{$tableName}` CHANGE COLUMN `{$columnName}` `{$newColumnName}` {$attributes} "; + $this->assertEquals($expected, $queue[0]); + } + + public function testCopyTable() + { + $tableName = 'users'; + $actual = $this->object->useTable($tableName); + $this->assertTrue($actual); + + $copyName = 'notsystem_user'; + $actual = $this->object->useTable($copyName); + $this->assertFalse($actual); + + $actual = $this->object->copyTable($tableName, $copyName, false); + $this->assertTrue($actual); + + $tables = $this->object->dumpTables(); + $this->assertEquals($tables[$tableName]['columns'], $tables[$copyName]['columns']); + $this->assertEquals($tables[$tableName]['keys'], $tables[$copyName]['keys']); + } + + public function testCreateIndex() + { + $tableName = 'users'; + $actual = $this->object->useTable($tableName); + $this->assertTrue($actual); + + $columnName = 'actkey'; + $indexName = 'user_actkey'; + + $this->object->addIndex($indexName, $tableName, $columnName); + $queue = $this->object->dumpQueue(); + + $expected = "ALTER TABLE `{$this->prefix}_{$tableName}` ADD INDEX `{$indexName}` (`{$columnName}`)"; + $this->assertEquals($expected, $queue[0]); + } + + public function testDropColumn() + { + $tableName = 'users'; + $actual = $this->object->useTable($tableName); + $this->assertTrue($actual); + + $columnName = 'actkey'; + + $this->object->dropColumn($tableName, $columnName); + $queue = $this->object->dumpQueue(); + + $expected = "ALTER TABLE `{$this->prefix}_{$tableName}` DROP COLUMN `{$columnName}`"; + $this->assertEquals($expected, $queue[0]); + } + + public function testDropIndex() + { + $tableName = 'users'; + $actual = $this->object->useTable($tableName); + $this->assertTrue($actual); + + $indexName = 'blahblah'; + + $this->object->dropIndex($indexName, $tableName); + $queue = $this->object->dumpQueue(); + + $expected = "ALTER TABLE `{$this->prefix}_{$tableName}` DROP INDEX `{$indexName}`"; + $this->assertEquals($expected, $queue[0]); + } + + public function testDropIndexes() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testDropPrimaryKey() + { + $tableName = 'users'; + $actual = $this->object->useTable($tableName); + $this->assertTrue($actual); + + $this->object->dropPrimaryKey($tableName); + $queue = $this->object->dumpQueue(); + + $expected = "ALTER TABLE `{$this->prefix}_{$tableName}` DROP PRIMARY KEY "; + $this->assertEquals($expected, $queue[0]); + } + + public function testDropTable() + { + $tableName = 'users'; + $actual = $this->object->useTable($tableName); + $this->assertTrue($actual); + + $this->object->dropTable($tableName); + $queue = $this->object->dumpQueue(); + + $expected = "DROP TABLE `{$this->prefix}_{$tableName}` "; + $this->assertEquals($expected, $queue[0]); + } + + public function testRenameTable() + { + $tableName = 'users'; + $actual = $this->object->useTable($tableName); + $this->assertTrue($actual); + + $newName = 'system_abuser'; + $this->object->renameTable($tableName, $newName); + $queue = $this->object->dumpQueue(); + + $expected = "ALTER TABLE `{$this->prefix}_{$tableName}` RENAME TO `{$this->prefix}_{$newName}`"; + $this->assertEquals($expected, $queue[0]); + } + + public function testSetTableOptions() + { + $tableName = 'users'; + $actual = $this->object->useTable($tableName); + $this->assertTrue($actual); + + $options = 'ENGINE=MEMORY DEFAULT CHARSET=utf8;'; + $this->object->setTableOptions($tableName, $options); + $queue = $this->object->dumpQueue(); + + $expected = "ALTER TABLE `{$this->prefix}_{$tableName}` {$options} "; + $this->assertEquals($expected, $queue[0]); + } + + public function testExecuteQueue() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testDelete() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testInsert() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testUpdate() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testTruncate() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testRenderTableCreate() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testGetLastError() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testGetLastErrNo() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testDumpTables() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testAddToQueue() + { + $this->object->resetQueue(); + $queue = $this->object->dumpQueue(); + $this->assertIsArray($queue); + $this->assertEmpty($queue); + + $expected = 'SELECT * FROM TEST.DUMMY'; + $this->object->addToQueue($expected); + + $queue = $this->object->dumpQueue(); + $this->assertIsArray($queue); + $this->assertSame(1, count($queue)); + $this->assertEquals($expected, reset($queue)); + + $this->object->resetQueue(); + $queue = $this->object->dumpQueue(); + $this->assertIsArray($queue); + $this->assertEmpty($queue); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/DebugTest.php b/htdocs/tests/Unit/class/libraries/Xmf/DebugTest.php new file mode 100644 index 000000000..c4882e074 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/DebugTest.php @@ -0,0 +1,91 @@ +object = new Debug; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testDump() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testBacktrace() + { + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + // changes to Kint have ccaused this to fail + //$x = Debug::backtrace(false, true, false); + //$this->assertTrue(is_string($x)); + } + + public function testStartTimer() + { + $this->markTestIncomplete(); + } + + public function testStopTimer() + { + $this->markTestIncomplete(); + } + + public function testStartQueuedTimer() + { + $this->markTestIncomplete(); + } + + public function teststopQueuedTimer() + { + $this->markTestIncomplete(); + } + + public function testdumpQueuedTimers() + { + $this->markTestIncomplete(); + } + + public function testStartTrace() + { + if (function_exists('xdebug_start_trace')) { + $this->markTestIncomplete(); + } + } + + public function testStopTrace() + { + if (function_exists('xdebug_stop_trace')) { + $this->markTestIncomplete(); + } + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/FilterInputTest.php b/htdocs/tests/Unit/class/libraries/Xmf/FilterInputTest.php new file mode 100644 index 000000000..e026e1329 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/FilterInputTest.php @@ -0,0 +1,120 @@ +object = FilterInput::getInstance(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testGetInstance() + { + $this->assertInstanceOf(FilterInput::class, $this->object); + + $instance = FilterInput::getInstance(); + $this->assertSame($instance, $this->object); + + $instance = FilterInput::getInstance([], [], 0, 0, 0); + $this->assertNotSame($instance, $this->object); + } + + public function testProcess() + { + $input = 'Lorem ipsum '; + $expected = 'Lorem ipsum alert();'; + $this->assertEquals($expected, $this->object->process($input)); + + $input = 'Lorem ipsum'; + $this->assertEquals($input, $this->object->process($input)); + } + + public function testClean() + { + $input = 'Lorem ipsum '; + $expected = 'Lorem ipsum alert();'; + $this->assertEquals($expected, FilterInput::clean($input, 'string')); + + $input = 'Lorem ipsum <script>alert();</script>'; + $expected = 'Lorem ipsum alert();'; + $this->assertEquals($expected, FilterInput::clean($input, 'string'), FilterInput::clean($input, 'string')); + + $input = 'Lorem ipsum'; + $expected = $input; + $this->assertEquals($expected, FilterInput::clean($input, 'string')); + } + + public function testCleanVarDefault() + { + $filter = FilterInput::getInstance(); + $safeTest = '

This is a simple test.

'; + $this->assertEquals('This is a simple test.', $filter->cleanVar($safeTest)); + } + + public function testCleanVarFilter() + { + $filter = FilterInput::getInstance([], [], 1, 1); + + $safeTest = '

This is a simple test.

'; + $this->assertEquals($safeTest, $filter->cleanVar($safeTest)); + } + + public function testCleanVarFilterXss() + { + $filter = FilterInput::getInstance([], [], 1, 1); + + $xssTest = '

This is a xss test.

'; + $xssTestExpect = '

This is a xss alert(); test.

'; + $this->assertEquals($xssTestExpect, $filter->cleanVar($xssTest)); + } + + public function getTestForCleanVarType() + { + return [ + ['100', 'int', 100], + ['100', 'INTEGER', 100], + ['55.1', 'FLOAT', 55.1], + ['55.1', 'DOUBLE', 55.1], + ['1', 'BOOL', true], + ['0', 'BOOLEAN', false], + ['Value', 'WORD', 'Value'], + ['Alpha99', 'ALPHANUM', 'Alpha99'], + ['Alpha99', 'ALNUM', 'Alpha99'], + ['value', 'ARRAY', ['value']], + // ['value', 'type', 'expected'], + ]; + } + + /** + * @dataProvider getTestForCleanVarType + */ + public function testCleanVarTypes($value, $type, $expected) + { + $this->assertSame($expected, $this->object->cleanVar($value, $type)); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/HighlighterTest.php b/htdocs/tests/Unit/class/libraries/Xmf/HighlighterTest.php new file mode 100644 index 000000000..7a4e67bf9 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/HighlighterTest.php @@ -0,0 +1,51 @@ +object = new Highlighter(); + $this->assertInstanceOf(Highlighter::class, $this->object); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testApply() + { + $output = Highlighter::apply('test', 'This test is OK.'); + $this->assertEquals('This test is OK.', $output); + + $output = Highlighter::apply(['test', 'ok'], 'This test is OK.', '', ''); + $this->assertEquals('This test is OK.', $output); + + $output = Highlighter::apply('test ok', 'This test is OK.', '', ''); + $this->assertEquals('This test is OK.', $output); + + $output = Highlighter::apply(['test', 'ok'], 'This test is OK.', '', ''); + $this->assertEquals('This test is OK.', $output); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/IPAddressTest.php b/htdocs/tests/Unit/class/libraries/Xmf/IPAddressTest.php new file mode 100644 index 000000000..a51efd67b --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/IPAddressTest.php @@ -0,0 +1,106 @@ +object = new IPAddress($this->testIPV4); + $this->objectV6 = new IPAddress($this->testIPV6); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testFromRequest() + { + $testAddress = '192.168.20.16'; + $_SERVER['REMOTE_ADDR'] = $testAddress; + $instance = IPAddress::fromRequest(); + $actual = $instance->asReadable(); + $this->assertEquals($testAddress, $actual); + + $testAddress = '3ffe:2a00:100:7031::1'; + $_SERVER['REMOTE_ADDR'] = $testAddress; + $instance = IPAddress::fromRequest(); + $actual = $instance->asReadable(); + $this->assertEquals($testAddress, $actual); + } + + public function testAsReadable() + { + $this->assertEquals($this->testIPV4, $this->object->asReadable()); + $this->assertEquals($this->testIPV6, $this->objectV6->asReadable()); + } + + public function testAsBinary() + { + $addressV6 = '3031:3233:3435:3637:3839:584F:4F50:5334'; + $instanceV6 = new IPAddress($addressV6); + $this->assertEquals('0123456789XOOPS4', $instanceV6->asBinary()); + + $addressV4 = '67.48.68.69'; + $instanceV4 = new IPAddress($addressV4); + $this->assertEquals('C0DE', $instanceV4->asBinary()); + } + + public function testIpVersion() + { + $this->assertSame(4, $this->object->ipVersion()); + $this->assertSame(6, $this->objectV6->ipVersion()); + + $instance = new IPAddress('garbage'); + $this->assertFalse($instance->ipVersion()); + } + + public function testSameSubnet() + { + $instanceV6 = new IPAddress('FE80:0000:0000:0000:0202:B3FF:FE1E:8329'); + $addressV6 = 'FE80:0000:0000:0000:8000:0000:0000:0000'; + + $this->assertFalse($instanceV6->sameSubnet($this->testIPV4, 16, 64)); + $this->assertTrue($instanceV6->sameSubnet($addressV6, 14, 56)); + $this->assertTrue($instanceV6->sameSubnet($addressV6, 16, 64)); + $this->assertFalse($instanceV6->sameSubnet($addressV6, 17, 65)); + $this->assertTrue($instanceV6->sameSubnet($instanceV6->asReadable(), 32, 128)); + + $instanceV4 = new IPAddress('255.255.255.1'); + $addressV4 = '255.255.255.129'; + $this->assertFalse($instanceV4->sameSubnet($instanceV6->asReadable(), 1, 1)); + $this->assertTrue($instanceV4->sameSubnet($addressV4, 8, 32)); + $this->assertTrue($instanceV4->sameSubnet($addressV4, 16, 64)); + $this->assertTrue($instanceV4->sameSubnet($addressV4, 24, 96)); + $this->assertFalse($instanceV4->sameSubnet($addressV6, 25, 98)); + $this->assertTrue($instanceV4->sameSubnet($instanceV4->asReadable(), 32, 128)); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Jwt/JsonWebTokenTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Jwt/JsonWebTokenTest.php new file mode 100644 index 000000000..ab22779d5 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Jwt/JsonWebTokenTest.php @@ -0,0 +1,85 @@ +storage = new ArrayStorage(); + $this->key = new Basic($this->storage, 'testkey'); + $this->key->create(); + $this->object = new JsonWebToken($this->key); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function test__construct() + { + $this->assertInstanceOf(JsonWebToken::class, $this->object); + + $this->expectException(\DomainException::class); + $actual = new JsonWebToken($this->key, 'badalgo'); + } + + public function testSetAlgorithm() + { + $actual = $this->object->setAlgorithm('HS512'); + $this->assertSame($this->object, $actual); + + $this->expectException(\DomainException::class); + $actual = $this->object->setAlgorithm('xxxxx'); + } + + public function testCreateDecode() + { + $token = $this->object->create(['test' => 'create'], 6); + $this->assertIsString($token); + + $this->assertFalse($this->object->decode($token, ['not-that-test' => 'create'])); + $this->assertFalse($this->object->decode($token, ['test' => 'notcreate'])); + + $decoder = new JsonWebToken($this->key); + $this->assertNotSame($this->object, $decoder); + + $actual = $decoder->decode($token, ['test' => 'create']); + $this->assertObjectHasAttribute('exp', $actual); + $this->assertObjectHasAttribute('test', $actual); + + // create expired token + $token = $this->object->create(['test' => 'create', 'exp' => (time() - 30)]); + $this->assertIsString($token); + + $actual = @$decoder->decode($token); + $this->assertFalse($actual); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Jwt/JsonWebTokenTest0.php b/htdocs/tests/Unit/class/libraries/Xmf/Jwt/JsonWebTokenTest0.php new file mode 100644 index 000000000..ab22779d5 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Jwt/JsonWebTokenTest0.php @@ -0,0 +1,85 @@ +storage = new ArrayStorage(); + $this->key = new Basic($this->storage, 'testkey'); + $this->key->create(); + $this->object = new JsonWebToken($this->key); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function test__construct() + { + $this->assertInstanceOf(JsonWebToken::class, $this->object); + + $this->expectException(\DomainException::class); + $actual = new JsonWebToken($this->key, 'badalgo'); + } + + public function testSetAlgorithm() + { + $actual = $this->object->setAlgorithm('HS512'); + $this->assertSame($this->object, $actual); + + $this->expectException(\DomainException::class); + $actual = $this->object->setAlgorithm('xxxxx'); + } + + public function testCreateDecode() + { + $token = $this->object->create(['test' => 'create'], 6); + $this->assertIsString($token); + + $this->assertFalse($this->object->decode($token, ['not-that-test' => 'create'])); + $this->assertFalse($this->object->decode($token, ['test' => 'notcreate'])); + + $decoder = new JsonWebToken($this->key); + $this->assertNotSame($this->object, $decoder); + + $actual = $decoder->decode($token, ['test' => 'create']); + $this->assertObjectHasAttribute('exp', $actual); + $this->assertObjectHasAttribute('test', $actual); + + // create expired token + $token = $this->object->create(['test' => 'create', 'exp' => (time() - 30)]); + $this->assertIsString($token); + + $actual = @$decoder->decode($token); + $this->assertFalse($actual); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Jwt/KeyFactoryTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Jwt/KeyFactoryTest.php new file mode 100644 index 000000000..d357992bb --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Jwt/KeyFactoryTest.php @@ -0,0 +1,65 @@ +object = new KeyFactory; + $this->storage = new ArrayStorage(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + $this->storage->delete($this->testKey); + } + + public function testBuild() + { + $instance = KeyFactory::build($this->testKey, $this->storage); + $this->assertInstanceOf(Basic::class, $instance); + $this->assertTrue($this->storage->exists($this->testKey)); + + $actual = KeyFactory::build($this->testKey, $this->storage); + $this->assertNotSame($instance, $actual); + + $this->assertEquals($instance->getSigning(), $actual->getSigning()); + } + + public function testBuildException() + { + $this->expectException(\InvalidArgumentException::class); + $instance = KeyFactory::build(['muck'], $this->storage); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Jwt/TokenFactoryTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Jwt/TokenFactoryTest.php new file mode 100644 index 000000000..23f138d12 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Jwt/TokenFactoryTest.php @@ -0,0 +1,71 @@ +storage = new ArrayStorage(); + $this->testKey = KeyFactory::build($this->testKeyName, $this->storage); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + $this->storage->delete($this->testKeyName); + } + + public function testBuild() + { + $claims = ['rat' => 'cute']; + $token = TokenFactory::build($this->testKey, $claims); + + $this->assertIsString($token); + + $jwt = new JsonWebToken($this->testKey); + + $actual = $jwt->decode($token, $claims); + + foreach ($claims as $name => $value) { + $this->assertEquals($value, $actual->$name); + } + + $claims = ['rat' => 'cute', 'exp' => (time() - 30)]; + $token = TokenFactory::build($this->testKey, $claims); + //$this->expectException('\PHPUnit\Framework\Error\Notice'); + $actual = @$jwt->decode($token); + $this->assertFalse($actual); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Jwt/TokenReaderTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Jwt/TokenReaderTest.php new file mode 100644 index 000000000..91ec213a7 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Jwt/TokenReaderTest.php @@ -0,0 +1,87 @@ +storage = new ArrayStorage(); + $this->testKey = KeyFactory::build($this->testKeyName, $this->storage); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + $this->storage->delete($this->testKeyName); + } + + public function testFromString() + { + $claims = ['rat' => 'cute']; + $jwt = new JsonWebToken($this->testKey); + $token = $jwt->create($claims); + + $actual = TokenReader::fromString($this->testKey, $token); + foreach ($claims as $name => $value) { + $this->assertEquals($value, $actual->$name); + } + + $actual = TokenReader::fromString($this->testKey, $token, ['rat' => 'odd']); + $this->assertFalse($actual); + } + + public function testFromCookie() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testFromRequest() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testFromHeader() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Key/ArrayStorageTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Key/ArrayStorageTest.php new file mode 100644 index 000000000..334fa2ab1 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Key/ArrayStorageTest.php @@ -0,0 +1,74 @@ +object = new ArrayStorage(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testSave() + { + $name = 'name'; + $data = 'data'; + $this->object->save($name, $data); + $this->assertEquals($data, $this->object[$name]); + } + + public function testFetch() + { + $name = 'name'; + $data = 'data'; + $this->assertFalse($this->object->fetch($name)); + $this->object->save($name, $data); + $this->assertEquals($this->object->fetch($name), $data); + } + + public function testExists() + { + $name = 'name'; + $data = 'data'; + $this->assertFalse($this->object->exists($name)); + $this->object->save($name, $data); + $this->assertTrue($this->object->exists($name)); + } + + public function testDelete() + { + $name = 'name'; + $data = 'data'; + $this->object->save($name, $data); + $this->assertTrue($this->object->exists($name)); + $actual = $this->object->delete($name); + $this->assertTrue($actual); + $actual = $this->object->delete($name); + $this->assertFalse($actual); + $this->assertFalse($this->object->exists($name)); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Key/BasicTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Key/BasicTest.php new file mode 100644 index 000000000..d6ccf130e --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Key/BasicTest.php @@ -0,0 +1,85 @@ +storage = new ArrayStorage(); + $this->object = new Basic($this->storage, 'test'); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testGetSigning() + { + $actual = $this->object->getSigning(); + $this->assertEmpty($actual); + $actual = $this->object->create(); + $this->assertTrue($actual); + $actual = $this->object->getSigning(); + $this->assertIsString($actual); + $this->assertMatchesRegularExpression('/^[0-9a-f]{128}$/', $actual); + } + + public function testGetVerifying() + { + $actual = $this->object->getVerifying(); + $this->assertEmpty($actual); + $actual = $this->object->create(); + $this->assertTrue($actual); + $actual = $this->object->getVerifying(); + $this->assertIsString($actual); + $this->assertMatchesRegularExpression('/^[0-9a-f]{128}$/', $actual); + } + + public function testCreate() + { + $actual = $this->object->create(); + $this->assertTrue($actual); + + $actual = $this->object->create(); + $this->assertFalse($actual); + } + + public function testKill() + { + $actual = $this->object->create(); + $this->assertTrue($actual); + + $this->assertTrue($this->storage->exists('test')); + + $actual = $this->object->kill(); + $this->assertTrue($actual); + + $this->assertFalse($this->storage->exists('test')); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Key/FileStorageTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Key/FileStorageTest.php new file mode 100644 index 000000000..c2943e963 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Key/FileStorageTest.php @@ -0,0 +1,77 @@ +markTestIncomplete('FileStorage testing incomplete'); + $this->object = new FileStorage('/tmp', 'fubar'); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + @$this->object->delete($this->testKey); + } + + public function testSave() + { + $name = $this->testKey; + $data = 'data'; + $this->object->save($name, $data); + $this->assertEquals($data, $this->object->fetch($name)); + } + + public function testFetch() + { + $name = $this->testKey; + $data = 'data'; + $this->assertFalse(@$this->object->fetch($name)); + $this->object->save($name, $data); + $this->assertEquals($this->object->fetch($name), $data); + } + + public function testExists() + { + $name = $this->testKey; + $data = 'data'; + $this->assertFalse($this->object->exists($name)); + $this->object->save($name, $data); + $this->assertTrue($this->object->exists($name)); + } + + public function testDelete() + { + $name = $this->testKey; + $data = 'data'; + $this->object->save($name, $data); + $this->assertTrue($this->object->exists($name)); + $this->assertTrue($this->object->delete($name)); + $this->assertFalse(@$this->object->delete($name)); + $this->assertFalse($this->object->exists($name)); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Key/KeyAbstractTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Key/KeyAbstractTest.php new file mode 100644 index 000000000..64eeeedb6 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Key/KeyAbstractTest.php @@ -0,0 +1,58 @@ +storage = new ArrayStorage(); + $this->object = $this->getMockForAbstractClass(KeyAbstract::class, [$this->storage, 'test']); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testConstruct() + { + $this->assertInstanceOf(KeyAbstract::class, $this->object); + + $class = new \ReflectionClass(KeyAbstract::class); + $method = $class->getMethod('__construct'); + $this->assertFalse($method->isAbstract()); + } + + public function testMethodsExist() + { + $this->assertTrue(method_exists($this->object, 'getSigning')); + $this->assertTrue(method_exists($this->object, 'getVerifying')); + $this->assertTrue(method_exists($this->object, 'create')); + $this->assertTrue(method_exists($this->object, 'kill')); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Key/StorageInterfaceTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Key/StorageInterfaceTest.php new file mode 100644 index 000000000..613bbf065 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Key/StorageInterfaceTest.php @@ -0,0 +1,43 @@ +object = $this->createMock(StorageInterface::class); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testContracts() + { + $this->assertInstanceOf(StorageInterface::class, $this->object); + $this->assertTrue(method_exists($this->object, 'save')); + $this->assertTrue(method_exists($this->object, 'fetch')); + $this->assertTrue(method_exists($this->object, 'exists')); + $this->assertTrue(method_exists($this->object, 'delete')); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/LanguageTest.php b/htdocs/tests/Unit/class/libraries/Xmf/LanguageTest.php new file mode 100644 index 000000000..09713affa --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/LanguageTest.php @@ -0,0 +1,57 @@ +object = new Language(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testTranslate() + { + $str = 'string'; + $x = Language::translate($str); + $this->assertSame($str, $x); + } + + public function testLoad() + { + $this->assertTrue(Language::load('xmf')); + + $this->assertFalse(Language::load('xmfblahblahblah')); + + $this->assertFalse(Language::load('xmf/Program Files/stuff')); + } + + public function testLoadException() + { + $str = "Test\0Test"; + $this->expectException(\InvalidArgumentException::class); + $x = Language::load($str); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/MetagenTest.php b/htdocs/tests/Unit/class/libraries/Xmf/MetagenTest.php new file mode 100644 index 000000000..76bf93316 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/MetagenTest.php @@ -0,0 +1,221 @@ +object = new Metagen(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testAssignTitle() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testAssignKeywords() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testAssignDescription() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testGenerateKeywords() + { + $body = self::DOI_TEXT; + $numKeys = 20; + $forced = ['declaration', 'independence']; + $keys = $this->object->generateKeywords($body, $numKeys, 3, $forced); + $this->assertEquals(count($keys), $numKeys); + // test that forced keywords and words with more than 2 occurances are present + // There should be one more word, one of the words with only one occurance. + // While repeatable, the choice of that is undefined behavior. + $this->assertContains('independence', $keys); + $this->assertContains('government', $keys); + $this->assertContains('among', $keys); + $this->assertContains('right', $keys); + $this->assertContains('powers', $keys); + $this->assertContains('causes', $keys); + $this->assertContains('mankind', $keys); + $this->assertContains('nature', $keys); + $this->assertContains('men', $keys); + $this->assertContains('governments', $keys); + $this->assertContains('long', $keys); + $this->assertContains('new', $keys); + $this->assertContains('equal', $keys); + $this->assertContains('happiness', $keys); + $this->assertContains('rights', $keys); + $this->assertContains('form', $keys); + $this->assertContains('people', $keys); + $this->assertContains('becomes', $keys); + $this->assertNotContains('wombat', $keys); + } + + public function testGenerateDescription() + { + $body = self::DOI_TEXT; + $numWords = 110; + $desc = $this->object->generateDescription($body, $numWords); + $actual = mb_substr($desc, -21, null, 'UTF-8'); + $expected = 'pursuit of Happiness.'; + $this->assertEquals($expected, $actual, $actual); + + $numWords = 20; + $desc = $this->object->generateDescription($body, $numWords); + $actual = mb_substr($desc, -(mb_strlen(Metagen::ELLIPSIS)), null, 'UTF-8'); + $expected = Metagen::ELLIPSIS; + $this->assertEquals($expected, $actual, $actual); + } + + public function testGenerateMetaTags() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testGenerateSeoTitle() + { + $title = 'XOOPS generates your SEO titles for you.'; + $expected = 'XOOPS-generates-SEO-titles'; + $actual = Metagen::generateSeoTitle($title); + $this->assertEquals($expected, $actual, $actual); + $expected = $expected . '.html'; + $actual = Metagen::generateSeoTitle($title, '.html'); + $this->assertEquals($expected, $actual, $actual); + $title = 'catégorie. 2 xmarticle'; + $expected = 'catégorie-2-xmarticle'; + $actual = Metagen::generateSeoTitle($title); + $this->assertEquals($expected, $actual, $actual); + } + + public function testGetSearchSummary() + { + $ellipsis = Metagen::ELLIPSIS; + $haystack = <<<'EOT' +Testing this method will require a long string that will exceed one hundred twenty +characters and will need to have in the middle and at each end some very different +significant keywords. +EOT; + + $needles = []; + $expected = 'Testing this method will require a long' . $ellipsis; + $actual = Metagen::getSearchSummary($haystack, $needles, 40); + $this->assertEquals($expected, $actual, $actual); + + $needles = ['testing']; + $expected = 'Testing this method will require a long' . $ellipsis; + $actual = Metagen::getSearchSummary($haystack, $needles, 40); + $this->assertEquals($expected, $actual, $actual); + + $needles = ['significant']; + $expected = $ellipsis . 'very different significant keywords.'; + $actual = Metagen::getSearchSummary($haystack, $needles, 40); + $this->assertEquals($expected, $actual, $actual); + + $needles = ['one hundred']; + $expected = $ellipsis . 'that will exceed one hundred twenty' . $ellipsis; + $actual = Metagen::getSearchSummary($haystack, $needles, 40); + $this->assertEquals($expected, $actual, $actual); + + $needles = ['testing', 'significant', 'one hundred']; + $expected = 'Testing this method will require a long' . $ellipsis; + $actual = Metagen::getSearchSummary($haystack, $needles, 40); + $this->assertEquals($expected, $actual, $actual); + + $needles = ['significant', 'one hundred', 'testing']; + $expected = 'Testing this method will require a long' . $ellipsis; + $actual = Metagen::getSearchSummary($haystack, $needles, 40); + $this->assertEquals($expected, $actual, $actual); + + $needles = ['will']; + $expected = 'Testing this method will require a long' . $ellipsis; + $actual = Metagen::getSearchSummary($haystack, $needles, 40); + $this->assertEquals($expected, $actual, $actual); + + $nowhitespace = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0abcdefghijklmnopqrstuvwxyz'; + $needles = ['0']; + $expected = $ellipsis . 'GHIJKLMNOPQRSTUVWXYZ0abcdefghijklmnopqrs' . $ellipsis; + $actual = Metagen::getSearchSummary($nowhitespace, $needles, 40); + $this->assertEquals($expected, $actual, $actual); + } + + public function testAsPlainText() + { + $method = new \ReflectionMethod(Metagen::class, 'asPlainText'); + $method->setAccessible(true); + $input = "

 This is\r\na test   of\ncleaning\rup a string.  
"; + $expected = 'This is a test of cleaning up a string.'; + try { + $actual = $method->invokeArgs($this->object, [$input]); + } catch (\ReflectionException $e) { + } + $this->assertEquals($expected, $actual, $actual); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Module/AdminTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Module/AdminTest.php new file mode 100644 index 000000000..767df1dc6 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Module/AdminTest.php @@ -0,0 +1,196 @@ +markTestSkipped('side effects'); + $this->object = Admin::getInstance(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testGetInstance() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testMenuIconPath() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testAddConfigBoxLine() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testAddInfoBox() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testAddInfoBoxLine() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testAddItemButton() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testRenderButton() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testDisplayButton() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testRenderInfoBox() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testDisplayInfoBox() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testRenderIndex() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testDisplayIndex() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testDisplayNavigation() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testRenderAbout() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testSetPaypal() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testDisplayAbout() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testAddConfigError() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testAddConfigAccept() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testIconUrl() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testCheckModuleVersion() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/AbstractHelperTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/AbstractHelperTest.php new file mode 100644 index 000000000..fd6cf0133 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/AbstractHelperTest.php @@ -0,0 +1,58 @@ +object = new \Xmf\Module\Helper\AbstractHelper; + $this->object = $this->getMockForAbstractClass(AbstractHelper::class); + //$this->object->expects($this->any()) + // ->method('getDefaultParams') + // ->will($this->returnValue(array())); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testSetDebug() + { + //TODO change $debug in AbstractHelper from protected to public, otherwise assertEquals() won't work + + $this->assertTrue(method_exists($this->object, 'setDebug')); + $this->object->setDebug(true); +// $this->assertAttributeEquals(true, 'debug', $this->object); + $this->assertEquals(true, $this->object->debug); + $this->object->setDebug(false); +// $this->assertAttributeEquals(false, 'debug', $this->object); + $this->assertEquals(false, $this->object->debug); + } + + public function testAddLog() + { + $this->assertTrue(method_exists($this->object, 'addLog')); + $this->object->addLog('message to send to bitbucket'); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/CacheTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/CacheTest.php new file mode 100644 index 000000000..7858b2b30 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/CacheTest.php @@ -0,0 +1,83 @@ +object = new Cache(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testInit() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testWrite() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testRead() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testDelete() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testCacheRead() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testClear() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/GenericHelperTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/GenericHelperTest.php new file mode 100644 index 000000000..31ebeeaa3 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/GenericHelperTest.php @@ -0,0 +1,155 @@ +scheme('kernel') + ->name($name) + ->optional((bool)$optional) + ->build(); + return $handler; + } +} + +class GenericHelperTest extends TestCase +{ + /** + * @var GenericHelper + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp(): void + { + $this->object = GenericHelperTestHelper::getHelper(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testGetModule() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testGetConfig() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testGetHandler() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testLoadLanguage() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testSetDebug() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testAddLog() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testIsCurrentModule() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testIsUserAdmin() + { + include_once XOOPS_ROOT_PATH . '/kernel/user.php'; + $GLOBALS['xoopsUser'] = ''; + $this->assertFalse($this->object->isUserAdmin()); + + $GLOBALS['xoopsUser'] = new \XoopsUser(); + $this->assertFalse($this->object->isUserAdmin()); + } + + public function testUrl() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testPath() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testRedirect() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/PermissionTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/PermissionTest.php new file mode 100644 index 000000000..dd8b2e244 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/PermissionTest.php @@ -0,0 +1,107 @@ +object = new Permission(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testInit() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testCheckPermission() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testCheckPermissionRedirect() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testGetUserGroups() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testGetGroupsForItem() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testSavePermissionForItem() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testDeletePermissionForItem() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testGetGroupSelectFormForItem() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testDefaultFieldName() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/SessionTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/SessionTest.php new file mode 100644 index 000000000..0a0fe0930 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Module/Helper/SessionTest.php @@ -0,0 +1,75 @@ +object = new Session(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testInit() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testSet() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testGet() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testDel() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + public function testDestroy() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/Module/HelperTest.php b/htdocs/tests/Unit/class/libraries/Xmf/Module/HelperTest.php new file mode 100644 index 000000000..017332672 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/Module/HelperTest.php @@ -0,0 +1,53 @@ +object = Helper::getHelper(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testGetHelper() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/RandomTest.php b/htdocs/tests/Unit/class/libraries/Xmf/RandomTest.php new file mode 100644 index 000000000..6e7711a78 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/RandomTest.php @@ -0,0 +1,58 @@ +object = new Random(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testGenerateOneTimeToken() + { + try { + $result = Random::generateOneTimeToken(); + } catch (\Exception $e) { + } + + $this->assertIsString($result); + $this->assertMatchesRegularExpression('/^[0-9a-f]{128}$/', $result); + } + + public function testGenerateKey() + { + try { + $result = Random::generateKey(); + } catch (\Exception $e) { + } + + $this->assertIsString($result); + $this->assertMatchesRegularExpression('/^[0-9a-f]{128}$/', $result); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/RequestTest.php b/htdocs/tests/Unit/class/libraries/Xmf/RequestTest.php new file mode 100644 index 000000000..f1d2d8e5c --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/RequestTest.php @@ -0,0 +1,242 @@ +object = new Request(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testGetMethod() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + $method = Request::getMethod(); + $this->assertContains($method, ['GET', 'HEAD', 'POST', 'PUT']); + } + + public function testGetVar() + { + $varname = 'RequestTest'; + $value = 'testing'; + $_REQUEST[$varname] = $value; + + $this->assertEquals($value, Request::getVar($varname)); + $this->assertNull(Request::getVar($varname . 'no-such-key')); + } + + public function testGetInt() + { + $varname = 'RequestTest'; + + $_REQUEST[$varname] = '9'; + $this->assertEquals(9, Request::getInt($varname)); + + $_REQUEST[$varname] = '123fred5'; + $this->assertEquals(123, Request::getInt($varname)); + + $_REQUEST[$varname] = '-123.45'; + $this->assertEquals(-123, Request::getInt($varname)); + + $_REQUEST[$varname] = 'notanumber'; + $this->assertEquals(0, Request::getInt($varname)); + + $this->assertEquals(0, Request::getInt($varname . 'no-such-key')); + } + + public function testGetFloat() + { + $varname = 'RequestTest'; + + $_REQUEST[$varname] = '1.23'; + $this->assertEquals(1.23, Request::getFloat($varname)); + + $_REQUEST[$varname] = '-1.23'; + $this->assertEquals(-1.23, Request::getFloat($varname)); + + $_REQUEST[$varname] = '5.68 blah blah'; + $this->assertEquals(5.68, Request::getFloat($varname)); + + $_REQUEST[$varname] = '1'; + $this->assertSame(1.0, Request::getFloat($varname)); + } + + public function testGetBool() + { + $varname = 'RequestTest'; + + $_REQUEST[$varname] = '9'; + $this->assertTrue(Request::getBool($varname)); + + $_REQUEST[$varname] = 'a string'; + $this->assertTrue(Request::getBool($varname)); + + $_REQUEST[$varname] = true; + $this->assertTrue(Request::getBool($varname)); + + $_REQUEST[$varname] = ''; + $this->assertFalse(Request::getBool($varname)); + + $_REQUEST[$varname] = false; + $this->assertFalse(Request::getBool($varname)); + + $this->assertFalse(Request::getBool($varname . 'no-such-key')); + } + + public function testGetWord() + { + $varname = 'RequestTest'; + + $_REQUEST[$varname] = 'Lorem'; + $this->assertEquals('Lorem', Request::getWord($varname)); + + $_REQUEST[$varname] = 'Lorem ipsum 88 59'; + $this->assertEquals('Loremipsum', Request::getWord($varname)); + + $_REQUEST[$varname] = '.99 Lorem_ipsum @%&'; + $this->assertEquals('Lorem_ipsum', Request::getWord($varname)); + //echo Request::getWord($varname); + } + + public function testGetCmd() + { + $varname = 'RequestTest'; + + $_REQUEST[$varname] = 'Lorem'; + $this->assertEquals('lorem', Request::getCmd($varname)); + + $_REQUEST[$varname] = 'Lorem ipsum 88 59'; + $this->assertEquals('loremipsum8859', Request::getCmd($varname)); + + $_REQUEST[$varname] = '.99 Lorem_ipsum @%&'; + $this->assertEquals('.99lorem_ipsum', Request::getCmd($varname), Request::getCmd($varname)); + } + + public function testGetString() + { + $varname = 'RequestTest'; + + $_REQUEST[$varname] = 'Lorem ipsum '; + $this->assertEquals('Lorem ipsum alert();', Request::getString($varname)); + } + + public function testGetString2() + { + $varname = 'RequestTest'; + + $safeTest = '

This is a simple test.

'; + $_POST[$varname] = $safeTest; + + $this->assertEquals('This is a simple test.', Request::getString($varname, '', 'POST')); + } + + public function testGetStringAllowHtml() + { + $varname = 'RequestTest'; + + $safeTest = '

This is a simple test.

'; + $_POST[$varname] = $safeTest; + + $this->assertEquals($safeTest, Request::getString($varname, '', 'POST', Request::MASK_ALLOW_HTML)); + } + + public function testGetStringAllowHtmlXss() + { + $varname = 'RequestTest'; + + $xssTest = '

This is a xss test.

'; + $_POST[$varname] = $xssTest; + $xssTestExpect = '

This is a xss alert(); test.

'; + $this->assertEquals($xssTestExpect, Request::getString($varname, '', 'POST', Request::MASK_ALLOW_HTML)); + } + + public function testGetArray() + { + $varname = 'RequestTest'; + + $testArray = ['one', 'two', 'three']; + $_REQUEST[$varname] = $testArray; + + $get = Request::getArray($varname, null, 'request'); + $this->assertIsArray($get); + $this->assertEquals($get, $testArray); + + $testArray2 = ['one', 'two', '']; + $_REQUEST[$varname] = $testArray2; + + $get = Request::getArray($varname, null, 'request'); + $this->assertIsArray($get); + $this->assertEquals($get, $testArray); + } + + public function testGetText() + { + $varname = 'RequestTest'; + + $_REQUEST[$varname] = 'Lorem ipsum '; + $this->assertEquals($_REQUEST[$varname], Request::getText($varname)); + } + + public function testHasVar() + { + $varname = 'RequestTest[HasVar]'; + $this->assertFalse(Request::hasVar($varname, 'GET')); + Request::setVar($varname, 'OK', 'get'); + $this->assertTrue(Request::hasVar($varname, 'GET')); + } + + public function testSetVar() + { + $varname = 'RequestTest'; + Request::setVar($varname, 'Porshca', 'get'); + $this->assertEquals('Porshca', $_REQUEST[$varname]); + } + + public function testGet() + { + $varname = 'RequestTest'; + + $_REQUEST[$varname] = 'Lorem'; + + $get = Request::get('request'); + $this->assertIsArray($get); + $this->assertEquals('Lorem', $get[$varname]); + + unset($get); + $_REQUEST[$varname] = 'Lorem ipsum '; + $get = Request::get('request'); + $this->assertEquals('Lorem ipsum alert();', $get[$varname]); + } + + public function testSet() + { + $varname = 'RequestTest'; + Request::set([$varname => 'Pourquoi'], 'get'); + $this->assertEquals('Pourquoi', $_REQUEST[$varname]); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/StopWordsTest.php b/htdocs/tests/Unit/class/libraries/Xmf/StopWordsTest.php new file mode 100644 index 000000000..4fe477a3a --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/StopWordsTest.php @@ -0,0 +1,53 @@ +stopwordList = array_fill_keys(['it', 'is', 'our', 'mock'], true); + } +} + +class StopWordsTest extends TestCase +{ + /** + * @var StopWords + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp(): void + { + $this->object = new MockStopWords(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testCheck() + { + $this->assertTrue($this->object->check('XOOPS')); + $this->assertFalse($this->object->check('is')); + $this->assertFalse($this->object->check('IS')); + } +} diff --git a/htdocs/tests/Unit/class/libraries/Xmf/UuidTest.php b/htdocs/tests/Unit/class/libraries/Xmf/UuidTest.php new file mode 100644 index 000000000..e3256fee6 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/UuidTest.php @@ -0,0 +1,104 @@ +assertMatchesRegularExpression($uuidMatch, $result); + + try { + $anotherResult = Uuid::generate(); + } catch (\Exception $e) { + } + $this->assertMatchesRegularExpression($uuidMatch, $anotherResult); + + $this->assertNotEquals($result, $anotherResult); + } + + public function testPackUnpack() + { + try { + $uuid = Uuid::generate(); + } catch (\Exception $e) { + } + $binUuid = Uuid::packAsBinary($uuid); + $strUuid = Uuid::unpackBinary($binUuid); + $this->assertEquals($uuid, $strUuid); + } + + public function testInvalidPack() + { + $this->expectException(\InvalidArgumentException::class); + $binUuid = Uuid::packAsBinary('garbage-data'); + } + + public function testInvalidUnpack() + { + $this->expectException(\InvalidArgumentException::class); + $binUuid = Uuid::unpackBinary('123456789012345'); + } + + public function testInvalidUnpack2() + { + $this->expectException(\UnexpectedValueException::class); + $binUuid = Uuid::unpackBinary('0000000000000000'); + } + + /* verify natural sort order is the same for readable and binary formats */ + public function testSortOrder() + { + $auuid = []; + $buuid = []; + for ($i = 1; $i < 10; ++$i) { + try { + $uuid = Uuid::generate(); + } catch (\Exception $e) { + } + $auuid[] = $uuid; + $buuid[] = Uuid::packAsBinary($uuid); + } + sort($auuid); + sort($buuid); + foreach ($auuid as $key => $uuid) { + $this->assertEquals($uuid, Uuid::unpackBinary($buuid[$key])); + } + } +} + diff --git a/htdocs/tests/Unit/class/libraries/Xmf/YamlTest.php b/htdocs/tests/Unit/class/libraries/Xmf/YamlTest.php new file mode 100644 index 000000000..27e15fa6d --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/YamlTest.php @@ -0,0 +1,112 @@ + 1, 'two' => [1, 2], 'three' => '']; + + $string = Yaml::dump($inputArray); + $this->assertNotEmpty($string); + $this->assertIsString($string); + + $outputArray = Yaml::load((string)$string); + $this->assertIsArray($outputArray); + $this->assertSame($inputArray, $outputArray); + } + + public function testSaveAndRead() + { + $tmpfname = tempnam(sys_get_temp_dir(), 'TEST'); + $inputArray = ['one' => 1, 'two' => [1, 2], 'three' => '']; + + $byteCount = Yaml::save($inputArray, $tmpfname); + $this->assertNotSame($byteCount, false); + $this->assertGreaterThan(0, $byteCount); + + $outputArray = Yaml::read($tmpfname); + $this->assertIsArray($outputArray); + $this->assertSame($inputArray, $outputArray); + + unlink($tmpfname); + } + + public function testDumpAndLoadWrapped() + { + $inputArray = ['one' => 1, 'two' => [1, 2], 'three' => '']; + + $string = Yaml::dumpWrapped($inputArray); + $this->assertNotEmpty($string); + $this->assertIsString($string); + + $outputArray = Yaml::loadWrapped((string)$string); + $this->assertIsArray($outputArray); + $this->assertSame($inputArray, $outputArray); + } + + public function testDumpAndLoadWrappedStress() + { + $inputArray = ['start' => '---', 'end' => '...', 'misc' => 'stuff']; + + $string = Yaml::dumpWrapped($inputArray); + $this->assertNotEmpty($string); + $this->assertIsString($string); + + $outputArray = Yaml::loadWrapped((string)$string); + $this->assertIsArray($outputArray); + $this->assertSame($inputArray, $outputArray); + } + + public function testDumpAndLoadWrappedStress2() + { + $inputArray = ['start' => '---', 'end' => '...', 'misc' => 'stuff']; + + $string = Yaml::dump($inputArray); + $this->assertNotEmpty($string); + $this->assertIsString($string); + + $outputArray = Yaml::loadWrapped((string)$string); + $this->assertIsArray($outputArray); + $this->assertSame($inputArray, $outputArray); + } + + public function testSaveAndReadWrapped() + { + $tmpfname = tempnam(sys_get_temp_dir(), 'TEST'); + $inputArray = ['one' => 1, 'two' => [1, 2], 'three' => '']; + + $byteCount = Yaml::saveWrapped($inputArray, $tmpfname); + $this->assertNotSame($byteCount, false); + $this->assertGreaterThan(0, $byteCount); + + $outputArray = Yaml::readWrapped($tmpfname); + $this->assertIsArray($outputArray); + $this->assertSame($inputArray, $outputArray); + + unlink($tmpfname); + } +} From 83ffa1d565e671dd18061e5402c42f4276346542 Mon Sep 17 00:00:00 2001 From: mambax7 Date: Thu, 9 Mar 2023 05:14:34 -0500 Subject: [PATCH 05/12] Misordered PHPUnit equality assertion method arguments --- htdocs/tests/Unit/class/libraries/Xmf/YamlTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/tests/Unit/class/libraries/Xmf/YamlTest.php b/htdocs/tests/Unit/class/libraries/Xmf/YamlTest.php index 27e15fa6d..3fdbca87f 100644 --- a/htdocs/tests/Unit/class/libraries/Xmf/YamlTest.php +++ b/htdocs/tests/Unit/class/libraries/Xmf/YamlTest.php @@ -45,7 +45,7 @@ public function testSaveAndRead() $inputArray = ['one' => 1, 'two' => [1, 2], 'three' => '']; $byteCount = Yaml::save($inputArray, $tmpfname); - $this->assertNotSame($byteCount, false); + $this->assertNotSame(false, $byteCount); $this->assertGreaterThan(0, $byteCount); $outputArray = Yaml::read($tmpfname); @@ -100,7 +100,7 @@ public function testSaveAndReadWrapped() $inputArray = ['one' => 1, 'two' => [1, 2], 'three' => '']; $byteCount = Yaml::saveWrapped($inputArray, $tmpfname); - $this->assertNotSame($byteCount, false); + $this->assertNotSame(false, $byteCount); $this->assertGreaterThan(0, $byteCount); $outputArray = Yaml::readWrapped($tmpfname); From df4290932a73b78f68fb48dd4bda5891d9660de6 Mon Sep 17 00:00:00 2001 From: mambax7 Date: Thu, 9 Mar 2023 05:16:45 -0500 Subject: [PATCH 06/12] changed $debug to public --- .../vendor/xoops/xmf/src/Module/Helper/AbstractHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/class/libraries/vendor/xoops/xmf/src/Module/Helper/AbstractHelper.php b/htdocs/class/libraries/vendor/xoops/xmf/src/Module/Helper/AbstractHelper.php index 92ae51b08..84bbee4c8 100644 --- a/htdocs/class/libraries/vendor/xoops/xmf/src/Module/Helper/AbstractHelper.php +++ b/htdocs/class/libraries/vendor/xoops/xmf/src/Module/Helper/AbstractHelper.php @@ -38,7 +38,7 @@ abstract class AbstractHelper /** * @var bool true if debug is enabled */ - protected $debug; + public $debug; /** * Instantiate a XoopsModule object for the helper to use. From be6565f71f0c61a9e7882e455e4389a4679af167 Mon Sep 17 00:00:00 2001 From: mambax7 Date: Thu, 9 Mar 2023 05:17:18 -0500 Subject: [PATCH 07/12] replaced $GLOBALS['xoopsModule'] --- .../vendor/xoops/xmf/src/Module/Helper/AbstractHelper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/class/libraries/vendor/xoops/xmf/src/Module/Helper/AbstractHelper.php b/htdocs/class/libraries/vendor/xoops/xmf/src/Module/Helper/AbstractHelper.php index 84bbee4c8..ef25f753a 100644 --- a/htdocs/class/libraries/vendor/xoops/xmf/src/Module/Helper/AbstractHelper.php +++ b/htdocs/class/libraries/vendor/xoops/xmf/src/Module/Helper/AbstractHelper.php @@ -60,7 +60,9 @@ public function __construct($dirname = null) if (isset($xoops)) { $this->module = $xoops->module; } else { - $this->module = $GLOBALS['xoopsModule']; +// $this->module = $GLOBALS['xoopsModule']; + global $xoopsModule; + $this->module = $xoopsModule; } } else { // assume dirname specified, try to get a module object From deec951d7f9263f98da19672c8c40ea631c57d51 Mon Sep 17 00:00:00 2001 From: mambax7 Date: Thu, 9 Mar 2023 05:19:02 -0500 Subject: [PATCH 08/12] replace $GLOBALS['xoops']->path( with dirname(__DIR__) --- htdocs/kernel/module.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/htdocs/kernel/module.php b/htdocs/kernel/module.php index 8a587e596..fbffb0b06 100644 --- a/htdocs/kernel/module.php +++ b/htdocs/kernel/module.php @@ -283,13 +283,20 @@ public function loadInfo($dirname, $verbose = true) return true; } global $xoopsConfig; - if (file_exists($file = $GLOBALS['xoops']->path('modules/' . $dirname . '/language/' . $xoopsConfig['language'] . '/modinfo.php'))) { +// if (file_exists($file = $GLOBALS['xoops']->path('modules/' . $dirname . '/language/' . $xoopsConfig['language'] . '/modinfo.php'))) { +// include_once $file; +// } elseif (file_exists($file = $GLOBALS['xoops']->path('modules/' . $dirname . '/language/english/modinfo.php'))) { +// include_once $file; +// } + + if (file_exists($file = dirname(__DIR__) . '/modules/' . $dirname . '/language/' . $xoopsConfig['language'] . '/modinfo.php')) { include_once $file; - } elseif (file_exists($file = $GLOBALS['xoops']->path('modules/' . $dirname . '/language/english/modinfo.php'))) { + } elseif (file_exists($file = dirname(__DIR__) . '/modules/' . $dirname . '/language/english/modinfo.php')) { include_once $file; } - if (!file_exists($file = $GLOBALS['xoops']->path('modules/' . $dirname . '/xoops_version.php'))) { +// if (!file_exists($file = $GLOBALS['xoops']->path('modules/' . $dirname . '/xoops_version.php'))) { + if (!file_exists($file = dirname(__DIR__) . '/modules/' . $dirname . '/xoops_version.php')) { if (false !== (bool)$verbose) { echo "Module File for $dirname Not Found!"; } @@ -322,7 +329,8 @@ public function search($term = '', $andor = 'AND', $limit = 0, $offset = 0, $use if ($this->getVar('hassearch') != 1 || !isset($search['file']) || !isset($search['func']) || $search['func'] == '' || $search['file'] == '') { return false; } - if (file_exists($file = $GLOBALS['xoops']->path('modules/' . $this->getVar('dirname') . '/' . $search['file']))) { +// if (file_exists($file = $GLOBALS['xoops']->path('modules/' . $this->getVar('dirname') . '/' . $search['file']))) { + if (file_exists($file = dirname(__DIR__) . '/modules/' . $this->getVar('dirname') . '/' . $search['file'])) { include_once $file; } else { return false; From e8f5a9dded9ecc3eb7a86d98548c0dd94260992e Mon Sep 17 00:00:00 2001 From: mambax7 Date: Thu, 9 Mar 2023 05:53:40 -0500 Subject: [PATCH 09/12] XoopsFormButtonTest --- .../class/xoopsform/XoopsFormButtonTest.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormButtonTest.php diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormButtonTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormButtonTest.php new file mode 100644 index 000000000..cff48d0f1 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormButtonTest.php @@ -0,0 +1,23 @@ +myClass('', '', ''); + $this->assertInstanceOf('XoopsFormButton', $instance); + } +} From 680ba35202224bd3452450ac4e238a599aa27164 Mon Sep 17 00:00:00 2001 From: mambax7 Date: Fri, 10 Mar 2023 02:20:41 -0500 Subject: [PATCH 10/12] form tests --- .../xoopsform/XoopsFormButtonTrayTest.php | 24 +++++++++++++ .../class/xoopsform/XoopsFormCaptchaTest.php | 23 ++++++++++++ .../class/xoopsform/XoopsFormCheckBoxTest.php | 23 ++++++++++++ .../xoopsform/XoopsFormColorPickerTest.php | 26 ++++++++++++++ .../class/xoopsform/XoopsFormDateTimeTest.php | 35 +++++++++++++++++++ .../xoopsform/XoopsFormDhtmlTextAreaTest.php | 23 ++++++++++++ .../class/xoopsform/XoopsFormEditorTest.php | 23 ++++++++++++ .../class/xoopsform/XoopsFormElementTest.php | 34 ++++++++++++++++++ .../xoopsform/XoopsFormElementTrayTest.php | 24 +++++++++++++ .../class/xoopsform/XoopsFormFileTest.php | 24 +++++++++++++ .../class/xoopsform/XoopsFormHiddenTest.php | 24 +++++++++++++ .../xoopsform/XoopsFormHiddenTokenTest.php | 25 +++++++++++++ .../class/xoopsform/XoopsFormLabelTest.php | 24 +++++++++++++ .../class/xoopsform/XoopsFormPasswordTest.php | 24 +++++++++++++ .../class/xoopsform/XoopsFormRadioTest.php | 24 +++++++++++++ .../class/xoopsform/XoopsFormRadioYNTest.php | 24 +++++++++++++ .../XoopsFormSelectCheckGroupTest.php | 23 ++++++++++++ .../xoopsform/XoopsFormSelectCountryTest.php | 23 ++++++++++++ .../xoopsform/XoopsFormSelectEditorTest.php | 26 ++++++++++++++ .../xoopsform/XoopsFormSelectGroupTest.php | 24 +++++++++++++ .../xoopsform/XoopsFormSelectLangTest.php | 23 ++++++++++++ .../XoopsFormSelectMatchOptionTest.php | 23 ++++++++++++ .../class/xoopsform/XoopsFormSelectTest.php | 23 ++++++++++++ .../xoopsform/XoopsFormSelectThemeTest.php | 23 ++++++++++++ .../xoopsform/XoopsFormSelectTimezoneTest.php | 23 ++++++++++++ .../xoopsform/XoopsFormSelectUserTest.php | 24 +++++++++++++ .../Unit/class/xoopsform/XoopsFormTest.php | 29 +++++++++++++++ .../class/xoopsform/XoopsFormTextAreaTest.php | 23 ++++++++++++ .../xoopsform/XoopsFormTextDateSelectTest.php | 25 +++++++++++++ .../class/xoopsform/XoopsFormTextTest.php | 24 +++++++++++++ .../xoopsform/XoopsGroupPermFormTest.php | 23 ++++++++++++ .../class/xoopsform/XoopsSimpleFormTest.php | 23 ++++++++++++ .../class/xoopsform/XoopsTableFormTest.php | 23 ++++++++++++ .../class/xoopsform/XoopsThemeFormTest.php | 23 ++++++++++++ 34 files changed, 832 insertions(+) create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormButtonTrayTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormCaptchaTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormCheckBoxTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormColorPickerTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormDateTimeTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormDhtmlTextAreaTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormEditorTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormElementTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormElementTrayTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormFileTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormHiddenTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormHiddenTokenTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormLabelTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormPasswordTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormRadioTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormRadioYNTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormSelectCheckGroupTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormSelectCountryTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormSelectEditorTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormSelectGroupTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormSelectLangTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormSelectMatchOptionTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormSelectTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormSelectThemeTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormSelectTimezoneTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormSelectUserTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormTextAreaTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormTextDateSelectTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsFormTextTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsGroupPermFormTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsSimpleFormTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsTableFormTest.php create mode 100644 htdocs/tests/Unit/class/xoopsform/XoopsThemeFormTest.php diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormButtonTrayTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormButtonTrayTest.php new file mode 100644 index 000000000..1c812d31c --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormButtonTrayTest.php @@ -0,0 +1,24 @@ +myClass(''); + $this->assertInstanceOf('XoopsFormButtonTray', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormCaptchaTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormCaptchaTest.php new file mode 100644 index 000000000..bd40d68c1 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormCaptchaTest.php @@ -0,0 +1,23 @@ +myClass(); + $this->assertInstanceOf('XoopsFormCaptcha', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormCheckBoxTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormCheckBoxTest.php new file mode 100644 index 000000000..af3e72e83 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormCheckBoxTest.php @@ -0,0 +1,23 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormCheckBox', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormColorPickerTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormColorPickerTest.php new file mode 100644 index 000000000..0fccc875f --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormColorPickerTest.php @@ -0,0 +1,26 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormColorPicker', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormDateTimeTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormDateTimeTest.php new file mode 100644 index 000000000..241f605ca --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormDateTimeTest.php @@ -0,0 +1,35 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormDateTime', $instance); + } + + public function test_const() + { + $this->assertNotNull(\XoopsFormDateTime::SHOW_BOTH); + $this->assertNotNull(\XoopsFormDateTime::SHOW_DATE); + $this->assertNotNull(\XoopsFormDateTime::SHOW_TIME); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormDhtmlTextAreaTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormDhtmlTextAreaTest.php new file mode 100644 index 000000000..237a3aca8 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormDhtmlTextAreaTest.php @@ -0,0 +1,23 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormDhtmlTextArea', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormEditorTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormEditorTest.php new file mode 100644 index 000000000..ab04de478 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormEditorTest.php @@ -0,0 +1,23 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormEditor', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormElementTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormElementTest.php new file mode 100644 index 000000000..41493f260 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormElementTest.php @@ -0,0 +1,34 @@ +myClass(); + $this->assertInstanceOf('XoopsFormElement', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormElementTrayTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormElementTrayTest.php new file mode 100644 index 000000000..2cc9a7d0b --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormElementTrayTest.php @@ -0,0 +1,24 @@ +myClass(''); + $this->assertInstanceOf('XoopsFormElementTray', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormFileTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormFileTest.php new file mode 100644 index 000000000..cede4d5ed --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormFileTest.php @@ -0,0 +1,24 @@ +myClass('', '', ''); + $this->assertInstanceOf('XoopsFormFile', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormHiddenTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormHiddenTest.php new file mode 100644 index 000000000..1579cf3ef --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormHiddenTest.php @@ -0,0 +1,24 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormHidden', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormHiddenTokenTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormHiddenTokenTest.php new file mode 100644 index 000000000..72feb0684 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormHiddenTokenTest.php @@ -0,0 +1,25 @@ +myClass(); + $this->assertInstanceOf('XoopsFormHiddenToken', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormLabelTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormLabelTest.php new file mode 100644 index 000000000..7d716e3c5 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormLabelTest.php @@ -0,0 +1,24 @@ +myClass(); + $this->assertInstanceOf('XoopsFormLabel', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormPasswordTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormPasswordTest.php new file mode 100644 index 000000000..309ee2f3e --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormPasswordTest.php @@ -0,0 +1,24 @@ +myClass('', '', '', ''); + $this->assertInstanceOf('XoopsFormPassword', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormRadioTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormRadioTest.php new file mode 100644 index 000000000..affb7dda8 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormRadioTest.php @@ -0,0 +1,24 @@ +myClass('',''); + $this->assertInstanceOf('XoopsFormRadio', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormRadioYNTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormRadioYNTest.php new file mode 100644 index 000000000..c0a315102 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormRadioYNTest.php @@ -0,0 +1,24 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormRadioYN', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectCheckGroupTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectCheckGroupTest.php new file mode 100644 index 000000000..bb2a9c056 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectCheckGroupTest.php @@ -0,0 +1,23 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormSelectCheckGroup', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectCountryTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectCountryTest.php new file mode 100644 index 000000000..ed821af48 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectCountryTest.php @@ -0,0 +1,23 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormSelectCountry', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectEditorTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectEditorTest.php new file mode 100644 index 000000000..d46b894dd --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectEditorTest.php @@ -0,0 +1,26 @@ +myClass($form); + $this->assertInstanceOf('XoopsFormSelectEditor', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectGroupTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectGroupTest.php new file mode 100644 index 000000000..0dd7c53bc --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectGroupTest.php @@ -0,0 +1,24 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormSelectGroup', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectLangTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectLangTest.php new file mode 100644 index 000000000..4e3030df1 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectLangTest.php @@ -0,0 +1,23 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormSelectLang', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectMatchOptionTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectMatchOptionTest.php new file mode 100644 index 000000000..fa291fd88 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectMatchOptionTest.php @@ -0,0 +1,23 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormSelectMatchOption', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectTest.php new file mode 100644 index 000000000..6fa42137a --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectTest.php @@ -0,0 +1,23 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormSelect', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectThemeTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectThemeTest.php new file mode 100644 index 000000000..2c9d94657 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectThemeTest.php @@ -0,0 +1,23 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormSelectTheme', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectTimezoneTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectTimezoneTest.php new file mode 100644 index 000000000..c220517e2 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectTimezoneTest.php @@ -0,0 +1,23 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormSelectTimezone', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectUserTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectUserTest.php new file mode 100644 index 000000000..0b524f226 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormSelectUserTest.php @@ -0,0 +1,24 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormSelectUser', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormTest.php new file mode 100644 index 000000000..15e6972e2 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormTest.php @@ -0,0 +1,29 @@ +myClass('', '', ''); + $this->assertInstanceOf('XoopsForm', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormTextAreaTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormTextAreaTest.php new file mode 100644 index 000000000..567758ecd --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormTextAreaTest.php @@ -0,0 +1,23 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormTextArea', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormTextDateSelectTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormTextDateSelectTest.php new file mode 100644 index 000000000..249543a91 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormTextDateSelectTest.php @@ -0,0 +1,25 @@ +myClass('', ''); + $this->assertInstanceOf('XoopsFormTextDateSelect', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsFormTextTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsFormTextTest.php new file mode 100644 index 000000000..a933ca47e --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsFormTextTest.php @@ -0,0 +1,24 @@ +myClass('', '', '', ''); + $this->assertInstanceOf('XoopsFormText', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsGroupPermFormTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsGroupPermFormTest.php new file mode 100644 index 000000000..198da2676 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsGroupPermFormTest.php @@ -0,0 +1,23 @@ +myClass('', 1, '', ''); + $this->assertInstanceOf('XoopsGroupPermForm', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsSimpleFormTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsSimpleFormTest.php new file mode 100644 index 000000000..efad6d5ac --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsSimpleFormTest.php @@ -0,0 +1,23 @@ +myClass('', '', ''); + $this->assertInstanceOf('XoopsSimpleForm', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsTableFormTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsTableFormTest.php new file mode 100644 index 000000000..8eed259a4 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsTableFormTest.php @@ -0,0 +1,23 @@ +myClass('', '', ''); + $this->assertInstanceOf('XoopsTableForm', $instance); + } +} diff --git a/htdocs/tests/Unit/class/xoopsform/XoopsThemeFormTest.php b/htdocs/tests/Unit/class/xoopsform/XoopsThemeFormTest.php new file mode 100644 index 000000000..4c0a06a66 --- /dev/null +++ b/htdocs/tests/Unit/class/xoopsform/XoopsThemeFormTest.php @@ -0,0 +1,23 @@ +myClass('', '', ''); + $this->assertInstanceOf('XoopsThemeForm', $instance); + } +} From 2aae96bccbd75b3643a31e171f6b5482803a746c Mon Sep 17 00:00:00 2001 From: mambax7 Date: Wed, 15 Mar 2023 06:22:30 -0400 Subject: [PATCH 11/12] add .ai --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index d1a15f948..9c6de9ae1 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ htdocs/xoops_data/protector/* htdocs/xoops_data/data/secure.php htdocs/xoops_data/data/license.php htdocs/xoops_data/data/*key* + +.ai \ No newline at end of file From 6ab6c4382cebdd9b69e00fd8fbb198607d88673d Mon Sep 17 00:00:00 2001 From: mambax7 Date: Mon, 20 Mar 2023 00:25:46 -0400 Subject: [PATCH 12/12] add ProxyCheckTest --- .../class/libraries/Xmf/ProxyCheckTest.php | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 htdocs/tests/Unit/class/libraries/Xmf/ProxyCheckTest.php diff --git a/htdocs/tests/Unit/class/libraries/Xmf/ProxyCheckTest.php b/htdocs/tests/Unit/class/libraries/Xmf/ProxyCheckTest.php new file mode 100644 index 000000000..2b2614c04 --- /dev/null +++ b/htdocs/tests/Unit/class/libraries/Xmf/ProxyCheckTest.php @@ -0,0 +1,75 @@ +proxyHeaderName = $name; + $this->proxyHeader = $header; + } +} + +class ProxyCheckTest extends TestCase +{ + /** + * @var ProxyCheck + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp(): void + { + $this->object = new ProxyCheck(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown(): void + { + } + + public function testGet() + { + $ip = $this->object->get(); + $this->assertFalse($ip); + } + + public function getProxyCheckTestData() + { + return array( +// ['name', 'header', 'expected'], + ['HTTP_FORWARDED', 'for=192.168.2.60;proto=http;by=203.0.113.43, for=192.0.2.43, for=198.51.100.17', false], + ['HTTP_FORWARDED', 'for=203.0.113.195;proto=http;by=203.0.113.43, for=192.0.2.43, for=198.51.100.17', '203.0.113.195'], + ['HTTP_FORWARDED', 'for="[2020:db8:85a3:8d3:1319:8a2e:370:7348]";proto=http;by=203.0.113.43', '2020:db8:85a3:8d3:1319:8a2e:370:7348'], + ['HTTP_NOT_FORWARDED', 'for="[2020:db8:85a3:8d3:1319:8a2e:370:7348]";proto=http;by=203.0.113.43', false], + ['HTTP_CLIENT_IP', '203.0.113.195, 70.41.3.18, 150.172.238.178', '203.0.113.195'], + ['STUFF', '2020:db8:85a3:8d3:1319:8a2e:370:7348', '2020:db8:85a3:8d3:1319:8a2e:370:7348'], + ); + } + + /** + * @dataProvider getProxyCheckTestData + */ + public function testProxyCheck($name, $header, $expected) + { + $obj = new localProxyCheck($name, $header); + $this->assertSame($expected, $obj->get()); + } + +} \ No newline at end of file