From 6262d351b777443bee2a1b5b534082268ebe72f9 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 7 Mar 2024 10:00:02 +0100 Subject: fix deprecation warning and add test --- Zotlabs/Lib/Activity.php | 9 +++++---- tests/unit/Lib/ActivityTest.php | 42 +++++++++++++++++++++++++++++++++++++++++ vendor/composer/installed.php | 4 ++-- 3 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 tests/unit/Lib/ActivityTest.php diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 4c89e22bd..3af6253f9 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -3282,17 +3282,18 @@ class Activity { return $content; } - static function get_textfield($act, $field) { + static function get_textfield($act, $field): null|string|array { + $content = null; - $content = false; - - if (array_key_exists($field, $act) && $act[$field]) + if (array_key_exists($field, $act) && $act[$field]) { $content = purify_html($act[$field]); + } elseif (array_key_exists($field . 'Map', $act) && $act[$field . 'Map']) { foreach ($act[$field . 'Map'] as $k => $v) { $content[escape_tags($k)] = purify_html($v); } } + return $content; } diff --git a/tests/unit/Lib/ActivityTest.php b/tests/unit/Lib/ActivityTest.php new file mode 100644 index 000000000..38c3d584c --- /dev/null +++ b/tests/unit/Lib/ActivityTest.php @@ -0,0 +1,42 @@ +assertEquals($expected, Activity::get_textfield($src, 'content')); + } + + /** + * Dataprovider for test_get_textfield. + */ + private function get_textfield_provider(): array { + return [ + 'get content field' => [ + ['content' => 'Some content'], + 'Some content' + ], + 'get content from map' => [ + ['contentMap' => ['en' => 'Some content']], + [ + 'en' => 'Some content' + ] + ], + 'get not available content' => [ + ['some_field' => 'Some content'], + null + ] + ]; + } + +} diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index b1f45b30d..bfd0c7e83 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'zotlabs/hubzilla', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '69bed9c889a5c153f7b9cece49be3b81bde24e32', + 'reference' => '27e57ff7aad9b70a4d088b880fac4af2920fdd31', 'type' => 'application', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -340,7 +340,7 @@ 'zotlabs/hubzilla' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '69bed9c889a5c153f7b9cece49be3b81bde24e32', + 'reference' => '27e57ff7aad9b70a4d088b880fac4af2920fdd31', 'type' => 'application', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), -- cgit v1.2.3