549 |
549 |
550 def test_printable_value_string(self): |
550 def test_printable_value_string(self): |
551 e = self.request().create_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`', |
551 e = self.request().create_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`', |
552 content_format=u'text/rest') |
552 content_format=u'text/rest') |
553 self.assertEqual(e.printable_value('content'), |
553 self.assertEqual(e.printable_value('content'), |
554 '<p>du <a class="reference" href="http://testing.fr/cubicweb/cwsource/system">*ReST*</a></p>\n') |
554 '<p>du <a class="reference" href="http://testing.fr/cubicweb/cwsource/system">*ReST*</a></p>') |
555 e.cw_attr_cache['content'] = 'du <em>html</em> <ref rql="CWUser X">users</ref>' |
555 e.cw_attr_cache['content'] = 'du <em>html</em> <ref rql="CWUser X">users</ref>' |
556 e.cw_attr_cache['content_format'] = 'text/html' |
556 e.cw_attr_cache['content_format'] = 'text/html' |
557 self.assertEqual(e.printable_value('content'), |
557 self.assertEqual(e.printable_value('content'), |
558 'du <em>html</em> <a href="http://testing.fr/cubicweb/view?rql=CWUser%20X">users</a>') |
558 'du <em>html</em> <a href="http://testing.fr/cubicweb/view?rql=CWUser%20X">users</a>') |
559 e.cw_attr_cache['content'] = 'du *texte*' |
559 e.cw_attr_cache['content'] = 'du *texte*' |
560 e.cw_attr_cache['content_format'] = 'text/plain' |
560 e.cw_attr_cache['content_format'] = 'text/plain' |
561 self.assertEqual(e.printable_value('content'), |
561 self.assertEqual(e.printable_value('content'), |
562 '<p>\ndu *texte*<br/>\n</p>') |
562 '<p>\ndu *texte*<br/></p>') |
563 e.cw_attr_cache['title'] = 'zou' |
563 e.cw_attr_cache['title'] = 'zou' |
564 e.cw_attr_cache['content'] = '''\ |
564 e.cw_attr_cache['content'] = '''\ |
565 a title |
565 a title |
566 ======= |
566 ======= |
567 du :eid:`1:*ReST*`''' |
567 du :eid:`1:*ReST*`''' |
588 if mttransforms.HAS_PYGMENTS_TRANSFORMS: |
588 if mttransforms.HAS_PYGMENTS_TRANSFORMS: |
589 import pygments |
589 import pygments |
590 if tuple(int(i) for i in pygments.__version__.split('.')[:2]) >= (1, 3): |
590 if tuple(int(i) for i in pygments.__version__.split('.')[:2]) >= (1, 3): |
591 self.assertEqual(e.printable_value('data'), |
591 self.assertEqual(e.printable_value('data'), |
592 '''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mi">1</span> |
592 '''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mi">1</span> |
593 </pre></div> |
593 </pre></div>''') |
594 ''') |
|
595 else: |
594 else: |
596 self.assertEqual(e.printable_value('data'), |
595 self.assertEqual(e.printable_value('data'), |
597 '''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mf">1</span> |
596 '''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mf">1</span> |
598 </pre></div> |
597 </pre></div>''') |
599 ''') |
|
600 else: |
598 else: |
601 self.assertEqual(e.printable_value('data'), |
599 self.assertEqual(e.printable_value('data'), |
602 '''<pre class="python"> |
600 '''<pre class="python"> |
603 <span style="color: #C00000;">lambda</span> <span style="color: #000000;">x</span><span style="color: #0000C0;">:</span> <span style="color: #0080C0;">1</span> |
601 <span style="color: #C00000;">lambda</span> <span style="color: #000000;">x</span><span style="color: #0000C0;">:</span> <span style="color: #0080C0;">1</span> |
604 </pre> |
602 </pre>''') |
605 ''') |
|
606 |
603 |
607 e = req.create_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest', |
604 e = req.create_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest', |
608 data_encoding=u'utf-8', data_name=u'toto.txt') |
605 data_encoding=u'utf-8', data_name=u'toto.txt') |
609 self.assertEqual(e.printable_value('data'), |
606 self.assertEqual(e.printable_value('data'), |
610 u'<p><em>héhéhé</em></p>\n') |
607 u'<p><em>héhéhé</em></p>') |
611 |
608 |
612 def test_printable_value_bad_html(self): |
609 def test_printable_value_bad_html(self): |
613 """make sure we don't crash if we try to render invalid XHTML strings""" |
610 """make sure we don't crash if we try to render invalid XHTML strings""" |
614 req = self.request() |
611 req = self.request() |
615 e = req.create_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |
612 e = req.create_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |