[PLUGIN][ActivityPub][Tests] Create Actor Tests
This commit is contained in:
parent
636cb681d6
commit
390c532456
|
@ -79,7 +79,10 @@ class Actor extends Model
|
|||
* Create an Entity from an ActivityStreams 2.0 JSON string
|
||||
* This will persist a new GSActor, ActivityPubRSA, and ActivityPubActor
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
|
||||
*/
|
||||
public static function fromJson(string|AbstractObject $json, array $options = []): ActivitypubActor
|
||||
{
|
||||
|
@ -187,7 +190,7 @@ class Actor extends Model
|
|||
} else {
|
||||
// Delete existing avatar if any
|
||||
try {
|
||||
$avatar = DB::findOneBy('avatar', ['actor_id' => $actor->getId()]);
|
||||
$avatar = DB::findOneBy(\Component\Avatar\Entity\Avatar::class, ['actor_id' => $actor->getId()]);
|
||||
$avatar->delete();
|
||||
Event::handle('AvatarUpdate', [$actor->getId()]);
|
||||
} catch (Exception) {
|
||||
|
|
48
plugins/ActivityPub/tests/Objects/GSGroupTest.php
Normal file
48
plugins/ActivityPub/tests/Objects/GSGroupTest.php
Normal 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\tests\Objects;
|
||||
|
||||
use App\Entity\Actor;
|
||||
use Plugin\ActivityPub\Entity\ActivitypubActor;
|
||||
use Plugin\ActivityPub\Entity\ActivitypubRsa;
|
||||
use Plugin\ActivityPub\tests\ActivityPubTestCase;
|
||||
use Plugin\ActivityPub\Util\Explorer;
|
||||
|
||||
class GSGroupTest extends ActivityPubTestCase
|
||||
{
|
||||
public function testGroupFromJson()
|
||||
{
|
||||
$group = Explorer::getOneFromUri('https://testv3.gnusocial.rocks/actor/21', try_online: false);
|
||||
$ap_group = ActivitypubActor::getByPK(['actor_id' => $group->getId()]);
|
||||
static::assertSame('https://testv3.gnusocial.rocks/actor/21/inbox.json', $ap_group->getInboxUri());
|
||||
static::assertSame('https://testv3.gnusocial.rocks/inbox.json', $ap_group->getInboxSharedUri());
|
||||
$group = $ap_group->getActor();
|
||||
static::assertSame('https://testv3.gnusocial.rocks/actor/21', $group->getUri());
|
||||
static::assertSame(Actor::GROUP, $group->getType());
|
||||
static::assertSame('hackers', $group->getNickname());
|
||||
static::assertSame('Hackers!', $group->getFullname());
|
||||
$public_key = ActivityPubRsa::getByActor($group)->getPublicKey();
|
||||
static::assertSame("-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoZyKL+GyJbTV/ilVBlzz\n8OL/UwNi3KpfV5kQwXU0pPcBbw6y2JOfWnKUT1CfiHG3ntiOFnc+wQfHZk4hRSE8\n9Xe/G5Y215xW+gqx/kjt2GOENqzSzYXdEZ5Qsx6yumZD/yb6VZK9Og0HjX2mpRs9\nbactY76w4BQVntjZ17gSkMhYcyPFZTAIe7QDkeSPk5lkXfTwtaB3YcJSbQ3+s7La\npeEgukQDkrLUIP6cxayKrgUl4fhHdpx1Yk4Bzd/1XkZCjeBca94lP1p2M12amI+Z\nOLSTuLyEiCcku8aN+Ms9plwATmIDaGvKFVk0YVtBHdIJlYXV0yIscab3bqyhsLBK\njwIDAQAB\n-----END PUBLIC KEY-----\n", $public_key);
|
||||
}
|
||||
}
|
48
plugins/ActivityPub/tests/Objects/GSPersonTest.php
Normal file
48
plugins/ActivityPub/tests/Objects/GSPersonTest.php
Normal 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\tests\Objects;
|
||||
|
||||
use App\Entity\Actor;
|
||||
use Plugin\ActivityPub\Entity\ActivitypubActor;
|
||||
use Plugin\ActivityPub\Entity\ActivitypubRsa;
|
||||
use Plugin\ActivityPub\tests\ActivityPubTestCase;
|
||||
use Plugin\ActivityPub\Util\Explorer;
|
||||
|
||||
class GSPersonTest extends ActivityPubTestCase
|
||||
{
|
||||
public function testPersonFromJson()
|
||||
{
|
||||
$person = Explorer::getOneFromUri('https://testv3.gnusocial.rocks/actor/42', try_online: false);
|
||||
$ap_person = ActivitypubActor::getByPK(['actor_id' => $person->getId()]);
|
||||
static::assertSame('https://testv3.gnusocial.rocks/actor/42/inbox.json', $ap_person->getInboxUri());
|
||||
static::assertSame('https://testv3.gnusocial.rocks/inbox.json', $ap_person->getInboxSharedUri());
|
||||
$person = $ap_person->getActor();
|
||||
static::assertSame('https://testv3.gnusocial.rocks/actor/42', $person->getUri());
|
||||
static::assertSame(Actor::PERSON, $person->getType());
|
||||
static::assertSame('diogo', $person->getNickname());
|
||||
static::assertSame('Diogo Peralta Cordeiro', $person->getFullname());
|
||||
$public_key = ActivityPubRsa::getByActor($person)->getPublicKey();
|
||||
static::assertSame("-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArBB+3ldwA2qC1hQTtIho\n9KYhvvMlPdydn8dA6OlyIQ3Jy57ADt2e144jDSY5RQ3esmzWm2QqsI8rAsZsAraO\nl2+855y7Fw35WH4GBc7PJ6MLAEvMk1YWeS/rttXaDzh2i4n/AXkMuxDjS1IBqw2w\nn0qTz2sdGcBJ+mop6AB9Qt2lseBc5IW040jSnfLEDDIaYgoc5m2yRsjGKItOh3BG\njGHDb6JB9FySToSMGIt0/tE5k06wfvAxtkxX5dfGeKtciBpC2MGT169iyMIOM8DN\nFhSl8mowtV1NJQ7nN692USrmNvSJjqe9ugPCDPPvwQ5A6A61Qrgpz5pav/o5Sz69\nzQIDAQAB\n-----END PUBLIC KEY-----\n", $public_key);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user