Test NonActivityHandler
This commit is contained in:
parent
52219a5e59
commit
c31eaf2d18
@ -2,11 +2,15 @@
|
||||
namespace ActivityPub\Activities;
|
||||
|
||||
use ActivityPub\Activities\OutboxActivityEvent;
|
||||
use ActivityPub\Entities\ActivityPubObject;
|
||||
use ActivityPub\Objects\ContextProvider;
|
||||
use ActivityPub\Objects\IdProvider;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* The NonActivityHandler wraps non-activity objects sent to the outbox in a Create activity
|
||||
* The NonActivityHandler wraps non-activity objects sent to the outbox in a
|
||||
* Create activity
|
||||
*/
|
||||
class NonActivityHandler implements EventSubscriberInterface
|
||||
{
|
||||
@ -37,6 +41,13 @@ class NonActivityHandler implements EventSubscriberInterface
|
||||
);
|
||||
}
|
||||
|
||||
public function __construct( ContextProvider $contextProvider,
|
||||
IdProvider $idProvider )
|
||||
{
|
||||
$this->contextProvider = $contextProvider;
|
||||
$this->idProvider = $idProvider;
|
||||
}
|
||||
|
||||
public function handle( OutboxActivityEvent $event )
|
||||
{
|
||||
$object = $event->getActivity();
|
||||
@ -73,6 +84,7 @@ class NonActivityHandler implements EventSubscriberInterface
|
||||
$create[$field] = $object[$field];
|
||||
}
|
||||
}
|
||||
return $create;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -1,14 +1,111 @@
|
||||
<?php
|
||||
namespace ActivityPub\Test\Activities;
|
||||
|
||||
use ActivityPub\Activities\OutboxActivityEvent;
|
||||
use ActivityPub\Activities\NonActivityHandler;
|
||||
use ActivityPub\Objects\ContextProvider;
|
||||
use ActivityPub\Objects\IdProvider;
|
||||
use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class NonActivityHandlerTest extends TestCase
|
||||
{
|
||||
public function testNonActivityHandler()
|
||||
{
|
||||
// TODO implement me
|
||||
$this->assertTrue( false );
|
||||
$contextProvider = new ContextProvider();
|
||||
$idProvider = $this->createMock( IdProvider::class );
|
||||
$idProvider->method( 'getId' )->willReturn( 'id1' );
|
||||
$nonActivityHandler = new NonActivityHandler( $contextProvider, $idProvider );
|
||||
$testCases = array(
|
||||
array(
|
||||
'id' => 'testItWrapsNonObjectActivity',
|
||||
'activity' => array(
|
||||
'type' => 'Note'
|
||||
),
|
||||
'actor' => TestActivityPubObject::fromArray( array(
|
||||
'id' => 'https://example.com/actor/1',
|
||||
) ),
|
||||
'expectedActivity' => array(
|
||||
'@context' => ContextProvider::DEFAULT_CONTEXT,
|
||||
'type' => 'Create',
|
||||
'id' => 'id1',
|
||||
'actor' => 'https://example.com/actor/1',
|
||||
'object' => array(
|
||||
'type' => 'Note',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 'testItDoesNotWrapActivity',
|
||||
'activity' => array(
|
||||
'type' => 'Update'
|
||||
),
|
||||
'actor' => TestActivityPubObject::fromArray( array(
|
||||
'id' => 'https://example.com/actor/1',
|
||||
) ),
|
||||
'expectedActivity' => array(
|
||||
'type' => 'Update',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 'testItPassesAudience',
|
||||
'activity' => array(
|
||||
'type' => 'Note',
|
||||
'audience' => array(
|
||||
'foo',
|
||||
),
|
||||
'to' => array(
|
||||
'bar',
|
||||
),
|
||||
'bcc' => array(
|
||||
'baz',
|
||||
),
|
||||
),
|
||||
'actor' => TestActivityPubObject::fromArray( array(
|
||||
'id' => 'https://example.com/actor/1',
|
||||
) ),
|
||||
'expectedActivity' => array(
|
||||
'@context' => ContextProvider::DEFAULT_CONTEXT,
|
||||
'type' => 'Create',
|
||||
'id' => 'id1',
|
||||
'actor' => 'https://example.com/actor/1',
|
||||
'object' => array(
|
||||
'type' => 'Note',
|
||||
'audience' => array(
|
||||
'foo',
|
||||
),
|
||||
'to' => array(
|
||||
'bar',
|
||||
),
|
||||
'bcc' => array(
|
||||
'baz',
|
||||
),
|
||||
),
|
||||
'audience' => array(
|
||||
'foo',
|
||||
),
|
||||
'to' => array(
|
||||
'bar',
|
||||
),
|
||||
'bcc' => array(
|
||||
'baz',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
foreach ( $testCases as $testCase ) {
|
||||
$actor = $testCase['actor'];
|
||||
$activity = $testCase['activity'];
|
||||
$request = Request::create( 'https://example.com/whatever' );
|
||||
$event = new OutboxActivityEvent( $activity, $actor, $request );
|
||||
$nonActivityHandler->handle( $event );
|
||||
$this->assertEquals(
|
||||
$testCase['expectedActivity'],
|
||||
$event->getActivity(),
|
||||
"Error on test $testCase[id]"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user