|
30 | 30 | */
|
31 | 31 |
|
32 | 32 | namespace GlpiPlugin\Formcreator\Field\tests\units;
|
33 |
| -use GlpiPlugin\Formcreator\Tests\CommonTestCase; |
34 | 33 |
|
| 34 | +use AuthLDAP; |
| 35 | +use GlpiPlugin\Formcreator\Tests\CommonTestCase; |
35 | 36 | class LdapSelectField extends CommonTestCase {
|
36 | 37 |
|
37 | 38 | public function testGetName() {
|
@@ -140,4 +141,49 @@ public function testGetValueForDesign($value, $expected) {
|
140 | 141 | $output = $instance->getValueForDesign();
|
141 | 142 | $this->string($output)->isEqualTo($expected);
|
142 | 143 | }
|
| 144 | + |
| 145 | + |
| 146 | + public function providerPrepareQuestionInputForSave() { |
| 147 | + $authLdap = new AuthLDAP(); |
| 148 | + $authLdap->add([]); |
| 149 | + |
| 150 | + return [ |
| 151 | + [ |
| 152 | + 'input' => [ |
| 153 | + 'ldap_auth' => $authLdap->getID(), |
| 154 | + 'ldap_filter' => 'по', // Some cyrillic sample |
| 155 | + 'ldap_attribute' => '', |
| 156 | + ], |
| 157 | + 'expected' => [ |
| 158 | + 'values' => json_encode([ |
| 159 | + 'ldap_auth' => $authLdap->getID(), |
| 160 | + 'ldap_filter' => 'по', |
| 161 | + 'ldap_attribute' => '', |
| 162 | + ], JSON_UNESCAPED_UNICODE), |
| 163 | + ] |
| 164 | + ], |
| 165 | + ]; |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * @dataProvider providerPrepareQuestionInputForSave |
| 170 | + * |
| 171 | + * @param array $input |
| 172 | + * @param array $expected |
| 173 | + * @return void |
| 174 | + */ |
| 175 | + public function testPrepareQuestionInputForSave(array $input, array $expected) { |
| 176 | + // Make the form private |
| 177 | + $question = $this->getQuestion([ |
| 178 | + 'ldap_auth' => $input['ldap_auth'], |
| 179 | + 'fieldtype' => 'ldapselect', |
| 180 | + 'ldap_filter' => '', |
| 181 | + 'ldap_attribute' => '', |
| 182 | + ]); |
| 183 | + |
| 184 | + $instance = $this->newTestedInstance($question); |
| 185 | + |
| 186 | + $output = $instance->prepareQuestionInputForSave($input); |
| 187 | + $this->array($output)->isEqualTo($expected); |
| 188 | + } |
143 | 189 | }
|
0 commit comments