1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Stinger Entity Search package. |
5
|
|
|
* |
6
|
|
|
* (c) Oliver Kotte <[email protected]> |
7
|
|
|
* (c) Florian Meyer <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
namespace StingerSoft\EntitySearchBundle\Tests; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Form\Test\TypeTestCase; |
15
|
|
|
use StingerSoft\EntitySearchBundle\Form\QueryType; |
16
|
|
|
use StingerSoft\EntitySearchBundle\Form\FacetType; |
17
|
|
|
use StingerSoft\EntitySearchBundle\Model\Query; |
18
|
|
|
use Symfony\Component\Form\PreloadedExtension; |
19
|
|
|
use StingerSoft\EntitySearchBundle\Model\Document; |
20
|
|
|
|
21
|
|
|
class QueryTypeTest extends TypeTestCase { |
22
|
|
|
|
23
|
|
|
public function testInitialCall() { |
24
|
|
|
$form = $this->factory->create(QueryType::class); |
25
|
|
|
|
26
|
|
|
$query = new Query('Hemelinger'); |
27
|
|
|
|
28
|
|
|
$formData = array( |
29
|
|
|
'searchTerm' => 'Hemelinger' |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
// submit the data to the form directly |
33
|
|
|
$form->submit($formData); |
34
|
|
|
|
35
|
|
|
$this->assertTrue($form->isSynchronized()); |
36
|
|
|
$this->assertTrue($form->isValid()); |
37
|
|
|
$this->assertEquals($query, $form->getData()); |
38
|
|
|
|
39
|
|
|
// $view = $form->createView(); |
|
|
|
|
40
|
|
|
// $children = $view->children; |
|
|
|
|
41
|
|
|
|
42
|
|
|
// foreach (array_keys($formData) as $key) { |
|
|
|
|
43
|
|
|
// $this->assertArrayHasKey($key, $children); |
|
|
|
|
44
|
|
|
// } |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
public function testWithNotExistingFacets(){ |
49
|
|
|
|
50
|
|
|
$query = new Query('Hemelinger', array(), array( |
51
|
|
|
Document::FIELD_TYPE |
52
|
|
|
)); |
53
|
|
|
|
54
|
|
|
$form = $this->factory->create(QueryType::class, $query, array( |
55
|
|
|
'used_facets' => $query->getUsedFacets(), |
56
|
|
|
)); |
57
|
|
|
|
58
|
|
|
$expectedQuery = new Query('Hemelinger', array( |
59
|
|
|
Document::FIELD_TYPE => array( |
60
|
|
|
'\StingerSoft\TestBundle\Entity\Test' |
61
|
|
|
) |
62
|
|
|
), array( |
63
|
|
|
Document::FIELD_TYPE |
64
|
|
|
)); |
65
|
|
|
|
66
|
|
|
$formData = array( |
67
|
|
|
'searchTerm' => 'Hemelinger', |
68
|
|
|
'facet_type' => array( |
69
|
|
|
'\StingerSoft\TestBundle\Entity\Test' |
70
|
|
|
) |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
// submit the data to the form directly |
74
|
|
|
$form->submit($formData); |
75
|
|
|
|
76
|
|
|
$this->assertTrue($form->isSynchronized()); |
77
|
|
|
$this->assertTrue($form->isValid()); |
78
|
|
|
$this->assertEquals($expectedQuery, $form->getData()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* |
83
|
|
|
* {@inheritDoc} |
84
|
|
|
* |
85
|
|
|
* @see \Symfony\Component\Form\Test\FormIntegrationTestCase::getExtensions() |
86
|
|
|
*/ |
87
|
|
|
protected function getExtensions() { |
88
|
|
|
return array( |
89
|
|
|
new PreloadedExtension(array( |
90
|
|
|
new QueryType(), |
91
|
|
|
new FacetType(), |
92
|
|
|
), array()) |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.