From f7bea58fd0888a8dc6ec787757aa1da1834c1099 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Wed, 19 Oct 2022 20:46:14 +0700 Subject: [PATCH 1/3] refactor: make it valid schema HTML refactor: make it valid schema html refactor: make it valid schema HTML refactor: make it valid schema HTML --- app/Config/DocTypes.php | 15 +++++++++ system/Common.php | 24 ++++++++++++++ system/Helpers/form_helper.php | 6 ++-- system/Helpers/html_helper.php | 2 +- tests/system/Helpers/FormHelperTest.php | 42 ++++++++++++------------- tests/system/Helpers/HTMLHelperTest.php | 6 ++-- 6 files changed, 67 insertions(+), 28 deletions(-) diff --git a/app/Config/DocTypes.php b/app/Config/DocTypes.php index 60a10585c437..7d50be7624e3 100755 --- a/app/Config/DocTypes.php +++ b/app/Config/DocTypes.php @@ -30,4 +30,19 @@ class DocTypes 'xhtml-rdfa-1' => '', 'xhtml-rdfa-2' => '', ]; + + /** + * Endline HTML Tag + * + * Generate endline HTML Tag by Document Type + * + * Currently : + * - html5 + * - Older HTML like `xhtml` + * + * For : + * - `` + * - `` + */ + public string $endlineTag = 'html5'; } diff --git a/system/Common.php b/system/Common.php index a90a32ec3ef7..ff0c6e9bdf1e 100644 --- a/system/Common.php +++ b/system/Common.php @@ -563,6 +563,30 @@ function function_usable(string $functionName): bool } } +if (! function_exists('htmltag_endline')) { + /** + * Endline HTML Tag + * + * Generates endline html tag by document type + */ + function htmltag_endline(): string + { + $config = new Config\DocTypes(); + $doctype = $config->endlineTag; + $listDoctypes = $config->list; + + if (! array_key_exists($doctype, $listDoctypes)) { + return ''; + } + + if ($doctype === 'html5') { + return '>'; + } + + return '/>'; + } +} + if (! function_exists('helper')) { /** * Loads a helper file into memory. Supports namespaced helpers, diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index d6b6e7bb9c48..2f2b15460c36 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -148,7 +148,7 @@ function form_input($data = '', string $value = '', $extra = '', string $type = 'value' => $value, ]; - return '\n"; + return '\n"; + return '\n"; + return ''; + return $img . stringify_attributes($attributes) . htmltag_endline(); } } diff --git a/tests/system/Helpers/FormHelperTest.php b/tests/system/Helpers/FormHelperTest.php index 2575b8664846..ae8455545850 100644 --- a/tests/system/Helpers/FormHelperTest.php +++ b/tests/system/Helpers/FormHelperTest.php @@ -101,7 +101,7 @@ public function testFormOpenWithoutAction() $Name = csrf_token(); $expected = << - + EOH; } else { @@ -128,7 +128,7 @@ public function testFormOpenWithoutMethod() $Name = csrf_token(); $expected = << - + EOH; } else { @@ -155,15 +155,15 @@ public function testFormOpenWithHidden() $Name = csrf_token(); $expected = << - - + + EOH; } else { $expected = <<<'EOH'
- + EOH; } @@ -189,7 +189,7 @@ public function testFormOpenMultipart() $Name = csrf_token(); $expected = << - + EOH; } else { @@ -214,7 +214,7 @@ public function testFormHidden() { $expected = <<\n + \n EOH; $this->assertSame($expected, form_hidden('username', 'johndoe')); } @@ -226,7 +226,7 @@ public function testFormHiddenArrayInput() ]; $expected = <<<'EOH' - + EOH; $this->assertSame($expected, form_hidden($data, null)); @@ -239,7 +239,7 @@ public function testFormHiddenArrayValues() ]; $expected = <<<'EOH' - + EOH; $this->assertSame($expected, form_hidden('name', $data)); @@ -248,7 +248,7 @@ public function testFormHiddenArrayValues() public function testFormInput() { $expected = <<\n + \n EOH; $data = [ 'name' => 'username', @@ -264,7 +264,7 @@ public function testFormInput() public function testFormInputWithExtra() { $expected = <<\n + \n EOH; $data = [ 'id' => 'identity', @@ -280,7 +280,7 @@ public function testFormInputWithExtra() public function testFormPassword() { $expected = <<\n + \n EOH; $this->assertSame($expected, form_password('password')); } @@ -288,7 +288,7 @@ public function testFormPassword() public function testFormUpload() { $expected = <<\n + \n EOH; $this->assertSame($expected, form_upload('attachment')); } @@ -612,7 +612,7 @@ public function testFormFieldsetClose() public function testFormCheckbox() { $expected = <<\n + \n EOH; $this->assertSame($expected, form_checkbox('newsletter', 'accept', true)); } @@ -625,7 +625,7 @@ public function testFormCheckboxArrayData() 'checked' => true, ]; $expected = <<<'EOH' - + EOH; $this->assertSame($expected, form_checkbox($data)); @@ -639,7 +639,7 @@ public function testFormCheckboxArrayDataWithCheckedFalse() 'checked' => false, ]; $expected = <<<'EOH' - + EOH; $this->assertSame($expected, form_checkbox($data)); @@ -648,7 +648,7 @@ public function testFormCheckboxArrayDataWithCheckedFalse() public function testFormRadio() { $expected = <<\n + \n EOH; $this->assertSame($expected, form_radio('newsletter', 'accept', true)); } @@ -656,7 +656,7 @@ public function testFormRadio() public function testFormSubmit() { $expected = <<\n + \n EOH; $this->assertSame($expected, form_submit('mysubmit', 'Submit Post!')); } @@ -683,7 +683,7 @@ public function testFormLabelWithAttributes() public function testFormReset() { $expected = <<\n + \n EOH; $this->assertSame($expected, form_reset('myreset', 'Reset')); } @@ -724,7 +724,7 @@ public function testFormDatalist() 'bar1', ]; $expected = <<<'EOH' - +