Skip to content

Commit

Permalink
test: update unit tests for the latest changes in implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
vbyndych committed Oct 13, 2023
1 parent 2c69b6c commit 9dcf98e
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 348 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function setPropertyUri(string $propertyUri): self

public function hasValueCollectionUri(): bool
{
return null !== $this->valueCollectionUri;
return !empty($this->valueCollectionUri);
}

public function getValueCollectionUri(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@
use oat\generis\model\OntologyRdf;
use oat\generis\model\OntologyRdfs;
use oat\generis\persistence\PersistenceManager;
use oat\search\base\QueryBuilderInterface;
use oat\search\base\QueryCriterionInterface;
use oat\search\base\QueryInterface;
use oat\search\QueryBuilder;
use oat\tao\model\Lists\Business\Contract\ValueCollectionRepositoryInterface;
use oat\tao\model\Lists\Business\Domain\CollectionType;
use oat\tao\model\Lists\Business\Domain\Value;
use oat\tao\model\Lists\Business\Domain\ValueCollection;
use oat\tao\model\Lists\Business\Domain\ValueCollectionSearchRequest;
use oat\tao\model\service\InjectionAwareService;
use Throwable;

class RdfValueCollectionRepository extends InjectionAwareService implements ValueCollectionRepositoryInterface
{
Expand Down Expand Up @@ -131,7 +130,7 @@ public function persist(ValueCollection $valueCollection): bool
return true;
} catch (ValueConflictException $exception) {
throw $exception;
} catch (Throwable $exception) {
} catch (\Throwable $exception) {
return false;
}
}
Expand Down Expand Up @@ -193,12 +192,12 @@ private function update(Value $value): void
}
}

private function enrichQueryWithOrderBy(QueryBuilder $query): void
private function enrichQueryWithOrderBy(QueryBuilderInterface $query): void
{
$query->sort([OntologyRdfs::RDFS_LABEL => 'asc']);
}

private function enrichWithLimit(ValueCollectionSearchRequest $searchRequest, QueryBuilder $query): void
private function enrichWithLimit(ValueCollectionSearchRequest $searchRequest, QueryBuilderInterface $query): void
{
if ($searchRequest->hasOffset()) {
$query->setOffset($searchRequest->getOffset());
Expand All @@ -221,7 +220,9 @@ private function enrichQueryWithPropertySearchConditions(
$searchProperty = new KernelProperty($searchRequest->getPropertyUri());
$typeList = $searchProperty->getPropertyValues($rangeProperty);

$query->add(OntologyRdf::RDF_TYPE)->in($typeList);
if (!empty($typeList)) {
$query->add(OntologyRdf::RDF_TYPE)->in($typeList);
}
}

private function enrichQueryWithValueCollectionSearchCondition(
Expand Down Expand Up @@ -287,34 +288,9 @@ public function count(ValueCollectionSearchRequest $searchRequest): int
return $search->getGateway()->count($queryBuilder);
}

private function extractLabel(
ValueCollectionSearchRequest $searchRequest,
iterable $labels,
string $subject
): ?string {
if (!empty($labels[$subject][$searchRequest->getDataLanguage()])) {
return $labels[$subject][$searchRequest->getDataLanguage()];
}

if (!empty($labels[$subject][$searchRequest->getDefaultLanguage()])) {
return $labels[$subject][$searchRequest->getDefaultLanguage()];
}

return '';
}

private function retrieveLabels(iterable $data): array
{
$labels = [];
foreach ($data as $element) {
$labels[$element['subject']][$element['datalanguage']] = $element['object'];
}
return $labels;
}

private function getQuery(
ComplexSearchService $search,
QueryBuilder $queryBuilder,
QueryBuilderInterface $queryBuilder,
ValueCollectionSearchRequest $searchRequest
): QueryInterface {
$search->setLanguage(
Expand Down
55 changes: 55 additions & 0 deletions test/unit/models/classes/Lists/DataAccess/Repository/QueryStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2023 (original work) Open Assessment Technologies SA;
*
*/

namespace oat\tao\test\unit\models\classes\Lists\DataAccess\Repository;

use oat\search\Query;

class QueryStub extends Query
{
private array $criteriaList = [];
private string $currentProperty = '';

public function add($property)
{
$this->currentProperty = $property;

return $this;
}

public function __call($name, $arguments)
{
$value = is_array($arguments) ? (array)reset($arguments) : [];

$this->criteriaList[] = sprintf(
'%s is %s [%s]',
$this->currentProperty,
$name,
implode(',', $value)
);

return $this;
}

public function getCriteriaList(): array
{
return $this->criteriaList;
}
}
Loading

0 comments on commit 9dcf98e

Please sign in to comment.