From c5e3077822dd0d76e6f05d1b39b52ed06fd1dcad Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 17 Oct 2023 09:18:47 +0200 Subject: [PATCH] test(glpiselectfield): check non editable rendering with user type --- .../Formcreator/Field/GlpiSelectField.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/3-unit/GlpiPlugin/Formcreator/Field/GlpiSelectField.php b/tests/3-unit/GlpiPlugin/Formcreator/Field/GlpiSelectField.php index e402d2555..53b0ae073 100644 --- a/tests/3-unit/GlpiPlugin/Formcreator/Field/GlpiSelectField.php +++ b/tests/3-unit/GlpiPlugin/Formcreator/Field/GlpiSelectField.php @@ -33,6 +33,7 @@ namespace GlpiPlugin\Formcreator\Field\tests\units; use GlpiPlugin\Formcreator\Tests\CommonTestCase; use Computer; +use User; class GlpiselectField extends CommonTestCase { @@ -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(); + } }