comparison MoinMoin/converter/_tests/test_include.py @ 1947:bc07c47e1aa8

fix 275 Cannot insert images into paragraphs
author Roger Haase <crosseyedpenguin@yahoo.com>
date Sun, 03 Feb 2013 10:49:45 -0700
parents 7f938234a924
children 286e315935ae
comparison
equal deleted inserted replaced
1946:8e263954d2e1 1947:bc07c47e1aa8
62 e = x[0] 62 e = x[0]
63 assert e.name == 'a' 63 assert e.name == 'a'
64 assert e.data == 'a(b)' 64 assert e.data == 'a(b)'
65 65
66 def test_IncludeHandlesCircularRecursion(self): 66 def test_IncludeHandlesCircularRecursion(self):
67 # issue #80 67 # detect circular recursion and create error message
68 # we use text/x.moin.wiki markup to make tests simple
69 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page2}}') 68 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page2}}')
70 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page3}}') 69 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page3}}')
71 update_item(u'page3', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page4}}') 70 update_item(u'page3', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page4}}')
72 update_item(u'page4', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page2}}') 71 update_item(u'page4', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page2}}')
73
74 page1 = Item.create(u'page1') 72 page1 = Item.create(u'page1')
75 rendered = page1.content._render_data() 73 rendered = page1.content._render_data()
76 # an error message will follow strong tag 74 # an error message will follow strong tag
77 assert '<strong class="moin-error">' in rendered 75 assert '<strong class="moin-error">' in rendered
78 76
79 def test_ExternalInclude(self): 77 def test_ExternalInclude(self):
78 # external include
80 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{http://moinmo.in}}') 79 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{http://moinmo.in}}')
81 rendered = Item.create(u'page1').content._render_data() 80 rendered = Item.create(u'page1').content._render_data()
82 assert '<object class="moin-http moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object>' in rendered 81 assert '<object class="moin-http moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object>' in rendered
82 # external include embedded within text (object is an inline tag)
83 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'before {{http://moinmo.in}} after')
84 rendered = Item.create(u'page1').content._render_data()
85 assert '<p>before <object class="moin-http moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object> after</p>' in rendered
86 # external include embedded within text italic and bold markup (object is an inline tag)
87 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u"before ''italic '''bold {{http://moinmo.in}} bold''' italic'' normal")
88 rendered = Item.create(u'page1').content._render_data()
89 assert '<p>before <em>italic <strong>bold <object class="moin-http moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object> bold</strong> italic</em> normal</p>' in rendered
83 90
84 def test_InlineInclude(self): 91 def test_InlineInclude(self):
85 # issue #28 92
86 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Content of page2 is "{{page2}}".') 93 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'before {{page2}} after')
87 94 # transclude single paragraph as inline
88 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Single line') 95 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Single line')
89 rendered = Item.create(u'page1').content._render_data() 96 rendered = Item.create(u'page1').content._render_data()
90 assert '<p>Content of page2 is "<span class="moin-transclusion" data-href="/page2">Single line</span>".</p>' in rendered 97 assert '<p>before <span class="moin-transclusion" data-href="/page2">Single line</span> after</p>' in rendered
91 98 # transclude multiple paragraphs as block
92 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Two\n\nParagraphs') 99 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Two\n\nParagraphs')
93 rendered = Item.create(u'page1').content._render_data() 100 rendered = Item.create(u'page1').content._render_data()
94 assert '<p>Content of page2 is "</p><div class="moin-transclusion" data-href="/page2"><p>Two</p><p>Paragraphs</p></div><p>".</p></div>' in rendered 101 assert '<p>before </p><div class="moin-transclusion" data-href="/page2"><p>Two</p><p>Paragraphs</p></div><p> after</p></div>' in rendered
95 102 # transclude single paragraph with internal markup as inline
96 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"this text contains ''italic'' string") 103 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"this text contains ''italic'' string")
97 rendered = Item.create(u'page1').content._render_data() 104 rendered = Item.create(u'page1').content._render_data()
98 assert 'Content of page2 is "<span class="moin-transclusion" data-href="/page2">this text contains <em>italic</em>' in rendered 105 assert 'before <span class="moin-transclusion" data-href="/page2">this text contains <em>italic</em>' in rendered
99 106 # transclude single paragraph as only content within a paragraph
100 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Content of page2 is\n\n{{page2}}') 107 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Content of page2 is\n\n{{page2}}')
101 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"Single Line") 108 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"Single Line")
102 rendered = Item.create(u'page1').content._render_data() 109 rendered = Item.create(u'page1').content._render_data()
103 assert '<p>Content of page2 is</p><p><span class="moin-transclusion" data-href="/page2">Single Line</span></p>' in rendered 110 assert '<p>Content of page2 is</p><p><span class="moin-transclusion" data-href="/page2">Single Line</span></p>' in rendered
104 111 # transclude single row table within a paragraph, block element forces paragraph to be split into 2 parts
105 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Content of page2 is "{{page2}}"') 112 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'before {{page2}} after')
106 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"|| table || cell ||") 113 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"|| table || cell ||")
107 rendered = Item.create(u'page1').content._render_data() 114 rendered = Item.create(u'page1').content._render_data()
108 assert 'Content of page2 is "</p>' in rendered 115 assert '<p>before </p><div class="moin-transclusion" data-href="/page2"><table' in rendered
109 assert '<table>' in rendered 116 assert '</table></div><p> after</p>' in rendered
110 assert rendered.count('<table>') == 1 117 assert rendered.count('<table>') == 1
111 118 # transclude two row table within a paragraph, block element forces paragraph to be split into 2 parts
112 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Content of page2 is "{{page2}}"') 119 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'before {{page2}} after')
113 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"|| this || has ||\n|| two || rows ||") 120 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"|| this || has ||\n|| two || rows ||")
114 rendered = Item.create(u'page1').content._render_data() 121 rendered = Item.create(u'page1').content._render_data()
115 assert 'Content of page2 is "</p>' in rendered 122 # inclusion of block item within a paragraph results in a before and after p
116 assert '<table>' in rendered 123 assert '<p>before </p><div class="moin-transclusion" data-href="/page2"><table' in rendered
124 assert '</table></div><p> after</p>' in rendered
117 assert rendered.count('<table>') == 1 125 assert rendered.count('<table>') == 1
118 126 # transclude nonexistent item
119 def test_InlineIncludeLogo(self): 127 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'before {{nonexistent}} after')
128 rendered = Item.create(u'page1').content._render_data()
129 assert '<p>before <span class="moin-transclusion" data-href="/nonexistent"><a href="/+modify/nonexistent">' in rendered
130 assert '</a></span> after</p>' in rendered
131 # transclude empty item
132 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'text {{page2}} text')
133 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"")
134 rendered = Item.create(u'page1').content._render_data()
135 assert '<p>text <span class="moin-transclusion" data-href="/page2"></span> text</p>' in rendered
136 def test_InlineIncludeCreole(self):
137 # transclude single paragraph as inline using creole parser
138 update_item(u'creole', {CONTENTTYPE: u'text/x.moin.creole;charset=utf-8'}, u'creole item')
139 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.creole;charset=utf-8'}, u'before {{creole}} after')
140 rendered = Item.create(u'page1').content._render_data()
141 assert '<p>before <span class="moin-transclusion" data-href="/creole">creole item</span> after</p>' in rendered
142 def test_InlineIncludeWithinMarkup(self):
143 # transclude single line item within italic and bold markup
144 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u"Normal ''italic '''bold {{page2}} bold''' italic'' normal")
145 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"Single Line")
146 rendered = Item.create(u'page1').content._render_data()
147 assert '<p>Normal <em>italic <strong>bold <span class="moin-transclusion" data-href="/page2">Single Line</span> bold</strong> italic</em> normal</p>' in rendered
148 # transclude double line item within italic and bold markup
149 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u"Normal ''italic '''bold {{page2}} bold''' italic'' normal")
150 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"Double\n\nLine")
151 rendered = Item.create(u'page1').content._render_data()
152 assert '<p>Normal <em>italic <strong>bold </strong></em></p><div class="moin-transclusion" data-href="/page2"><p>Double</p><p>Line</p></div><p><em><strong> bold</strong> italic</em> normal</p>' in rendered
153 # transclude single line item within comment
154 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u"comment /* before {{page2}} after */")
155 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"Single Line")
156 rendered = Item.create(u'page1').content._render_data()
157 assert '<p>comment <span class="comment">before <span class="moin-transclusion" data-href="/page2">Single Line</span> after</span></p>' in rendered
158 # transclude double line item within comment
159 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u"comment /* before {{page2}} after */")
160 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"Double\n\nLine")
161 rendered = Item.create(u'page1').content._render_data()
162 assert '<p>comment <span class="comment">before </span></p><div class="comment moin-transclusion" data-href="/page2"><p>Double</p><p>Line</p></div><p><span class="comment"> after</span></p>' in rendered
163
164 def test_InlineIncludeImage(self):
120 # the 3rd parameter, u'', should be a binary string defining a png image, but it is not needed for this simple test 165 # the 3rd parameter, u'', should be a binary string defining a png image, but it is not needed for this simple test
121 update_item(u'logo', {CONTENTTYPE: u'image/png'}, u'') 166 update_item(u'logo.png', {CONTENTTYPE: u'image/png'}, u'')
122 167 # simple transclusion
123 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{logo}}') 168 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{logo.png}}')
124 rendered = Item.create(u'page1').content._render_data() 169 rendered = Item.create(u'page1').content._render_data()
125 assert '<div class="moin-transclusion" data-href="/logo"><img alt="logo"' in rendered 170 assert '<p><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
126 171 assert '/logo.png" /></span></p>' in rendered
127 # <p /> is not valid html5; should be <p></p>. to be valid. Even better, there should be no empty p's. 172 # within paragraph
128 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{logo}}{{logo}}') 173 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'text {{logo.png}} text')
129 rendered = Item.create(u'page1').content._render_data() 174 rendered = Item.create(u'page1').content._render_data()
175 assert '<p>text <span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
176 assert '/logo.png" /></span> text</p>' in rendered
177 # within markup
178 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u"Normal ''italic '''bold {{logo.png}} bold''' italic'' normal")
179 rendered = Item.create(u'page1').content._render_data()
180 assert '<p>Normal <em>italic <strong>bold <span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
181 assert '/logo.png" /></span> bold</strong> italic</em> normal</p>' in rendered
182 # multiple transclusions
183 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{logo.png}}{{logo.png}}')
184 rendered = Item.create(u'page1').content._render_data()
185 assert '<p><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
186 assert '/logo.png" /></span><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
187 # check for old bug
130 assert '<p />' not in rendered 188 assert '<p />' not in rendered
131 assert '<p></p>' not in rendered 189 assert '<p></p>' not in rendered
190
191 def test_IncludeAsLinkAlternate(self):
192 # image as link alternate
193 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u"text [[page2|{{logo.png}}]] text")
194 rendered = Item.create(u'page1').content._render_data()
195 assert '<p>text <a href="/page2"><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src="' in rendered
196 assert '/logo.png" /></span></a> text</p>' in rendered
197 # link alternate with image embedded in markup
198 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u"text [[page2|plain '''bold {{logo.png}} bold''' plain]] text")
199 rendered = Item.create(u'page1').content._render_data()
200 assert '<p>text <a href="/page2">plain <strong>bold <span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src="' in rendered
201 assert '/logo.png" /></span> bold</strong> plain</a> text</p>' in rendered
202 # nonexistent image used in link alternate
203 # XXX html validation errora: A inside A - the image alternate turns into an A-tag to create the non-existant image. Error is easily seen.
204 # IE9, Firefox, Chrome, Safari, and Opera display this OK; the only usable hyperlink is to create the missing image.
205 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u"text [[page2|{{logoxxx.png}}]] text")
206 rendered = Item.create(u'page1').content._render_data()
207 assert '<p>text <a href="/page2"><span class="moin-transclusion" data-href="/logoxxx.png"><a href="/+modify/logoxxx.png">' in rendered
208 assert '</a></span></a> text</p>' in rendered
209 # image used as alternate to nonexistent page
210 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u"text [[page2xxx|{{logo.png}}]] text")
211 rendered = Item.create(u'page1').content._render_data()
212 assert '<p>text <a class="moin-nonexistent" href="/page2xxx"><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src="' in rendered
213 assert '/logo.png" /></span></a> text</p>' in rendered
214 # transclude block elem as link alternate to nonexistent page
215 # XXX html validation errors, block element inside A.
216 # IE9, Firefox, Chrome, Safari, and Opera display this OK; the hyperlink is the entire div enclosing the block elem
217 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'text [[MyPage|{{page2}}]] text')
218 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"Double\n\nLine")
219 rendered = Item.create(u'page1').content._render_data()
220 assert '<p>text <a class="moin-nonexistent" href="/MyPage"><div class="moin-transclusion" data-href="/page2"><p>Double</p><p>Line</p></div></a> text</p>' in rendered
221 # transclude empty item as link alternate to nonexistent page
222 # hyperlink will be empty span and invisible
223 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'text [[MyPage|{{page2}}]] text')
224 update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"")
225 rendered = Item.create(u'page1').content._render_data()
226 assert '<p>text <a class="moin-nonexistent" href="/MyPage"><span class="moin-transclusion" data-href="/page2"></span></a> text</p>' in rendered
227 # transclude external page as link alternate to nonexistent page
228 update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'text [[MyPage|{{http://moinmo.in}}]] text')
229 rendered = Item.create(u'page1').content._render_data()
230 assert '<p>text <a class="moin-nonexistent" href="/MyPage"><object class="moin-http moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object></a> text</p>' in rendered