[PLUGIN][ActivityPub][Test] Activity: Create Page

Fixed a couple of bugs
This commit is contained in:
Diogo Peralta Cordeiro 2022-03-19 22:21:15 +00:00
parent 6955872e05
commit 2f7fdf6ee4
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
9 changed files with 150 additions and 94 deletions

View File

@ -17,22 +17,31 @@
"@id": "gs:inConversation",
"@type": "@id"
}
},
{
"@language": "en"
}
],
"id": "https://instance.gnusocial.test/activity/1338",
"published": "2022-03-01T18:19:51+00:00",
"published": "2022-03-17T23:30:26+00:00",
"actor": "https://instance.gnusocial.test/actor/42",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [
"https://instance.gnusocial.test/actor/21"
],
"object": {
"type": "Page",
"id": "https://instance.gnusocial.test/object/note/1338",
"published": "2022-03-01T22:44:29+00:00",
"published": "2022-03-17T23:30:26+00:00",
"attributedTo": "https://instance.gnusocial.test/actor/42",
"name": "hello, world.",
"content": "<p>This is an interesting page.</p>",
"mediaType": "text/html",
"source": {
"content": "This is an interesting page.",
"mediaType": "text/plain"
"mediaType": "text/markdown"
},
"attachment": [],
"tag": [],
@ -41,15 +50,7 @@
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [
"https://instance.gnusocial.test/actor/42/subscribers",
"https://instance.gnusocial.test/actor/21"
]
},
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [
"https://instance.gnusocial.test/actor/42/subscribers",
"https://instance.gnusocial.test/actor/21"
]
}
}

View File

@ -17,6 +17,9 @@
"@id": "gs:inConversation",
"@type": "@id"
}
},
{
"@language": "en"
}
],
"id": "https://instance.gnusocial.test/object/note/1337",

View File

@ -17,6 +17,9 @@
"@id": "gs:inConversation",
"@type": "@id"
}
},
{
"@language": "en"
}
],
"id": "https://instance.gnusocial.test/object/note/1340",

View File

@ -17,17 +17,20 @@
"@id": "gs:inConversation",
"@type": "@id"
}
},
{
"@language": "en"
}
],
"id": "https://instance.gnusocial.test/object/note/1338",
"published": "2022-03-01T22:44:29+00:00",
"published": "2022-03-17T23:30:26+00:00",
"attributedTo": "https://instance.gnusocial.test/actor/42",
"name": "hello, world.",
"content": "<p>This is an interesting page.</p>",
"mediaType": "text/html",
"source": {
"content": "This is an interesting page.",
"mediaType": "text/plain"
"mediaType": "text/markdown"
},
"attachment": [],
"tag": [],
@ -36,7 +39,6 @@
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [
"https://instance.gnusocial.test/actor/42/subscribers",
"https://instance.gnusocial.test/actor/21"
]
}

View File

@ -17,6 +17,9 @@
"@id": "gs:inConversation",
"@type": "@id"
}
},
{
"@language": "en"
}
],
"id": "https://instance.gnusocial.test/object/note/1339",

View File

@ -0,0 +1,48 @@
<?php
declare(strict_types = 1);
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
namespace Plugin\ActivityPub\Test\Objects;
use App\Util\GNUsocialTestCase;
use Plugin\ActivityPub\Entity\ActivitypubActivity;
use Plugin\ActivityPub\Util\Explorer;
class GSActivityCreatePageTest extends GNUsocialTestCase
{
public function testNoteFromJson()
{
self::bootKernel();
$activity_uri = 'https://instance.gnusocial.test/activity/1338';
$group_uri = 'https://instance.gnusocial.test/actor/21';
$ap_activity = ActivitypubActivity::getByPK(['activity_uri' => $activity_uri]);
$activity = $ap_activity->getActivity();
static::assertSame('create', $activity->getVerb());
static::assertSame('note', $activity->getObjectType());
static::assertSame('ActivityPub', $activity->getSource());
static::assertCount(1, $attT = $ap_activity->getAttentionTargets());
static::assertObjectEquals(Explorer::getOneFromUri($group_uri, try_online: false), $attT[0]);
}
}

