Skip to content

Commit

Permalink
test(glpiselectfield): check non editable rendering with user type
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Oct 17, 2023
1 parent af43a9c commit c5e3077
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/3-unit/GlpiPlugin/Formcreator/Field/GlpiSelectField.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
namespace GlpiPlugin\Formcreator\Field\tests\units;
use GlpiPlugin\Formcreator\Tests\CommonTestCase;
use Computer;
use User;

class GlpiselectField extends CommonTestCase {

Expand Down Expand Up @@ -330,4 +331,43 @@ public function testGetValueForApi($input, $expected) {
$output = $instance->getValueForApi();
$this->array($output)->isEqualTo($expected);
}


public function providerGetRenderedHtml() {
$question = $this->getQuestion([
'fieldtype' => 'glpiselect',
'itemtype' => User::class,
]);
$field = $question->getSubField();

yield [
'field' => $field,
'value' => User::getIdByName('glpi'),
'expectFunction' => function () use ($field) {
$this->string($field->getRenderedHtml('', false))->isEqualTo('glpi');
},
];

$login = $this->getUniqueString();
$this->getGlpiCoreItem(User::class, [
'name' => $login,
'firstname' => 'Alan',
'realname' => 'Turing'
]);
yield [
'field' => $field,
'value' => User::getIdByName($login),
'expectFunction' => function () use ($field) {
$this->string($field->getRenderedHtml('', false))->isEqualTo('Turing Alan');
},
];
}

/**
* @dataProvider providerGetRenderedHtml
*/
public function testGetRenderedHtml($field, $value, $expectFunction) {
$field->deserializeValue($value);
$expectFunction();
}
}

0 comments on commit c5e3077

Please sign in to comment.