Fixes #360, svg now handled by <img> instead of <object>, added tests
authorsharky93 <rishabhr123@gmail.com>
Sat, 20 Apr 2013 19:51:48 +0530
changeset 209511ba582e3063
parent 2091 7c00da767896
child 2096 c99479988451
Fixes #360, svg now handled by <img> instead of <object>, added tests
MoinMoin/converter/_tests/test_image.py
MoinMoin/converter/html_out.py
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/MoinMoin/converter/_tests/test_image.py	Sat Apr 20 19:51:48 2013 +0530
     1.3 @@ -0,0 +1,40 @@
     1.4 +# Copyright: 2013 MoinMoin:RishabhRaj
     1.5 +# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
     1.6 +
     1.7 +"""
     1.8 +MoinMoin - Tests for MoinMoin.converter for different imagetypes
     1.9 +"""
    1.10 +
    1.11 +import pytest
    1.12 +
    1.13 +from emeraldtree import tree as ET
    1.14 +
    1.15 +from MoinMoin.converter.html_out import ConverterPage
    1.16 +
    1.17 +
    1.18 +class TestImg(object):
    1.19 +    def setup_class(self):
    1.20 +        self.converter = ConverterPage()
    1.21 +
    1.22 +    def testImage(self):
    1.23 +        tree_xml = ('<ns0:page ns0:page-href="wiki:///Home" xmlns:ns0="http://moinmo.in/namespaces/page" '
    1.24 +                    'xmlns:ns1="http://www.w3.org/2001/XInclude" xmlns:ns2="http://www.w3.org/1999/xhtml" '
    1.25 +                    'xmlns:ns3="http://www.w3.org/1999/xlink"><ns0:body><ns0:p ns2:data-lineno="1">'
    1.26 +                    '<ns0:page ns2:class="moin-transclusion" ns0:page-href="wiki:///imagetest" ns2:data-href="/imagetest">'
    1.27 +                    '<ns0:body><ns0:object ns3:href="/+get/+2882c905b2ab409fbf79cd05637a112d/imagetest" ns0:type="{0}" />'
    1.28 +                    '</ns0:body></ns0:page></ns0:p></ns0:body></ns0:page>')
    1.29 +        tests = [
    1.30 +            ('image/jpeg', 'img'),
    1.31 +            ('image/svg+xml', 'img'),
    1.32 +            ('image/png', 'img'),
    1.33 +            ('image/gif', 'img'),
    1.34 +        ]
    1.35 +
    1.36 +        for imagetype, tag_expected in tests:
    1.37 +            self.runTest(tree_xml.format(imagetype), tag_expected)
    1.38 +
    1.39 +    def runTest(self, tree_xml, tag_expected):
    1.40 +        tree = ET.XML(tree_xml)
    1.41 +        tree = self.converter(tree)
    1.42 +        assert len(tree) and len(tree[0]) and len(tree[0][0]) == 1
    1.43 +        assert tree[0][0][0].tag.name == tag_expected
     2.1 --- a/MoinMoin/converter/html_out.py	Thu Apr 11 21:21:30 2013 +0200
     2.2 +++ b/MoinMoin/converter/html_out.py	Sat Apr 20 19:51:48 2013 +0530
     2.3 @@ -338,9 +338,7 @@
     2.4          Return value is an str, one of the following:
     2.5              image, video, audio, object
     2.6          """
     2.7 -        if Type('image/').issupertype(mimetype) and not Type('image/svg+xml').issupertype(mimetype):
     2.8 -            # Firefox fails completely to show svg in img tags (displays: nothing).
     2.9 -            # Firefox displays them with on object tag (but sometimes displays scrollbars without need).
    2.10 +        if Type('image/').issupertype(mimetype):
    2.11              return "img"
    2.12          elif Type('video/').issupertype(mimetype):
    2.13              return "video"