diff --git a/system/Common.php b/system/Common.php
index 03f72640e92e..c964e10ea899 100644
--- a/system/Common.php
+++ b/system/Common.php
@@ -886,11 +886,20 @@ function redirect(?string $route = null): RedirectResponse
/**
* Generates the solidus character (`/`) depending on the HTML5 compatibility flag in `Config\DocTypes`
*
+ * @param DocTypes|null $docTypesConfig New config. For testing purpose only.
+ *
* @internal
*/
- function _solidus(): string
+ function _solidus(?DocTypes $docTypesConfig = null): string
{
- $docTypes = new DocTypes();
+ static $docTypes = null;
+
+ if ($docTypesConfig !== null) {
+ $docTypes = $docTypesConfig;
+ }
+
+ $docTypes ??= new DocTypes();
+
if ($docTypes->html5 ?? false) {
return '';
}
diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php
index c678a0dd1fbb..b6702c5a7376 100644
--- a/tests/system/CommonFunctionsTest.php
+++ b/tests/system/CommonFunctionsTest.php
@@ -31,6 +31,7 @@
use CodeIgniter\Test\TestLogger;
use Config\App;
use Config\Cookie;
+use Config\DocTypes;
use Config\Logger;
use Config\Modules;
use Config\Routing;
@@ -180,14 +181,24 @@ public function testSolidusElement(): void
public function testSolidusElementXHTML(): void
{
- $doctypes = config('DocTypes');
- $default = $doctypes->html5;
- $doctypes->html5 = false;
+ $this->disableHtml5();
$this->assertSame(' /', _solidus());
- // Reset
- $doctypes->html5 = $default;
+ $this->enableHtml5();
+ }
+
+ private function disableHtml5()
+ {
+ $doctypes = new DocTypes();
+ $doctypes->html5 = false;
+ _solidus($doctypes);
+ }
+
+ private function enableHtml5()
+ {
+ $doctypes = new DocTypes();
+ _solidus($doctypes);
}
public function testView(): void
diff --git a/tests/system/Helpers/FormHelperTest.php b/tests/system/Helpers/FormHelperTest.php
index 8ed1bdeb7201..3b2482513581 100644
--- a/tests/system/Helpers/FormHelperTest.php
+++ b/tests/system/Helpers/FormHelperTest.php
@@ -14,6 +14,7 @@
use CodeIgniter\HTTP\SiteURI;
use CodeIgniter\Test\CIUnitTestCase;
use Config\App;
+use Config\DocTypes;
use Config\Filters;
use Config\Services;
@@ -262,9 +263,7 @@ public function testFormInput(): void
public function testFormInputXHTML(): void
{
- $doctypes = config('DocTypes');
- $default = $doctypes->html5;
- $doctypes->html5 = false;
+ $this->disableHtml5();
$expected = <<\n
@@ -279,8 +278,20 @@ public function testFormInputXHTML(): void
];
$this->assertSame($expected, form_input($data));
- // Reset
- $doctypes->html5 = $default;
+ $this->enableHtml5();
+ }
+
+ private function disableHtml5()
+ {
+ $doctypes = new DocTypes();
+ $doctypes->html5 = false;
+ _solidus($doctypes);
+ }
+
+ private function enableHtml5()
+ {
+ $doctypes = new DocTypes();
+ _solidus($doctypes);
}
public function testFormInputWithExtra(): void
@@ -317,17 +328,14 @@ public function testFormUpload(): void
public function testFormUploadXHTML(): void
{
- $doctypes = config('DocTypes');
- $default = $doctypes->html5;
- $doctypes->html5 = false;
+ $this->disableHtml5();
$expected = <<\n
EOH;
$this->assertSame($expected, form_upload('attachment'));
- // Reset
- $doctypes->html5 = $default;
+ $this->enableHtml5();
}
public function testFormTextarea(): void
@@ -656,17 +664,14 @@ public function testFormCheckbox(): void
public function testFormCheckboxXHTML(): void
{
- $doctypes = config('DocTypes');
- $default = $doctypes->html5;
- $doctypes->html5 = false;
+ $this->disableHtml5();
$expected = <<\n
EOH;
$this->assertSame($expected, form_checkbox('newsletter', 'accept', true));
- // Reset
- $doctypes->html5 = $default;
+ $this->enableHtml5();
}
public function testFormCheckboxArrayData(): void
diff --git a/tests/system/Helpers/HTMLHelperTest.php b/tests/system/Helpers/HTMLHelperTest.php
index 0d9452640730..f591b841024d 100755
--- a/tests/system/Helpers/HTMLHelperTest.php
+++ b/tests/system/Helpers/HTMLHelperTest.php
@@ -15,6 +15,7 @@
use CodeIgniter\Files\Exceptions\FileNotFoundException;
use CodeIgniter\Test\CIUnitTestCase;
use Config\App;
+use Config\DocTypes;
/**
* @internal
@@ -206,41 +207,48 @@ public function testIMGWithIndexpage(): void
public function testIMGXHTML(): void
{
- $doctypes = config('DocTypes');
- $default = $doctypes->html5;
- $doctypes->html5 = false;
+ $this->disableHtml5();
$target = 'http://site.com/images/picture.jpg';
$expected = '';
$this->assertSame($expected, img($target));
- $doctypes->html5 = $default;
+ $this->enableHtml5();
}
- public function testIMGXHTMLWithoutProtocol(): void
+ private function disableHtml5()
{
- $doctypes = config('DocTypes');
- $default = $doctypes->html5;
+ $doctypes = new DocTypes();
$doctypes->html5 = false;
+ _solidus($doctypes);
+ }
+
+ private function enableHtml5()
+ {
+ $doctypes = new DocTypes();
+ _solidus($doctypes);
+ }
+
+ public function testIMGXHTMLWithoutProtocol(): void
+ {
+ $this->disableHtml5();
$target = 'assets/mugshot.jpg';
$expected = '';
$this->assertSame($expected, img($target));
- $doctypes->html5 = $default;
+ $this->enableHtml5();
}
public function testIMGXHTMLWithIndexpage(): void
{
- $doctypes = config('DocTypes');
- $default = $doctypes->html5;
- $doctypes->html5 = false;
+ $this->disableHtml5();
$target = 'assets/mugshot.jpg';
$expected = '';
$this->assertSame($expected, img($target, true));
- $doctypes->html5 = $default;
+ $this->enableHtml5();
}
public function testImgData(): void
@@ -355,16 +363,13 @@ public function testLinkTag(): void
public function testLinkTagXHTML(): void
{
- $doctypes = config('DocTypes');
- $default = $doctypes->html5;
- $doctypes->html5 = false;
+ $this->disableHtml5();
$target = 'css/mystyles.css';
$expected = '';
$this->assertSame($expected, link_tag($target));
- // Reset
- $doctypes->html5 = $default;
+ $this->enableHtml5();
}
public function testLinkTagMedia(): void
@@ -509,9 +514,7 @@ public function testVideoWithTracks(): void
public function testVideoWithTracksXHTML(): void
{
- $doctypes = config('DocTypes');
- $default = $doctypes->html5;
- $doctypes->html5 = false;
+ $this->disableHtml5();
$expected = <<<'EOH'