def test_display_source_with_default_alignement(self):
        """If you render without any layer, you will see the code
        source rendered.
        """
        version = self.root.document.get_editable()
        factory = getMultiAdapter((version, TestRequest()), ITransformerFactory)
        transformer = factory(
            "body",
            version.body,
            """
<div class="external-source default" data-source-instance="%s">
</div>
"""
            % self.instance_key,
            IDisplayFilter,
        )
        tests.assertXMLEqual(
            unicode(transformer),
            """
<div class="citation">
 Don't trust citations on the Internet
 <div class="author">
  Charlemagne
 </div>
 <div class="source">
  The Internet
 </div>
</div>
""",
        )
        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 1)
    def test_render_image_resolution(self):
        """Test render a piece of text with an image that is refering
        an asset in Silva.
        """
        version = self.root.document.get_editable()
        save_editor_text(
            version.test, u"""
<h2>This is simple piece of text</h2>
<p>
  This simple piece of text contains a magic chocobo:
</p>
<div class="image">
  <img alt="Chocobo" resolution="thumbnail" reference="{image}" />
</div>""",
            content=version,
            image_content=self.root.chocobo,
            image_name=u'test image')

        factory = getMultiAdapter((version, TestRequest()), ITransformerFactory)
        transformer = factory(
            'test', version.test, unicode(version.test), IDisplayFilter)
        tests.assertXMLEqual(
            unicode(transformer),
            u"""
<h2>This is simple piece of text</h2>
<p>
  This simple piece of text contains a magic chocobo:
</p>
<div class="image">
  <img alt="Chocobo" height="120" width="120"
       src="http://localhost/root/chocobo?thumbnail" />
</div>""")
    def test_display_source_with_default_alignement(self):
        """If you render without any layer, you will see the code
        source rendered.
        """
        version = self.root.document.get_editable()
        factory = getMultiAdapter((version, TestRequest()),
                                  ITransformerFactory)
        transformer = factory(
            'body', version.body, """
<div class="external-source default" data-source-instance="%s">
</div>
""" % self.instance_key, IDisplayFilter)
        tests.assertXMLEqual(
            unicode(transformer), """
<div class="citation">
 Don't trust citations on the Internet
 <div class="author">
  Charlemagne
 </div>
 <div class="source">
  The Internet
 </div>
</div>
""")
        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 1)
    def test_render_reference_link_with_anchor(self):
        """Test render a piece of text with a link that is a reference
        to an another content in Silva, with an extra anchor.
        """
        version = self.root.document.get_editable()
        save_editor_text(
            version.test, u"""
<h2>This is simple piece of text</h2>
<p>
   This simple piece of text contains a simple piece of link:
   <a class="link" target="_self" reference="{link}" anchor="top">paragraph</a>.
</p>""",
            content=version,
            link_content=self.root.other,
            link_name=u'test link')

        factory = getMultiAdapter((version, TestRequest()), ITransformerFactory)
        transformer = factory(
            'test', version.test, unicode(version.test), IDisplayFilter)
        tests.assertXMLEqual(
            unicode(transformer),
            u"""
<h2>This is simple piece of text</h2>
<p>
  This simple piece of text contains a simple piece of link:
  <a class="link" target="_self" href="http://localhost/root/other#top">
    paragraph
  </a>.
</p>""")
    def test_create_source(self):
        """Create a source using the transformer.
        """
        version = self.root.document.get_editable()
        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 0)

        # We now save the source, this going to create it.
        saved_text = self.transform(
            """
<h1>
   Document Example
</h1>
<div class="external-source"
     data-silva-name="cs_citation"
     data-silva-settings="field_citation=Super%20citation&field_author=moi">
</div>
""",
            ISaveEditorFilter,
            version,
        )

        # One source have been created.
        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 1)
        instance_key = list(sources.all())[0]
        parameters, source = sources.get_parameters(instance=instance_key)
        self.assertTrue(verifyObject(IExternalSourceInstance, parameters))
        self.assertEqual(parameters.get_source_identifier(), "cs_citation")
        self.assertEqual(parameters.get_parameter_identifier(), instance_key)
        self.assertEqual(source.id, "cs_citation")
        self.assertEqual(parameters.citation, u"Super citation")
        self.assertEqual(parameters.author, u"moi")
        self.assertEqual(parameters.source, u"")
        tests.assertXMLEqual(
            saved_text,
            """
<div class="external-source" data-source-instance="%s">
</div>
"""
            % instance_key,
        )

        # You can render this source for the editor
        editor_text = self.transform(saved_text, IInputEditorFilter, version)
        tests.assertXMLEqual(
            editor_text,
            """
<h1>
   Document Example
</h1>
<div class="external-source" data-silva-instance="%s">
</div>
"""
            % instance_key,
        )

        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 1)
    def test_multiple_root_element(self):
        """On input, mutliple root elements stays unchanged.
        """
        intern_format = self.transform("<div><p>Simple text</p><p>Other text</p></div><p>Last</p>", ISaveEditorFilter)
        tests.assertXMLEqual(intern_format, "<div><p>Simple text</p><p>Other text</p></div><p>Last</p>")

        extern_format = self.transform(intern_format, IInputEditorFilter)
        tests.assertXMLEqual(extern_format, "<div><p>Simple text</p><p>Other text</p></div><p>Last</p>")
    def test_div(self):
        """On input, div stays unchanged.
        """
        intern_format = self.transform("<div><p>Simple text</p><p>Other text</p></div>", ISaveEditorFilter)
        tests.assertXMLEqual(intern_format, "<div><p>Simple text</p><p>Other text</p></div>")

        extern_format = self.transform(intern_format, IInputEditorFilter)
        tests.assertXMLEqual(extern_format, "<div><p>Simple text</p><p>Other text</p></div>")
    def test_paragraph(self):
        """On input, text stays unmodified.
        """
        intern_format = self.transform("<p>Simple text<i>Italic</i></p>", ISaveEditorFilter)
        tests.assertXMLEqual(intern_format, "<p>Simple text<i>Italic</i></p>")

        extern_format = self.transform(intern_format, IInputEditorFilter)
        tests.assertXMLEqual(extern_format, "<p>Simple text<i>Italic</i></p>")
    def test_new_anchor(self):
        """On input, anchors are collected, and the HTML stays the same.
        """
        version = self.root.document.get_editable()
        index = ITextIndexEntries(version.test)
        self.assertTrue(verifyObject(ITextIndexEntries, index))
        self.assertEqual(len(index.entries), 0)

        intern_format = self.transform(
            """
<p>
   <a class="anchor" name="simple" title="Simple Anchor" href="javascript:void(0)">
     Simple Anchor
   </a>
   The ultimate store of the anchors.

   <a class="anchor" name="advanced" title="Advanced Anchor">Advanced Anchor</a>

</p>
""",
            ISaveEditorFilter,
        )
        tests.assertXMLEqual(
            intern_format,
            """
<p>
   <a class="anchor" name="simple" title="Simple Anchor">Simple Anchor</a>
   The ultimate store of the anchors.

   <a class="anchor" name="advanced" title="Advanced Anchor">Advanced Anchor</a>
</p>
""",
        )

        index = ITextIndexEntries(version.test)
        self.assertEqual(len(index.entries), 2)
        self.assertEqual(index.entries[0].anchor, u"simple")
        self.assertEqual(index.entries[0].title, u"Simple Anchor")
        self.assertEqual(index.entries[1].anchor, u"advanced")
        self.assertEqual(index.entries[1].title, u"Advanced Anchor")

        extern_format = self.transform(intern_format, IInputEditorFilter)
        tests.assertXMLEqual(
            extern_format,
            """
<p>
   <a class="anchor" name="simple" title="Simple Anchor">
      Simple Anchor
   </a>
   The ultimate store of the anchors.

   <a class="anchor" name="advanced" title="Advanced Anchor">
      Advanced Anchor
   </a>
</p>
""",
        )
    def test_delete_source(self):
        """If you save again without provided the html for the source,
        it is removed.
        """
        version = self.root.document.get_editable()
        factory = getMultiAdapter((version, TestRequest()), ITransformerFactory)
        transformer = factory("body", version.body, "", ISaveEditorFilter)
        tests.assertXMLEqual(unicode(transformer), "")

        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 0)
    def test_delete_source(self):
        """If you save again without provided the html for the source,
        it is removed.
        """
        version = self.root.document.get_editable()
        factory = getMultiAdapter((version, TestRequest()),
                                  ITransformerFactory)
        transformer = factory('body', version.body, "", ISaveEditorFilter)
        tests.assertXMLEqual(unicode(transformer), "")

        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 0)
 def test_sanitize_css_with_error_first(self):
     html = """
             <div>
                 <a href="http://infrae.com/" style="invalid\asdchunck;text-decoration: underline;">link</a>
             </div>
             """
     sanitized = html_sanitize(html, self.allowed_html_tags, ['href'], ['text-decoration'])
     expected = """
                 <div>
                     <a href="http://infrae.com/" style="text-decoration: underline;">link</a>
                 </div>
                 """
     tests.assertXMLEqual(expected, sanitized)
 def test_sanitize_attributes(self):
     html = """
             <div>
                 <a href="http://infrae.com/" REL="media" CapitalizedNotAllowed="val">text</a>
             </div>
             """
     sanitized = html_sanitize(html, self.allowed_html_tags, ['href', 'rel'])
     expected = """
                 <div>
                     <a href="http://infrae.com/" rel="media">text</a>
                 </div>
                 """
     tests.assertXMLEqual(expected, sanitized)
 def test_sanitize_css(self):
     html = """
             <div>
                 <a href="http://infrae.com/" style="text-decoration: underline; font-size: 20px; display:block">link</a>
             </div>
             """
     sanitized = html_sanitize(html, self.allowed_html_tags, ['href'], ['text-decoration', 'display'])
     expected = """
                 <div>
                     <a href="http://infrae.com/" style="text-decoration: underline;display: block;">link</a>
                 </div>
                 """
     tests.assertXMLEqual(expected, sanitized)
    def test_create_source(self):
        """Create a source using the transformer.
        """
        version = self.root.document.get_editable()
        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 0)

        # We now save the source, this going to create it.
        saved_text = self.transform(
            """
<h1>
   Document Example
</h1>
<div class="external-source"
     data-silva-name="cs_citation"
     data-silva-settings="field_citation=Super%20citation&field_author=moi">
</div>
""", ISaveEditorFilter, version)

        # One source have been created.
        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 1)
        instance_key = list(sources.all())[0]
        parameters, source = sources.get_parameters(instance=instance_key)
        self.assertTrue(verifyObject(IExternalSourceInstance, parameters))
        self.assertEqual(parameters.get_source_identifier(), 'cs_citation')
        self.assertEqual(parameters.get_parameter_identifier(), instance_key)
        self.assertEqual(source.id, 'cs_citation')
        self.assertEqual(parameters.citation, u'Super citation')
        self.assertEqual(parameters.author, u'moi')
        self.assertEqual(parameters.source, u'')
        tests.assertXMLEqual(
            saved_text, """
<div class="external-source" data-source-instance="%s">
</div>
""" % instance_key)

        # You can render this source for the editor
        editor_text = self.transform(saved_text, IInputEditorFilter, version)
        tests.assertXMLEqual(
            editor_text, """
<h1>
   Document Example
</h1>
<div class="external-source" data-silva-instance="%s">
</div>
""" % instance_key)

        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 1)
    def test_empty_anchor(self):
        """On input, empty anchors are not collected.
        """
        version = self.root.document.get_editable()
        index = ITextIndexEntries(version.test)
        self.assertTrue(verifyObject(ITextIndexEntries, index))
        self.assertEqual(len(index.entries), 0)

        intern_format = self.transform(
            """
<p>
   <a class="anchor" name="missing" href="javascript:void(0)">Missing Title</a>
   The ultimate store of the anchors.
   <a class="anchor" name="empty" title="">Empty Title</a>
   <a class="anchor" name="space" title=" ">Title with a space</a>
</p>
""",
            ISaveEditorFilter,
        )
        tests.assertXMLEqual(
            intern_format,
            """
<p>
   <a class="anchor" name="missing">Missing Title</a>
   The ultimate store of the anchors.
   <a class="anchor" name="empty" title="">Empty Title</a>
   <a class="anchor" name="space" title="">Title with a space</a>
</p>
""",
        )

        index = ITextIndexEntries(version.test)
        self.assertEqual(len(index.entries), 0)

        extern_format = self.transform(intern_format, IInputEditorFilter)
        tests.assertXMLEqual(
            extern_format,
            """
<p>
   <a class="anchor" name="missing">Missing Title</a>
   The ultimate store of the anchors.
   <a class="anchor" name="empty" title="">
     Empty Title
   </a>
   <a class="anchor" name="space" title="">
     Title with a space
   </a>
</p>
""",
        )
    def test_display_broken_xml_source_public(self):
        """Test a source that have an invalid or missing
        data-source-instance.
        """
        version = self.root.document.get_editable()
        factory = getMultiAdapter((version, TestRequest()),
                                  ITransformerFactory)
        transformer = factory('body', version.body,
                              '<div class="external-source"></div>',
                              IDisplayFilter)

        tests.assertXMLEqual(unicode(transformer), """
<div class="external-source">
</div>
""")
    def test_display_broken_xml_source_public(self):
        """Test a source that have an invalid or missing
        data-source-instance.
        """
        version = self.root.document.get_editable()
        factory = getMultiAdapter((version, TestRequest()), ITransformerFactory)
        transformer = factory("body", version.body, '<div class="external-source"></div>', IDisplayFilter)

        tests.assertXMLEqual(
            unicode(transformer),
            """
<div class="external-source">
</div>
""",
        )
    def test_self_closing_tags(self):
        version = self.root.document.get_editable()
        save_editor_text(version.test, """
<h2>This is simple piece of text</h2>
<p>That contains <br>a paragraph.</p>
""")

        factory = getMultiAdapter((version, TestRequest()), ITransformerFactory)
        transformer = factory(
            'test', version.test, unicode(version.test), IDisplayFilter)
        tests.assertXMLEqual(
            unicode(transformer),
            u"""
<h2>This is simple piece of text</h2>
<p>That contains <br>a paragraph.</p>""")
 def test_sanitize_no_attributes_no_properties_allowed(self):
     html = """
             <div id="mydiv" class="myclass" title="mytitle" dir="rtl">
                 <span id="mydiv" class="myclass" title="mytitle" dir="rtl">this is inside the span</span>
                 <p>This is inside the p</p>
             </div>
             """
     allowed_html_tags = set([PerTagAllowedAttributes('div'),
                              PerTagAllowedAttributes('span')])
     sanitized = html_sanitize(html, allowed_html_tags, [])
     expected = """
                 <div>
                     <span>this is inside the span</span>
                 </div>
                 """
     tests.assertXMLEqual(expected, sanitized)
    def test_sanitize_per_tag_html_attributes(self):
        html = """
                <div id="mydiv" class="myclass" title="mytitle" dir="rtl">
                    <span id="mydiv" class="myclass" title="mytitle" dir="rtl">this is inside the span</span>
                </div>
                """
        allowed_html_tags = set([PerTagAllowedAttributes('div', set(['class', 'id'])),
                                 PerTagAllowedAttributes('span', set(['title']))])

        sanitized = html_sanitize(html, allowed_html_tags, ['dir'])
        expected = """
                    <div id="mydiv" class="myclass" dir="rtl">
                        <span title="mytitle" dir="rtl">this is inside the span</span>
                    </div>
                    """
        tests.assertXMLEqual(expected, sanitized)
    def test_sanitize_per_tag_css_properties(self):
        html = """
                <div style="color: red; background-color: blue; text-decoration: underline;">
                    <a href="http://infrae.com/" style="color: red; background-color: blue; text-decoration: underline;">link</a>
                </div>
                """
        allowed_html_tags = set([PerTagAllowedAttributes('a', css_properties=set(['color'])),
                                 PerTagAllowedAttributes('div', css_properties=set(['background-color']))])

        sanitized = html_sanitize(html, allowed_html_tags, ['href'], ['text-decoration'])
        expected = """
                    <div style="background-color: blue;text-decoration: underline;">
                        <a href="http://infrae.com/" style="color: red;text-decoration: underline;">link</a>
                    </div>
                    """
        tests.assertXMLEqual(expected, sanitized)
    def test_edit_anchor(self):
        """On input, unused anchors are removed.
        """
        version = self.root.document.get_editable()
        index = ITextIndexEntries(version.test)
        index.add(u"simple", u"Simple Anchor")
        index.add(u"useless", u"Useless Anchor")
        index.add(u"really_useless", u"Really Useless Anchor")
        self.assertTrue(verifyObject(ITextIndexEntries, index))
        self.assertEqual(len(index.entries), 3)

        intern_format = self.transform(
            """
<p>
   <a class="anchor" name="simple" title="Simple Anchor">Simple Anchor</a>
   The ultimate survivor.
</p>
""",
            ISaveEditorFilter,
        )
        tests.assertXMLEqual(
            intern_format,
            """
<p>
   <a class="anchor" name="simple" title="Simple Anchor">Simple Anchor</a>
   The ultimate survivor.
</p>
""",
        )

        index = ITextIndexEntries(version.test)
        self.assertEqual(len(index.entries), 1)
        self.assertEqual(index.entries[0].anchor, u"simple")
        self.assertEqual(index.entries[0].title, u"Simple Anchor")

        extern_format = self.transform(intern_format, IInputEditorFilter)
        tests.assertXMLEqual(
            extern_format,
            """
<p>
   <a class="anchor" name="simple" title="Simple Anchor">
      Simple Anchor
   </a>
   The ultimate survivor.
</p>
""",
        )
    def test_sanitize_tags(self):
        html = """
                <div>
                    <A href="http://infrae.com/">text<FORM><input type="submit" value="button" /></FORM> after</A>
                </div>
                """
        allowed_html_tags = set([PerTagAllowedAttributes('a'),
                                 PerTagAllowedAttributes('div'),
                                 PerTagAllowedAttributes('input')])

        sanitized = html_sanitize(html, allowed_html_tags, ['href'])
        expected = """
                    <div>
                        <a href="http://infrae.com/">text after</a>
                    </div>
                    """
        tests.assertXMLEqual(expected, sanitized)
    def test_display_source_with_multi_tags(self):
        """Display and render a source that have multiple top level
        tags.
        """
        version = self.root.document.get_editable()
        factory = getMultiAdapter((version, TestRequest()), ITransformerFactory)
        transformer = factory("body", version.body, self.saved_text, IDisplayFilter)
        tests.assertXMLEqual(
            unicode(transformer),
            """
<h1>This is a title</h1>
<a href="http://silvacms.org">SilvaCMS</a>
<b>Silva is cool</b>
<p>Well good bye!</p>
""",
        )
        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 1)
    def test_display_source_with_multi_tags(self):
        """Display and render a source that have multiple top level
        tags.
        """
        version = self.root.document.get_editable()
        factory = getMultiAdapter((version, TestRequest()),
                                  ITransformerFactory)
        transformer = factory('body', version.body, self.saved_text,
                              IDisplayFilter)
        tests.assertXMLEqual(
            unicode(transformer), """
<h1>This is a title</h1>
<a href="http://silvacms.org">SilvaCMS</a>
<b>Silva is cool</b>
<p>Well good bye!</p>
""")
        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 1)
    def test_display_broken_source_public(self):
        """If you delete the code source object, and render without a
        preview layer, you have no message.
        """
        self.root.manage_delObjects(['cs_citation'])

        version = self.root.document.get_editable()
        factory = getMultiAdapter((version, TestRequest()),
                                  ITransformerFactory)
        transformer = factory('body', version.body, self.saved_text,
                              IDisplayFilter)
        tests.assertXMLEqual(unicode(transformer), """
<div class="external-source">
</div>
""")

        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 1)
    def test_display_broken_source_public(self):
        """If you delete the code source object, and render without a
        preview layer, you have no message.
        """
        self.root.manage_delObjects(["cs_citation"])

        version = self.root.document.get_editable()
        factory = getMultiAdapter((version, TestRequest()), ITransformerFactory)
        transformer = factory("body", version.body, self.saved_text, IDisplayFilter)
        tests.assertXMLEqual(
            unicode(transformer),
            """
<div class="external-source">
</div>
""",
        )

        sources = getWrapper(version, IExternalSourceManager)
        self.assertEqual(len(sources.all()), 1)
    def test_sanitize_input(self):
        html = """
<p>
    <script type="text/javascript">
        function hello() {
            alert('hello');
        }
    </script>
    <a class="anchor" name="advanced" title="Advanced Anchor">Advanced <form><input type="submit" value="send" /></form>Anchor</a>
</p>
"""

        expected = """
<p>
    <a class="anchor" name="advanced" title="Advanced Anchor">Advanced Anchor</a>
</p>
"""
        sanitized = self.transform(html, ISaveEditorFilter)
        tests.assertXMLEqual(expected, sanitized)
