1 require File.dirname(__FILE__) + '/../test_helper'
3 class PageContextTest < Test::Unit::TestCase
4 fixtures :pages, :page_parts, :layouts, :snippets, :users
9 @context = PageContext.new(@page)
10 @parser = Radius::Parser.new(@context, :tag_prefix => 'r')
14 assert_equal(@page, @context.page)
18 assert_raises(StandardTags::TagError) { @parser.parse '<r:missing />' }
19 def @context.testing?() false end
20 assert_parse_output_match "undefined tag `missing'", '<r:missing />'
23 def test_request_is_passed_around
24 @context.define_tag "if_request" do |tag|
25 tag.expand if tag.locals.page.request
27 assert_parse_output_match /^$/, '<r:if_request>tada!</r:if_request>'
29 @page.request = ActionController::TestRequest.new
30 assert_parse_output_match "tada!", '<r:if_request>tada!</r:if_request>'
31 assert_parse_output_match "tada!", '<r:find url="/another/"><r:if_request>tada!</r:if_request></r:find>'
34 def test_response_is_passed_around
35 @context.define_tag "if_response" do |tag|
36 tag.expand if tag.locals.page.response
38 assert_parse_output_match /^$/, '<r:if_response>tada!</r:if_response>'
40 @page.response = ActionController::TestResponse.new
41 assert_parse_output_match "tada!", '<r:if_response>tada!</r:if_response>'
42 assert_parse_output_match "tada!", '<r:find url="/another/"><r:if_response>tada!</r:if_response></r:find>'
45 def test_exception_pops_stack
46 assert_equal '', @context.current_nesting
47 @context.define_tag("error") {|tag| raise "Broken!"}
48 def @context.testing?(); false; end
49 assert_parse_output_match /Broken\!/, "<r:error/>"
50 assert_equal '', @context.current_nesting
55 def assert_parse_output_match(regexp, input)
56 output = @parser.parse(input)
57 assert_match regexp, output