[WIP] Make it compatible with PHP 5.5; fix PHPStorm warnings
This commit is contained in:
parent
eba10d28e9
commit
9c4c39fb0b
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
vendor/
|
||||
test/db.sqlite
|
||||
test/db.sqlite
|
||||
./.idea/
|
||||
/.idea
|
||||
|
@ -30,11 +30,13 @@
|
||||
"symfony/dependency-injection": "^4.2",
|
||||
"symfony/http-kernel": "^4.2",
|
||||
"symfony/psr-http-message-bridge": "^1.1",
|
||||
"zendframework/zend-diactoros": "^1.8"
|
||||
"zendframework/zend-diactoros": "^1.8",
|
||||
"ext-json": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/dbunit": "^4.0",
|
||||
"phpunit/phpunit": "^7.4"
|
||||
"phpunit/dbunit": "^2.0",
|
||||
"phpunit/phpunit": "^4.0",
|
||||
"ext-pdo": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
975
composer.lock
generated
975
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -86,4 +86,4 @@ class ActivityEvent extends Event
|
||||
$this->response = $response;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
<?php
|
||||
namespace ActivityPub\Activities;
|
||||
|
||||
use ActivityPub\Activities\InboxActivityEvent;
|
||||
use ActivityPub\Activities\OutboxActivityEvent;
|
||||
use ActivityPub\Objects\CollectionsService;
|
||||
use ActivityPub\Objects\IdProvider;
|
||||
use ActivityPub\Objects\ObjectsService;
|
||||
@ -11,7 +9,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
class CreateHandler implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @var ObjextsService
|
||||
* @var ObjectsService
|
||||
*/
|
||||
private $objectsService;
|
||||
|
||||
@ -128,4 +126,4 @@ class CreateHandler implements EventSubscriberInterface
|
||||
return $targetObj;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -77,7 +77,7 @@ class DeleteHandler implements EventSubscriberInterface
|
||||
->format( DateTime::ISO8601 );
|
||||
}
|
||||
|
||||
public function authorized( Request $request, string $objectId )
|
||||
public function authorized( Request $request, $objectId )
|
||||
{
|
||||
if ( ! $request->attributes->has( 'actor' ) ) {
|
||||
return false;
|
||||
@ -94,4 +94,4 @@ class DeleteHandler implements EventSubscriberInterface
|
||||
return $requestActor['id'] === $attributedActorId;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -28,7 +28,7 @@ class FollowHandler implements EventSubscriberInterface
|
||||
);
|
||||
}
|
||||
|
||||
public function __construct( bool $autoAccepts,
|
||||
public function __construct( $autoAccepts,
|
||||
ContextProvider $contextProvider )
|
||||
{
|
||||
$this->autoAccepts = $autoAccepts;
|
||||
@ -36,7 +36,7 @@ class FollowHandler implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
public function handleInbox( InboxActivityEvent $event,
|
||||
string $eventName,
|
||||
$eventName,
|
||||
EventDispatcher $eventDispatcher )
|
||||
{
|
||||
$activity = $event->getActivity();
|
||||
@ -68,10 +68,13 @@ class FollowHandler implements EventSubscriberInterface
|
||||
),
|
||||
json_encode( $accept )
|
||||
);
|
||||
$request->attributes->set( 'actor', $localActor );
|
||||
$request->attributes->add( array(
|
||||
'actor' => $localActor,
|
||||
'follow' => $activity,
|
||||
) );
|
||||
$outboxEvent = new OutboxActivityEvent( $accept, $localActor, $request );
|
||||
$eventDispatcher->dispatch( OutboxActivityEvent::NAME, $outboxEvent );
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -7,4 +7,4 @@ class InboxActivityEvent extends ActivityEvent
|
||||
{
|
||||
const NAME = 'inbox.activity';
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -18,15 +18,18 @@ class NonActivityHandler implements EventSubscriberInterface
|
||||
*/
|
||||
private $contextProvider;
|
||||
|
||||
const ACTIVITY_TYPES = array(
|
||||
'Accept', 'Add', 'Announce', 'Arrive',
|
||||
'Block', 'Create', 'Delete', 'Dislike',
|
||||
'Flag', 'Follow', 'Ignore', 'Invite',
|
||||
'Join', 'Leave', 'Like', 'Listen',
|
||||
'Move', 'Offer', 'Question', 'Reject',
|
||||
'Read', 'Remove', 'TentativeReject', 'TentativeAccept',
|
||||
'Travel', 'Undo', 'Update', 'View',
|
||||
);
|
||||
public static function activityTypes()
|
||||
{
|
||||
return array(
|
||||
'Accept', 'Add', 'Announce', 'Arrive',
|
||||
'Block', 'Create', 'Delete', 'Dislike',
|
||||
'Flag', 'Follow', 'Ignore', 'Invite',
|
||||
'Join', 'Leave', 'Like', 'Listen',
|
||||
'Move', 'Offer', 'Question', 'Reject',
|
||||
'Read', 'Remove', 'TentativeReject', 'TentativeAccept',
|
||||
'Travel', 'Undo', 'Update', 'View',
|
||||
);
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
@ -43,7 +46,7 @@ class NonActivityHandler implements EventSubscriberInterface
|
||||
public function handle( OutboxActivityEvent $event )
|
||||
{
|
||||
$object = $event->getActivity();
|
||||
if ( in_array( $object['type'], self::ACTIVITY_TYPES ) ) {
|
||||
if ( in_array( $object['type'], self::activityTypes() ) ) {
|
||||
return;
|
||||
}
|
||||
$request = $event->getRequest();
|
||||
@ -78,4 +81,4 @@ class NonActivityHandler implements EventSubscriberInterface
|
||||
return $create;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -7,4 +7,4 @@ class OutboxActivityEvent extends ActivityEvent
|
||||
{
|
||||
const NAME = 'outbox.activity';
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -8,14 +8,20 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
class ValidationHandler implements EventSubscriberInterface
|
||||
{
|
||||
const OBJECT_REQUIRED_TYPES = array(
|
||||
'Create', 'Update', 'Delete', 'Follow',
|
||||
'Add', 'Remove', 'Like', 'Block', 'Undo',
|
||||
);
|
||||
public static function getObjectRequiredTypes()
|
||||
{
|
||||
return array(
|
||||
'Create', 'Update', 'Delete', 'Follow',
|
||||
'Add', 'Remove', 'Like', 'Block', 'Undo',
|
||||
);
|
||||
}
|
||||
|
||||
const TARGET_REQUIRED_TYPES = array(
|
||||
'Add', 'Remove',
|
||||
);
|
||||
public static function getTargetRequiredTypes()
|
||||
{
|
||||
return array(
|
||||
'Add', 'Remove',
|
||||
);
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
@ -30,11 +36,11 @@ class ValidationHandler implements EventSubscriberInterface
|
||||
$activity = $event->getActivity();
|
||||
$requiredFields = array( 'type', 'id', 'actor' );
|
||||
if ( array_key_exists( 'type', $activity ) &&
|
||||
in_array( $activity['type'], self::OBJECT_REQUIRED_TYPES ) ) {
|
||||
in_array( $activity['type'], self::getObjectRequiredTypes() ) ) {
|
||||
$requiredFields[] = 'object';
|
||||
}
|
||||
if ( array_key_exists( 'type', $activity ) &&
|
||||
in_array( $activity['type'], self::TARGET_REQUIRED_TYPES ) ) {
|
||||
in_array( $activity['type'], self::getTargetRequiredTypes() ) ) {
|
||||
$requiredFields[] = 'target';
|
||||
}
|
||||
$this->requireFields( $activity, $requiredFields );
|
||||
@ -45,11 +51,11 @@ class ValidationHandler implements EventSubscriberInterface
|
||||
$activity = $event->getActivity();
|
||||
$requiredFields = array( 'type', 'actor' );
|
||||
if ( array_key_exists( 'type', $activity ) &&
|
||||
in_array( $activity['type'], self::OBJECT_REQUIRED_TYPES ) ) {
|
||||
in_array( $activity['type'], self::getObjectRequiredTypes() ) ) {
|
||||
$requiredFields[] = 'object';
|
||||
}
|
||||
if ( array_key_exists( 'type', $activity ) &&
|
||||
in_array( $activity['type'], self::TARGET_REQUIRED_TYPES ) ) {
|
||||
in_array( $activity['type'], self::getTargetRequiredTypes() ) ) {
|
||||
$requiredFields[] = 'target';
|
||||
}
|
||||
$this->requireFields( $activity, $requiredFields );
|
||||
@ -70,4 +76,4 @@ class ValidationHandler implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace ActivityPub;
|
||||
|
||||
use ActivityPub\Activities\CreateHandler;
|
||||
use ActivityPub\Activities\DeleteHandler;
|
||||
use ActivityPub\Activities\NonActivityHandler;
|
||||
use ActivityPub\Activities\UpdateHandler;
|
||||
use ActivityPub\Activities\ValidationHandler;
|
||||
@ -12,13 +14,14 @@ use ActivityPub\Config\ActivityPubModule;
|
||||
use ActivityPub\Http\Router;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\HttpKernel;
|
||||
use Symfony\Component\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
|
||||
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
|
||||
use Symfony\Component\HttpKernel\EventListener\ExceptionListener;
|
||||
use Symfony\Component\HttpKernel\HttpKernel;
|
||||
|
||||
class ActivityPub
|
||||
{
|
||||
@ -98,4 +101,4 @@ class ActivityPub
|
||||
$dispatcher->addSubscriber( $this->module->get( DeleteHandler::class ) );
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -64,4 +64,4 @@ class AuthListener implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -63,4 +63,4 @@ class AuthService
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -82,4 +82,4 @@ class SignatureListener implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
namespace ActivityPub\Collections;
|
||||
|
||||
use ActivityPub\Entities\ActivityPubObject;
|
||||
use ActivityPub\Objects\ObjectsService;
|
||||
|
||||
class CollectionsService
|
||||
{
|
||||
/**
|
||||
* Creates a new collection - ordered/unordered and paged/unpaged
|
||||
*
|
||||
* @return ActivityPubObject The created Collection object
|
||||
*/
|
||||
public function createCollection()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the object to the collection
|
||||
*
|
||||
* This method handles ordered/unordered and paged/unpaged collections.
|
||||
* @param string $collectionId The id of collection
|
||||
* @param ActivityPubObject $object The object to add to the collection
|
||||
*/
|
||||
public function addToCollection( string $collectionId, ActivityPubObject $object )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the object from the collection
|
||||
*
|
||||
* This method handles ordered/unordered and paged/unpaged collections.
|
||||
* @param string $collectionId The id of the collection
|
||||
* @param string $objectId The id of the object to remove
|
||||
*/
|
||||
public function removeFromCollection( string $collectionId, string $objectId )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the collection by replacing it with a Tombstone object
|
||||
*
|
||||
* None of the items in the collection will be deleted; however, if it is
|
||||
* a PagedCollection then all the collection page objects will be deleted.
|
||||
* @param string $collectionId The id of the collection
|
||||
* @return ActivityPubObject The Tombstone that the collection was replaced with
|
||||
*/
|
||||
public function deleteCollection( string $collectionId )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
@ -55,7 +55,7 @@ class ActivityPubConfig
|
||||
$this->idPathPrefix = $builder->getIdPathPrefix();
|
||||
}
|
||||
|
||||
public function createBuilder()
|
||||
public static function createBuilder()
|
||||
{
|
||||
return new ActivityPubConfigBuilder();
|
||||
}
|
||||
@ -109,4 +109,4 @@ class ActivityPubConfig
|
||||
return $this->idPathPrefix;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace ActivityPub\Config;
|
||||
use ActivityPub\Config\ActivityPubConfig;
|
||||
use ActivityPub\Objects\ContextProvider;
|
||||
use ActivityPub\Objects\IdProvider;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* The ActivityPubConfigBuilder is a builder class to create ActivityPub config data
|
||||
@ -64,7 +65,7 @@ class ActivityPubConfigBuilder
|
||||
$this->authFunction = function() {
|
||||
return false;
|
||||
};
|
||||
$this->jsonLDContext = ContextProvider::DEFAULT_CONTEXT;
|
||||
$this->jsonLdContext = ContextProvider::getDefaultContext();
|
||||
$this->idPathPrefix = IdProvider::DEFAULT_ID_PATH_PREFIX;
|
||||
}
|
||||
|
||||
@ -72,6 +73,7 @@ class ActivityPubConfigBuilder
|
||||
* Validates and builds the config instance
|
||||
*
|
||||
* @return ActivityPubConfig
|
||||
* @throws Exception If the configuration is invalid
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
@ -79,6 +81,9 @@ class ActivityPubConfigBuilder
|
||||
return new ActivityPubConfig( $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private function validate()
|
||||
{
|
||||
if ( ! $this->dbConnectionParams ) {
|
||||
@ -119,7 +124,7 @@ class ActivityPubConfigBuilder
|
||||
* @param bool $isDevMode
|
||||
* @return ActivityPubConfigBuilder The builder instance
|
||||
*/
|
||||
public function setIsDevMode( bool $isDevMode )
|
||||
public function setIsDevMode( $isDevMode )
|
||||
{
|
||||
$this->isDevMode = $isDevMode;
|
||||
return $this;
|
||||
@ -145,7 +150,7 @@ class ActivityPubConfigBuilder
|
||||
* @param string $dbPrefix
|
||||
* @return ActivityPubConfigBuilder The builder instance
|
||||
*/
|
||||
public function setDbPrefix( string $dbPrefix )
|
||||
public function setDbPrefix( $dbPrefix )
|
||||
{
|
||||
$this->dbPrefix = $dbPrefix;
|
||||
return $this;
|
||||
@ -217,7 +222,7 @@ class ActivityPubConfigBuilder
|
||||
* @param string $idPathPrefix The id path prefix
|
||||
* @return ActivityPubConfigBuilder The builder instance
|
||||
*/
|
||||
public function setIdPathPrefix( string $idPathPrefix )
|
||||
public function setIdPathPrefix( $idPathPrefix )
|
||||
{
|
||||
$this->idPathPrefix = $idPathPrefix;
|
||||
return $this;
|
||||
@ -231,4 +236,4 @@ class ActivityPubConfigBuilder
|
||||
return $this->idPathPrefix;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -91,7 +91,8 @@ class ActivityPubModule
|
||||
->addArgument( self::COLLECTION_PAGE_SIZE )
|
||||
->addArgument( new Reference( AuthService::class ) )
|
||||
->addArgument( new Reference( ContextProvider::class ) )
|
||||
->addArgument( new Reference( Client::class ) );
|
||||
->addArgument( new Reference( Client::class ) )
|
||||
->addArgument( new Reference( SimpleDateTimeProvider::class ));
|
||||
|
||||
$this->injector->register( RandomProvider::class, RandomProvider::class );
|
||||
|
||||
@ -136,9 +137,9 @@ class ActivityPubModule
|
||||
* @param string $id The id of the service instance to get
|
||||
* @return object The service instance
|
||||
*/
|
||||
public function get( string $id )
|
||||
public function get( $id )
|
||||
{
|
||||
return $this->injector->get( $id );
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -2,13 +2,13 @@
|
||||
namespace ActivityPub\Controllers;
|
||||
|
||||
use ActivityPub\Auth\AuthService;
|
||||
use ActivityPub\Entities\ActivityPubObject;
|
||||
use ActivityPub\Objects\CollectionsService;
|
||||
use ActivityPub\Objects\ObjectsService;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* The GetController is responsible for rendering ActivityPub objects as JSON
|
||||
@ -75,4 +75,4 @@ class GetController
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -97,6 +97,7 @@ class PostController
|
||||
} else if ( is_string( $actor ) ) {
|
||||
return $this->objectsService->dereference( $actor );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function authorized( Request $request, ActivityPubObject $activityActor )
|
||||
@ -111,7 +112,7 @@ class PostController
|
||||
return true;
|
||||
}
|
||||
|
||||
private function objectWithField( string $name, string $value )
|
||||
private function objectWithField( $name, $value )
|
||||
{
|
||||
$results = $this->objectsService->query( array( $name => $value ) );
|
||||
if ( count( $results ) === 0 ) {
|
||||
@ -130,4 +131,4 @@ class PostController
|
||||
return $uri;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -15,12 +15,6 @@ use Symfony\Component\HttpFoundation\HeaderUtils;
|
||||
class HttpSignatureService
|
||||
{
|
||||
// TODO handle the Digest header better, both on generating and verifying
|
||||
const DEFAULT_HEADERS = array(
|
||||
'(request-target)',
|
||||
'host',
|
||||
'date',
|
||||
);
|
||||
|
||||
const REPLAY_THRESHOLD = 300;
|
||||
|
||||
/**
|
||||
@ -47,7 +41,16 @@ class HttpSignatureService
|
||||
$this->dateTimeProvider = $dateTimeProvider;
|
||||
$this->psr7Factory = new DiactorosFactory();
|
||||
}
|
||||
|
||||
|
||||
public static function getDefaultHeaders()
|
||||
{
|
||||
return array(
|
||||
'(request-target)',
|
||||
'host',
|
||||
'date',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a signature given the request and private key
|
||||
*
|
||||
@ -58,9 +61,12 @@ class HttpSignatureService
|
||||
* (default ['(request-target)', 'host', 'date'])
|
||||
* @return string The Signature header value
|
||||
*/
|
||||
public function sign( RequestInterface $request, string $privateKey,
|
||||
string $keyId, $headers = self::DEFAULT_HEADERS )
|
||||
public function sign( RequestInterface $request, $privateKey,
|
||||
$keyId, $headers = null )
|
||||
{
|
||||
if ( ! $headers ) {
|
||||
$headers = self::getDefaultHeaders();
|
||||
}
|
||||
$headers = array_map( 'strtolower', $headers );
|
||||
$signingString = $this->getSigningString( $request, $headers );
|
||||
$keypair = RsaKeypair::fromPrivateKey( $privateKey );
|
||||
@ -79,7 +85,7 @@ class HttpSignatureService
|
||||
* @param string $publicKey The public key to use to verify the request
|
||||
* @return bool True if the signature is valid, false if it is missing or invalid
|
||||
*/
|
||||
public function verify( Request $request, string $publicKey )
|
||||
public function verify( Request $request, $publicKey )
|
||||
{
|
||||
$params = array();
|
||||
$headers = $request->headers;
|
||||
@ -155,7 +161,7 @@ class HttpSignatureService
|
||||
* e.g. 'keyId="theKey",algorithm="rsa-sha256"'
|
||||
* @return array The params as an associative array
|
||||
*/
|
||||
private function parseSignatureParams( string $paramsStr )
|
||||
private function parseSignatureParams( $paramsStr )
|
||||
{
|
||||
$params = array();
|
||||
$split = HeaderUtils::split( $paramsStr, ',=' );
|
||||
@ -170,4 +176,4 @@ class HttpSignatureService
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -22,7 +22,7 @@ class RsaKeypair
|
||||
*/
|
||||
private $privateKey;
|
||||
|
||||
public function __construct( string $publicKey, string $privateKey )
|
||||
public function __construct( $publicKey, $privateKey )
|
||||
{
|
||||
$this->publicKey = $publicKey;
|
||||
$this->privateKey = $privateKey;
|
||||
@ -112,7 +112,7 @@ class RsaKeypair
|
||||
* @param string $publicKey The public key
|
||||
* @return RsaKeypair
|
||||
*/
|
||||
public function fromPublicKey( string $publicKey )
|
||||
public static function fromPublicKey( $publicKey )
|
||||
{
|
||||
return new RsaKeypair( $publicKey, '' );
|
||||
}
|
||||
@ -126,9 +126,9 @@ class RsaKeypair
|
||||
* @param string $privateKey The private key
|
||||
* @return RsaKeypair
|
||||
*/
|
||||
public function fromPrivateKey( string $privateKey)
|
||||
public static function fromPrivateKey( $privateKey)
|
||||
{
|
||||
return new RsaKeypair( '', $privateKey );
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -49,4 +49,4 @@ class PrefixNamingStrategy implements NamingStrategy
|
||||
return $propertyName.'_'.$embeddedColumnName;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -73,7 +73,7 @@ class ActivityPubObject implements ArrayAccess
|
||||
*
|
||||
* @return array|string Either the object or its id if $depth is < 0
|
||||
*/
|
||||
public function asArray( int $depth = 1 ) {
|
||||
public function asArray( $depth = 1 ) {
|
||||
if ( $depth < 0 && $this->hasField( 'id' ) ) {
|
||||
return $this->getFieldValue( 'id' );
|
||||
}
|
||||
@ -139,7 +139,7 @@ class ActivityPubObject implements ArrayAccess
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasField( string $name )
|
||||
public function hasField( $name )
|
||||
{
|
||||
foreach( $this->getFields() as $field ) {
|
||||
if ( $field->getName() === $name ) {
|
||||
@ -155,13 +155,14 @@ class ActivityPubObject implements ArrayAccess
|
||||
* @param string $name The name of the field to get
|
||||
* @return Field|null
|
||||
*/
|
||||
public function getField( string $name )
|
||||
public function getField( $name )
|
||||
{
|
||||
foreach( $this->getFields() as $field ) {
|
||||
if ( $field->getName() === $name ) {
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -173,7 +174,7 @@ class ActivityPubObject implements ArrayAccess
|
||||
* @return string|ActivityPubObject|null The field's value, or null if
|
||||
* the field is not found
|
||||
*/
|
||||
public function getFieldValue( string $name )
|
||||
public function getFieldValue( $name )
|
||||
{
|
||||
foreach( $this->getFields() as $field ) {
|
||||
if ( $field->getName() === $name ) {
|
||||
@ -206,7 +207,7 @@ class ActivityPubObject implements ArrayAccess
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasReferencingField( string $name )
|
||||
public function hasReferencingField( $name )
|
||||
{
|
||||
foreach( $this->getReferencingFields() as $field ) {
|
||||
if ( $field->getName() === $name ) {
|
||||
@ -222,13 +223,14 @@ class ActivityPubObject implements ArrayAccess
|
||||
* @param string $name The name of the referencing to get
|
||||
* @return Field|null
|
||||
*/
|
||||
public function getReferencingField( string $name )
|
||||
public function getReferencingField( $name )
|
||||
{
|
||||
foreach( $this->getReferencingFields() as $field ) {
|
||||
if ( $field->getName() === $name ) {
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -262,7 +264,7 @@ class ActivityPubObject implements ArrayAccess
|
||||
/**
|
||||
* Removes a field from the object
|
||||
* @param Field $field The field to remove
|
||||
*
|
||||
* @param DateTime|null $time
|
||||
*/
|
||||
public function removeField( Field $field, DateTime $time = null )
|
||||
{
|
||||
@ -299,7 +301,7 @@ class ActivityPubObject implements ArrayAccess
|
||||
*
|
||||
* @param string $key The new private key value
|
||||
*/
|
||||
public function setPrivateKey( string $key )
|
||||
public function setPrivateKey( $key )
|
||||
{
|
||||
if ( $this->hasPrivateKey() ) {
|
||||
$this->privateKey->setKey( $key );
|
||||
@ -353,4 +355,4 @@ class ActivityPubObject implements ArrayAccess
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -84,7 +84,7 @@ class Field
|
||||
* @param string $value The value of the field
|
||||
* @return Field The new field
|
||||
*/
|
||||
public static function withValue( ActivityPubObject $object, string $name, string $value, DateTime $time = null )
|
||||
public static function withValue( ActivityPubObject $object, $name, $value, DateTime $time = null )
|
||||
{
|
||||
if ( ! $time ) {
|
||||
$time = new DateTime( "now" );
|
||||
@ -105,7 +105,7 @@ class Field
|
||||
* @return Field The new field
|
||||
*/
|
||||
public static function withObject( ActivityPubObject $object,
|
||||
string $name,
|
||||
$name,
|
||||
ActivityPubObject $targetObject,
|
||||
DateTime $time = null )
|
||||
{
|
||||
@ -143,12 +143,12 @@ class Field
|
||||
$this->lastUpdated = $time;
|
||||
}
|
||||
|
||||
protected function setName( string $name )
|
||||
protected function setName( $name )
|
||||
{
|
||||
$this->name= $name;
|
||||
}
|
||||
|
||||
public function setValue( string $value, DateTime $time = null )
|
||||
public function setValue( $value, DateTime $time = null )
|
||||
{
|
||||
if ( ! $time ) {
|
||||
$time = new DateTime( "now" );
|
||||
@ -284,4 +284,4 @@ class Field
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -41,7 +41,7 @@ class PrivateKey
|
||||
* @param string $key The private key as a string
|
||||
* @param ActivityPubObject $object The object associated with this key
|
||||
*/
|
||||
public function __construct( string $key, ActivityPubObject $object )
|
||||
public function __construct( $key, ActivityPubObject $object )
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->object = $object;
|
||||
@ -53,9 +53,9 @@ class PrivateKey
|
||||
* Don't call this directly - instead, use ActivityPubObject->setPrivateKey()
|
||||
* @param string $key The private key as a string
|
||||
*/
|
||||
public function setKey( string $key )
|
||||
public function setKey( $key )
|
||||
{
|
||||
$this->key = $key;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -57,4 +57,4 @@ class Router implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -3,9 +3,11 @@ namespace ActivityPub\Objects;
|
||||
|
||||
use ActivityPub\Auth\AuthService;
|
||||
use ActivityPub\Entities\ActivityPubObject;
|
||||
use ActivityPub\Objects\ContextProvider;
|
||||
use ActivityPub\Entities\Field;
|
||||
use ActivityPub\Utils\DateTimeProvider;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Request as Psr7Request;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
@ -32,15 +34,22 @@ class CollectionsService
|
||||
*/
|
||||
private $httpClient;
|
||||
|
||||
public function __construct( int $pageSize,
|
||||
/**
|
||||
* @var DateTimeProvider
|
||||
*/
|
||||
private $dateTimeProvider;
|
||||
|
||||
public function __construct( $pageSize,
|
||||
AuthService $authService,
|
||||
ContextProvider $contextProvider,
|
||||
Client $httpClient )
|
||||
Client $httpClient,
|
||||
DateTimeProvider $dateTimeProvider )
|
||||
{
|
||||
$this->pageSize = $pageSize;
|
||||
$this->authService = $authService;
|
||||
$this->contextProvider = $contextProvider;
|
||||
$this->httpClient = $httpClient;
|
||||
$this->dateTimeProvider = $dateTimeProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,7 +62,7 @@ class CollectionsService
|
||||
{
|
||||
if ( $request->query->has( 'offset' ) ) {
|
||||
return $this->getCollectionPage(
|
||||
$collection, $request, $request->query->get( 'offset' ), $this->pageSize
|
||||
$collection, $request, intval( $request->query->get( 'offset' ) ), $this->pageSize
|
||||
);
|
||||
}
|
||||
$colArr = array();
|
||||
@ -108,6 +117,24 @@ class CollectionsService
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds $item to $collection
|
||||
*
|
||||
* @param ActivityPubObject $collection
|
||||
* @param array $item
|
||||
*/
|
||||
public function addItem( ActivityPubObject $collection, array $item )
|
||||
{
|
||||
if ( ! $collection->hasField( 'items' ) ) {
|
||||
$items = new ActivityPubObject(
|
||||
$this->dateTimeProvider->getTime( 'collections-service.create' )
|
||||
);
|
||||
$itemsField = Field::withObject( $collection, 'items', $items );
|
||||
} else {
|
||||
$items = $collection['items'];
|
||||
}
|
||||
}
|
||||
|
||||
private function getPageItems( array $collectionPage )
|
||||
{
|
||||
$items = array();
|
||||
@ -128,22 +155,22 @@ class CollectionsService
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function fetchPage( string $pageId )
|
||||
private function fetchPage( $pageId )
|
||||
{
|
||||
$request = new Psr7Request( 'GET', $pageId, array(
|
||||
'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
|
||||
) );
|
||||
$response = $this->httpClient->send( $request );
|
||||
if ( $response->getStatusCode() !== 200 || empty( $response->getBody() ) ) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
return json_decode( $response->getBody(), true );
|
||||
}
|
||||
|
||||
private function getCollectionPage( ActivityPubObject $collection,
|
||||
Request $request,
|
||||
int $offset,
|
||||
int $pageSize )
|
||||
$offset,
|
||||
$pageSize )
|
||||
{
|
||||
$itemsKey = 'items';
|
||||
$pageType = 'CollectionPage';
|
||||
@ -162,7 +189,7 @@ class CollectionsService
|
||||
$idx = $offset;
|
||||
$count = 0;
|
||||
while ( $count < $pageSize ) {
|
||||
$item = $collectionItems->getFieldValue( $idx );
|
||||
$item = $collectionItems->getFieldValue( strval( $idx ) );
|
||||
if ( ! $item ) {
|
||||
break;
|
||||
}
|
||||
@ -196,16 +223,16 @@ class CollectionsService
|
||||
return $page;
|
||||
}
|
||||
|
||||
private function hasNextItem( $request, $collectionItems, $idx )
|
||||
private function hasNextItem( Request $request, ActivityPubObject $collectionItems, $idx )
|
||||
{
|
||||
$next = $collectionItems->getFieldValue( $idx );
|
||||
$next = $collectionItems->getFieldValue( strval( $idx ) );
|
||||
while ( $next ) {
|
||||
if ( is_string( $next ) ||
|
||||
$this->authService->isAuthorized( $request, $next ) ) {
|
||||
return $idx;
|
||||
}
|
||||
$idx++;
|
||||
$next = $collectionsItems->getFieldValue( $idx );
|
||||
$next = $collectionItems->getFieldValue( strval( $idx ) );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -223,4 +250,4 @@ class CollectionsService
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -3,17 +3,12 @@ namespace ActivityPub\Objects;
|
||||
|
||||
class ContextProvider
|
||||
{
|
||||
const DEFAULT_CONTEXT = array(
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://w3id.org/security/v1',
|
||||
);
|
||||
|
||||
private $ctx;
|
||||
|
||||
public function __construct( $ctx = null )
|
||||
{
|
||||
if ( ! $ctx ) {
|
||||
$ctx = self::DEFAULT_CONTEXT;
|
||||
$ctx = self::getDefaultContext();
|
||||
}
|
||||
$this->ctx = $ctx;
|
||||
}
|
||||
@ -22,5 +17,13 @@ class ContextProvider
|
||||
{
|
||||
return $this->ctx;
|
||||
}
|
||||
|
||||
public static function getDefaultContext()
|
||||
{
|
||||
return array(
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://w3id.org/security/v1',
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -33,7 +33,7 @@ class IdProvider
|
||||
|
||||
public function __construct( ObjectsService $objectsService,
|
||||
RandomProvider $randomProvider,
|
||||
string $pathPrefix )
|
||||
$pathPrefix )
|
||||
{
|
||||
$this->objectsService = $objectsService;
|
||||
$this->randomProvider = $randomProvider;
|
||||
@ -49,7 +49,7 @@ class IdProvider
|
||||
* and after the path prefix. Default: "object"
|
||||
* @return string The new id
|
||||
*/
|
||||
public function getId( Request $request, string $path = "objects" )
|
||||
public function getId( Request $request, $path = "objects" )
|
||||
{
|
||||
$baseUri = $request->getSchemeAndHttpHost();
|
||||
if ( ! empty( $path ) ) {
|
||||
@ -66,4 +66,4 @@ class IdProvider
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -7,6 +7,7 @@ use ActivityPub\Entities\Field;
|
||||
use ActivityPub\Utils\Util;
|
||||
use ActivityPub\Utils\DateTimeProvider;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
|
||||
@ -47,7 +48,7 @@ class ObjectsService
|
||||
*
|
||||
* @return ActivityPubObject The created object
|
||||
*/
|
||||
public function persist( array $fields, string $context = 'objects-service.create' )
|
||||
public function persist( array $fields, $context = 'objects-service.create' )
|
||||
{
|
||||
// TODO should I do JSON-LD compaction here?
|
||||
if ( array_key_exists( 'id', $fields ) ) {
|
||||
@ -62,6 +63,7 @@ class ObjectsService
|
||||
foreach ( $fields as $name => $value ) {
|
||||
$this->persistField( $object, $name, $value, $context );
|
||||
}
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$this->entityManager->flush();
|
||||
return $object;
|
||||
}
|
||||
@ -129,11 +131,11 @@ class ObjectsService
|
||||
) );
|
||||
$response = $this->httpClient->send( $request );
|
||||
if ( $response->getStatusCode() !== 200 || empty( $response->getBody() ) ) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
$object = json_decode( $response->getBody(), true );
|
||||
if ( ! $object ) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
return $this->persist( $object );
|
||||
}
|
||||
@ -225,6 +227,7 @@ class ObjectsService
|
||||
if ( ! empty( $results ) ) {
|
||||
return $results[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -246,7 +249,7 @@ class ObjectsService
|
||||
{
|
||||
$object = $this->getObject( $id );
|
||||
if ( ! $object ) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
foreach( $updatedFields as $fieldName => $newValue ) {
|
||||
if ( $newValue === null && $object->hasField( $fieldName ) ) {
|
||||
@ -306,7 +309,7 @@ class ObjectsService
|
||||
{
|
||||
$existing = $this->getObject( $id );
|
||||
if ( ! $existing ) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
foreach ( $existing->getFields() as $field ) {
|
||||
if ( ! array_key_exists( $field->getName(), $replacement ) ) {
|
||||
@ -316,4 +319,4 @@ class ObjectsService
|
||||
return $this->update( $id, $replacement );
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace ActivityPub\Utils;
|
||||
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* An interface to provide DateTime objects, so that DateTimes can be fixed in tests
|
||||
*/
|
||||
@ -15,4 +17,4 @@ interface DateTimeProvider
|
||||
*/
|
||||
public function getTime( $context = '' );
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -13,7 +13,7 @@ class RandomProvider
|
||||
* @param int $length The length of the random string to generate
|
||||
* @return string
|
||||
*/
|
||||
public function randomString( int $length )
|
||||
public function randomString( $length )
|
||||
{
|
||||
$str = '';
|
||||
for ( $i = 0; $i < $length; $i++ ) {
|
||||
@ -22,4 +22,4 @@ class RandomProvider
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -18,4 +18,4 @@ class SimpleDateTimeProvider implements DateTimeProvider
|
||||
return new DateTime( "now" );
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -32,4 +32,4 @@ class Util
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -10,26 +10,28 @@ use ActivityPub\Objects\ContextProvider;
|
||||
use ActivityPub\Objects\IdProvider;
|
||||
use ActivityPub\Objects\ObjectsService;
|
||||
use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
||||
use ActivityPub\Utils\SimpleDateTimeProvider;
|
||||
use GuzzleHttp\Client;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class CreateHandlerTest extends TestCase
|
||||
class CreateHandlerTest extends APTestCase
|
||||
{
|
||||
private $eventDispatcher;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->eventDispatcher = new EventDispatcher();
|
||||
$objectsService = $this->createMock( ObjectsService::class );
|
||||
$idProvider = $this->createMock( IdProvider::class );
|
||||
$objectsService = $this->getMock( ObjectsService::class );
|
||||
$idProvider = $this->getMock( IdProvider::class );
|
||||
// TODO provision mocks
|
||||
$collectionsService = new CollectionsService(
|
||||
4,
|
||||
$this->createMock( AuthService::class ),
|
||||
$this->getMock( AuthService::class ),
|
||||
new ContextProvider(),
|
||||
$this->createMock( Client::class )
|
||||
$this->getMock( Client::class ),
|
||||
new SimpleDateTimeProvider()
|
||||
);
|
||||
$createHandler = new CreateHandler(
|
||||
$objectsService, $idProvider, $collectionsService
|
||||
@ -259,4 +261,4 @@ class CreateHandlerTest extends TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -8,25 +8,28 @@ use ActivityPub\Objects\ObjectsService;
|
||||
use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
||||
use ActivityPub\Test\TestUtils\TestDateTimeProvider;
|
||||
use DateTime;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
class DeleteHandlerTest extends TestCase
|
||||
class DeleteHandlerTest extends APTestCase
|
||||
{
|
||||
const OBJECTS = array(
|
||||
'https://elsewhere.com/objects/1' => array(
|
||||
'id' => 'https://elsewhere.com/objects/1',
|
||||
'type' => 'Note',
|
||||
'attributedTo' => 'https://elsewhere.com/actors/1',
|
||||
),
|
||||
'https://example.com/objects/1' => array(
|
||||
'id' => 'https://example.com/objects/1',
|
||||
'type' => 'Note',
|
||||
'attributedTo' => 'https://example.com/actors/1',
|
||||
)
|
||||
);
|
||||
private static function getObjects()
|
||||
{
|
||||
return array(
|
||||
'https://elsewhere.com/objects/1' => array(
|
||||
'id' => 'https://elsewhere.com/objects/1',
|
||||
'type' => 'Note',
|
||||
'attributedTo' => 'https://elsewhere.com/actors/1',
|
||||
),
|
||||
'https://example.com/objects/1' => array(
|
||||
'id' => 'https://example.com/objects/1',
|
||||
'type' => 'Note',
|
||||
'attributedTo' => 'https://example.com/actors/1',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testDeleteHandler()
|
||||
{
|
||||
@ -141,13 +144,15 @@ class DeleteHandlerTest extends TestCase
|
||||
->getMock();
|
||||
$objectsService->method( 'dereference' )->will( $this->returnCallback(
|
||||
function( $id ) {
|
||||
if ( array_key_exists( $id, self::OBJECTS ) ) {
|
||||
return TestActivityPubObject::fromArray( self::OBJECTS[$id] );
|
||||
if ( array_key_exists( $id, self::getObjects()) ) {
|
||||
$objects = self::getObjects();
|
||||
return TestActivityPubObject::fromArray( $objects[$id] );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
) );
|
||||
if ( array_key_exists( 'expectedException', $testCase ) ) {
|
||||
$this->expectException( $testCase['expectedException'] );
|
||||
$this->setExpectedException( $testCase['expectedException'] );
|
||||
} else {
|
||||
$objectsService->expects( $this->once() )
|
||||
->method( 'replace' )
|
||||
@ -169,4 +174,4 @@ class DeleteHandlerTest extends TestCase
|
||||
return $request;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -6,11 +6,11 @@ use ActivityPub\Activities\InboxActivityEvent;
|
||||
use ActivityPub\Activities\OutboxActivityEvent;
|
||||
use ActivityPub\Objects\ContextProvider;
|
||||
use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class FollowHandlerTest extends TestCase
|
||||
class FollowHandlerTest extends APTestCase
|
||||
{
|
||||
public function testFollowHandler()
|
||||
{
|
||||
@ -29,12 +29,12 @@ class FollowHandlerTest extends TestCase
|
||||
'object' => 'https://example.com/actor/1',
|
||||
);
|
||||
$eventDispatcher->addListener( OutboxActivityEvent::NAME, function( $event, $name )
|
||||
use ( &$outboxDispatched, $actor )
|
||||
use ( &$outboxDispatched, $actor, $follow )
|
||||
{
|
||||
$this->assertEquals( OutboxActivityEvent::NAME, $name );
|
||||
$outboxDispatched = true;
|
||||
$accept = array(
|
||||
'@context' => ContextProvider::DEFAULT_CONTEXT,
|
||||
'@context' => ContextProvider::getDefaultContext(),
|
||||
'type' => 'Accept',
|
||||
'actor' => 'https://example.com/actor/1',
|
||||
'object' => 'https://elsewhere.com/activities/1',
|
||||
@ -49,7 +49,10 @@ class FollowHandlerTest extends TestCase
|
||||
),
|
||||
json_encode( $accept )
|
||||
);
|
||||
$expectedRequest->attributes->set( 'actor', $actor );
|
||||
$expectedRequest->attributes->add( array(
|
||||
'actor' => $actor,
|
||||
'follow' => $follow,
|
||||
) );
|
||||
$this->assertEquals(
|
||||
new OutboxActivityEvent( $accept, $actor, $expectedRequest ), $event
|
||||
);
|
||||
@ -91,4 +94,4 @@ class FollowHandlerTest extends TestCase
|
||||
$this->assertFalse( $outboxDispatched );
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -5,10 +5,10 @@ use ActivityPub\Activities\OutboxActivityEvent;
|
||||
use ActivityPub\Activities\NonActivityHandler;
|
||||
use ActivityPub\Objects\ContextProvider;
|
||||
use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class NonActivityHandlerTest extends TestCase
|
||||
class NonActivityHandlerTest extends APTestCase
|
||||
{
|
||||
public function testNonActivityHandler()
|
||||
{
|
||||
@ -24,7 +24,7 @@ class NonActivityHandlerTest extends TestCase
|
||||
'id' => 'https://example.com/actor/1',
|
||||
) ),
|
||||
'expectedActivity' => array(
|
||||
'@context' => ContextProvider::DEFAULT_CONTEXT,
|
||||
'@context' => ContextProvider::getDefaultContext(),
|
||||
'type' => 'Create',
|
||||
'actor' => 'https://example.com/actor/1',
|
||||
'object' => array(
|
||||
@ -62,7 +62,7 @@ class NonActivityHandlerTest extends TestCase
|
||||
'id' => 'https://example.com/actor/1',
|
||||
) ),
|
||||
'expectedActivity' => array(
|
||||
'@context' => ContextProvider::DEFAULT_CONTEXT,
|
||||
'@context' => ContextProvider::getDefaultContext(),
|
||||
'type' => 'Create',
|
||||
'actor' => 'https://example.com/actor/1',
|
||||
'object' => array(
|
||||
@ -103,4 +103,4 @@ class NonActivityHandlerTest extends TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -6,45 +6,55 @@ use ActivityPub\Activities\OutboxActivityEvent;
|
||||
use ActivityPub\Activities\UpdateHandler;
|
||||
use ActivityPub\Objects\ObjectsService;
|
||||
use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
class UpdateHandlerTest extends TestCase
|
||||
class UpdateHandlerTest extends APTestCase
|
||||
{
|
||||
const OBJECTS = array(
|
||||
'https://elsewhere.com/objects/1' => array(
|
||||
'id' => 'https://elsewhere.com/objects/1',
|
||||
'attributedTo' => 'https://elsewhere.com/actors/1',
|
||||
),
|
||||
'https://example.com/objects/1' => array(
|
||||
'id' => 'https://example.com/objects/1',
|
||||
'attributedTo' => 'https://example.com/actors/1',
|
||||
'type' => 'Note',
|
||||
'content' => 'This is a note',
|
||||
),
|
||||
);
|
||||
private static function getObjects()
|
||||
{
|
||||
return array(
|
||||
'https://elsewhere.com/objects/1' => array(
|
||||
'id' => 'https://elsewhere.com/objects/1',
|
||||
'attributedTo' => 'https://elsewhere.com/actors/1',
|
||||
),
|
||||
'https://example.com/objects/1' => array(
|
||||
'id' => 'https://example.com/objects/1',
|
||||
'attributedTo' => 'https://example.com/actors/1',
|
||||
'type' => 'Note',
|
||||
'content' => 'This is a note',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var EventDispatcher
|
||||
*/
|
||||
private $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $objects;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$objectsService = $this->createMock( ObjectsService::class );
|
||||
$this->objects = self::getObjects();
|
||||
$objectsService = $this->getMock( ObjectsService::class );
|
||||
$objectsService->method( 'dereference' )->will( $this->returnCallback(
|
||||
function( $id ) {
|
||||
if ( array_key_exists( $id, self::OBJECTS ) ) {
|
||||
return TestActivityPubObject::fromArray( self::OBJECTS[$id] );
|
||||
if ( array_key_exists( $id, $this->objects ) ) {
|
||||
return TestActivityPubObject::fromArray( $this->objects[$id] );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
) );
|
||||
$objectsService->method( 'update' )->will( $this->returnCallback(
|
||||
function( $id, $updateFields ) {
|
||||
if ( array_key_exists( $id, self::OBJECTS ) ) {
|
||||
$existing = self::OBJECTS[$id];
|
||||
if ( array_key_exists( $id, $this->objects ) ) {
|
||||
$existing = $this->objects[$id];
|
||||
foreach ( $updateFields as $field => $newValue ) {
|
||||
if ( $newValue === null && array_key_exists( $field, $existing ) ) {
|
||||
unset( $existing[$field] );
|
||||
@ -54,6 +64,7 @@ class UpdateHandlerTest extends TestCase
|
||||
}
|
||||
return TestActivityPubObject::fromArray( $existing );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
) );
|
||||
$updateHandler = new UpdateHandler( $objectsService );
|
||||
@ -204,7 +215,7 @@ class UpdateHandlerTest extends TestCase
|
||||
foreach ( $testCases as $testCase ) {
|
||||
$event = $testCase['event'];
|
||||
if ( array_key_exists( 'expectedException', $testCase ) ) {
|
||||
$this->expectException( $testCase['expectedException'] );
|
||||
$this->setExpectedException( $testCase['expectedException'] );
|
||||
}
|
||||
$this->eventDispatcher->dispatch( $testCase['eventName'], $event );
|
||||
if ( array_key_exists( 'expectedEvent', $testCase ) ) {
|
||||
@ -222,4 +233,4 @@ class UpdateHandlerTest extends TestCase
|
||||
return $request;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -5,12 +5,12 @@ use ActivityPub\Activities\InboxActivityEvent;
|
||||
use ActivityPub\Activities\OutboxActivityEvent;
|
||||
use ActivityPub\Activities\ValidationHandler;
|
||||
use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
class ValidationHandlerTest extends TestCase
|
||||
class ValidationHandlerTest extends APTestCase
|
||||
{
|
||||
/**
|
||||
* @var EventDispatcher
|
||||
@ -161,19 +161,16 @@ class ValidationHandlerTest extends TestCase
|
||||
foreach ( $testCases as $testCase ) {
|
||||
$event = $testCase['event'];
|
||||
if ( array_key_exists( 'expectedException', $testCase ) ) {
|
||||
$this->expectException(
|
||||
$testCase['expectedException'],
|
||||
"Error on test $testCase[id]"
|
||||
);
|
||||
}
|
||||
if ( array_key_exists( 'expectedExceptionMessage', $testCase ) ) {
|
||||
$this->expectExceptionMessage(
|
||||
$testCase['expectedExceptionMessage'],
|
||||
"Error on test $testCase[id]"
|
||||
$expectedExceptionMessage = '';
|
||||
if ( array_key_exists( 'expectedExceptionMessage', $testCase )) {
|
||||
$expectedExceptionMessage = $testCase['expectedExceptionMessage'];
|
||||
}
|
||||
$this->setExpectedException(
|
||||
$testCase['expectedException'], $expectedExceptionMessage
|
||||
);
|
||||
}
|
||||
$this->eventDispatcher->dispatch( $testCase['eventName'], $event );
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -35,4 +35,4 @@ class ActivityPubTest extends SQLiteTestCase
|
||||
return dirname( __FILE__ ) . '/db.sqlite';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -8,15 +8,15 @@ use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
|
||||
class AuthListenerTest extends TestCase
|
||||
class AuthListenerTest extends APTestCase
|
||||
{
|
||||
private $objectsService;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->objectsService = $this->createMock( ObjectsService::class );
|
||||
$this->objectsService = $this->getMock( ObjectsService::class );
|
||||
$this->objectsService->method( 'dereference' )->will( $this->returnValueMap( array(
|
||||
array( 'https://example.com/actor/1', TestActivityPubObject::fromArray( array(
|
||||
'id' => 'https://example.com/actor/1',
|
||||
@ -29,7 +29,7 @@ class AuthListenerTest extends TestCase
|
||||
|
||||
public function getEvent()
|
||||
{
|
||||
$kernel = $this->createMock( HttpKernelInterface::class );
|
||||
$kernel = $this->getMock( HttpKernelInterface::class );
|
||||
$request = Request::create( 'https://example.com/foo', Request::METHOD_GET );
|
||||
return new GetResponseEvent(
|
||||
$kernel, $request, HttpKernelInterface::MASTER_REQUEST
|
||||
@ -108,4 +108,4 @@ class AuthListenerTest extends TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -3,10 +3,10 @@ namespace ActivityPub\Test\Auth;
|
||||
|
||||
use ActivityPub\Auth\AuthService;
|
||||
use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class AuthServiceTest extends TestCase
|
||||
class AuthServiceTest extends APTestCase
|
||||
{
|
||||
private $authService;
|
||||
|
||||
@ -72,4 +72,4 @@ class AuthServiceTest extends TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -12,12 +12,11 @@ use ActivityPub\Test\TestUtils\TestDateTimeProvider;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
|
||||
class SignatureListenerTest extends TestCase
|
||||
class SignatureListenerTest extends APTestCase
|
||||
{
|
||||
const ACTOR_ID = 'https://example.com/actor/1';
|
||||
const ACTOR = array( 'id' => self::ACTOR_ID );
|
||||
const KEY_ID = 'https://example.com/actor/1/key';
|
||||
const PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----
|
||||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCFENGw33yGihy92pDjZQhl0C3
|
||||
@ -25,14 +24,26 @@ MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCFENGw33yGihy92pDjZQhl0C3
|
||||
Z4UMR7EOcpfdUE9Hf3m/hs+FUR45uBJeDK1HSFHD8bHKD6kv8FPGfJTotc+2xjJw
|
||||
oYi+1hqp1fIekaxsyQIDAQAB
|
||||
-----END PUBLIC KEY-----";
|
||||
const KEY = array(
|
||||
'id' => self::KEY_ID,
|
||||
'owner' => 'https://example.com/actor/1',
|
||||
'publicKeyPem' => self::PUBLIC_KEY,
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* @var SignatureListener
|
||||
*/
|
||||
private $signatureListener;
|
||||
|
||||
private static function getActor()
|
||||
{
|
||||
return array( 'id' => self::ACTOR_ID );
|
||||
}
|
||||
|
||||
private static function getKey()
|
||||
{
|
||||
return array(
|
||||
'id' => self::KEY_ID,
|
||||
'owner' => 'https://example.com/actor/1',
|
||||
'publicKeyPem' => self::PUBLIC_KEY,
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$dateTimeProvider = new TestDateTimeProvider( array(
|
||||
@ -41,11 +52,11 @@ oYi+1hqp1fIekaxsyQIDAQAB
|
||||
),
|
||||
) );
|
||||
$httpSignatureService = new HttpSignatureService( $dateTimeProvider );
|
||||
$objectsService = $this->createMock( ObjectsService::class );
|
||||
$objectsService = $this->getMock( ObjectsService::class );
|
||||
$objectsService->method( 'dereference' )
|
||||
->will( $this->returnValueMap( array(
|
||||
array( self::KEY_ID, TestActivityPubObject::fromArray( self::KEY ) ),
|
||||
array( self::ACTOR_ID, TestActivityPubObject::fromArray( self::ACTOR ) ),
|
||||
array( self::KEY_ID, TestActivityPubObject::fromArray( self::getKey()) ),
|
||||
array( self::ACTOR_ID, TestActivityPubObject::fromArray( self::getActor()) ),
|
||||
) ) );
|
||||
$this->signatureListener = new SignatureListener(
|
||||
$httpSignatureService, $objectsService
|
||||
@ -54,7 +65,7 @@ oYi+1hqp1fIekaxsyQIDAQAB
|
||||
|
||||
private function getEvent()
|
||||
{
|
||||
$kernel = $this->createMock( HttpKernelInterface::class );
|
||||
$kernel = $this->getMock( HttpKernelInterface::class );
|
||||
$request = Request::create(
|
||||
'https://example.com/foo?param=value&pet=dog',
|
||||
Request::METHOD_POST,
|
||||
@ -145,4 +156,4 @@ oYi+1hqp1fIekaxsyQIDAQAB
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -5,9 +5,9 @@ use ActivityPub\Config\ActivityPubConfig;
|
||||
use ActivityPub\Config\ActivityPubModule;
|
||||
use ActivityPub\Http\Router;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
|
||||
class ActivityPubModuleTest extends TestCase
|
||||
class ActivityPubModuleTest extends APTestCase
|
||||
{
|
||||
private $module;
|
||||
|
||||
@ -33,4 +33,4 @@ class ActivityPubModuleTest extends TestCase
|
||||
$this->assertInstanceOf( Router::class, $router );
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -9,69 +9,85 @@ use ActivityPub\Objects\ContextProvider;
|
||||
use ActivityPub\Objects\CollectionsService;
|
||||
use ActivityPub\Objects\ObjectsService;
|
||||
use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
||||
use ActivityPub\Utils\SimpleDateTimeProvider;
|
||||
use GuzzleHttp\Client;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
|
||||
class GetControllerTest extends TestCase
|
||||
class GetControllerTest extends APTestCase
|
||||
{
|
||||
const OBJECTS = array(
|
||||
'https://example.com/objects/1' => array(
|
||||
'id' => 'https://example.com/objects/1',
|
||||
'object' => array(
|
||||
'id' => 'https://example.com/objects/2',
|
||||
'type' => 'Note',
|
||||
private static function getObjects()
|
||||
{
|
||||
return array(
|
||||
'https://example.com/objects/1' => array(
|
||||
'id' => 'https://example.com/objects/1',
|
||||
'object' => array(
|
||||
'id' => 'https://example.com/objects/2',
|
||||
'type' => 'Note',
|
||||
),
|
||||
'audience' => array( 'https://www.w3.org/ns/activitystreams#Public' ),
|
||||
'type' => 'Create',
|
||||
),
|
||||
'audience' => array( 'https://www.w3.org/ns/activitystreams#Public' ),
|
||||
'type' => 'Create',
|
||||
),
|
||||
'https://example.com/objects/2' => array(
|
||||
'id' => 'https://example.com/objects/2',
|
||||
'object' => array(
|
||||
'https://example.com/objects/2' => array(
|
||||
'id' => 'https://example.com/objects/2',
|
||||
'object' => array(
|
||||
'id' => 'https://example.com/objects/3',
|
||||
'type' => 'Note',
|
||||
),
|
||||
'to' => array( 'https://example.com/actor/1' ),
|
||||
'type' => 'Create',
|
||||
'actor' => array(
|
||||
'id' => 'https://example.com/actor/2',
|
||||
),
|
||||
),
|
||||
'https://example.com/objects/3' => array(
|
||||
'id' => 'https://example.com/objects/3',
|
||||
'type' => 'Note',
|
||||
'object' => array(
|
||||
'id' => 'https://example.com/objects/2',
|
||||
'type' => 'Note',
|
||||
),
|
||||
'type' => 'Like',
|
||||
'actor' => array(
|
||||
'id' => 'https://example.com/actor/2',
|
||||
),
|
||||
),
|
||||
'to' => array( 'https://example.com/actor/1' ),
|
||||
'type' => 'Create',
|
||||
'actor' => array(
|
||||
'id' => 'https://example.com/actor/2',
|
||||
'https://example.com/objects/4' => array(
|
||||
'id' => 'https://example.com/objects/4',
|
||||
'type' => 'Tombstone',
|
||||
),
|
||||
),
|
||||
'https://example.com/objects/3' => array(
|
||||
'id' => 'https://example.com/objects/3',
|
||||
'object' => array(
|
||||
'id' => 'https://example.com/objects/2',
|
||||
'type' => 'Note',
|
||||
),
|
||||
'type' => 'Like',
|
||||
'actor' => array(
|
||||
'id' => 'https://example.com/actor/2',
|
||||
),
|
||||
),
|
||||
'https://example.com/objects/4' => array(
|
||||
'id' => 'https://example.com/objects/4',
|
||||
'type' => 'Tombstone',
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var GetController
|
||||
*/
|
||||
private $getController;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $objects;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$objectsService = $this->createMock( ObjectsService::class );
|
||||
$this->objects = self::getObjects();
|
||||
$objectsService = $this->getMock( ObjectsService::class );
|
||||
$objectsService->method( 'dereference' )->will(
|
||||
$this->returnCallback( function( $uri ) {
|
||||
if ( array_key_exists( $uri, self::OBJECTS ) ) {
|
||||
return TestActivityPubObject::fromArray( self::OBJECTS[$uri] );
|
||||
if ( array_key_exists( $uri, $this->objects) ) {
|
||||
return TestActivityPubObject::fromArray( $this->objects[$uri] );
|
||||
}
|
||||
return null;
|
||||
})
|
||||
);
|
||||
$authService = new AuthService();
|
||||
$contextProvider = new ContextProvider();
|
||||
$httpClient = $this->createMock( Client::class );
|
||||
$collectionsService = new CollectionsService( 4, $authService, $contextProvider, $httpClient );
|
||||
$httpClient = $this->getMock( Client::class );
|
||||
$collectionsService = new CollectionsService(
|
||||
4, $authService, $contextProvider, $httpClient, new SimpleDateTimeProvider()
|
||||
);
|
||||
$this->getController = new GetController(
|
||||
$objectsService, $collectionsService, $authService
|
||||
);
|
||||
@ -83,7 +99,7 @@ class GetControllerTest extends TestCase
|
||||
$response = $this->getController->handle( $request );
|
||||
$this->assertNotNull( $response );
|
||||
$this->assertEquals(
|
||||
json_encode( self::OBJECTS['https://example.com/objects/1'] ),
|
||||
json_encode( $this->objects['https://example.com/objects/1'] ),
|
||||
$response->getContent()
|
||||
);
|
||||
$this->assertEquals( 'application/json', $response->headers->get( 'Content-Type' ) );
|
||||
@ -92,14 +108,14 @@ class GetControllerTest extends TestCase
|
||||
public function testItThrowsNotFound()
|
||||
{
|
||||
$request = Request::create( 'https://example.com/objects/notreal' );
|
||||
$this->expectException( NotFoundHttpException::class );
|
||||
$this->setExpectedException( NotFoundHttpException::class );
|
||||
$this->getController->handle( $request );
|
||||
}
|
||||
|
||||
public function testItDeniesAccess()
|
||||
{
|
||||
$request = Request::create( 'https://example.com/objects/2' );
|
||||
$this->expectException( UnauthorizedHttpException::class );
|
||||
$this->setExpectedException( UnauthorizedHttpException::class );
|
||||
$this->getController->handle( $request );
|
||||
}
|
||||
|
||||
@ -110,7 +126,7 @@ class GetControllerTest extends TestCase
|
||||
$response = $this->getController->handle( $request );
|
||||
$this->assertNotNull( $response );
|
||||
$this->assertEquals(
|
||||
json_encode( self::OBJECTS['https://example.com/objects/2'] ),
|
||||
json_encode( $this->objects['https://example.com/objects/2'] ),
|
||||
$response->getContent()
|
||||
);
|
||||
$this->assertEquals( 'application/json', $response->headers->get( 'Content-Type' ) );
|
||||
@ -123,7 +139,7 @@ class GetControllerTest extends TestCase
|
||||
$response = $this->getController->handle( $request );
|
||||
$this->assertNotNull( $response );
|
||||
$this->assertEquals(
|
||||
json_encode( self::OBJECTS['https://example.com/objects/2'] ),
|
||||
json_encode( $this->objects['https://example.com/objects/2'] ),
|
||||
$response->getContent()
|
||||
);
|
||||
$this->assertEquals( 'application/json', $response->headers->get( 'Content-Type' ) );
|
||||
@ -135,7 +151,7 @@ class GetControllerTest extends TestCase
|
||||
$response = $this->getController->handle( $request );
|
||||
$this->assertNotNull( $response );
|
||||
$this->assertEquals(
|
||||
json_encode( self::OBJECTS['https://example.com/objects/3'] ),
|
||||
json_encode( $this->objects['https://example.com/objects/3'] ),
|
||||
$response->getContent()
|
||||
);
|
||||
$this->assertEquals( 'application/json', $response->headers->get( 'Content-Type' ) );
|
||||
@ -147,7 +163,7 @@ class GetControllerTest extends TestCase
|
||||
$response = $this->getController->handle( $request );
|
||||
$this->assertNotNull( $response );
|
||||
$this->assertEquals(
|
||||
json_encode( self::OBJECTS['https://example.com/objects/1'] ),
|
||||
json_encode( $this->objects['https://example.com/objects/1'] ),
|
||||
$response->getContent()
|
||||
);
|
||||
$this->assertEquals( 'application/json', $response->headers->get( 'Content-Type' ) );
|
||||
@ -159,11 +175,11 @@ class GetControllerTest extends TestCase
|
||||
$response = $this->getController->handle( $request );
|
||||
$this->assertNotNull( $response );
|
||||
$this->assertEquals(
|
||||
json_encode( self::OBJECTS['https://example.com/objects/4'] ),
|
||||
json_encode( $this->objects['https://example.com/objects/4'] ),
|
||||
$response->getContent()
|
||||
);
|
||||
$this->assertEquals( 'application/json', $response->headers->get( 'Content-Type' ) );
|
||||
$this->assertEquals( 410, $response->getStatusCode() );
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -6,60 +6,78 @@ use ActivityPub\Activities\OutboxActivityEvent;
|
||||
use ActivityPub\Controllers\PostController;
|
||||
use ActivityPub\Objects\ObjectsService;
|
||||
use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
class PostControllerTest extends TestCase
|
||||
class PostControllerTest extends APTestCase
|
||||
{
|
||||
const OBJECTS = array(
|
||||
'https://example.com/actor/1/inbox' => array(
|
||||
'id' => 'https://example.com/actor/1/inbox',
|
||||
),
|
||||
'https://example.com/actor/1/outbox' => array(
|
||||
'id' => 'https://example.com/actor/1/outbox',
|
||||
),
|
||||
'https://example.com/actor/1' => array(
|
||||
'id' => 'https://example.com/actor/1',
|
||||
'inbox' => array(
|
||||
private static function getObjects()
|
||||
{
|
||||
return array(
|
||||
'https://example.com/actor/1/inbox' => array(
|
||||
'id' => 'https://example.com/actor/1/inbox',
|
||||
),
|
||||
'outbox' => array(
|
||||
'https://example.com/actor/1/outbox' => array(
|
||||
'id' => 'https://example.com/actor/1/outbox',
|
||||
),
|
||||
),
|
||||
'https://elsewhere.com/actor/1' => array(
|
||||
'id' => 'https://elsewhere.com/actor/1',
|
||||
),
|
||||
);
|
||||
const REFS = array(
|
||||
'https://example.com/actor/1/inbox' => array(
|
||||
'field' => 'inbox',
|
||||
'referencingObject' => 'https://example.com/actor/1',
|
||||
),
|
||||
'https://example.com/actor/1/outbox' => array(
|
||||
'field' => 'outbox',
|
||||
'referencingObject' => 'https://example.com/actor/1',
|
||||
),
|
||||
);
|
||||
'https://example.com/actor/1' => array(
|
||||
'id' => 'https://example.com/actor/1',
|
||||
'inbox' => array(
|
||||
'id' => 'https://example.com/actor/1/inbox',
|
||||
),
|
||||
'outbox' => array(
|
||||
'id' => 'https://example.com/actor/1/outbox',
|
||||
),
|
||||
),
|
||||
'https://elsewhere.com/actor/1' => array(
|
||||
'id' => 'https://elsewhere.com/actor/1',
|
||||
),
|
||||
);
|
||||
}
|
||||
private static function getRefs()
|
||||
{
|
||||
return array(
|
||||
'https://example.com/actor/1/inbox' => array(
|
||||
'field' => 'inbox',
|
||||
'referencingObject' => 'https://example.com/actor/1',
|
||||
),
|
||||
'https://example.com/actor/1/outbox' => array(
|
||||
'field' => 'outbox',
|
||||
'referencingObject' => 'https://example.com/actor/1',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $objects;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $refs;
|
||||
|
||||
public function testPostController()
|
||||
{
|
||||
$objectsService = $this->createMock( ObjectsService::class );
|
||||
$this->objects = self::getObjects();
|
||||
$this->refs = self::getRefs();
|
||||
$objectsService = $this->getMock( ObjectsService::class );
|
||||
$objectsService->method( 'query' )->will(
|
||||
$this->returnCallback( function( $query ) {
|
||||
if ( array_key_exists( 'id', $query ) &&
|
||||
array_key_exists( $query['id'], self::OBJECTS ) ) {
|
||||
array_key_exists( $query['id'], $this->objects ) ) {
|
||||
$object = TestActivityPubObject::fromArray(
|
||||
self::OBJECTS[$query['id']]
|
||||
$this->objects[$query['id']]
|
||||
);
|
||||
if ( array_key_exists( $query['id'], self::REFS ) ) {
|
||||
$ref = self::REFS[$query['id']];
|
||||
if ( array_key_exists( $query['id'], $this->refs ) ) {
|
||||
$ref = $this->refs[$query['id']];
|
||||
$referencingObject = TestActivityPubObject::fromArray(
|
||||
self::OBJECTS[$ref['referencingObject']]
|
||||
$this->objects[$ref['referencingObject']]
|
||||
);
|
||||
$referencingField = $referencingObject->getField( $ref['field'] );
|
||||
$object->addReferencingField( $referencingField );
|
||||
@ -72,8 +90,8 @@ class PostControllerTest extends TestCase
|
||||
);
|
||||
$objectsService->method( 'dereference' )->will(
|
||||
$this->returnCallback( function( $id ) {
|
||||
if ( array_key_exists( $id, self::OBJECTS ) ) {
|
||||
return TestActivityPubObject::fromArray( self::OBJECTS[$id] );
|
||||
if ( array_key_exists( $id, $this->objects ) ) {
|
||||
return TestActivityPubObject::fromArray( $this->objects[$id] );
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -89,7 +107,7 @@ class PostControllerTest extends TestCase
|
||||
array(
|
||||
'signed' => true,
|
||||
'actor' => TestActivityPubObject::fromArray(
|
||||
self::OBJECTS['https://elsewhere.com/actor/1']
|
||||
$this->objects['https://elsewhere.com/actor/1']
|
||||
),
|
||||
)
|
||||
),
|
||||
@ -100,7 +118,7 @@ class PostControllerTest extends TestCase
|
||||
'actor' => 'https://elsewhere.com/actor/1'
|
||||
),
|
||||
TestActivityPubObject::fromArray(
|
||||
self::OBJECTS['https://example.com/actor/1']
|
||||
$this->objects['https://example.com/actor/1']
|
||||
),
|
||||
$this->makeRequest(
|
||||
'https://example.com/actor/1/inbox',
|
||||
@ -109,7 +127,7 @@ class PostControllerTest extends TestCase
|
||||
array(
|
||||
'signed' => true,
|
||||
'actor' => TestActivityPubObject::fromArray(
|
||||
self::OBJECTS['https://elsewhere.com/actor/1']
|
||||
$this->objects['https://elsewhere.com/actor/1']
|
||||
),
|
||||
)
|
||||
)
|
||||
@ -123,7 +141,7 @@ class PostControllerTest extends TestCase
|
||||
'{"type": "Create"}',
|
||||
array(
|
||||
'actor' => TestActivityPubObject::fromArray(
|
||||
self::OBJECTS['https://example.com/actor/1']
|
||||
$this->objects['https://example.com/actor/1']
|
||||
),
|
||||
)
|
||||
),
|
||||
@ -131,7 +149,7 @@ class PostControllerTest extends TestCase
|
||||
'expectedEvent' => new OutboxActivityEvent(
|
||||
array( 'type' => 'Create' ),
|
||||
TestActivityPubObject::fromArray(
|
||||
self::OBJECTS['https://example.com/actor/1']
|
||||
$this->objects['https://example.com/actor/1']
|
||||
),
|
||||
$this->makeRequest(
|
||||
'https://example.com/actor/1/outbox',
|
||||
@ -139,7 +157,7 @@ class PostControllerTest extends TestCase
|
||||
'{"type": "Create"}',
|
||||
array(
|
||||
'actor' => TestActivityPubObject::fromArray(
|
||||
self::OBJECTS['https://example.com/actor/1']
|
||||
$this->objects['https://example.com/actor/1']
|
||||
),
|
||||
)
|
||||
)
|
||||
@ -153,7 +171,7 @@ class PostControllerTest extends TestCase
|
||||
'{"type": "Create", "actor": "https://elsewhere.com/actor/1"}',
|
||||
array(
|
||||
'actor' => TestActivityPubObject::fromArray(
|
||||
self::OBJECTS['https://elsewhere.com/actor/1']
|
||||
$this->objects['https://elsewhere.com/actor/1']
|
||||
),
|
||||
)
|
||||
),
|
||||
@ -178,7 +196,7 @@ class PostControllerTest extends TestCase
|
||||
array(
|
||||
'signed' => true,
|
||||
'actor' => TestActivityPubObject::fromArray(
|
||||
self::OBJECTS['https://elsewhere.com/actor/1']
|
||||
$this->objects['https://elsewhere.com/actor/1']
|
||||
),
|
||||
)
|
||||
),
|
||||
@ -193,7 +211,7 @@ class PostControllerTest extends TestCase
|
||||
array(
|
||||
'signed' => true,
|
||||
'actor' => TestActivityPubObject::fromArray(
|
||||
self::OBJECTS['https://elsewhere.com/actor/1']
|
||||
$this->objects['https://elsewhere.com/actor/1']
|
||||
),
|
||||
)
|
||||
),
|
||||
@ -208,7 +226,7 @@ class PostControllerTest extends TestCase
|
||||
array(
|
||||
'signed' => 'true',
|
||||
'actor' => TestActivityPubObject::fromArray(
|
||||
self::OBJECTS['https://elsewhere.com/actor/1']
|
||||
$this->objects['https://elsewhere.com/actor/1']
|
||||
),
|
||||
)
|
||||
),
|
||||
@ -230,7 +248,7 @@ class PostControllerTest extends TestCase
|
||||
$postController = new PostController( $eventDispatcher, $objectsService );
|
||||
$request = $testCase['request'];
|
||||
if ( array_key_exists( 'expectedException', $testCase ) ) {
|
||||
$this->expectException( $testCase['expectedException'] );
|
||||
$this->setExpectedException( $testCase['expectedException'] );
|
||||
}
|
||||
$postController->handle( $request );
|
||||
}
|
||||
@ -247,4 +265,4 @@ class PostControllerTest extends TestCase
|
||||
return $request;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -5,10 +5,10 @@ use DateTime;
|
||||
use ActivityPub\Crypto\HttpSignatureService;
|
||||
use ActivityPub\Test\TestUtils\TestDateTimeProvider;
|
||||
use GuzzleHttp\Psr7\Request as PsrRequest;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class HttpSignatureServiceTest extends TestCase
|
||||
class HttpSignatureServiceTest extends APTestCase
|
||||
{
|
||||
const PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----
|
||||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCFENGw33yGihy92pDjZQhl0C3
|
||||
@ -230,4 +230,4 @@ G6aFKaqQfOXKCyWoUiVknQJAXrlgySFci/2ueKlIE1QqIiLSZ8V8OlpFLRnb1pzI
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
<?php
|
||||
namespace ActivityPub\Test\Crypto;
|
||||
|
||||
use BadMethodCallException;
|
||||
use ActivityPub\Crypto\RsaKeypair;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Error\Error;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
use BadMethodCallException;
|
||||
|
||||
class RsaKeypairTest extends TestCase
|
||||
class RsaKeypairTest extends APTestCase
|
||||
{
|
||||
public function testItCreatesKeypair()
|
||||
{
|
||||
@ -37,7 +36,7 @@ class RsaKeypairTest extends TestCase
|
||||
$keypair = RsaKeypair::generate();
|
||||
$data = 'This is some data';
|
||||
$signature = 'not a real signature';
|
||||
$this->expectException( Error::class );
|
||||
$this->setExpectedException( \PHPUnit_Framework_Error::class );
|
||||
$verified = $keypair->verify( $data, $signature );
|
||||
}
|
||||
|
||||
@ -66,9 +65,8 @@ class RsaKeypairTest extends TestCase
|
||||
$fullKeypair = RsaKeypair::generate();
|
||||
$publicKeyOnly = RsaKeypair::fromPublicKey( $fullKeypair->getPublicKey() );
|
||||
$data = 'This is some data';
|
||||
$this->expectException( BadMethodCallException::class );
|
||||
$this->expectExceptionMessage( 'Unable to sign data without a private key' );
|
||||
$signature = $publicKeyOnly->sign( $data );
|
||||
$this->setExpectedException( BadMethodCallException::class, 'Unable to sign data without a private key' );
|
||||
$publicKeyOnly->sign( $data );
|
||||
}
|
||||
|
||||
public function testItSignsAndVerifiesEmptyData()
|
||||
@ -90,4 +88,4 @@ class RsaKeypairTest extends TestCase
|
||||
$this->assertFalse( $verified );
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -110,4 +110,4 @@ class EntityTest extends SQLiteTestCase
|
||||
$this->assertTablesEqual( $expectedKeysTable, $keysQueryTable );
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -4,14 +4,14 @@ namespace ActivityPub\Test\Http;
|
||||
use ActivityPub\Controllers\GetController;
|
||||
use ActivityPub\Controllers\PostController;
|
||||
use ActivityPub\Http\Router;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||
use Symfony\Component\HttpKernel\HttpKernel;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
class RouterTest extends TestCase
|
||||
class RouterTest extends APTestCase
|
||||
{
|
||||
/**
|
||||
* @var Router
|
||||
@ -24,10 +24,10 @@ class RouterTest extends TestCase
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->getController = $this->createMock( GetController::class );
|
||||
$this->postController = $this->createMock( PostController::class );
|
||||
$this->getController = $this->getMock( GetController::class );
|
||||
$this->postController = $this->getMock( PostController::class );
|
||||
$this->router = new Router( $this->getController, $this->postController );
|
||||
$this->kernel = $this->createMock( Kernel::class );
|
||||
$this->kernel = $this->getMock( HttpKernel::class );
|
||||
}
|
||||
|
||||
public function testRouter()
|
||||
@ -55,7 +55,7 @@ class RouterTest extends TestCase
|
||||
$this->kernel, $request, HttpKernelInterface::MASTER_REQUEST
|
||||
);
|
||||
if ( array_key_exists( 'expectedException', $testCase ) ) {
|
||||
$this->expectException( $testCase['expectedException'] );
|
||||
$this->setExpectedException( $testCase['expectedException'] );
|
||||
}
|
||||
$this->router->route( $event );
|
||||
$this->assertEquals(
|
||||
@ -66,4 +66,4 @@ class RouterTest extends TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace ActivityPub\Test\Objects;
|
||||
|
||||
use ActivityPub\Utils\SimpleDateTimeProvider;
|
||||
use Exception;
|
||||
use ActivityPub\Auth\AuthService;
|
||||
use ActivityPub\Objects\ContextProvider;
|
||||
@ -8,19 +9,22 @@ use ActivityPub\Objects\CollectionsService;
|
||||
use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Response as Psr7Response;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class CollectionsServiceTest extends TestCase
|
||||
class CollectionsServiceTest extends APTestCase
|
||||
{
|
||||
/**
|
||||
* @var CollectionsService
|
||||
*/
|
||||
private $collectionsService;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$authService = new AuthService();
|
||||
$contextProvider = new ContextProvider();
|
||||
$httpClient = $this->createMock( Client::class );
|
||||
$httpClient = $this->getMock( Client::class );
|
||||
$httpClient->method( 'send' )->willReturn(
|
||||
new Psr7Response( 200, array(), json_encode( array(
|
||||
'type' => 'OrderedCollectionPage',
|
||||
@ -31,7 +35,7 @@ class CollectionsServiceTest extends TestCase
|
||||
) ) )
|
||||
);
|
||||
$this->collectionsService = new CollectionsService(
|
||||
4, $authService, $contextProvider, $httpClient
|
||||
4, $authService, $contextProvider, $httpClient, new SimpleDateTimeProvider()
|
||||
);
|
||||
}
|
||||
|
||||
@ -375,7 +379,7 @@ class CollectionsServiceTest extends TestCase
|
||||
);
|
||||
foreach ( $testCases as $testCase ) {
|
||||
if ( array_key_exists( 'expectedException', $testCase ) ) {
|
||||
$this->expectException( $testCase['expectedException'] );
|
||||
$this->setExpectedException( $testCase['expectedException'] );
|
||||
}
|
||||
$request = $testCase['request'];
|
||||
if ( array_key_exists( 'requestAttributes', $testCase ) ) {
|
||||
@ -490,7 +494,7 @@ class CollectionsServiceTest extends TestCase
|
||||
foreach ( $testCases as $testCase ) {
|
||||
$collection = $testCase['collection'];
|
||||
if ( array_key_exists( 'expectedException', $testCase ) ) {
|
||||
$this->expectException( $testCase['expectedException'] );
|
||||
$this->setExpectedException( $testCase['expectedException'] );
|
||||
}
|
||||
$actual = $this->collectionsService->normalizeCollection( $collection );
|
||||
$this->assertEquals(
|
||||
@ -499,4 +503,4 @@ class CollectionsServiceTest extends TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -4,10 +4,10 @@ namespace ActivityPub\Test\Objects;
|
||||
use ActivityPub\Objects\IdProvider;
|
||||
use ActivityPub\Objects\ObjectsService;
|
||||
use ActivityPub\Utils\RandomProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class IdProviderTest extends TestCase
|
||||
class IdProviderTest extends APTestCase
|
||||
{
|
||||
const EXISTING_ID_STR = 'exists';
|
||||
|
||||
@ -15,7 +15,7 @@ class IdProviderTest extends TestCase
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->objectsService = $this->createMock( ObjectsService::class );
|
||||
$this->objectsService = $this->getMock( ObjectsService::class );
|
||||
$this->objectsService->method( 'query' )
|
||||
->will( $this->returnCallback( function( $query) {
|
||||
$existsId = sprintf(
|
||||
@ -50,7 +50,7 @@ class IdProviderTest extends TestCase
|
||||
),
|
||||
);
|
||||
foreach ( $testCases as $testCase ) {
|
||||
$randomProvider = $this->createMock( RandomProvider::class );
|
||||
$randomProvider = $this->getMock( RandomProvider::class );
|
||||
call_user_func_array(
|
||||
array( $randomProvider->method( 'randomString' ), 'willReturnOnConsecutiveCalls' ),
|
||||
$testCase['providedRnd']
|
||||
@ -67,4 +67,4 @@ class IdProviderTest extends TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -15,7 +15,6 @@ use ActivityPub\Test\TestUtils\TestDateTimeProvider;
|
||||
use Doctrine\ORM\Tools\Setup;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use PHPUnit\DbUnit\TestCaseTrait;
|
||||
|
||||
class ObjectsServiceTest extends SQLiteTestCase
|
||||
{
|
||||
@ -46,7 +45,7 @@ class ObjectsServiceTest extends SQLiteTestCase
|
||||
'objects-service.create' => new DateTime( "12:00" ),
|
||||
'objects-service.update' => new DateTime( "12:01" ),
|
||||
) );
|
||||
$this->httpClient = $this->createMock( Client::class );
|
||||
$this->httpClient = $this->getMock( Client::class );
|
||||
$this->httpClient->method( 'send' )
|
||||
->willReturn( new Response( 404 ) );
|
||||
$this->objectsService = new ObjectsService(
|
||||
@ -1130,7 +1129,7 @@ class ObjectsServiceTest extends SQLiteTestCase
|
||||
);
|
||||
$now = $this->getTime( 'objects-service.create' );
|
||||
$object = $this->objectsService->persist( $fields );
|
||||
$this->expectException( BadMethodCallException::class );
|
||||
$this->setExpectedException( BadMethodCallException::class );
|
||||
$object['content'] = 'This should break';
|
||||
}
|
||||
|
||||
@ -1143,7 +1142,7 @@ class ObjectsServiceTest extends SQLiteTestCase
|
||||
);
|
||||
$now = $this->getTime( 'objects-service.create' );
|
||||
$object = $this->objectsService->persist( $fields );
|
||||
$this->expectException( BadMethodCallException::class );
|
||||
$this->setExpectedException( BadMethodCallException::class );
|
||||
unset( $object['content'] );
|
||||
}
|
||||
|
||||
@ -1280,7 +1279,7 @@ class ObjectsServiceTest extends SQLiteTestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
|
||||
|
||||
|
12
test/TestConfig/APTestCase.php
Normal file
12
test/TestConfig/APTestCase.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace ActivityPub\Test\TestConfig;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
abstract class APTestCase extends TestCase
|
||||
{
|
||||
function getMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = false, $callOriginalClone = false, $callAutoload = true, $cloneArguments = false, $callOriginalMethods = false, $proxyTarget = null)
|
||||
{
|
||||
return parent::getMock($originalClassName, $methods, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods, $proxyTarget); // TODO: Change the autogenerated stub
|
||||
}
|
||||
}
|
@ -2,12 +2,8 @@
|
||||
namespace ActivityPub\Test\TestConfig;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\DbUnit\DataSet\AbstractDataSet;
|
||||
use PHPUnit\DbUnit\DataSet\DefaultTableMetadata;
|
||||
use PHPUnit\DbUnit\DataSet\DefaultTable;
|
||||
use PHPUnit\DbUnit\DataSet\DefaultTableIterator;
|
||||
|
||||
class ArrayDataSet extends AbstractDataSet
|
||||
class ArrayDataSet extends \PHPUnit_Extensions_Database_DataSet_AbstractDataSet
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
@ -25,8 +21,8 @@ class ArrayDataSet extends AbstractDataSet
|
||||
$columns = array_keys($rows[0]);
|
||||
}
|
||||
|
||||
$metaData = new DefaultTableMetadata($tableName, $columns);
|
||||
$table = new DefaultTable($metaData);
|
||||
$metaData = new \PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $columns);
|
||||
$table = new \PHPUnit_Extensions_Database_DataSet_DefaultTable($metaData);
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$table->addRow($row);
|
||||
@ -37,7 +33,7 @@ class ArrayDataSet extends AbstractDataSet
|
||||
|
||||
protected function createIterator($reverse = false)
|
||||
{
|
||||
return new DefaultTableIterator($this->tables, $reverse);
|
||||
return new \PHPUnit_Extensions_Database_DataSet_DefaultTableIterator($this->tables, $reverse);
|
||||
}
|
||||
|
||||
public function getTable($tableName)
|
||||
|
@ -3,14 +3,11 @@ namespace ActivityPub\Test\TestConfig;
|
||||
|
||||
use ActivityPub\ActivityPub;
|
||||
use ActivityPub\Config\ActivityPubConfig;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\DbUnit\TestCaseTrait;
|
||||
use PHPUnit\DbUnit\Operation\Composite;
|
||||
use PHPUnit\DbUnit\Operation\Factory;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
|
||||
abstract class SQLiteTestCase extends TestCase
|
||||
abstract class SQLiteTestCase extends APTestCase
|
||||
{
|
||||
use TestCaseTrait;
|
||||
use \PHPUnit_Extensions_Database_TestCase_Trait;
|
||||
|
||||
private $pdo = null;
|
||||
private $conn = null;
|
||||
@ -58,4 +55,4 @@ abstract class SQLiteTestCase extends TestCase
|
||||
return $this->conn;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -62,4 +62,4 @@ class TestActivityPubObject extends ActivityPubObject
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -28,4 +28,4 @@ class TestDateTimeProvider implements DateTimeProvider
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace ActivityPub\Test\TestUtils;
|
||||
|
||||
use ActivityPub\Entities\ActivityPubObject;
|
||||
use ActivityPub\Entities\Field;
|
||||
use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
||||
|
||||
@ -20,7 +21,7 @@ class TestField extends Field
|
||||
$this->fixedTime = $time;
|
||||
}
|
||||
|
||||
public function setTargetObject( $targetObject, $time = null )
|
||||
public function setTargetObject( ActivityPubObject $targetObject, $time = null )
|
||||
{
|
||||
parent::setTargetObject( $targetObject, $time );
|
||||
$this->lastUpdated = $this->fixedTime;
|
||||
@ -43,4 +44,4 @@ class TestField extends Field
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
namespace ActivityPub\Test\Utils;
|
||||
|
||||
use ActivityPub\Utils\Util;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ActivityPub\Test\TestConfig\APTestCase;
|
||||
|
||||
class UtilTest extends TestCase
|
||||
class UtilTest extends APTestCase
|
||||
{
|
||||
public function testItFindsAssocArray()
|
||||
{
|
||||
@ -82,4 +82,4 @@ class UtilTest extends TestCase
|
||||
$this->assertTrue( $keysExist );
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -16,4 +16,4 @@ $config = ActivityPubConfig::createBuilder()
|
||||
->build();
|
||||
$activityPub = new ActivityPub( $config );
|
||||
$activityPub->updateSchema();
|
||||
?>
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
<phpunit bootstrap="./bootstrap.php">
|
||||
<phpunit bootstrap="./bootstrap.php" backupGlobals="false">
|
||||
</phpunit>
|
||||
|
Loading…
Reference in New Issue
Block a user