[PLUGIN][ActivityPub][Tests] Create a TestCase for the plugin

This commit is contained in:
Diogo Peralta Cordeiro 2022-03-13 15:54:14 +00:00
parent 7d84323df4
commit 636cb681d6
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0

View File

@ -0,0 +1,61 @@
<?php
declare(strict_types = 1);
namespace Plugin\ActivityPub\tests;
use App\Core\DB\DB;
use App\Util\GNUsocialTestCase;
use Plugin\ActivityPub\Util\Model\Activity;
use Plugin\ActivityPub\Util\Model\Actor;
use Plugin\ActivityPub\Util\Model\Note;
class ActivityPubTestCase extends GNUsocialTestCase
{
private static bool $loaded_fixtures = false;
private static string $fixtures_path = INSTALLDIR . '/plugins/ActivityPub/tests/fixtures';
public static function fixturesPath(string $path, string $ontology = 'gnusocial'): string
{
return self::$fixtures_path . \DIRECTORY_SEPARATOR . $ontology . \DIRECTORY_SEPARATOR . $path;
}
public static function setUpBeforeClass(): void
{
static::bootKernel();
if (!static::$loaded_fixtures) {
static::loadFixtures();
}
static::$loaded_fixtures = true;
}
public static function loadFixtures(string $ontology = 'gnusocial'): void
{
/*
* Beware that it's important to Load Actors, Objects, Activities in this sequence
* because we're running offline tests here.
*/
// Load Actors
$person = Actor::fromJson(file_get_contents(self::fixturesPath('objects/person.jsonld', $ontology)));
DB::flush();
$group = Actor::fromJson(file_get_contents(self::fixturesPath('objects/group.jsonld', $ontology)));
DB::flush();
// Load Objects
$note = Note::fromJson(file_get_contents(self::fixturesPath('objects/note.jsonld', $ontology)));
DB::flush();
$page = Note::fromJson(file_get_contents(self::fixturesPath('objects/page.jsonld', $ontology)));
DB::flush();
$reply = Note::fromJson(file_get_contents(self::fixturesPath('objects/reply.jsonld', $ontology)));
DB::flush();
// Load Activities
$create_note = Activity::fromJson(file_get_contents(self::fixturesPath('activities/create_note.jsonld', $ontology)));
DB::flush();
$create_page = Activity::fromJson(file_get_contents(self::fixturesPath('activities/create_page.jsonld', $ontology)));
DB::flush();
$create_reply = Activity::fromJson(file_get_contents(self::fixturesPath('activities/create_reply.jsonld', $ontology)));
DB::flush();
}
}