531 |
531 |
532 def test_printable_value_string(self): |
532 def test_printable_value_string(self): |
533 e = self.request().create_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`', |
533 e = self.request().create_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`', |
534 content_format=u'text/rest') |
534 content_format=u'text/rest') |
535 self.assertEqual(e.printable_value('content'), |
535 self.assertEqual(e.printable_value('content'), |
536 '<p>du <a class="reference" href="http://testing.fr/cubicweb/cwsource/system">*ReST*</a></p>\n') |
536 '<p>du <a class="reference" href="http://testing.fr/cubicweb/cwsource/system">*ReST*</a></p>') |
537 e.cw_attr_cache['content'] = 'du <em>html</em> <ref rql="CWUser X">users</ref>' |
537 e.cw_attr_cache['content'] = 'du <em>html</em> <ref rql="CWUser X">users</ref>' |
538 e.cw_attr_cache['content_format'] = 'text/html' |
538 e.cw_attr_cache['content_format'] = 'text/html' |
539 self.assertEqual(e.printable_value('content'), |
539 self.assertEqual(e.printable_value('content'), |
540 'du <em>html</em> <a href="http://testing.fr/cubicweb/view?rql=CWUser%20X">users</a>') |
540 'du <em>html</em> <a href="http://testing.fr/cubicweb/view?rql=CWUser%20X">users</a>') |
541 e.cw_attr_cache['content'] = 'du *texte*' |
541 e.cw_attr_cache['content'] = 'du *texte*' |
542 e.cw_attr_cache['content_format'] = 'text/plain' |
542 e.cw_attr_cache['content_format'] = 'text/plain' |
543 self.assertEqual(e.printable_value('content'), |
543 self.assertEqual(e.printable_value('content'), |
544 '<p>\ndu *texte*<br/>\n</p>') |
544 '<p>\ndu *texte*<br/></p>') |
545 e.cw_attr_cache['title'] = 'zou' |
545 e.cw_attr_cache['title'] = 'zou' |
546 e.cw_attr_cache['content'] = '''\ |
546 e.cw_attr_cache['content'] = '''\ |
547 a title |
547 a title |
548 ======= |
548 ======= |
549 du :eid:`1:*ReST*`''' |
549 du :eid:`1:*ReST*`''' |
570 if mttransforms.HAS_PYGMENTS_TRANSFORMS: |
570 if mttransforms.HAS_PYGMENTS_TRANSFORMS: |
571 import pygments |
571 import pygments |
572 if tuple(int(i) for i in pygments.__version__.split('.')[:2]) >= (1, 3): |
572 if tuple(int(i) for i in pygments.__version__.split('.')[:2]) >= (1, 3): |
573 self.assertEqual(e.printable_value('data'), |
573 self.assertEqual(e.printable_value('data'), |
574 '''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mi">1</span> |
574 '''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mi">1</span> |
575 </pre></div> |
575 </pre></div>''') |
576 ''') |
|
577 else: |
576 else: |
578 self.assertEqual(e.printable_value('data'), |
577 self.assertEqual(e.printable_value('data'), |
579 '''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mf">1</span> |
578 '''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mf">1</span> |
580 </pre></div> |
579 </pre></div>''') |
581 ''') |
|
582 else: |
580 else: |
583 self.assertEqual(e.printable_value('data'), |
581 self.assertEqual(e.printable_value('data'), |
584 '''<pre class="python"> |
582 '''<pre class="python"> |
585 <span style="color: #C00000;">lambda</span> <span style="color: #000000;">x</span><span style="color: #0000C0;">:</span> <span style="color: #0080C0;">1</span> |
583 <span style="color: #C00000;">lambda</span> <span style="color: #000000;">x</span><span style="color: #0000C0;">:</span> <span style="color: #0080C0;">1</span> |
586 </pre> |
584 </pre>''') |
587 ''') |
|
588 |
585 |
589 e = req.create_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest', |
586 e = req.create_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest', |
590 data_encoding=u'utf-8', data_name=u'toto.txt') |
587 data_encoding=u'utf-8', data_name=u'toto.txt') |
591 self.assertEqual(e.printable_value('data'), |
588 self.assertEqual(e.printable_value('data'), |
592 u'<p><em>héhéhé</em></p>\n') |
589 u'<p><em>héhéhé</em></p>') |
593 |
590 |
594 def test_printable_value_bad_html(self): |
591 def test_printable_value_bad_html(self): |
595 """make sure we don't crash if we try to render invalid XHTML strings""" |
592 """make sure we don't crash if we try to render invalid XHTML strings""" |
596 req = self.request() |
593 req = self.request() |
597 e = req.create_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |
594 e = req.create_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |