From f128a1bba1dfa6ebcf7e9fbd1068776d37a788ef Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 18 Feb 2021 23:27:23 +0530 Subject: [PATCH] Fix return value for Boolean::process(). Closes #308 --- src/Model/Filter/Boolean.php | 24 +++++++++++---------- tests/TestCase/Model/Filter/BooleanTest.php | 6 ++++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/Model/Filter/Boolean.php b/src/Model/Filter/Boolean.php index 868aaff5..d2181dfd 100644 --- a/src/Model/Filter/Boolean.php +++ b/src/Model/Filter/Boolean.php @@ -41,25 +41,27 @@ public function process(): bool $bool = false; } - if ($bool !== null) { - if (!$this->manager()->getRepository() instanceof Table) { - foreach ($this->fields() as $field) { - $this->getQuery()->where([ - $field => $bool, - ]); - } - - return true; - } + if ($bool === null) { + return false; + } + if ($this->manager()->getRepository() instanceof Table) { $conditions = []; foreach ($this->fields() as $field) { $conditions[] = [$field => $bool]; } $this->getQuery()->andWhere([$this->getConfig('mode') => $conditions]); + + return true; + } + + foreach ($this->fields() as $field) { + $this->getQuery()->where([ + $field => $bool, + ]); } - return false; + return true; } } diff --git a/tests/TestCase/Model/Filter/BooleanTest.php b/tests/TestCase/Model/Filter/BooleanTest.php index 299d4e47..c82c75d1 100644 --- a/tests/TestCase/Model/Filter/BooleanTest.php +++ b/tests/TestCase/Model/Filter/BooleanTest.php @@ -29,8 +29,9 @@ public function testProcessWithFlagOn() $filter = new Boolean('is_active', $manager); $filter->setArgs(['is_active' => 'on']); $filter->setQuery($articles->find()); - $filter->process(); + $result = $filter->process(); + $this->assertTrue($result); $this->assertRegExp( '/WHERE Articles\.is_active = \:c0$/', $filter->getQuery()->sql() @@ -246,8 +247,9 @@ public function testProcessWithFlagInvalid() $filter = new Boolean('is_active', $manager); $filter->setArgs(['is_active' => 'neitherTruthyNorFalsy']); $filter->setQuery($articles->find()); - $filter->process(); + $result = $filter->process(); + $this->assertFalse($result); $this->assertEmpty($filter->getQuery()->clause('where')); $filter->getQuery()->sql(); $this->assertEmpty($filter->getQuery()->getValueBinder()->bindings());