@@ 10-73 (lines=64) @@ | ||
7 | use Kunstmaan\AdminListBundle\Tests\UnitTester; |
|
8 | use Symfony\Component\HttpFoundation\Request; |
|
9 | ||
10 | class BooleanFilterTypeTest extends Unit |
|
11 | { |
|
12 | /** |
|
13 | * @var UnitTester |
|
14 | */ |
|
15 | protected $tester; |
|
16 | ||
17 | /** |
|
18 | * @var BooleanFilterType |
|
19 | */ |
|
20 | protected $object; |
|
21 | ||
22 | /** |
|
23 | * Sets up the fixture, for example, opens a network connection. |
|
24 | * This method is called before a test is executed. |
|
25 | */ |
|
26 | protected function _before() |
|
27 | { |
|
28 | $this->object = new BooleanFilterType('boolean', 'b'); |
|
29 | } |
|
30 | ||
31 | public function testBindRequest() |
|
32 | { |
|
33 | $request = new Request(array('filter_value_boolean' => 'true')); |
|
34 | ||
35 | $data = array(); |
|
36 | $uniqueId = 'boolean'; |
|
37 | $this->object->bindRequest($request, $data, $uniqueId); |
|
38 | ||
39 | $this->assertEquals(array('value' => 'true'), $data); |
|
40 | } |
|
41 | ||
42 | /** |
|
43 | * @param mixed $value |
|
44 | * |
|
45 | * @dataProvider applyDataProvider |
|
46 | */ |
|
47 | public function testApply($value) |
|
48 | { |
|
49 | $qb = $this->tester->getORMQueryBuilder(); |
|
50 | $qb->select('b') |
|
51 | ->from('Entity', 'b'); |
|
52 | $this->object->setQueryBuilder($qb); |
|
53 | $this->object->apply(array('value' => $value), 'boolean'); |
|
54 | ||
55 | $this->assertEquals("SELECT b FROM Entity b WHERE b.boolean = $value", $qb->getDQL()); |
|
56 | } |
|
57 | ||
58 | /** |
|
59 | * @return array |
|
60 | */ |
|
61 | public static function applyDataProvider() |
|
62 | { |
|
63 | return array( |
|
64 | array('true'), |
|
65 | array('false'), |
|
66 | ); |
|
67 | } |
|
68 | ||
69 | public function testGetTemplate() |
|
70 | { |
|
71 | $this->assertEquals('KunstmaanAdminListBundle:FilterType:booleanFilter.html.twig', $this->object->getTemplate()); |
|
72 | } |
|
73 | } |
|
74 |
@@ 13-84 (lines=72) @@ | ||
10 | /** |
|
11 | * Class BooleanFilterTypeTest |
|
12 | */ |
|
13 | class BooleanFilterTypeTest extends Unit |
|
14 | { |
|
15 | /** |
|
16 | * @var UnitTester |
|
17 | */ |
|
18 | protected $tester; |
|
19 | ||
20 | /** |
|
21 | * @var BooleanFilterType |
|
22 | */ |
|
23 | protected $object; |
|
24 | ||
25 | /** |
|
26 | * Sets up the fixture, for example, opens a network connection. |
|
27 | * This method is called before a test is executed. |
|
28 | */ |
|
29 | protected function _before() |
|
30 | { |
|
31 | $this->object = new BooleanFilterType('boolean', 'e'); |
|
32 | } |
|
33 | ||
34 | /** |
|
35 | * Tears down the fixture, for example, closes a network connection. |
|
36 | * This method is called after a test is executed. |
|
37 | */ |
|
38 | protected function tearDown() |
|
39 | { |
|
40 | } |
|
41 | ||
42 | public function testBindRequest() |
|
43 | { |
|
44 | $request = new Request(array('filter_value_boolean' => 'true')); |
|
45 | ||
46 | $data = array(); |
|
47 | $uniqueId = 'boolean'; |
|
48 | $this->object->bindRequest($request, $data, $uniqueId); |
|
49 | ||
50 | $this->assertEquals(array('value' => 'true'), $data); |
|
51 | } |
|
52 | ||
53 | /** |
|
54 | * @param mixed $value |
|
55 | * |
|
56 | * @dataProvider applyDataProvider |
|
57 | */ |
|
58 | public function testApply($value) |
|
59 | { |
|
60 | $qb = $this->tester->getDBALQueryBuilder(); |
|
61 | $qb->select('*') |
|
62 | ->from('entity', 'e'); |
|
63 | $this->object->setQueryBuilder($qb); |
|
64 | $this->object->apply(array('value' => $value), 'boolean'); |
|
65 | ||
66 | $this->assertEquals("SELECT * FROM entity e WHERE e.boolean = $value", $qb->getSQL()); |
|
67 | } |
|
68 | ||
69 | /** |
|
70 | * @return array |
|
71 | */ |
|
72 | public static function applyDataProvider() |
|
73 | { |
|
74 | return array( |
|
75 | array('true'), |
|
76 | array('false'), |
|
77 | ); |
|
78 | } |
|
79 | ||
80 | public function testGetTemplate() |
|
81 | { |
|
82 | $this->assertEquals('KunstmaanAdminListBundle:FilterType:booleanFilter.html.twig', $this->object->getTemplate()); |
|
83 | } |
|
84 | } |
|
85 |