require 'test_helper' class ZazenTest < Zena::View::TestCase include Zena::Use::Zazen::ViewMethods include Zena::Use::HtmlTags::ViewMethods include Zena::Use::Refactor::ViewMethods # fquote, render_to_string include Zena::Use::Urls::ViewMethods # zen_path, etc include Bricks::Captcha::ViewMethods # mailhide test # ============ stubs ============ def _(str) ApplicationController.send(:_, str) end def js_data @js_data ||= [] end # =============================== def assert_zazen_match(css, code) assert_css css, zazen(code) end # all these additions are replaced by the traduction of 'unknown link' if the user does not have read access to the linked node. def test_bad_link assert_match %r{unknown link}, zazen('"hello":99') end def test_wiki_link login(:tiger) assert_equal "

? colors? I like yellow mug

", zazen("? colors? I like ?yellow mug?") assert_match %r{blah blih test it}, zazen('??blah?? ??blih ?test? it??') end def test_image_title login(:tiger) assert_match %r{
]*>

blah

}, zazen("!30/blah \"\":21!") assert_match %r{

blah

}, zazen("!30_pv/blah \"\":21!") assert_match %r{

Photo taken from.*

}, zazen("!30/!") end def test_make_link login(:tiger) # * ["":34] creates a link to node 34 with node's title. assert_equal '

Clean Water project

', zazen('"":21') # * ["title":34] creates a link to node 34 with the given title. assert_equal '

hello

', zazen('"hello":21') # * ["":034] if the node id starts with '0', creates a popup link. assert_match %r{/oo/projects/cleanWater.*window.open.*hello}, zazen('"hello":021') end def test_make_link_sharp login(:tiger) assert_equal '

hello

', zazen('"hello":34#') assert_equal '

hello

', zazen('"hello":34#[id]') assert_equal '

hello

', zazen('"hello":34#[zip]') assert_equal '

hello

', zazen('"hello":34#[name]') # * ["":34#[parent/]] if the node id starts with '0', creates a popup link. assert_equal '

hello

', zazen('"hello":34#[parent/]') assert_equal '

hello

', zazen('"hello":34#[parent/id]') assert_equal '

hello

', zazen('"hello":34#[parent/zip]') assert_equal '

hello

', zazen('"hello":34#[parent/name]') end def test_make_image login(:tiger) # * [!24!] inline image 24. (default format is 'pv' defined in #ImageBuilder). Options are : assert_equal "

it's a lake

", zazen('!24!') # ** [!024!] inline image, default format, link to full image. assert_equal "

it's a lake

", zazen('!024!') end def test_make_image_with_document login(:tiger) assert_match %r{

}, zazen('!25!') assert_match %r{

}, zazen('!025!') # same as '!25!' assert_match %r{

}, zazen('!25_pv!') end def test_make_bad_image assert_match %r{unknown document}, zazen('!99!') end def test_make_image_align # ** [!<.24!] or [!<24!] inline image surrounded with

assert_match %r{class='img_left'.*img.*/en/projects/cleanWater/image24_std.jpg.*class='std'}, zazen('!<.24!') assert_match %r{class='img_left'.*img.*/en/projects/cleanWater/image24_std.jpg.*class='std'}, zazen('!<24!') # ** [!>.24!] inline image surrounded with

assert_match %r{class='img_right'.*img.*/en/projects/cleanWater/image24_std.jpg.*class='std'}, zazen('!>.24!') assert_match %r{class='img_right'.*img.*/en/projects/cleanWater/image24_std.jpg.*class='std'}, zazen('!>24!') # ** [!=.24!] inline image with

assert_match %r{class='img_center'.*img.*/en/projects/cleanWater/image24_std.jpg.*class='std'}, zazen('!=.24!') assert_match %r{class='img_center'.*img.*/en/projects/cleanWater/image24_std.jpg.*class='std'}, zazen('!=24!') end def test_make_iformat # ** [!24_pv!] inline image transformed to format 'pv'. Formats are defined in #ImageBuilder. assert_match %r{.*img.*/en/projects/cleanWater/image24.jpg.*600.*440.*class='full'}, zazen('!24_full!') assert_match %r{.*img.*/en/projects/cleanWater/image24_tiny.jpg.*16.*16.*class='tiny'}, zazen('!24_tiny!') end def test_all_options # ** all the options above can be used together as in [!>.26.std!] : inline image on the right, size 'med'. assert_match %r{class='img_right'.*img.*/en/projects/cleanWater/image24_mini.jpg.*32.*32.*class='mini'}, zazen('!>24_mini!') assert_match %r{class='img_right'.*img.*/en/projects/cleanWater/image24_mini.jpg.*32.*32.*class='mini'}, zazen('!>.24_mini!') end def test_make_gallery login(:anon) # ** [![2,3,5]!] gallery : inline preview with javascript inline viewer assert_match %r{table.*gallery.*Zena.transfer.*image24_pv.jpg.*image24_std.jpg.*image30_pv.jpg.*image30_std.jpg}m, zazen('![24,30]!') @node = secure!(Node) { Node.find(nodes_id(:wiki)) } # ** [![]!] gallery with all images contained in the current node assert_match %r{table.*gallery.*Zena.transfer.*image30_pv.jpg.*image30_std.jpg.*image31_pv.jpg.*image31_std.jpg}m, zazen('![]!') end def test_make_gallery_bad_zips login(:anon) @node = secure!(Node) { Node.find(nodes_id(:wiki)) } assert_nil secure(Node) { Node.find_by_id(999)} assert_nothing_raised { zazen("this ![999]!") } end def test_list_nodes login(:lion) # * [!{7,9}!] documents listing for documents 7 and 9 assert_match %r{table.*tr.*bird.*tr.*water}m, zazen('!{30,25}!') # water, forest # * [!{}!] list all documents (with images) for the current node @node = secure!(Node) { Node.find(nodes_id(:cleanWater))} assert_match %r{table.*tr.*water}m, zazen('!{}!') # * [!{i}!] list all images for the current node assert_no_match %r{water}m, (i=zazen('!{i}!')) # * [!{d}!] list all documents (without images) for the current node @node = secure!(Node) { Node.find(nodes_id(:wiki)) } assert_no_match %r{flower}m, (d=zazen('!{d}!')) end def test_image_as_link # * [!26!:37] you can use an image as the source for a link assert_zazen_match "p a[@href='/en/projects/cleanWater'] img.std[@src='/en/image30_std.jpg?929831698949'][@width='440'][@height='400']", '!30!:21' # * [!26!:www.example.com] use an image for an outgoing link assert_zazen_match "p a[@href='http://www.example.com'] img.std[@src='/en/image30_std.jpg?929831698949']", '!30!:http://www.example.com' end def test_full assert_zazen_match "div.img_left a[@href='/en/projects/cleanWater'][@onclick*=window.open] img.std[@src='/en/projects/cleanWater/image24_std.jpg?929831698949'][@width='545'][@height='400'][@alt='it\\'s a lake']", '!<.24_3!:021' end def test_empty_image_ref assert_equal '

