[Zope-CVS] CVS: Products/CompositePage/tests - test_macro.py:1.1

Shane Hathaway shane at zope.com
Sat Oct 4 14:10:06 EDT 2003


Update of /cvs-repository/Products/CompositePage/tests
In directory cvs.zope.org:/tmp/cvs-serv22368/tests

Added Files:
	test_macro.py 
Log Message:
Added support for composite templating based on METAL macros.

Now, instead of:

  <div tal:repeat="element here/slots/foo/multiple"
    tal:content="structure element" />

you can use:

  <div metal:define-slot="foo" />

To accomplish this, the composite generates a TAL program and executes 
it using the standard TALIntepreter.



=== Added File Products/CompositePage/tests/test_macro.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""Macro support tests.

$Id: test_macro.py,v 1.1 2003/10/04 18:10:05 shane Exp $
"""

import unittest

import ZODB
from OFS.Folder import Folder
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
from Products.CompositePage.macro import renderMacro
from Products.CompositePage.slot import Slot
from Products.CompositePage.composite import Composite

template_text = '''
<html metal:define-macro="page">
<body>
<div metal:define-slot="slot_a">slot_a</div>
<span metal:define-slot="slot_b">slot_b</span>
</body>
</html>
'''


class MacroTests(unittest.TestCase):

    def setUp(self):
        f = Folder()
        f.getPhysicalPath = lambda: ()
        f.getPhysicalRoot = lambda: f
        f.composite = Composite()
        f.composite._setId("composite")
        f.composite.template = ZopePageTemplate(
            id="template", text=template_text, content_type="text/html")
        f.composite.filled_slots.slot_a = slot_a = Slot("slot_a")
        a1 = ZopePageTemplate(id="a1", text="<b>Slot A</b>")
        slot_a._setObject(a1.id, a1)
        self.composite = f.composite


    def assertTextEqual(self, a, b):
        a = a.strip().replace("\n", "")
        b = b.strip().replace("\n", "")
        self.assertEqual(a, b)


    def testRender(self):
        c = self.composite
        rendered = renderMacro(c.template.macros["page"], c)
        expected = "<html><body><div><b>Slot A</b></div></body></html>"
        self.assertTextEqual(rendered, expected)


if __name__ == "__main__":
    unittest.main()





More information about the Zope-CVS mailing list