i'm writing tests packages , need verify if static resources being registered correctly.
before plone 5 can accessing resource registries this:
self.portal.portal_javascripts.getresourceids() self.portal.portal_css.getresourceids()
how can accomplish task in plone 5?
it appear answer lies in tests resources in products.cmfplone.
specifically, in test cases in file there number of tests use configuration registry access registered bundles , resources so:
from products.cmfplone.interfaces import ibundleregistry products.cmfplone.interfaces import iresourceregistry plone.registry.interfaces import iregistry zope.component import getutility resources = getutility(iregistry).collectionofinterface( iresourceregistry, prefix="plone.resources" ) bundles = getutility(iregistry).collectionofinterface( ibundleregistry, prefix="plone.bundles" )
the return values of these calls dict-like objects , contain pointers configuration registry entries bundles or resources have been registered using registry.xml
generic setup import step.
so, example, if have registered in product bundle using following xml:
<records prefix="plone.bundles/my-product" interface='products.cmfplone.interfaces.ibundleregistry'> <value key="resources"> <element>my-resource</element> </value> <value key="enabled">true</value> <value key="jscompilation">++plone++static/my-compiled.js</value> <value key="csscompilation">++plone++static/my-compiled.css</value> <value key="last_compilation">2014-08-14 00:00:00</value> </records>
then in bundles
returned resource registry above, able use part of "prefix" of bundle following slash ( 'my-product'
) registry record proxy bundle so:
my_bundle = bundles['my-product']
that record provide attribute access defined interface of bundle (see products.cmfplone.interfaces.resources.ibundleregistry details). should able check has right values set compiled js or css:
assert my_bundle.jscompilation == '++plone++static/my-compiled.js' assert my_bundle.csscompilation == '++plone++static/my-compiled.css'
records registered resources work same way, dict-like object keys corresponding part of "prefix" resource registration in registry.xml
after slash. records returned in case support products.cmfplone.interfaces.resources.iresourceregistry instead. you'll still able use attribute access verify values expect registered.
if have resources registered using deprecated portal_javascript
or portal_css
tools (using jsregistry.xml
or cssregistry.xml
generic setup import steps), key finding them plone automatically include such resources in special bundle called plone-legacy
. since bundles have resources
attribute provides list of resources included in bundle, should able this:
bundles = getutility(iregistry).collectionofinterface( ibundleregistry, prefix="plone.bundles" ) legacy_bundle = bundles['plone-legacy'] assert "my-oldskool.js" in legacy_bundle.resources
examples of can found in tests resources in products.cmfplone. in particular, in testresourcenodeimporter
test case.
Comments
Post a Comment