Skip to content

Commit 37ebc6f

Browse files
authored
Merge pull request #7872 from kenjis/fix-FactoriesCache-error
fix: replace `config(DocTypes::class)` with `new DocTypes()`
2 parents f7e6cff + 3474bc5 commit 37ebc6f

File tree

5 files changed

+85
-71
lines changed

5 files changed

+85
-71
lines changed

system/Common.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,11 +886,21 @@ function redirect(?string $route = null): RedirectResponse
886886
/**
887887
* Generates the solidus character (`/`) depending on the HTML5 compatibility flag in `Config\DocTypes`
888888
*
889+
* @param DocTypes|null $docTypesConfig New config. For testing purpose only.
890+
*
889891
* @internal
890892
*/
891-
function _solidus(): string
893+
function _solidus(?DocTypes $docTypesConfig = null): string
892894
{
893-
if (config(DocTypes::class)->html5 ?? false) {
895+
static $docTypes = null;
896+
897+
if ($docTypesConfig !== null) {
898+
$docTypes = $docTypesConfig;
899+
}
900+
901+
$docTypes ??= new DocTypes();
902+
903+
if ($docTypes->html5 ?? false) {
894904
return '';
895905
}
896906

system/Typography/Typography.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,11 @@ protected function protectCharacters(array $match): string
323323
*/
324324
public function nl2brExceptPre(string $str): string
325325
{
326-
$newstr = '';
326+
$newstr = '';
327+
$docTypes = new DocTypes();
327328

328329
for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++) {
329-
$xhtml = ! (config(DocTypes::class)->html5 ?? false);
330+
$xhtml = ! ($docTypes->html5 ?? false);
330331
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i], $xhtml) : $ex[$i];
331332

332333
if ($ct - 1 !== $i) {

tests/system/CommonFunctionsTest.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use CodeIgniter\Test\TestLogger;
3232
use Config\App;
3333
use Config\Cookie;
34+
use Config\DocTypes;
3435
use Config\Logger;
3536
use Config\Modules;
3637
use Config\Routing;
@@ -180,14 +181,24 @@ public function testSolidusElement(): void
180181

181182
public function testSolidusElementXHTML(): void
182183
{
183-
$doctypes = config('DocTypes');
184-
$default = $doctypes->html5;
185-
$doctypes->html5 = false;
184+
$this->disableHtml5();
186185

187186
$this->assertSame(' /', _solidus());
188187

189-
// Reset
190-
$doctypes->html5 = $default;
188+
$this->enableHtml5();
189+
}
190+
191+
private function disableHtml5()
192+
{
193+
$doctypes = new DocTypes();
194+
$doctypes->html5 = false;
195+
_solidus($doctypes);
196+
}
197+
198+
private function enableHtml5()
199+
{
200+
$doctypes = new DocTypes();
201+
_solidus($doctypes);
191202
}
192203

193204
public function testView(): void

tests/system/Helpers/FormHelperTest.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use CodeIgniter\HTTP\SiteURI;
1515
use CodeIgniter\Test\CIUnitTestCase;
1616
use Config\App;
17+
use Config\DocTypes;
1718
use Config\Filters;
1819
use Config\Services;
1920

@@ -262,9 +263,7 @@ public function testFormInput(): void
262263

263264
public function testFormInputXHTML(): void
264265
{
265-
$doctypes = config('DocTypes');
266-
$default = $doctypes->html5;
267-
$doctypes->html5 = false;
266+
$this->disableHtml5();
268267

269268
$expected = <<<EOH
270269
<input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%" />\n
@@ -279,8 +278,20 @@ public function testFormInputXHTML(): void
279278
];
280279
$this->assertSame($expected, form_input($data));
281280

282-
// Reset
283-
$doctypes->html5 = $default;
281+
$this->enableHtml5();
282+
}
283+
284+
private function disableHtml5()
285+
{
286+
$doctypes = new DocTypes();
287+
$doctypes->html5 = false;
288+
_solidus($doctypes);
289+
}
290+
291+
private function enableHtml5()
292+
{
293+
$doctypes = new DocTypes();
294+
_solidus($doctypes);
284295
}
285296

286297
public function testFormInputWithExtra(): void
@@ -317,17 +328,14 @@ public function testFormUpload(): void
317328

318329
public function testFormUploadXHTML(): void
319330
{
320-
$doctypes = config('DocTypes');
321-
$default = $doctypes->html5;
322-
$doctypes->html5 = false;
331+
$this->disableHtml5();
323332

324333
$expected = <<<EOH
325334
<input type="file" name="attachment" />\n
326335
EOH;
327336
$this->assertSame($expected, form_upload('attachment'));
328337

329-
// Reset
330-
$doctypes->html5 = $default;
338+
$this->enableHtml5();
331339
}
332340

333341
public function testFormTextarea(): void
@@ -656,17 +664,14 @@ public function testFormCheckbox(): void
656664

657665
public function testFormCheckboxXHTML(): void
658666
{
659-
$doctypes = config('DocTypes');
660-
$default = $doctypes->html5;
661-
$doctypes->html5 = false;
667+
$this->disableHtml5();
662668

663669
$expected = <<<EOH
664670
<input type="checkbox" name="newsletter" value="accept" checked="checked" />\n
665671
EOH;
666672
$this->assertSame($expected, form_checkbox('newsletter', 'accept', true));
667673

668-
// Reset
669-
$doctypes->html5 = $default;
674+
$this->enableHtml5();
670675
}
671676

672677
public function testFormCheckboxArrayData(): void

tests/system/Helpers/HTMLHelperTest.php

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use CodeIgniter\Files\Exceptions\FileNotFoundException;
1616
use CodeIgniter\Test\CIUnitTestCase;
1717
use Config\App;
18+
use Config\DocTypes;
1819

1920
/**
2021
* @internal
@@ -206,41 +207,48 @@ public function testIMGWithIndexpage(): void
206207

207208
public function testIMGXHTML(): void
208209
{
209-
$doctypes = config('DocTypes');
210-
$default = $doctypes->html5;
211-
$doctypes->html5 = false;
210+
$this->disableHtml5();
212211

213212
$target = 'http://site.com/images/picture.jpg';
214213
$expected = '<img src="http://site.com/images/picture.jpg" alt="" />';
215214
$this->assertSame($expected, img($target));
216215

217-
$doctypes->html5 = $default;
216+
$this->enableHtml5();
218217
}
219218

220-
public function testIMGXHTMLWithoutProtocol(): void
219+
private function disableHtml5()
221220
{
222-
$doctypes = config('DocTypes');
223-
$default = $doctypes->html5;
221+
$doctypes = new DocTypes();
224222
$doctypes->html5 = false;
223+
_solidus($doctypes);
224+
}
225+
226+
private function enableHtml5()
227+
{
228+
$doctypes = new DocTypes();
229+
_solidus($doctypes);
230+
}
231+
232+
public function testIMGXHTMLWithoutProtocol(): void
233+
{
234+
$this->disableHtml5();
225235

226236
$target = 'assets/mugshot.jpg';
227237
$expected = '<img src="http://example.com/assets/mugshot.jpg" alt="" />';
228238
$this->assertSame($expected, img($target));
229239

230-
$doctypes->html5 = $default;
240+
$this->enableHtml5();
231241
}
232242

233243
public function testIMGXHTMLWithIndexpage(): void
234244
{
235-
$doctypes = config('DocTypes');
236-
$default = $doctypes->html5;
237-
$doctypes->html5 = false;
245+
$this->disableHtml5();
238246

239247
$target = 'assets/mugshot.jpg';
240248
$expected = '<img src="http://example.com/index.php/assets/mugshot.jpg" alt="" />';
241249
$this->assertSame($expected, img($target, true));
242250

243-
$doctypes->html5 = $default;
251+
$this->enableHtml5();
244252
}
245253

246254
public function testImgData(): void
@@ -355,16 +363,13 @@ public function testLinkTag(): void
355363

356364
public function testLinkTagXHTML(): void
357365
{
358-
$doctypes = config('DocTypes');
359-
$default = $doctypes->html5;
360-
$doctypes->html5 = false;
366+
$this->disableHtml5();
361367

362368
$target = 'css/mystyles.css';
363369
$expected = '<link href="http://example.com/css/mystyles.css" rel="stylesheet" type="text/css" />';
364370
$this->assertSame($expected, link_tag($target));
365371

366-
// Reset
367-
$doctypes->html5 = $default;
372+
$this->enableHtml5();
368373
}
369374

370375
public function testLinkTagMedia(): void
@@ -509,9 +514,7 @@ public function testVideoWithTracks(): void
509514

510515
public function testVideoWithTracksXHTML(): void
511516
{
512-
$doctypes = config('DocTypes');
513-
$default = $doctypes->html5;
514-
$doctypes->html5 = false;
517+
$this->disableHtml5();
515518

516519
$expected = <<<'EOH'
517520
<video src="http://example.com/test.mp4" controls>
@@ -531,8 +534,7 @@ public function testVideoWithTracksXHTML(): void
531534
$video = video($target, $message, 'controls', $tracks);
532535
$this->assertSame($expected, $video);
533536

534-
// Reset
535-
$doctypes->html5 = $default;
537+
$this->enableHtml5();
536538
}
537539

538540
public function testVideoWithTracksAndIndex(): void
@@ -581,9 +583,7 @@ public function testVideoMultipleSources(): void
581583

582584
public function testVideoMultipleSourcesXHTML(): void
583585
{
584-
$doctypes = config('DocTypes');
585-
$default = $doctypes->html5;
586-
$doctypes->html5 = false;
586+
$this->disableHtml5();
587587

588588
$expected = <<<'EOH'
589589
<video class="test" controls>
@@ -613,8 +613,7 @@ public function testVideoMultipleSourcesXHTML(): void
613613

614614
$this->assertSame($expected, $video);
615615

616-
// Reset
617-
$doctypes->html5 = $default;
616+
$this->enableHtml5();
618617
}
619618

620619
public function testAudio(): void
@@ -642,9 +641,7 @@ public function testAudio(): void
642641

643642
public function testAudioXHTML(): void
644643
{
645-
$doctypes = config('DocTypes');
646-
$default = $doctypes->html5;
647-
$doctypes->html5 = false;
644+
$this->disableHtml5();
648645

649646
$expected = <<<'EOH'
650647
<audio id="test" controls>
@@ -670,8 +667,7 @@ public function testAudioXHTML(): void
670667

671668
$this->assertSame($expected, $audio);
672669

673-
// Reset
674-
$doctypes->html5 = $default;
670+
$this->enableHtml5();
675671
}
676672

677673
public function testAudioSimple(): void
@@ -774,15 +770,12 @@ public function testSource(): void
774770

775771
public function testSourceXHTML(): void
776772
{
777-
$doctypes = config('DocTypes');
778-
$default = $doctypes->html5;
779-
$doctypes->html5 = false;
773+
$this->disableHtml5();
780774

781775
$expected = '<source src="http://example.com/index.php/sound.mpeg" type="audio/mpeg" />';
782776
$this->assertSame($expected, source('sound.mpeg', 'audio/mpeg', '', true));
783777

784-
// Reset
785-
$doctypes->html5 = $default;
778+
$this->enableHtml5();
786779
}
787780

788781
public function testEmbed(): void
@@ -799,9 +792,7 @@ public function testEmbed(): void
799792

800793
public function testEmbedXHTML(): void
801794
{
802-
$doctypes = config('DocTypes');
803-
$default = $doctypes->html5;
804-
$doctypes->html5 = false;
795+
$this->disableHtml5();
805796

806797
$expected = <<<'EOH'
807798
<embed src="http://example.com/movie.mov" type="video/quicktime" class="test" />
@@ -812,8 +803,7 @@ public function testEmbedXHTML(): void
812803
$embed = embed('movie.mov', $type, 'class="test"');
813804
$this->assertSame($expected, $embed);
814805

815-
// Reset
816-
$doctypes->html5 = $default;
806+
$this->enableHtml5();
817807
}
818808

819809
public function testEmbedIndexed(): void
@@ -862,9 +852,7 @@ public function testObjectWithParams(): void
862852

863853
public function testObjectWithParamsXHTML(): void
864854
{
865-
$doctypes = config('DocTypes');
866-
$default = $doctypes->html5;
867-
$doctypes->html5 = false;
855+
$this->disableHtml5();
868856

869857
$expected = <<<'EOH'
870858
<object data="http://example.com/movie.swf" class="test">
@@ -882,8 +870,7 @@ public function testObjectWithParamsXHTML(): void
882870
$object = object('movie.swf', $type, 'class="test"', $parms);
883871
$this->assertSame($expected, $object);
884872

885-
// Reset
886-
$doctypes->html5 = $default;
873+
$this->enableHtml5();
887874
}
888875

889876
public function testObjectIndexed(): void

0 commit comments

Comments
 (0)