mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 09:05:13 -07:00
Test tag disabling using custom tags (#1318)
Since I don't think we have any use case to disable the `raw` or `echo` tags, so I would like liquid-c to not have to support that
This commit is contained in:
@@ -5,36 +5,44 @@ require 'test_helper'
|
|||||||
class TagDisableableTest < Minitest::Test
|
class TagDisableableTest < Minitest::Test
|
||||||
include Liquid
|
include Liquid
|
||||||
|
|
||||||
class DisableRaw < Block
|
module RenderTagName
|
||||||
disable_tags "raw"
|
def render(_context)
|
||||||
|
tag_name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class DisableRawEcho < Block
|
class Custom < Tag
|
||||||
disable_tags "raw", "echo"
|
|
||||||
end
|
|
||||||
|
|
||||||
class DisableableRaw < Liquid::Raw
|
|
||||||
prepend Liquid::Tag::Disableable
|
prepend Liquid::Tag::Disableable
|
||||||
|
include RenderTagName
|
||||||
end
|
end
|
||||||
|
|
||||||
class DisableableEcho < Liquid::Echo
|
class Custom2 < Tag
|
||||||
prepend Liquid::Tag::Disableable
|
prepend Liquid::Tag::Disableable
|
||||||
|
include RenderTagName
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_disables_raw
|
class DisableCustom < Block
|
||||||
|
disable_tags "custom"
|
||||||
|
end
|
||||||
|
|
||||||
|
class DisableBoth < Block
|
||||||
|
disable_tags "custom", "custom2"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_block_tag_disabling_nested_tag
|
||||||
with_disableable_tags do
|
with_disableable_tags do
|
||||||
with_custom_tag('disable', DisableRaw) do
|
with_custom_tag('disable', DisableCustom) do
|
||||||
output = Template.parse('{% disable %}{% raw %}Foobar{% endraw %}{% echo "foo" %}{% enddisable %}').render
|
output = Template.parse('{% disable %}{% custom %};{% custom2 %}{% enddisable %}').render
|
||||||
assert_equal('Liquid error: raw usage is not allowed in this contextfoo', output)
|
assert_equal('Liquid error: custom usage is not allowed in this context;custom2', output)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_disables_echo_and_raw
|
def test_block_tag_disabling_multiple_nested_tags
|
||||||
with_disableable_tags do
|
with_disableable_tags do
|
||||||
with_custom_tag('disable', DisableRawEcho) do
|
with_custom_tag('disable', DisableBoth) do
|
||||||
output = Template.parse('{% disable %}{% raw %}Foobar{% endraw %}{% echo "foo" %}{% enddisable %}').render
|
output = Template.parse('{% disable %}{% custom %};{% custom2 %}{% enddisable %}').render
|
||||||
assert_equal('Liquid error: raw usage is not allowed in this contextLiquid error: echo usage is not allowed in this context', output)
|
assert_equal('Liquid error: custom usage is not allowed in this context;Liquid error: custom2 usage is not allowed in this context', output)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -42,8 +50,8 @@ class TagDisableableTest < Minitest::Test
|
|||||||
private
|
private
|
||||||
|
|
||||||
def with_disableable_tags
|
def with_disableable_tags
|
||||||
with_custom_tag('raw', DisableableRaw) do
|
with_custom_tag('custom', Custom) do
|
||||||
with_custom_tag('echo', DisableableEcho) do
|
with_custom_tag('custom2', Custom2) do
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user