@@ 12-83 (lines=72) @@ | ||
9 | /** |
|
10 | * Generated by PHPUnit_SkeletonGenerator on 2012-09-26 at 13:21:33. |
|
11 | */ |
|
12 | class StringFilterTypeTest extends Unit |
|
13 | { |
|
14 | /** |
|
15 | * @var \UnitTester |
|
16 | */ |
|
17 | protected $tester; |
|
18 | ||
19 | /** |
|
20 | * @var StringFilterType |
|
21 | */ |
|
22 | protected $object; |
|
23 | ||
24 | /** |
|
25 | * Sets up the fixture, for example, opens a network connection. |
|
26 | * This method is called before a test is executed. |
|
27 | */ |
|
28 | protected function _before() |
|
29 | { |
|
30 | $this->object = new StringFilterType('string', 'e'); |
|
31 | } |
|
32 | ||
33 | public function testBindRequest() |
|
34 | { |
|
35 | $request = new Request(array('filter_comparator_string' => 'equals', 'filter_value_string' => 'TheStringValue')); |
|
36 | ||
37 | $data = array(); |
|
38 | $uniqueId = 'string'; |
|
39 | $this->object->bindRequest($request, $data, $uniqueId); |
|
40 | ||
41 | $this->assertEquals(array('comparator' => 'equals', 'value' => 'TheStringValue'), $data); |
|
42 | } |
|
43 | ||
44 | /** |
|
45 | * @param string $comparator The comparator |
|
46 | * @param string $whereClause The where clause |
|
47 | * @param mixed $value The value |
|
48 | * @param mixed $testValue The test value |
|
49 | * |
|
50 | * @dataProvider applyDataProvider |
|
51 | */ |
|
52 | public function testApply($comparator, $whereClause, $value, $testValue) |
|
53 | { |
|
54 | $qb = $this->tester->getDBALQueryBuilder(); |
|
55 | $qb->select('*') |
|
56 | ->from('entity', 'e'); |
|
57 | $this->object->setQueryBuilder($qb); |
|
58 | $this->object->apply(array('comparator' => $comparator, 'value' => $value), 'string'); |
|
59 | ||
60 | $this->assertEquals("SELECT * FROM entity e WHERE e.string $whereClause", $qb->getSQL()); |
|
61 | $this->assertEquals($testValue, $qb->getParameter('var_string')); |
|
62 | } |
|
63 | ||
64 | /** |
|
65 | * @return array |
|
66 | */ |
|
67 | public static function applyDataProvider() |
|
68 | { |
|
69 | return array( |
|
70 | array('equals', '= :var_string', 'AStringValue1', 'AStringValue1'), |
|
71 | array('notequals', '<> :var_string', 'AStringValue2', 'AStringValue2'), |
|
72 | array('contains', 'LIKE :var_string', 'AStringValue3', '%AStringValue3%'), |
|
73 | array('doesnotcontain', 'NOT LIKE :var_string', 'AStringValue4', '%AStringValue4%'), |
|
74 | array('startswith', 'LIKE :var_string', 'AStringValue5', 'AStringValue5%'), |
|
75 | array('endswith', 'LIKE :var_string', 'AStringValue6', '%AStringValue6'), |
|
76 | ); |
|
77 | } |
|
78 | ||
79 | public function testGetTemplate() |
|
80 | { |
|
81 | $this->assertEquals('KunstmaanAdminListBundle:FilterType:stringFilter.html.twig', $this->object->getTemplate()); |
|
82 | } |
|
83 | } |
|
84 |
@@ 12-83 (lines=72) @@ | ||
9 | /** |
|
10 | * Generated by PHPUnit_SkeletonGenerator on 2012-09-26 at 13:21:34. |
|
11 | */ |
|
12 | class StringFilterTypeTest extends Unit |
|
13 | { |
|
14 | /** |
|
15 | * @var \UnitTester |
|
16 | */ |
|
17 | protected $tester; |
|
18 | ||
19 | /** |
|
20 | * @var StringFilterType |
|
21 | */ |
|
22 | protected $object; |
|
23 | ||
24 | /** |
|
25 | * Sets up the fixture, for example, opens a network connection. |
|
26 | * This method is called before a test is executed. |
|
27 | */ |
|
28 | protected function _before() |
|
29 | { |
|
30 | $this->object = new StringFilterType('string', 'b'); |
|
31 | } |
|
32 | ||
33 | public function testBindRequest() |
|
34 | { |
|
35 | $request = new Request(array('filter_comparator_string' => 'equals', 'filter_value_string' => 'TheStringValue')); |
|
36 | ||
37 | $data = array(); |
|
38 | $uniqueId = 'string'; |
|
39 | $this->object->bindRequest($request, $data, $uniqueId); |
|
40 | ||
41 | $this->assertEquals(array('comparator' => 'equals', 'value' => 'TheStringValue'), $data); |
|
42 | } |
|
43 | ||
44 | /** |
|
45 | * @param string $comparator The comparator |
|
46 | * @param string $whereClause The where clause |
|
47 | * @param mixed $value The value |
|
48 | * @param mixed $testValue The test value |
|
49 | * |
|
50 | * @dataProvider applyDataProvider |
|
51 | */ |
|
52 | public function testApply($comparator, $whereClause, $value, $testValue) |
|
53 | { |
|
54 | $qb = $this->tester->getORMQueryBuilder(); |
|
55 | $qb->select('b') |
|
56 | ->from('Entity', 'b'); |
|
57 | $this->object->setQueryBuilder($qb); |
|
58 | $this->object->apply(array('comparator' => $comparator, 'value' => $value), 'string'); |
|
59 | ||
60 | $this->assertEquals("SELECT b FROM Entity b WHERE b.string $whereClause", $qb->getDQL()); |
|
61 | $this->assertEquals($testValue, $qb->getParameter('var_string')->getValue()); |
|
62 | } |
|
63 | ||
64 | /** |
|
65 | * @return array |
|
66 | */ |
|
67 | public static function applyDataProvider() |
|
68 | { |
|
69 | return array( |
|
70 | array('equals', '= :var_string', 'AStringValue1', 'AStringValue1'), |
|
71 | array('notequals', '<> :var_string', 'AStringValue2', 'AStringValue2'), |
|
72 | array('contains', 'LIKE :var_string', 'AStringValue3', '%AStringValue3%'), |
|
73 | array('doesnotcontain', 'NOT LIKE :var_string', 'AStringValue4', '%AStringValue4%'), |
|
74 | array('startswith', 'LIKE :var_string', 'AStringValue5', 'AStringValue5%'), |
|
75 | array('endswith', 'LIKE :var_string', 'AStringValue6', '%AStringValue6'), |
|
76 | ); |
|
77 | } |
|
78 | ||
79 | public function testGetTemplate() |
|
80 | { |
|
81 | $this->assertEquals('KunstmaanAdminListBundle:FilterType:stringFilter.html.twig', $this->object->getTemplate()); |
|
82 | } |
|
83 | } |
|
84 |