From 8f72f43e7ba4e2d034790c9f56a798b59e5d1a67 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Wed, 1 Feb 2017 08:41:33 +0100 Subject: [PATCH 1/2] Add truncation param to query builder --- src/Component/Query/RecordQueryBuilder.php | 32 ++++++++++++++++++- .../Query/RecordQueryBuilderTest.php | 26 +++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/Component/Query/RecordQueryBuilder.php b/src/Component/Query/RecordQueryBuilder.php index f14984e..7ed7877 100644 --- a/src/Component/Query/RecordQueryBuilder.php +++ b/src/Component/Query/RecordQueryBuilder.php @@ -100,6 +100,11 @@ class RecordQueryBuilder */ private $sortType = null; + /** + * @var bool Whether to activate truncation search mode + */ + private $enableTruncation = false; + /** * Sets the record search query string. Format follows the same specification as the Phraseanet search * engine. @@ -413,6 +418,30 @@ public function setFields(array $fields) return $this; } + /** + * Enables truncation search mode. + */ + public function enableTruncation() + { + $this->enableTruncation = true; + } + + /** + * Disables truncation search mode + */ + public function disableTruncation() + { + $this->enableTruncation = false; + } + + /** + * @return bool + */ + public function isTruncationEnabled() + { + return $this->enableTruncation; + } + /** * Returns the built query. * @@ -425,7 +454,8 @@ public function getQuery() 'bases' => array_unique($this->collections), 'offset_start' => $this->offsetStart, 'per_page' => $this->recordsPerPage, - 'search_type' => $this->searchType + 'search_type' => $this->searchType, + 'truncation' => $this->enableTruncation ? 1 : 0 ); $query = $this->appendRecordType($query); diff --git a/tests/unit/Component/Query/RecordQueryBuilderTest.php b/tests/unit/Component/Query/RecordQueryBuilderTest.php index c1a6035..905e12a 100644 --- a/tests/unit/Component/Query/RecordQueryBuilderTest.php +++ b/tests/unit/Component/Query/RecordQueryBuilderTest.php @@ -378,4 +378,30 @@ public function testSetFieldsWithInvalidNameThrowsException($name) $builder->setFields(array('bacon', 'eggs', $name)); } + + public function testTruncationIsDisabledByDefault() + { + $builder = new RecordQueryBuilder(); + + $this->assertFalse($builder->isTruncationEnabled(), 'Truncation should be disabled by default'); + } + + public function testTruncationCanBeEnabled() + { + $builder = new RecordQueryBuilder(); + + $builder->enableTruncation(); + + $this->assertTrue($builder->isTruncationEnabled(), 'Truncation should be enabled after calling enable'); + } + + public function testTruncationCanBeDisabled() + { + $builder = new RecordQueryBuilder(); + + $builder->enableTruncation(); + $builder->disableTruncation(); + + $this->assertFalse($builder->isTruncationEnabled(), 'Truncation should be disabled after calling disable'); + } } From cfcc7cbf679d5016ea9d2c0cfeaecb6317e95417 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Wed, 1 Feb 2017 08:54:50 +0100 Subject: [PATCH 2/2] CS fix --- src/Component/Predicate/NullPredicate.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Component/Predicate/NullPredicate.php b/src/Component/Predicate/NullPredicate.php index 723546c..2bd91b5 100644 --- a/src/Component/Predicate/NullPredicate.php +++ b/src/Component/Predicate/NullPredicate.php @@ -14,6 +14,5 @@ class NullPredicate extends AbstractPredicate */ public function acceptPredicateVisitor(PredicateVisitor $visitor) { - } }