View File

@ -50,7 +50,7 @@ class GSObjectNoteTest extends GNUsocialTestCase
static::assertFalse($note->getIsLocal());
static::assertSame(VisibilityScope::EVERYWHERE, $note->getScope());
static::assertSame($object_uri, $note->getUrl());
static::assertNull($note->getLanguageId());
static::assertSame('en', $note->getLanguageLocale());
static::assertSame('note', $note->getType());
static::assertNull($note->getTitle());
@ -83,7 +83,7 @@ class GSObjectNoteTest extends GNUsocialTestCase
static::assertFalse($note->getIsLocal());
static::assertSame(VisibilityScope::EVERYWHERE, $note->getScope());
static::assertSame($object_uri, $note->getUrl());
static::assertNull($note->getLanguageId());
static::assertSame('en', $note->getLanguageLocale());
static::assertSame('note', $note->getType());
static::assertNull($note->getTitle());

View File

@ -38,11 +38,12 @@ class GSObjectPageTest extends GNUsocialTestCase
$actor_uri = 'https://instance.gnusocial.test/actor/42';
$object_uri = 'https://instance.gnusocial.test/object/note/1338';
$group_uri = 'https://instance.gnusocial.test/actor/21';
$page = ActivityPub::getObjectByUri($object_uri, try_online: false);
static::assertInstanceOf(Note::class, $page);
static::assertSame(Explorer::getOneFromUri($actor_uri)->getId(), $page->getActorId());
static::assertSame('text/plain', $page->getContentType());
static::assertSame('text/markdown', $page->getContentType());
static::assertSame('This is an interesting page.', $page->getContent());
static::assertSame('<p>This is an interesting page.</p>', $page->getRendered());
static::assertSame('ActivityPub', $page->getSource());
@ -50,7 +51,7 @@ class GSObjectPageTest extends GNUsocialTestCase
static::assertFalse($page->getIsLocal());
static::assertSame(VisibilityScope::EVERYWHERE, $page->getScope());
static::assertSame($object_uri, $page->getUrl());
static::assertNull($page->getLanguageId());
static::assertSame('en', $page->getLanguageLocale());
static::assertSame('page', $page->getType());
static::assertSame('hello, world.', $page->getTitle());
@ -59,6 +60,8 @@ class GSObjectPageTest extends GNUsocialTestCase
static::assertSame($object_uri, $ap_object->getObjectUri());
static::assertSame($page->getId(), $ap_object->getObjectId());
//dd($page->getAttentionTargets(), $page->getMentionTargets());
static::assertCount(1, $attT = $page->getAttentionTargets());
static::assertObjectEquals(Explorer::getOneFromUri($group_uri, try_online: false), $attT[0]);
static::assertSame([], $page->getMentionTargets());
}
}

View File

@ -143,9 +143,9 @@ class Note extends Model
}
// Figure the locale of the note when possible
$locale = null;
if (\array_key_exists('@language', $type_note->get('@context'))) {
$locale = $type_note->get('@context')['@language'];
$locale = array_column($type_note->get('@context'), '@language');
if ($locale !== []) {
$locale = $locale[0];
if ($locale === 'und') {
$locale = null;
}
@ -155,7 +155,7 @@ class Note extends Model
'is_local' => false,
'created' => new DateTime($type_note->get('published') ?? 'now'),
'title' => $type_note->get('name') ?? null,
'language_id' => $type_note->get('contentLang') ?? null,
'language_id' => \is_null($locale) ? null : Language::getByLocale($locale)->getId(),
'url' => $type_note->get('url') ?? $type_note->get('id'),
'actor_id' => $actor_id,
'reply_to' => $reply_to = $handleInReplyTo($type_note),
@ -167,13 +167,6 @@ class Note extends Model
'source' => $source,
];
// Language
if (!\is_null($map['language_id'])) {
$map['language_id'] = Language::getByLocale($map['language_id'])->getId();
} else {
$map['language_id'] = null;
}
// Scope
if (\in_array('https://www.w3.org/ns/activitystreams#Public', $to)) {
// Public: Visible for all, shown in public feeds