Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into temp_1.3_to_4.5
  • Loading branch information
vidarl committed Feb 20, 2024
2 parents 4e5b883 + aa31bb2 commit 174c906
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@ public function buildQueryConstraint(
FilteringQueryBuilder $queryBuilder,
FilteringCriterion $criterion
): ?string {
$tableAlias = uniqid('osl_');

/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\ObjectStateId $criterion */
$queryBuilder
->joinOnce(
->join(
'content',
Gateway::OBJECT_STATE_LINK_TABLE,
'object_state_link',
'content.id = object_state_link.contentobject_id',
$tableAlias,
'content.id = ' . $tableAlias . '.contentobject_id',
);

$value = (array)$criterion->value;

return $queryBuilder->expr()->in(
'object_state_link.contentobject_state_id',
$tableAlias . '.contentobject_state_id',
$queryBuilder->createNamedParameter($value, Connection::PARAM_INT_ARRAY)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Ibexa\Tests\Integration\Core\Repository\Filtering;

use Ibexa\Contracts\Core\Repository\Values\ObjectState\ObjectStateCreateStruct;
use Ibexa\Contracts\Core\Repository\Values\ObjectState\ObjectStateGroupCreateStruct;
use function array_map;
use function count;
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
Expand Down Expand Up @@ -333,6 +335,75 @@ private function performAndAssertSimpleSortClauseQuery(FilteringSortClause $sort
self::assertSame(57, $contentList->getIterator()[0]->id);
}

/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception
*/
public function testObjectStateIdCriterionOnMultipleObjectStates(): void
{
$contentService = $this->getRepository()->getContentService();
$contentTypeService = $this->getRepository()->getContentTypeService();
$locationService = $this->getRepository()->getLocationService();
$objectStateService = $this->getRepository()->getObjectStateService();

// Create additional Object States
$objectStateGroupStruct = new ObjectStateGroupCreateStruct();
$objectStateGroupStruct->identifier = 'domain';
$objectStateGroupStruct->names = ['eng-GB' => 'Domain'];
$objectStateGroupStruct->defaultLanguageCode = 'eng-GB';
$objectStateGroup = $objectStateService->createObjectStateGroup($objectStateGroupStruct);

$objectStateCreateStruct = new ObjectStateCreateStruct();
$objectStateCreateStruct->identifier = 'public';
$objectStateCreateStruct->names = ['eng-GB' => 'Public'];
$objectStateCreateStruct->defaultLanguageCode = 'eng-GB';
$objectStateService->createObjectState($objectStateGroup, $objectStateCreateStruct);

$objectStateCreateStruct->identifier = 'private';
$objectStateCreateStruct->names = ['eng-GB' => 'Private'];
$objectStatePrivate = $objectStateService->createObjectState($objectStateGroup, $objectStateCreateStruct);

// Create a new content object and assign object state "Private" to it:
$contentCreate = $contentService->newContentCreateStruct(
$contentTypeService->loadContentTypeByIdentifier('folder'),
'eng-GB'
);
$contentCreate->setField('name', 'Private Folder');
$content = $contentService->createContent(
$contentCreate,
[$locationService->newLocationCreateStruct(2)]
);
$contentService->publishVersion(
$content->getVersionInfo()
);
$objectStateService->setContentState(
$content->getVersionInfo()->getContentInfo(),
$objectStateGroup,
$objectStatePrivate
);

$filter = new Filter();
$filter
->withCriterion(new Criterion\LogicalAnd([
new Criterion\ParentLocationId(2),
new Criterion\LogicalAnd([
new Criterion\ObjectStateId(1),
new Criterion\ObjectStateId($objectStatePrivate->id),
]),
]));

$results = $this->find($filter);

self::assertEquals(
1,
$results->getTotalCount(),
'Expected to find only one object which has state "not_locked" and "private"'
);

foreach ($results as $result) {
self::assertEquals($result->id, $content->id, 'Expected to find "Private Folder"');
}
}

public function getListOfSupportedSortClauses(): iterable
{
yield 'Content\\Id' => [SortClause\ContentId::class];
Expand Down

0 comments on commit 174c906

Please sign in to comment.