aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-03-07 10:00:02 +0100
committerMario <mario@mariovavti.com>2024-03-07 10:00:02 +0100
commit6262d351b777443bee2a1b5b534082268ebe72f9 (patch)
tree4eb6d2b7f4677f76a3c392552691b8726d75522b
parent27e57ff7aad9b70a4d088b880fac4af2920fdd31 (diff)
downloadvolse-hubzilla-6262d351b777443bee2a1b5b534082268ebe72f9.tar.gz
volse-hubzilla-6262d351b777443bee2a1b5b534082268ebe72f9.tar.bz2
volse-hubzilla-6262d351b777443bee2a1b5b534082268ebe72f9.zip
fix deprecation warning and add test
-rw-r--r--Zotlabs/Lib/Activity.php9
-rw-r--r--tests/unit/Lib/ActivityTest.php42
-rw-r--r--vendor/composer/installed.php4
3 files changed, 49 insertions, 6 deletions
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 @@
+<?php
+namespace Zotlabs\Tests\Unit\Lib;
+
+error_reporting(E_ALL);
+
+use Zotlabs\Tests\Unit\UnitTestCase;
+use Zotlabs\Lib\Activity;
+use Zotlabs\Lib\ActivityStreams;
+
+class ActivityTest extends UnitTestCase {
+ /**
+ * Test get a textfield from an activitystreams object
+ *
+ * @dataProvider get_textfield_provider
+ */
+ public function test_get_textfield(array $src, null|string|array $expected): void {
+ $this->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(),