From 8aec8e5028be114d7e1277ddfb846f2f8f470053 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Tue, 3 Dec 2019 17:47:06 +0800 Subject: [PATCH] Add more tests --- app/Services/OptionForm.php | 11 ++++++----- tests/ServicesTest/OptionFormTest.php | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/Services/OptionForm.php b/app/Services/OptionForm.php index 5327b986..6427a9fb 100644 --- a/app/Services/OptionForm.php +++ b/app/Services/OptionForm.php @@ -550,7 +550,12 @@ class OptionFormGroup extends OptionFormItem $placeholder = trans()->has($key) ? trans($key) : ''; } - $this->items[] = ['type' => 'text', 'id' => $id, 'value' => $value, 'placeholder' => $placeholder]; + $this->items[] = [ + 'type' => 'text', + 'id' => $id, + 'value' => $value, + 'placeholder' => $placeholder + ]; return $this; } @@ -571,10 +576,6 @@ class OptionFormGroup extends OptionFormItem $rendered = []; foreach ($this->items as $item) { - if ($item['id'] && is_null($item['value'])) { - $item['value'] = option_localized($item['id']); - } - $rendered[] = view('forms.'.$item['type'])->with([ 'id' => $item['id'], 'value' => $item['value'], diff --git a/tests/ServicesTest/OptionFormTest.php b/tests/ServicesTest/OptionFormTest.php index 3c3dc8fa..3861b0aa 100644 --- a/tests/ServicesTest/OptionFormTest.php +++ b/tests/ServicesTest/OptionFormTest.php @@ -251,4 +251,20 @@ class OptionFormTest extends TestCase $crawler = new Crawler(sprintf('%s', $form)); $this->assertCount(1, $crawler->filter('div.card')); } + + public function testFormItemValue() + { + $form = new OptionForm('test'); + $form->text('t')->value('abc'); + $crawler = new Crawler($form->render()); + $this->assertEquals('abc', $crawler->filter('[name=t]')->attr('value')); + } + + public function testFormItemDisabled() + { + $form = new OptionForm('test'); + $form->text('t')->disabled(); + $crawler = new Crawler($form->render()); + $this->assertEquals('disabled', $crawler->filter('[name=t]')->attr('disabled')); + } }