|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Admingenerator\GeneratorBundle\Tests\Generator; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Util\Inflector; |
|
6
|
|
|
use Admingenerator\GeneratorBundle\Tests\TestCase; |
|
7
|
|
|
use Admingenerator\GeneratorBundle\Generator\Column; |
|
8
|
|
|
|
|
9
|
|
|
class ColumnTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
public function testGetName() |
|
13
|
|
|
{ |
|
14
|
|
|
$from_to_array = array( |
|
15
|
|
|
'name' => 'name', |
|
16
|
|
|
'underscored_name' => 'underscored_name', |
|
17
|
|
|
); |
|
18
|
|
|
|
|
19
|
|
|
$this->checkColumn($from_to_array, 'getName'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testGetGetter() |
|
23
|
|
|
{ |
|
24
|
|
|
$from_to_array = array( |
|
25
|
|
|
'name' => 'name', |
|
26
|
|
|
'underscored_name' => 'underscoredName', |
|
27
|
|
|
); |
|
28
|
|
|
|
|
29
|
|
|
$this->checkColumn($from_to_array, 'getGetter'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testGetLabel() |
|
33
|
|
|
{ |
|
34
|
|
|
$from_to_array = array( |
|
35
|
|
|
'name' => 'Name', |
|
36
|
|
|
'underscored_name' => 'Underscored name', |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
$this->checkColumn($from_to_array, 'getLabel'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testSetProperty() |
|
43
|
|
|
{ |
|
44
|
|
|
$options = array( |
|
45
|
|
|
'label' => 'my label', |
|
46
|
|
|
'getter' => 'getFoo', |
|
47
|
|
|
'sort_on' => 'foo', |
|
48
|
|
|
'sortOn' => 'foo', |
|
49
|
|
|
'dbType' => 'text', |
|
50
|
|
|
'formType' => 'choices', |
|
51
|
|
|
'formOptions' => array('foo' => 'bar'), |
|
52
|
|
|
'filterType' => 'choice', |
|
53
|
|
|
'filterOptions' => array('bar' => 'foo'), |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
$column = new Column("test", false); |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
foreach ($options as $option => $value) { |
|
59
|
|
|
$column->setProperty($option, $value); |
|
60
|
|
|
$this->assertEquals($value, call_user_func_array(array($column, 'get'.Inflector::classify($option)), array())); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testSetAddFormFilterOptionsPhpFunction() |
|
65
|
|
|
{ |
|
66
|
|
|
$column = new Column("test", false); |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
$addOptions = array('years' => array('.range' => array('from' => 1900, 'to' => 1915, 'step' => 5))); |
|
69
|
|
|
|
|
70
|
|
|
$column->setAddFormOptions($addOptions); |
|
71
|
|
|
|
|
72
|
|
|
$options = $column->getFormOptions(); |
|
73
|
|
|
|
|
74
|
|
|
$testOptions = array(1900, 1905, 1910, 1915); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertEquals($testOptions, $options['years']); |
|
77
|
|
|
|
|
78
|
|
|
$column->setAddFilterOptions($addOptions); |
|
79
|
|
|
|
|
80
|
|
|
$options = $column->getFilterOptions(); |
|
81
|
|
|
|
|
82
|
|
|
$this->assertEquals($testOptions, $options['years']); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function testCredentials() |
|
86
|
|
|
{ |
|
87
|
|
|
$column = new Column('test', false); |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
$column->setCredentials(array('credential1', 'credential2')); |
|
|
|
|
|
|
90
|
|
|
$column->setFiltersCredentials(array('credential3', 'credential4')); |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
$this->assertEquals(array('credential1', 'credential2'), $column->getCredentials()); |
|
93
|
|
|
$this->assertEquals(array('credential3', 'credential4'), $column->getFiltersCredentials()); |
|
94
|
|
|
|
|
95
|
|
|
$column->setFiltersCredentials(array()); |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
$this->assertEquals(array(), $column->getFiltersCredentials()); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function testFiltersCredentialsFallbackOnCredentialsIfNotCustomized() |
|
101
|
|
|
{ |
|
102
|
|
|
$column = new Column('test', false); |
|
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
$column->setCredentials(array('credential1', 'credential2')); |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
$this->assertEquals(array('credential1', 'credential2'), $column->getFiltersCredentials()); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @param string $method |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function checkColumn($from_to_array, $method) |
|
114
|
|
|
{ |
|
115
|
|
|
foreach ($from_to_array as $from => $to) { |
|
116
|
|
|
$column = new Column($from, false); |
|
|
|
|
|
|
117
|
|
|
$this->assertEquals($to, $column->$method()); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: