aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2025-04-14 13:23:49 +0200
committerMario Vavti <mario@mariovavti.com>2025-04-14 13:23:49 +0200
commit0d51ff1906df6e02f2aa028b753f25ae988d5d64 (patch)
tree38832811e268e0a3fe2b3faaee8ab5e7b2c5cbeb /tests
parent679b5098dabde4d8fd8c389a5e2a2bdeb4d8c904 (diff)
downloadvolse-hubzilla-0d51ff1906df6e02f2aa028b753f25ae988d5d64.tar.gz
volse-hubzilla-0d51ff1906df6e02f2aa028b753f25ae988d5d64.tar.bz2
volse-hubzilla-0d51ff1906df6e02f2aa028b753f25ae988d5d64.zip
add test for Activity::getUUID() and Avtivity::getMessageID() methods
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/Lib/ActivityTest.php73
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/unit/Lib/ActivityTest.php b/tests/unit/Lib/ActivityTest.php
index 0e2703f2b..eef4ee555 100644
--- a/tests/unit/Lib/ActivityTest.php
+++ b/tests/unit/Lib/ActivityTest.php
@@ -5,8 +5,13 @@ error_reporting(E_ALL);
use Zotlabs\Tests\Unit\UnitTestCase;
use Zotlabs\Lib\Activity;
+use Zotlabs\Lib\ActivityStreams;
+use phpmock\phpunit\PHPMock;
class ActivityTest extends UnitTestCase {
+ // Import PHPMock methods into this class
+ use PHPMock;
+
/**
* Test get a textfield from an activitystreams object
*
@@ -36,4 +41,72 @@ class ActivityTest extends UnitTestCase {
];
}
+ public function test_get_mid_and_uuid(): void {
+ $payload = <<<JSON
+ {
+ "actor": "https://somesite.test/c/technology",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "object": {
+ "id": "https://somesite.test/activities/like/e6e38c8b-beee-406f-9523-9da7ec97a823",
+ "uuid": "e6e38c8b-beee-406f-9523-9da7ec97a823",
+ "actor": "https://somesite.test/u/SomePerson",
+ "object": "https://somesite.test/post/1197552",
+ "type": "Like",
+ "audience": "https://somesite.test/c/technology"
+ },
+ "cc": [
+ "https://somesite.test/c/technology/followers"
+ ],
+ "type": "Announce",
+ "id": "https://somesite.test/activities/announce/like/9e583a54-e4e0-4436-9726-975a14f923ed",
+ "uuid": "9e583a54-e4e0-4436-9726-975a14f923ed"
+ }
+ JSON;
+
+ //
+ // Mock z_fetch_url to prevent us from spamming real servers during test runs
+ //
+ // We just create some sample ActivityStreams objects to return for the various
+ // URL's to make it a somewhat realistic test. Each object will have it's URL as
+ // it's id and only specify the object type as laid out in the $urlmap below.
+
+ $urlmap = [
+ 'https://somesite.test/u/SomePerson' => [ 'type' => 'Person' ],
+ 'https://somesite.test/post/1197552' => [ 'type' => 'Note' ],
+ ];
+
+ $z_fetch_url_stub = $this->getFunctionMock('Zotlabs\Lib', 'z_fetch_url');
+ $z_fetch_url_stub
+ ->expects($this->any())
+ ->willReturnCallback(function ($url) use ($urlmap) {
+ if (isset($urlmap[$url])) {
+ $body = json_encode(
+ array_merge([ 'id' => $url ], $urlmap[$url]),
+ JSON_FORCE_OBJECT,
+ );
+
+ return [
+ 'success' => true,
+ 'body' => $body,
+ ];
+ } else {
+ // We should perhaps throw an error here to fail the test,
+ // as we're receiving an unexpected URL.
+ return [
+ 'success' => false,
+ ];
+ }
+ });
+
+ // Make sure we have a sys channel before we start
+ create_sys_channel();
+
+ $as = new ActivityStreams($payload);
+
+ $this->assertEquals('https://somesite.test/activities/announce/like/9e583a54-e4e0-4436-9726-975a14f923ed', Activity::getMessageID($as));
+ $this->assertEquals('9e583a54-e4e0-4436-9726-975a14f923ed', Activity::getUUID($as));
+ }
+
}