!!

', zazen('!!') assert_equal "

!\n
!

", zazen("!\n!") assert_equal "

!!!

", zazen('!!!') end def test_no_images assert_match %r{salut les \[image: bird\]}, zazen('salut les !30_pv!', :images=>false) end def test_pseudo_id assert_zazen_match "a[@href='/en/contact15.html'][text()='people/lion']", 'This is a "link"::lio.' assert_zazen_match "a[@href='/en/image30_pv.jpg?967816914293'][text()='projects/wiki/bird_pv.jpg']", 'This is a "link"::bir_pv.data.' end def test_pseudo_id_numbers_only login(:lion) lion = secure!(Node) { nodes(:lion) } assert lion.update_attributes(:name => '1234') login(:anon) assert_equal '

This is a people/1234.

', zazen('This is a "link"::123.') end def test_pseudo_path login(:lion) lion = secure!(Node) { nodes(:lion) } assert lion.update_attributes(:name => 'status') @node = secure!(Node) { nodes(:cleanWater) } assert_equal '

Read projects/cleanWater/status

', zazen('Read "":(/projects/cleanWater/status)') assert_equal '

Read projects/cleanWater/status

', zazen('Read "":(status)') @node = secure!(Node) { nodes(:people) } assert_equal '

Read projects/cleanWater/status

', zazen('Read "":(/projects/cleanWater/status)') assert_equal "

See bird

", zazen('See !:(/projects/wiki/bird)_side!') assert_equal "

See bird

", zazen('See !:(/projects/wiki/bird)_side!:(status)') assert_equal '

Read people/status

', zazen('Read "":(status)') @node = secure!(Node) { nodes(:wiki) } assert_equal "

See bird

", zazen('See !:(bird)_side!:(/projects/cleanWater)') end def test_bad_pseudo_path login(:lion) lion = secure!(Node) { nodes(:lion) } @node = secure!(Node) { nodes(:cleanWater) } assert_equal '

Read [(shmol) not found]

', zazen('Read "":(shmol)') assert_equal 'Read "":(shmol)', zazen('Read "":(shmol)', :translate_ids => :zip, :node => lion) end def test_translate_ids login(:anon) projects = secure!(Node) { nodes(:projects) } zena = secure!(Node) { nodes(:zena) } assert_equal "This \"is\":33 \"a\":#{nodes_zip(:wiki)} !#{nodes_zip(:bird_jpg)}! \"link\":#{nodes_zip(:lion)}.", zazen('This "is":33 "a":(projects/wiki) !(projects/wiki/bird)! "link"::lio.', :translate_ids => :zip, :node => zena) assert_equal 'This "is":(../collections/art) "a":(wiki) !(wiki/bird)! !{(wiki/bird)}! ![(wiki/bird)]! "link":(../people/lion).', zazen('This "is":33 "a":(/projects/wiki) !30! !{30}! ![30]! "link"::lio.', :translate_ids => :relative_path, :node => projects) assert_equal "This \"is\":33 \"a\":#{nodes_zip(:wiki)} !#{nodes_zip(:bird_jpg)}! \"link\":#{nodes_zip(:lion)}.", zazen('This "is":(../collections/art) "a":(wiki) !(wiki/bird)! "link":(../people/lion).', :translate_ids => :zip, :node => projects) assert_equal "This \"is\":33 \"a\":#{nodes_zip(:wiki)} !#{nodes_zip(:bird_jpg)}! \"link\":#{nodes_zip(:lion)}.", zazen('This "is":(collections/art) "a":(/projects/wiki) !(/projects/wiki/bird)! "link":(people/lion).', :translate_ids => :zip, :node => zena) end def test_table_asset login(:tiger) @node = secure!(Node) { nodes(:status) } assert_match %r{titleproblem.*solution.*cost.*.*dead hard drive}m, zazen("This is a table test:\n\n|problems|") end # only works if recaptcha plugin is installed def test_mail_hide login(:lion) assert current_site.update_attributes(:d_mail_hide_priv => '1234', :d_mail_hide_pub => '3456') @node = secure!(Node) { nodes(:status) } assert_match %r{