2019-01-20 20:02:37 +00:00
|
|
|
<?php
|
|
|
|
namespace ActivityPub\Test\Objects;
|
|
|
|
|
2019-01-20 22:20:24 +00:00
|
|
|
use ActivityPub\Auth\AuthService;
|
|
|
|
use ActivityPub\Objects\ContextProvider;
|
|
|
|
use ActivityPub\Objects\CollectionsService;
|
|
|
|
use ActivityPub\Test\TestUtils\TestUtils;
|
2019-01-20 20:02:37 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-01-20 22:20:24 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2019-01-20 20:02:37 +00:00
|
|
|
|
|
|
|
class CollectionsServiceTest extends TestCase
|
|
|
|
{
|
2019-01-20 22:20:24 +00:00
|
|
|
private $collectionsService;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$authService = new AuthService();
|
|
|
|
$contextProvider = new ContextProvider();
|
|
|
|
$this->collectionsService = new CollectionsService(
|
|
|
|
4, $authService, $contextProvider
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-20 20:02:37 +00:00
|
|
|
public function testCollectionsService()
|
|
|
|
{
|
2019-01-20 22:20:24 +00:00
|
|
|
$testCases = array(
|
|
|
|
array(
|
|
|
|
'id' => 'lessThanOnePage',
|
|
|
|
'collection' => array(
|
|
|
|
'@context' => array(
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
),
|
|
|
|
'id' => 'https://example.com/objects/1',
|
|
|
|
'type' => 'OrderedCollection',
|
|
|
|
'orderedItems' => array(
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/2',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/3',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/4',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'request' => Request::create(
|
|
|
|
'https://example.com/objects/1',
|
|
|
|
Request::METHOD_GET
|
|
|
|
),
|
|
|
|
'expectedResult' => array(
|
|
|
|
'@context' => array(
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
),
|
|
|
|
'id' => 'https://example.com/objects/1',
|
|
|
|
'type' => 'OrderedCollection',
|
|
|
|
'first' => array(
|
|
|
|
'@context' => array(
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
),
|
|
|
|
'id' => 'https://example.com/objects/1?offset=0',
|
|
|
|
'type' => 'OrderedCollectionPage',
|
|
|
|
'partOf' => 'https://example.com/objects/1',
|
|
|
|
'startIndex' => 0,
|
|
|
|
'orderedItems' => array(
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/2',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/3',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/4',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2019-01-20 22:35:33 +00:00
|
|
|
array(
|
|
|
|
'id' => 'moreThanOnePage',
|
|
|
|
'collection' => array(
|
|
|
|
'@context' => array(
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
),
|
|
|
|
'id' => 'https://example.com/objects/1',
|
|
|
|
'type' => 'OrderedCollection',
|
|
|
|
'orderedItems' => array(
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/2',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/3',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/4',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/5',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/6',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'request' => Request::create(
|
|
|
|
'https://example.com/objects/1',
|
|
|
|
Request::METHOD_GET
|
|
|
|
),
|
|
|
|
'expectedResult' => array(
|
|
|
|
'@context' => array(
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
),
|
|
|
|
'id' => 'https://example.com/objects/1',
|
|
|
|
'type' => 'OrderedCollection',
|
|
|
|
'first' => array(
|
|
|
|
'@context' => array(
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
),
|
|
|
|
'id' => 'https://example.com/objects/1?offset=0',
|
|
|
|
'type' => 'OrderedCollectionPage',
|
|
|
|
'partOf' => 'https://example.com/objects/1',
|
|
|
|
'startIndex' => 0,
|
|
|
|
'next' => 'https://example.com/objects/1?offset=4',
|
|
|
|
'orderedItems' => array(
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/2',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/3',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/4',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/5',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'notFirstPage',
|
|
|
|
'collection' => array(
|
|
|
|
'@context' => array(
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
),
|
|
|
|
'id' => 'https://example.com/objects/1',
|
|
|
|
'type' => 'OrderedCollection',
|
|
|
|
'orderedItems' => array(
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/2',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/3',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/4',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/5',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/6',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'request' => Request::create(
|
|
|
|
'https://example.com/objects/1?offset=3',
|
|
|
|
Request::METHOD_GET,
|
|
|
|
),
|
|
|
|
'expectedResult' => array(
|
|
|
|
'@context' => array(
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
),
|
|
|
|
'id' => 'https://example.com/objects/1?offset=3',
|
|
|
|
'type' => 'OrderedCollectionPage',
|
|
|
|
'partOf' => 'https://example.com/objects/1',
|
|
|
|
'startIndex' => 3,
|
|
|
|
'orderedItems' => array(
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/5',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'https://example.com/objects/6',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2019-01-20 22:20:24 +00:00
|
|
|
);
|
|
|
|
foreach ( $testCases as $testCase ) {
|
|
|
|
$actual = $this->collectionsService->pageAndFilterCollection(
|
|
|
|
$testCase['request'], TestUtils::objectFromArray( $testCase['collection'] )
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$testCase['expectedResult'], $actual, "Error on test $testCase[id]"
|
|
|
|
);
|
|
|
|
}
|
2019-01-20 20:02:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|