2019-01-22 22:36:21 +00:00
|
|
|
<?php
|
2019-02-16 17:51:24 +00:00
|
|
|
|
2019-03-20 23:16:56 +00:00
|
|
|
namespace ActivityPub\Test\ActivityEventHandlers;
|
2019-01-22 22:36:21 +00:00
|
|
|
|
2019-03-20 23:14:10 +00:00
|
|
|
use ActivityPub\ActivityEventHandlers\NonActivityHandler;
|
|
|
|
use ActivityPub\ActivityEventHandlers\OutboxActivityEvent;
|
2019-01-23 21:54:53 +00:00
|
|
|
use ActivityPub\Objects\ContextProvider;
|
2019-02-07 03:48:00 +00:00
|
|
|
use ActivityPub\Test\TestConfig\APTestCase;
|
2019-02-16 17:51:24 +00:00
|
|
|
use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
2019-01-23 21:54:53 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2019-01-22 22:36:21 +00:00
|
|
|
|
2019-02-07 03:48:00 +00:00
|
|
|
class NonActivityHandlerTest extends APTestCase
|
2019-01-22 22:36:21 +00:00
|
|
|
{
|
2019-04-12 03:41:25 +00:00
|
|
|
public function provideTestNonActivityHandler()
|
2019-01-22 22:36:21 +00:00
|
|
|
{
|
2019-04-12 03:41:25 +00:00
|
|
|
return array(
|
|
|
|
array( array(
|
2019-01-23 21:54:53 +00:00
|
|
|
'id' => 'testItWrapsNonObjectActivity',
|
|
|
|
'activity' => array(
|
|
|
|
'type' => 'Note'
|
|
|
|
),
|
|
|
|
'actor' => TestActivityPubObject::fromArray( array(
|
|
|
|
'id' => 'https://example.com/actor/1',
|
|
|
|
) ),
|
|
|
|
'expectedActivity' => array(
|
2019-02-07 03:48:00 +00:00
|
|
|
'@context' => ContextProvider::getDefaultContext(),
|
2019-01-23 21:54:53 +00:00
|
|
|
'type' => 'Create',
|
|
|
|
'actor' => 'https://example.com/actor/1',
|
|
|
|
'object' => array(
|
|
|
|
'type' => 'Note',
|
|
|
|
),
|
|
|
|
),
|
2019-04-12 03:41:25 +00:00
|
|
|
) ),
|
|
|
|
array( array(
|
2019-01-23 21:54:53 +00:00
|
|
|
'id' => 'testItDoesNotWrapActivity',
|
|
|
|
'activity' => array(
|
|
|
|
'type' => 'Update'
|
|
|
|
),
|
|
|
|
'actor' => TestActivityPubObject::fromArray( array(
|
|
|
|
'id' => 'https://example.com/actor/1',
|
|
|
|
) ),
|
|
|
|
'expectedActivity' => array(
|
|
|
|
'type' => 'Update',
|
|
|
|
),
|
2019-04-12 03:41:25 +00:00
|
|
|
) ),
|
|
|
|
array( array(
|
2019-01-23 21:54:53 +00:00
|
|
|
'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(
|
2019-02-07 03:48:00 +00:00
|
|
|
'@context' => ContextProvider::getDefaultContext(),
|
2019-01-23 21:54:53 +00:00
|
|
|
'type' => 'Create',
|
|
|
|
'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',
|
|
|
|
),
|
|
|
|
),
|
2019-04-12 03:41:25 +00:00
|
|
|
) )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideTestNonActivityHandler
|
|
|
|
*/
|
|
|
|
public function testNonActivityHandler( $testCase )
|
|
|
|
{
|
|
|
|
$contextProvider = new ContextProvider();
|
|
|
|
$nonActivityHandler = new NonActivityHandler( $contextProvider );
|
|
|
|
$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]"
|
2019-01-23 21:54:53 +00:00
|
|
|
);
|
2019-01-22 22:36:21 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-07 03:48:00 +00:00
|
|
|
|