From 272bddffde72bc05128e580559c2ea77bbca250d Mon Sep 17 00:00:00 2001 From: Tortue Torche Date: Thu, 21 Jan 2021 16:37:01 +0100 Subject: [PATCH] Fix Former::plaintext() with Bootstrap 4 (#602) Replace 'form-control-static' CSS class with 'form-control-plaintext' Usage with Laravel: {!! Former::open()->method('GET') !!} {!! Former::plaintext('test_static')->value('Plain Text') !!} {!! Former::close() !!} Reference: https://getbootstrap.com/docs/4.5/components/forms/#readonly-plain-text --- src/Former/Framework/TwitterBootstrap4.php | 2 +- tests/Fields/PlainTextTest.php | 43 ++++++++++++++++++++++ tests/TestCases/FormerTests.php | 15 ++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/Former/Framework/TwitterBootstrap4.php b/src/Former/Framework/TwitterBootstrap4.php index 36fb2d2b..83c9c202 100644 --- a/src/Former/Framework/TwitterBootstrap4.php +++ b/src/Former/Framework/TwitterBootstrap4.php @@ -295,7 +295,7 @@ public function getUneditableClasses() */ public function getPlainTextClasses() { - return 'form-control-static'; + return 'form-control-plaintext'; } /** diff --git a/tests/Fields/PlainTextTest.php b/tests/Fields/PlainTextTest.php index 1691022c..08e754d2 100644 --- a/tests/Fields/PlainTextTest.php +++ b/tests/Fields/PlainTextTest.php @@ -72,6 +72,22 @@ public function matchPlainTextInput() ); } + /** + * Matches an plain text input as a p tag + * + * @return array + */ + public function matchPlainTextInputWithBS4() + { + return array( + 'tag' => 'div', + 'content' => 'bar', + 'attributes' => array( + 'class' => 'form-control-plaintext', + ), + ); + } + /** * Matches an plain text input as a div tag * @@ -126,6 +142,21 @@ protected function formStaticGroup( return $this->formGroup($input, $label); } + /** + * Matches a Form Static Group + * + * @param string $input + * @param string $label + * + * @return boolean + */ + protected function formStaticGroupForBS4( + $input = '
bar
', + $label = '' + ) { + return $this->formGroupWithBS4($input, $label); + } + /** * Matches a Form Static Group with HTML value escaped * @@ -188,6 +219,18 @@ public function testCanCreatePlainTextFieldsWithBS3() $this->assertEquals($matcher, $input); } + public function testCanCreatePlainTextFieldsWithBS4() + { + $this->former->framework('TwitterBootstrap4'); + $input = $this->former->plaintext('foo')->value('bar')->__toString(); + + $this->assertHTML($this->matchPlainLabelWithBS3(), $input); + $this->assertHTML($this->matchPlainTextInputWithBS4(), $input); + + $matcher = $this->formStaticGroupForBS4(); + $this->assertEquals($matcher, $input); + } + public function testCanCreatePlainTextFieldsWithHtmlValueEscaped() { $this->former->framework('TwitterBootstrap3'); diff --git a/tests/TestCases/FormerTests.php b/tests/TestCases/FormerTests.php index d3f63a2c..1d325f5e 100644 --- a/tests/TestCases/FormerTests.php +++ b/tests/TestCases/FormerTests.php @@ -302,6 +302,21 @@ protected function formGroup( return '
'.$label.'
'.$input.'
'; } + /** + * Matches a Form Group + * + * @param string $input + * @param string $label + * + * @return boolean + */ + protected function formGroupWithBS4( + $input = '', + $label = '' + ) { + return '
'.$label.'
'.$input.'
'; + } + /** * Matches a required Control Group *