|
6 | 6 | use PHPUnit\Framework\Attributes\Test; |
7 | 7 | use Statamic\Facades\Antlers; |
8 | 8 | use Statamic\Facades\Cascade; |
| 9 | +use Statamic\Fields\Field; |
| 10 | +use Statamic\Fields\Value; |
| 11 | +use Statamic\Fieldtypes\Text; |
9 | 12 | use Statamic\View\Events\ViewRendered; |
10 | 13 | use Statamic\View\View; |
11 | 14 | use Tests\FakesViews; |
@@ -243,15 +246,43 @@ public function view_gets_full_config_but_antlers_parse_gets_allowlisted_config_ |
243 | 246 |
|
244 | 247 | $template = 'hello {{ name }} [{{ config:app:name }}] [{{ config:top:secret }}] [{{ config:allowlisted:foo }}]'; |
245 | 248 |
|
246 | | - $data = ['name' => 'world', Cascade::instance()->toArray()]; |
| 249 | + $data = ['name' => 'world', Cascade::instance()->hydrate()->toArray()]; |
| 250 | + |
| 251 | + $parsed = (string) Antlers::parse($template, $data); |
| 252 | + $this->assertStringNotContainsString('123', $parsed, 'Parsed string contains unexpected config value.'); |
| 253 | + $this->assertSame('hello world [test] [] [bar]', $parsed); |
247 | 254 |
|
248 | 255 | $this->viewShouldReturnRaw('template', $template); |
249 | 256 | $parsed = (string) View::make('template', $data)->render(); |
250 | 257 | $this->assertStringContainsString('123', $parsed, 'Parsed view is missing config value.'); |
251 | 258 | $this->assertSame('hello world [test] [123] [bar]', $parsed); |
| 259 | + } |
252 | 260 |
|
253 | | - $parsed = (string) Antlers::parse($template, $data); |
254 | | - $this->assertStringNotContainsString('123', $parsed, 'Parsed string contains unexpected config value.'); |
255 | | - $this->assertSame('hello world [test] [] [bar]', $parsed); |
| 261 | + #[Test] |
| 262 | + public function antlers_fields_gets_allowlisted_config_only_in_view() |
| 263 | + { |
| 264 | + config([ |
| 265 | + 'app.name' => 'test', // allowed by default |
| 266 | + 'allowlisted.foo' => 'bar', // allowlisted |
| 267 | + 'top.secret' => '123', |
| 268 | + 'statamic.system.view_config_allowlist' => ['@default', 'allowlisted.foo'], |
| 269 | + ]); |
| 270 | + |
| 271 | + $template = 'hello {{ name }} [{{ config:app:name }}] [{{ config:top:secret }}] [{{ config:allowlisted:foo }}]'; |
| 272 | + |
| 273 | + $textFieldtype = new Text(); |
| 274 | + $field = new Field('text_field', [ |
| 275 | + 'type' => 'text', |
| 276 | + 'antlers' => true, |
| 277 | + ]); |
| 278 | + $textFieldtype->setField($field); |
| 279 | + |
| 280 | + $value = new Value($template, fieldtype: $textFieldtype); |
| 281 | + |
| 282 | + $data = ['name' => 'world', 'test' => $value]; |
| 283 | + |
| 284 | + $this->viewShouldReturnRaw('template', '[view:{{ config:top:secret }}] {{ test }}'); |
| 285 | + $parsed = (string) View::make('template', $data)->render(); |
| 286 | + $this->assertSame('[view:123] hello world [test] [] [bar]', $parsed); |
256 | 287 | } |
257 | 288 | } |
0 commit comments