Example #1
0
    def test_transforms_with_cdata(self):
        """Test fix for issue where layouts with inline js got rendered with
        quoted (and therefore broken) <![CDATA[...]]> block
        """

        class TransformedView(object):
            implements(IBlocksTransformEnabled)

            def __init__(self, ret_body):
                self.__call__ = lambda b=ret_body: b

        body = """\
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><script type="text/javascript"><![CDATA[]]></script></head>
<body></body>
</html>"""
        request = self.layer['request']
        request.set('PUBLISHED', TransformedView(body))
        request.response.setBase(request.getURL())
        request.response.setHeader('content-type', 'text/html')
        request.response.setBody(body)

        alsoProvides(request, IBlocksLayer)
        result = applyTransform(request)
        self.assertIn('<![CDATA[]]>', ''.join(result))
Example #2
0
    def test_transforms_with_crlf(self):
        """Test fix for issue where layouts with CR[+LF] line-endings are
        somehow turned into having &#13; line-endings and getting their heads
        being dropped
        """

        class TransformedView(object):
            implements(IBlocksTransformEnabled)

            def __init__(self, ret_body):
                self.__call__ = lambda b=ret_body: b

        body = """\
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">&#13;
<head></head>&#13;
<body></body>&#13;
</html>"""
        request = self.layer['request']
        request.set('PUBLISHED', TransformedView(body))
        request.response.setBase(request.getURL())
        request.response.setHeader('content-type', 'text/html')
        request.response.setBody(body)

        alsoProvides(request, IBlocksLayer)
        result = applyTransform(request)
        self.assertIn('<head>', ''.join(result))
Example #3
0
    def test_transform_gridsystem_default_deco(self):
        registry = queryUtility(IRegistry)
        settings = registry.forInterface(IBlocksSettings)
        settings.default_grid_system = 'deco'

        request = self.layer['request']
        request.set('PUBLISHED', TestTransformedView(gridsystem_test_body))
        request.response.setBase(request.getURL())
        request.response.setHeader('content-type', 'text/html')
        request.response.setBody(gridsystem_test_body)

        alsoProvides(request, IBlocksLayer)
        result = ''.join(applyTransform(request))
        self.assertIn('cell position-0 width-12', result)
        self.assertIn('mosaic-grid-row row', result)
Example #4
0
    def get_page_source(self):
        """ Returns the HTML source of a web page, considering
        that the URL of the page is contained in the form under
        the 'page_url' key.
        """

        if not 'page_url' in self.request.form:
            self.errors.append('no_source')
            return

        url = self.request.form['page_url']
        context_url = self.context.absolute_url()

        view_name, get_params = extract_from_url(url, context_url)

        # Now we will reinject the GET parameters in the request.
        if get_params:
            for key in get_params:
                self.request.form[key] = get_params[key]

        try:
            view = self.context.restrictedTraverse(view_name)
        except:
            # For some reason, 'view' as view name can fail (at least
            # in a client project in Plone 3.3.5), where calling the
            # same url in a browser works just fine...  The error here is:
            # AttributeError: 'view' object has no attribute '__of__'
            # Just take the context as view then.

            # Note that this has the same effect as calling
            # self.context.restrictedTraverse(x), where x is None or
            # an empty string.
            view = self.context

        body = view()
        result = applyTransform(self.request, body=body)
        return update_relative_url(result, self.context)