|
10 | 10 | use Keepsuit\Liquid\Tests\Stubs\ContextSensitiveDrop; |
11 | 11 | use Keepsuit\Liquid\Tests\Stubs\CounterDrop; |
12 | 12 | use Keepsuit\Liquid\Tests\Stubs\HundredCents; |
| 13 | +use Keepsuit\Liquid\Tests\Stubs\MagicClass; |
| 14 | +use Keepsuit\Liquid\Tests\Stubs\SimpleClass; |
13 | 15 |
|
14 | 16 | test('variables', function (bool $strict) { |
15 | 17 | $context = new RenderContext(options: new RenderContextOptions(strictVariables: $strict)); |
@@ -691,3 +693,45 @@ function () use (&$global) { |
691 | 693 | 'default' => false, |
692 | 694 | 'strict' => true, |
693 | 695 | ]); |
| 696 | + |
| 697 | +test('internal context lookup with simple object', function (bool $strict) { |
| 698 | + $context = new RenderContext(options: new RenderContextOptions(strictVariables: $strict)); |
| 699 | + $context->set('object', new SimpleClass); |
| 700 | + |
| 701 | + expect($context->get('object.simpleProperty'))->toBe('foo'); |
| 702 | + expect($context->get('object.nullProperty'))->toBe(null); |
| 703 | + expect($context->get('object.staticProperty'))->toBe('foo'); |
| 704 | + expect($context->get('object.staticNullProperty'))->toBe(null); |
| 705 | + |
| 706 | + if ($strict) { |
| 707 | + expect($context->get('object.protectedProperty'))->toBeInstanceOf(UndefinedVariable::class); |
| 708 | + expect($context->get('object.nonExistingProperty'))->toBeInstanceOf(UndefinedVariable::class); |
| 709 | + expect($context->get('object.simpleMethod'))->toBeInstanceOf(UndefinedVariable::class); |
| 710 | + } else { |
| 711 | + expect($context->get('object.protectedProperty'))->toBe(null); |
| 712 | + expect($context->get('object.nonExistingProperty'))->toBe(null); |
| 713 | + expect($context->get('object.simpleMethod'))->toBe(null); |
| 714 | + } |
| 715 | +})->with([ |
| 716 | + 'default' => false, |
| 717 | + 'strict' => true, |
| 718 | +]); |
| 719 | + |
| 720 | +test('internal context lookup magic object', function (bool $strict) { |
| 721 | + $context = new RenderContext(options: new RenderContextOptions(strictVariables: $strict)); |
| 722 | + $context->set('object', new MagicClass); |
| 723 | + |
| 724 | + expect($context->get('object.simpleProperty'))->toBe('foo'); |
| 725 | + expect($context->get('object.nullProperty'))->toBe(null); |
| 726 | + |
| 727 | + if ($strict) { |
| 728 | + expect($context->get('object.nonExistingProperty'))->toBeInstanceOf(UndefinedVariable::class); |
| 729 | + expect($context->get('object.simpleMethod'))->toBeInstanceOf(UndefinedVariable::class); |
| 730 | + } else { |
| 731 | + expect($context->get('object.nonExistingProperty'))->toBe(null); |
| 732 | + expect($context->get('object.simpleMethod'))->toBe(null); |
| 733 | + } |
| 734 | +})->with([ |
| 735 | + 'default' => false, |
| 736 | + 'strict' => true, |
| 737 | +]); |
0 commit comments