Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit 516d5e5

Browse files
author
Jens Schulze
committed
Merge branch 'hotfix/fix-filter-bool'
2 parents 98dc3f0 + 735c920 commit 516d5e5

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

src/Model/Product/Filter.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ public function getFields()
4343

4444
protected function valueToString($value)
4545
{
46-
if (is_numeric($value)) {
46+
if (is_int($value) || is_float($value)) {
4747
return $value;
4848
}
49+
if (is_bool($value)) {
50+
return $value ? 'true': 'false';
51+
}
4952
if (is_string($value)) {
5053
return '"' . $value . '"';
5154
}
@@ -61,7 +64,7 @@ public function __toString()
6164
$facet = $this->getName();
6265
$value = $this->getValue();
6366
$alias = $this->getAlias();
64-
if ($value) {
67+
if (!is_null($value)) {
6568
$facet .= ':' . $this->valueToString($value);
6669
}
6770
if ($alias) {

tests/unit/Model/Product/FilterTest.php

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,27 @@ public function testNumeric()
1717
$this->assertSame('test:10', (string)$filter);
1818
}
1919

20+
public function testIntString()
21+
{
22+
$filter = new Filter();
23+
$filter->setName('test')->setValue('10');
24+
$this->assertSame('test:"10"', (string)$filter);
25+
}
26+
27+
public function testIntStringArray()
28+
{
29+
$filter = new Filter('array');
30+
$filter->setName('test')->setValue(['1', '2', '3']);
31+
$this->assertSame('test:"1","2","3"', (string)$filter);
32+
}
33+
34+
public function testFloatStringArray()
35+
{
36+
$filter = new Filter('array');
37+
$filter->setName('test')->setValue(['1.1', '2.2', '3.3']);
38+
$this->assertSame('test:"1.1","2.2","3.3"', (string)$filter);
39+
}
40+
2041
public function testDefaultType()
2142
{
2243
$filter = new Filter();
@@ -38,13 +59,20 @@ public function testString()
3859
$this->assertSame('test:"key" as foo', (string)$filter);
3960
}
4061

41-
public function testArray()
62+
public function testIntArray()
4263
{
4364
$filter = new Filter('array');
44-
$filter->setName('test')->setValue([1,2,3])->setAlias('foo');
65+
$filter->setName('test')->setValue([1, 2, 3])->setAlias('foo');
4566
$this->assertSame('test:1,2,3 as foo', (string)$filter);
4667
}
4768

69+
public function testFloatArray()
70+
{
71+
$filter = new Filter('array');
72+
$filter->setName('test')->setValue([1.1, 2.2, 3.3])->setAlias('foo');
73+
$this->assertSame('test:1.1,2.2,3.3 as foo', (string)$filter);
74+
}
75+
4876
public function testSingleStringInArray()
4977
{
5078
$filter = new Filter('array');
@@ -63,4 +91,18 @@ public function testRange()
6391
$filter->setName('test')->setValue($filterRangeCollection)->setAlias('foo');
6492
$this->assertSame('test:range(1 to 10),(11 to 20) as foo', (string)$filter);
6593
}
94+
95+
public function testBoolTrue()
96+
{
97+
$filter = new Filter('bool');
98+
$filter->setName('test')->setValue(true);
99+
$this->assertSame('test:true', (string)$filter);
100+
}
101+
102+
public function testBoolFalse()
103+
{
104+
$filter = new Filter('bool');
105+
$filter->setName('test')->setValue(false);
106+
$this->assertSame('test:false', (string)$filter);
107+
}
66108
}

0 commit comments

Comments
 (0)