gnu-social/plugins/ActivityPub/tests/ActivityPubTestCase.php

62 lines
2.2 KiB
PHP
Raw Normal View History

<?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();
}
}