Skip to content

Commit

Permalink
EZP-30029: As a Developer I'd like API for bulk loading Content Info …
Browse files Browse the repository at this point in the history
…Items (#2529)
  • Loading branch information
andrerom committed Feb 19, 2019
1 parent d51dd8d commit 7a8b5f7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Repository/ContentService.php
Expand Up @@ -38,6 +38,17 @@ interface ContentService
*/
public function loadContentInfo($contentId);

/**
* Bulk-load ContentInfo items by id's.
*
* Note: It does not throw exceptions on load, just skips erroneous (NotFound or Unauthorized) ContentInfo items.
*
* @param int[] $contentIds
*
* @return \eZ\Publish\API\Repository\Values\Content\ContentInfo[] list of ContentInfo with Content Ids as keys
*/
public function loadContentInfoList(array $contentIds): iterable;

/**
* Loads a content info object for the given remoteId.
*
Expand Down
18 changes: 18 additions & 0 deletions Repository/Tests/ContentServiceAuthorizationTest.php
Expand Up @@ -139,6 +139,24 @@ public function testSudo()
);
}

/**
* Test for the loadContentInfoList() method.
*
* @see \eZ\Publish\API\Repository\ContentService::loadContentInfoList()
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfoList
*/
public function testLoadContentInfoListSkipsUnauthorizedItems()
{
$repository = $this->getRepository();
$contentId = $this->generateId('object', 10);
$contentService = $repository->getContentService();
$repository->setCurrentUser($this->createAnonymousWithEditorRole());

$list = $contentService->loadContentInfoList([$contentId]);

$this->assertCount(0, $list);
}

/**
* Test for the loadContentInfoByRemoteId() method.
*
Expand Down
38 changes: 38 additions & 0 deletions Repository/Tests/ContentServiceTest.php
Expand Up @@ -571,6 +571,44 @@ public function testLoadContentInfoThrowsNotFoundException()
/* END: Use Case */
}

/**
* Test for the loadContentInfoList() method.
*
* @see \eZ\Publish\API\Repository\ContentService::loadContentInfoList()
*/
public function testLoadContentInfoList()
{
$repository = $this->getRepository();

$mediaFolderId = $this->generateId('object', 41);
$contentService = $repository->getContentService();
$list = $contentService->loadContentInfoList([$mediaFolderId]);

$this->assertCount(1, $list);
$this->assertEquals([$mediaFolderId], array_keys($list), 'Array key was not content id');
$this->assertInstanceOf(
ContentInfo::class,
$list[$mediaFolderId]
);
}

/**
* Test for the loadContentInfoList() method.
*
* @see \eZ\Publish\API\Repository\ContentService::loadContentInfoList()
* @depends testLoadContentInfoList
*/
public function testLoadContentInfoListSkipsNotFoundItems()
{
$repository = $this->getRepository();

$nonExistentContentId = $this->generateId('object', self::DB_INT_MAX);
$contentService = $repository->getContentService();
$list = $contentService->loadContentInfoList([$nonExistentContentId]);

$this->assertCount(0, $list);
}

/**
* Test for the loadContentInfoByRemoteId() method.
*
Expand Down

0 comments on commit 7a8b5f7

Please sign in to comment.