1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mdiyakov\DoctrineSolrBundle\Tests\Filter\Field; |
4
|
|
|
|
5
|
|
|
use Mdiyakov\DoctrineSolrBundle\Filter\Field\EntityFieldEqualFilter; |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class StringObject |
9
|
|
|
{ |
10
|
|
|
private $value; |
11
|
|
|
|
12
|
|
|
public function __construct($value) |
13
|
|
|
{ |
14
|
|
|
$this->value = strval($value); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function __toString() |
18
|
|
|
{ |
19
|
|
|
return $this->value; |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
class EntityFieldEqualFilterTest extends \PHPUnit_Framework_TestCase |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
public function testIsFilterValidForScalar() |
28
|
|
|
{ |
29
|
|
|
$string = 'string'; |
30
|
|
|
$int = 123; |
31
|
|
|
$bool = true; |
32
|
|
|
$null = null; |
33
|
|
|
|
34
|
|
|
$entity = new \stdClass(); |
35
|
|
|
$filter = new EntityFieldEqualFilter(); |
36
|
|
|
$filter->setEntityFieldName('title'); |
37
|
|
|
|
38
|
|
|
$entity->title = $int; |
39
|
|
|
$filter->setEntityFieldValue($int); |
40
|
|
|
$this->assertEquals(true, $filter->isFilterValid($entity)); |
41
|
|
|
|
42
|
|
|
$entity->title = $string; |
43
|
|
|
$filter->setEntityFieldValue($string); |
44
|
|
|
$this->assertEquals(true, $filter->isFilterValid($entity)); |
45
|
|
|
|
46
|
|
|
$entity->title = $bool; |
47
|
|
|
$filter->setEntityFieldValue($bool); |
48
|
|
|
$this->assertEquals(true, $filter->isFilterValid($entity)); |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
$entity->title = $null; |
52
|
|
|
$filter->setEntityFieldValue($null); |
53
|
|
|
$this->assertEquals(true, $filter->isFilterValid($entity)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testIsFilterValidStringObject() |
57
|
|
|
{ |
58
|
|
|
$object = new StringObject('test'); |
59
|
|
|
$entity = new \stdClass(); |
60
|
|
|
$filter = new EntityFieldEqualFilter(); |
61
|
|
|
$filter->setEntityFieldName('title'); |
62
|
|
|
|
63
|
|
|
$entity->title = $object; |
64
|
|
|
$filter->setEntityFieldValue('test'); |
65
|
|
|
$this->assertEquals(true, $filter->isFilterValid($entity)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @expectedException \Mdiyakov\DoctrineSolrBundle\Exception\FilterConfigException |
70
|
|
|
*/ |
71
|
|
|
public function testIsFilterValidNotStringObject() |
72
|
|
|
{ |
73
|
|
|
$object = new \stdClass(); |
74
|
|
|
$entity = new \stdClass(); |
75
|
|
|
$filter = new EntityFieldEqualFilter(); |
76
|
|
|
$filter->setEntityFieldName('title'); |
77
|
|
|
|
78
|
|
|
$entity->title = $object; |
79
|
|
|
$filter->setEntityFieldValue('test'); |
80
|
|
|
$filter->isFilterValid($entity); |
81
|
|
|
} |
82
|
|
|
} |