Beispiel #30
0
    def test_display_broken_xml_source_preview(self):
        """Test a source that have an invalid or missing
        data-source-instance.
        """
        version = self.root.document.get_editable()
        factory = getMultiAdapter(
            (version, TestRequest(layers=[IPreviewLayer])),
            ITransformerFactory)
        transformer = factory('body', version.body,
                              '<div class="external-source"></div>',
                              IDisplayFilter)

        tests.assertXMLEqual(
            str(transformer), """
<div class="external-source broken-source">
 <p>
   External Source parameters are missing.
 </p>
</div>
""")
    def test_sanitize_chunk(self):
        sanitized = html_sanitize(
            self.HTML_CHUNCK, DEFAULT_PER_TAG_WHITELISTS, DEFAULT_HTML_ATTR_WHITELIST)
        expected = """
                    <div>
                        <p data-timestamp="42">
                            H&#233;las! mon ami, l'&#233;poque est triste, et mes contes, je vous en pr&#233;viens,
                            
                            ne seront pas gais. Seulement, vous permettrez que, lass&#233; de ce que je vois se passer tous les jours
                            dans le monde r&#233;el, j'aille chercher mes r&#233;cits dans le monde imaginaire. H&#233;las! j'ai bien peur que tous
                            les esprits un peu &#233;lev&#233;s, un peu po&#233;tiques, un peu r&#234;veurs, n'en soient &#224; cette heure o&#249; en est le mien, c'est-&#224;-dire
                            &#224; la recherche de l'id&#233;al, le seul, refuge que Dieu nous laisse contre la r&#233;alit&#233;.

                        <a href="http://www.gutenberg.org/files/15208/15208-h/15208-h.htm">source</a>
                            </p>
                        <ul><li>French</li>
                            <li>English</li>
                            <li>Netherlands</li>
                        </ul>
                    </div>
                    """
        tests.assertXMLEqual(expected, sanitized)
    def test_render_image_with_internal_link_and_anchor_and_query(self):
        """Test render a piece of text with an image that is referring
        an asset in Silva, and with a link referring an another
        document in Silva, an anchor and an extra query.
        """
        version = self.root.document.get_editable()
        save_editor_text(
            version.test, u"""
<h2>This is simple piece of text</h2>
<p>
  This simple piece of text contains a magic chocobo:
</p>
<div class="image">
  <a class="image-link" anchor="top" reference={link} query="malabar">
    <img alt="Chocobo" reference="{image}" />
  </a>
</div>""",
            content=version,
            link_content=self.root.other,
            link_name=u'test image link',
            image_content=self.root.chocobo,
            image_name=u'test image')

        factory = getMultiAdapter((version, TestRequest()), ITransformerFactory)
        transformer = factory(
            'test', version.test, unicode(version.test), IDisplayFilter)
        tests.assertXMLEqual(
            unicode(transformer),
            u"""
<h2>This is simple piece of text</h2>
<p>
  This simple piece of text contains a magic chocobo:
</p>
<div class="image">
  <a class="image-link" href="http://localhost/root/other?malabar#top">
    <img alt="Chocobo" height="256" width="256"
         src="http://localhost/root/chocobo" />
  </a>
</div>""")
    def test_render_external_link_with_anchor(self):
        """Test render a piece of text with a link that is an external
        URL with an extra anchor.
        """
        version = self.root.document.get_editable()
        save_editor_text(
            version.test, u"""
<h2>This is simple piece of text</h2>
<p>
  This simple piece of text contains a simple piece of link:
  <a class="link" href="http://infrae.com" anchor="top">paragraph</a>.
</p>""")

        factory = getMultiAdapter((version, TestRequest()), ITransformerFactory)
        transformer = factory(
            'test', version.test, unicode(version.test), IDisplayFilter)
        tests.assertXMLEqual(
            unicode(transformer),
            u"""
<h2>This is simple piece of text</h2>
<p>
  This simple piece of text contains a simple piece of link:
  <a class="link" href="http://infrae.com#top">paragraph</a>.
</p>""")
    def test_render_anchor_link(self):
        """Test render a piece of text with a link that is just
        refering an anchor on the same page.
        """
        version = self.root.document.get_editable()
        save_editor_text(
            version.test, u"""
<h2>This is simple piece of text</h2>
<p>
  This simple piece of text contains a simple piece of link:
  <a class="link" target="_self" anchor="top">paragraph</a>.
</p>""")

        factory = getMultiAdapter((version, TestRequest()), ITransformerFactory)
        transformer = factory(
            'test', version.test, unicode(version.test), IDisplayFilter)
        tests.assertXMLEqual(
            unicode(transformer),
            u"""
<h2>This is simple piece of text</h2>
<p>
  This simple piece of text contains a simple piece of link:
  <a class="link" target="_self" href="#top">paragraph</a>.
</p>""")
    def test_news_item_with_text_news_item_reference(self):
        """Test the NewsitemReference for a NewsItem
        """
        version = self.root.news.testing.get_editable()
        version.body.save(
            version,
            TestRequest(),
            u"""
<h1>Testing of a code source</h1>
<h2>Today is the day of the Internet!</h2>
<h3>Yes it is</h3>
<p>
  This the day of free internet ! The Internet is a global system of
  interconnected computer networks that use the standard Internet
  protocol suite (often called TCP/IP, although not all applications
  use TCP) to serve billions of users worldwide. It is a network of
  networks that consists of millions of private, public, academic,
  business, and government networks, of local to global scope, that
  are linked by a broad array of electronic, wireless and optical
  networking technologies. The Internet carries an extensive range of
  information resources and services, such as the inter-linked
  hypertext documents of the World Wide Web (WWW) and the
  infrastructure to support email.
</p>
<div class="image">
  <img src="foo" data-silva-reference="news" data-silva-target="%s" />
</div>
<p>
  I am not kidding.
</p>
""" % (get_content_id(self.root.listing)))
        binding = getUtility(IMetadataService).getMetadata(version)
        binding.setValues(
            'silva-extra',
            {'content_description':
                 'This is an exciting news item about the Interwebs.'})


        # Publish news item so we see it.
        IPublicationWorkflow(self.root.news.testing).publish()
        version = self.root.news.testing.get_viewable()

        items = get_items(self.root.news.index, TestRequest(), 10)
        self.assertEqual(len(items), 1)
        item = items[0]
        self.assertTrue(verifyObject(INewsItemReference, item))
        self.assertEqual(item.context, version)
        self.assertEqual(item.id(), 'testing')
        self.assertEqual(
            item.title(),
            'Testing of a code source')
        self.assertEqual(
            item.description(),
            'This is an exciting news item about the Interwebs.')
        self.assertEqual(
            item.description(10),
            'This is an')
        self.assertEqual(
            item.thumbnail_url(),
            'http://localhost/root/listing?thumbnail')
        self.assertEqual(
            item.image_url(),
            'http://localhost/root/listing')
        tests.assertXMLEqual(
            item.thumbnail(),
            u"""<div class="inv_thumbnail">
   <a class="newsitemthumbnaillink" href="http://localhost/root/news/testing">
      <img src="http://localhost/root/listing?thumbnail"
           width="120" height="75" class="thumbnail" />
   </a>
</div>""")
        tests.assertXMLEqual(
            item.introduction(),
            u"""
<p>
  This the day of free internet ! The Internet is a global system of
  interconnected computer networks that use the standard Internet
  protocol suite (often called TCP/IP, although not all applications
  use TCP) to serve billions of users worldwide. It is a network of
  networks that consists of millions of private, public, academic,
  business, and government networks, of local to global scope, that
  are linked by a broad array of electronic, wireless and optical
  networking technologies. The Internet carries an extensive range of
  information resources and services, such as the inter-linked
  hypertext documents of the World Wide Web (WWW) and the
  infrastructure to support email.
</p>""")
        tests.assertXMLEqual(
            item.introduction(128),
            u"""
<p>
  This the day of free internet ! The Internet is a global system of interconnected computer networks that use the standard Inter&#8230;
</p>""")
        self.assertEqual(item.link(), 'http://localhost/root/news/testing')
        self.assertEqual(item.start_datetime(), None)
        self.assertEqual(item.end_datetime(), None)
        self.assertEqual(item.location(), None)