[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Publisher/Browser/tests - testIconDirective.py:1.3
Marius Gedminas
mgedmin@delfi.lt
Tue, 25 Jun 2002 11:26:12 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/Publisher/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv1528/lib/python/Zope/App/Publisher/Browser/tests
Modified Files:
testIconDirective.py
Log Message:
<browser:icon> now accepts resource as well as file attributes (e.g. you can
refer to a i18n-resource to have internationalized icons).
=== Zope3/lib/python/Zope/App/Publisher/Browser/tests/testIconDirective.py 1.2 => 1.3 ===
from Zope.ComponentArchitecture import queryView, getView, getResource
from Zope.Security.Proxy import ProxyFactory
+from Zope.Configuration.Exceptions import ConfigurationError
import Zope.App.Publisher.Browser
@@ -82,9 +83,65 @@
resource = removeAllProxies(resource)
self.assertEqual(resource._testData(), open(path, 'rb').read())
+ def testResource(self):
+ self.assertEqual(queryView(ob, 'zmi_icon', request), None)
+
+ import Zope.App.Publisher.Browser.tests as p
+ path = os.path.split(p.__file__)[0]
+ path = os.path.join(path, 'test.gif')
-
-
+ xmlconfig(StringIO(template % (
+ """
+ <browser:resource name="zmi_icon_res"
+ image="%s" />
+ <browser:icon name="zmi_icon"
+ for="Zope.ComponentArchitecture.tests.TestViews.IC"
+ resource="zmi_icon_res" />
+ """ % path
+ )))
+
+ view = getView(ob, 'zmi_icon', request)
+ rname = "zmi_icon_res"
+ self.assertEqual(
+ view(),
+ '<img src="/@@/%s" alt="IC" width="16" height="16" border="0" />'
+ % rname)
+
+ resource = getResource(ob, rname, request)
+ resource = ProxyFactory(resource)
+
+ self.assertRaises(Forbidden, getattr, resource, '_testData')
+ resource = removeAllProxies(resource)
+ self.assertEqual(resource._testData(), open(path, 'rb').read())
+
+ def testResourceErrors(self):
+ self.assertEqual(queryView(ob, 'zmi_icon', request), None)
+
+ import Zope.App.Publisher.Browser.tests as p
+ path = os.path.split(p.__file__)[0]
+ path = os.path.join(path, 'test.gif')
+
+ config = StringIO(template % (
+ """
+ <browser:resource name="zmi_icon_res"
+ image="%s" />
+ <browser:icon name="zmi_icon"
+ for="Zope.ComponentArchitecture.tests.TestViews.IC"
+ file="%s"
+ resource="zmi_icon_res" />
+ """ % (path, path)
+ ))
+ self.assertRaises(ConfigurationError, xmlconfig, config)
+
+ config = StringIO(template % (
+ """
+ <browser:icon name="zmi_icon"
+ for="Zope.ComponentArchitecture.tests.TestViews.IC"
+ />
+ """
+ ))
+ self.assertRaises(ConfigurationError, xmlconfig, config)
+
def test_suite():
return TestSuite((