Navigation Menu

Skip to content

Commit

Permalink
Merge branch '7.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Longosz committed Sep 17, 2018
2 parents ae82a7e + caaece5 commit e9a24dc
Show file tree
Hide file tree
Showing 9 changed files with 625 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Repository/ContentService.php
Expand Up @@ -150,6 +150,23 @@ public function loadContent($contentId, array $languages = null, $versionNo = nu
*/
public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true);

/**
* Bulk-load Content items by the list of ContentInfo Value Objects.
*
* Note: it does not throw exceptions on load, just ignores erroneous Content item.
* Moreover, since the method works on pre-loaded ContentInfo list, it is assumed that user is
* allowed to access every Content on the list.
*
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo[] $contentInfoList
* @param string[] $languages A language priority, filters returned fields and is used as prioritized language code on
* returned value object. If not given all languages are returned.
* @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true,
* unless all languages have been asked for.
*
* @return \eZ\Publish\API\Repository\Values\Content\Content[] list of Content items with Content Ids as keys
*/
public function loadContentListByContentInfo(array $contentInfoList, array $languages = [], $useAlwaysAvailable = true);

/**
* Creates a new content draft assigned to the authenticated user.
*
Expand Down
19 changes: 19 additions & 0 deletions Repository/LocationService.php
Expand Up @@ -212,4 +212,23 @@ public function newLocationCreateStruct($parentLocationId);
* @return \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct
*/
public function newLocationUpdateStruct();

/**
* Get the total number of all existing Locations. Can be combined with loadAllLocations.
*
* @see loadAllLocations
*
* @return int Total number of Locations
*/
public function getAllLocationsCount(): int;

/**
* Bulk-load all existing Locations, constrained by $limit and $offset to paginate results.
*
* @param int $limit
* @param int $offset
*
* @return \eZ\Publish\API\Repository\Values\Content\Location[]
*/
public function loadAllLocations(int $offset = 0, int $limit = 25): array;
}
40 changes: 40 additions & 0 deletions Repository/Tests/BaseTest.php
Expand Up @@ -10,6 +10,7 @@

use eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException;
use eZ\Publish\API\Repository\Tests\PHPUnitConstraint\ValidationErrorOccurs as PHPUnitConstraintValidationErrorOccurs;
use eZ\Publish\API\Repository\Values\Content\Location;
use EzSystems\EzPlatformSolrSearchEngine\Tests\SetupFactory\LegacySetupFactory as LegacySolrSetupFactory;
use PHPUnit\Framework\TestCase;
use eZ\Publish\API\Repository\Repository;
Expand Down Expand Up @@ -622,4 +623,43 @@ protected function assertValidationErrorOccurs(

self::assertThat($exception, $constraint);
}

/**
* Create 'folder' Content.
*
* @param array $names Folder names in the form of <code>['&lt;language_code&gt;' => '&lt;name&gt;']</code>
* @param int $parentLocationId
*
* @return \eZ\Publish\API\Repository\Values\Content\Content published Content
*
* @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
protected function createFolder(array $names, $parentLocationId)
{
$repository = $this->getRepository(false);
$contentService = $repository->getContentService();
$contentTypeService = $repository->getContentTypeService();
$locationService = $repository->getLocationService();

if (empty($names)) {
throw new \RuntimeException(sprintf('%s expects non-empty names list', __METHOD__));
}
$mainLanguageCode = array_keys($names)[0];

$struct = $contentService->newContentCreateStruct(
$contentTypeService->loadContentTypeByIdentifier('folder'),
$mainLanguageCode
);
foreach ($names as $languageCode => $translatedName) {
$struct->setField('name', $translatedName, $languageCode);
}
$contentDraft = $contentService->createContent(
$struct,
[$locationService->newLocationCreateStruct($parentLocationId)]
);

return $contentService->publishVersion($contentDraft->versionInfo);
}
}
28 changes: 28 additions & 0 deletions Repository/Tests/Common/SlugConverter.php
@@ -0,0 +1,28 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Publish\API\Repository\Tests\Common;

use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter as LegacySlugConverter;

/**
* Overridden Slug Converter for test purposes (to make Service configuration mutable).
*
* @see \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter
*/
class SlugConverter extends LegacySlugConverter
{
/**
* Set service-wide configuration value.
*
* @param string $key
* @param string $value
*/
public function setConfigurationValue($key, $value)
{
$this->configuration[$key] = $value;
}
}
34 changes: 33 additions & 1 deletion Repository/Tests/ContentServiceTest.php
Expand Up @@ -9,6 +9,7 @@
namespace eZ\Publish\API\Repository\Tests;

use eZ\Publish\API\Repository\Values\Content\Content;
use eZ\Publish\API\Repository\Exceptions\UnauthorizedException;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct;
use eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct;
Expand All @@ -27,7 +28,7 @@
/**
* Test case for operations in the ContentService using in memory storage.
*
* @see eZ\Publish\API\Repository\ContentService
* @see \eZ\Publish\API\Repository\ContentService
* @group content
*/
class ContentServiceTest extends BaseContentServiceTest
Expand Down Expand Up @@ -5737,6 +5738,37 @@ public function testDeleteTranslationFromDraftThrowsInvalidArgumentException()
$contentService->deleteTranslationFromDraft($draft->versionInfo, $languageCode);
}

/**
* Test loading list of Content items.
*/
public function testLoadContentListByContentInfo()
{
$repository = $this->getRepository();
$contentService = $repository->getContentService();
$locationService = $repository->getLocationService();

$allLocationsCount = $locationService->getAllLocationsCount();
$contentInfoList = array_map(
function (Location $location) {
return $location->contentInfo;
},
$locationService->loadAllLocations(0, $allLocationsCount)
);

$contentList = $contentService->loadContentListByContentInfo($contentInfoList);
self::assertCount(count($contentInfoList), $contentList);
foreach ($contentList as $content) {
try {
$loadedContent = $contentService->loadContent($content->id);
self::assertEquals($loadedContent, $content, "Failed to properly bulk-load Content {$content->id}");
} catch (NotFoundException $e) {
self::fail("Failed to load Content {$content->id}: {$e->getMessage()}");
} catch (UnauthorizedException $e) {
self::fail("Failed to load Content {$content->id}: {$e->getMessage()}");
}
}
}

/**
* Asserts that all aliases defined in $expectedAliasProperties with the
* given properties are available in $actualAliases and not more.
Expand Down
3 changes: 3 additions & 0 deletions Repository/Tests/SetupFactory/Legacy.php
Expand Up @@ -391,6 +391,9 @@ public function getServiceContainer()
$containerBuilder->addCompilerPass(new Compiler\Search\SearchEngineSignalSlotPass('legacy'));
$containerBuilder->addCompilerPass(new Compiler\Search\FieldRegistryPass());

// load overrides just before creating test Container
$loader->load('tests/override.yml');

self::$serviceContainer = new ServiceContainer(
$containerBuilder,
$installDir,
Expand Down
3 changes: 3 additions & 0 deletions Repository/Tests/SetupFactory/LegacyElasticsearch.php
Expand Up @@ -69,6 +69,9 @@ public function getServiceContainer()
self::$ioRootDir . '/' . $containerBuilder->getParameter('storage_dir')
);

// load overrides just before creating test Container
$loader->load('tests/override.yml');

self::$serviceContainer = new ServiceContainer(
$containerBuilder,
$installDir,
Expand Down

0 comments on commit e9a24dc

Please sign in to comment.