-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH Improve type safety to support refactored template layer (#3010)
- Loading branch information
1 parent
f7b0f01
commit 1034dc5
Showing
6 changed files
with
101 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/php/Controllers/ContentControllerTest/DummyTemplateContentController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace SilverStripe\CMS\Tests\Controllers\ContentControllerTest; | ||
|
||
use SilverStripe\CMS\Controllers\ContentController; | ||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\View\TemplateEngine; | ||
|
||
class DummyTemplateContentController extends ContentController implements TestOnly | ||
{ | ||
protected function getTemplateEngine(): TemplateEngine | ||
{ | ||
return new DummyTemplateEngine(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
tests/php/Controllers/ContentControllerTest/DummyTemplateEngine.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace SilverStripe\CMS\Tests\Controllers\ContentControllerTest; | ||
|
||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\View\TemplateEngine; | ||
use SilverStripe\View\ViewLayerData; | ||
|
||
/** | ||
* A dummy template renderer that doesn't actually render any templates. | ||
*/ | ||
class DummyTemplateEngine implements TemplateEngine, TestOnly | ||
{ | ||
private string $output = '<html><head></head><body></body></html>'; | ||
|
||
private string|array $templates; | ||
|
||
public function __construct(string|array $templateCandidates = []) | ||
{ | ||
$this->templates = $templateCandidates; | ||
} | ||
|
||
public function setTemplate(string|array $templateCandidates): static | ||
{ | ||
$this->templates = $templateCandidates; | ||
return $this; | ||
} | ||
|
||
public function hasTemplate(string|array $templateCandidates): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function renderString(string $template, ViewLayerData $model, array $overlay = [], bool $cache = true): string | ||
{ | ||
return $this->output; | ||
} | ||
|
||
public function render(ViewLayerData $model, array $overlay = []): string | ||
{ | ||
return $this->output; | ||
} | ||
|
||
public function setOutput(string $output): void | ||
{ | ||
$this->output = $output; | ||
} | ||
|
||
/** | ||
* Returns the template candidates that were passed to the constructor or to setTemplate() | ||
*/ | ||
public function getTemplates(): array | ||
{ | ||
return $this->templates; | ||
} | ||
} |