Index: /quintagroup.portlet.pfg/trunk/quintagroup/portlet/pfg/pfg.pt
===================================================================
--- /quintagroup.portlet.pfg/trunk/quintagroup/portlet/pfg/pfg.pt	(revision 2815)
+++ /quintagroup.portlet.pfg/trunk/quintagroup/portlet/pfg/pfg.pt	(revision 2816)
@@ -1,3 +1,4 @@
-<dl class="portlet">
+<dl class="portlet"
+    tal:condition="view/available">
   <dt class="portletHeader">
     <span class="portletTitle"
Index: /quintagroup.portlet.pfg/trunk/quintagroup/portlet/pfg/pfg.py
===================================================================
--- /quintagroup.portlet.pfg/trunk/quintagroup/portlet/pfg/pfg.py	(revision 2815)
+++ /quintagroup.portlet.pfg/trunk/quintagroup/portlet/pfg/pfg.py	(revision 2816)
@@ -59,16 +59,18 @@
 
     def pfgTitle(self):
-	    return self.pfg_object().Title()
+        form = self.pfg_object()
+        if form is not None:
+            return form.Title()
 
     def available(self):
-        """By default, portlets are available
-        """
         return self.pfg_object() and True or False
 
     def render_form(self):
-        pfg_path = self.pfg_object().absolute_url(True)
-        form_view = self.portal.restrictedTraverse('%s/@@embedded' % pfg_path)
-        form_view.prefix = 'pfgportlet'
-        return form_view()
+        form = self.pfg_object()
+        if form is not None:
+            form_path = '/'.join(form.getPhysicalPath()[2:])
+            form_view = self.portal.restrictedTraverse('%s/@@embedded' % form_path)
+            form_view.prefix = 'pfgportlet'
+            return form_view()
 
 class AddForm(base.AddForm):
Index: /quintagroup.portlet.pfg/trunk/quintagroup/portlet/pfg/tests/base.py
===================================================================
--- /quintagroup.portlet.pfg/trunk/quintagroup/portlet/pfg/tests/base.py	(revision 2816)
+++ /quintagroup.portlet.pfg/trunk/quintagroup/portlet/pfg/tests/base.py	(revision 2816)
@@ -0,0 +1,45 @@
+from Products.Five import zcml
+from Products.Five import fiveconfigure
+
+from Testing import ZopeTestCase as ztc
+
+from Products.PloneTestCase import PloneTestCase as ptc
+from Products.PloneTestCase.layer import onsetup
+
+ztc.installProduct('PloneFormGen')
+
+@onsetup
+def setup_product():
+    """Set up additional products and ZCML required to test this product.
+
+    The @onsetup decorator causes the execution of this body to be deferred
+    until the setup of the Plone site testing layer.
+    """
+
+    # Load the ZCML configuration for this package and its dependencies
+
+    fiveconfigure.debug_mode = True
+    import quintagroup.portlet.pfg
+    zcml.load_config('configure.zcml', quintagroup.portlet.pfg)
+    fiveconfigure.debug_mode = False
+
+    # We need to tell the testing framework that these products
+    # should be available. This can't happen until after we have loaded
+    # the ZCML.
+
+    ztc.installPackage('quintagroup.portlet.pfg')
+
+# The order here is important: We first call the deferred function and then
+# let PloneTestCase install it during Plone site setup
+
+setup_product()
+ptc.setupPloneSite(products=['Products.PloneFormGen',
+                             'quintagroup.portlet.pfg'])
+
+class TestCase(ptc.PloneTestCase):
+    """Base class used for test cases
+    """
+
+class FunctionalTestCase(ptc.FunctionalTestCase):
+    """Test case class used for functional (doc-)tests
+    """
Index: /quintagroup.portlet.pfg/trunk/quintagroup/portlet/pfg/tests/test_portlet.py
===================================================================
--- /quintagroup.portlet.pfg/trunk/quintagroup/portlet/pfg/tests/test_portlet.py	(revision 2816)
+++ /quintagroup.portlet.pfg/trunk/quintagroup/portlet/pfg/tests/test_portlet.py	(revision 2816)
@@ -0,0 +1,96 @@
+from zope.component import getUtility, getMultiAdapter
+
+from plone.portlets.interfaces import IPortletType
+from plone.portlets.interfaces import IPortletManager
+from plone.portlets.interfaces import IPortletAssignment
+from plone.portlets.interfaces import IPortletDataProvider
+from plone.portlets.interfaces import IPortletRenderer
+
+from plone.app.portlets.storage import PortletAssignmentMapping
+
+from quintagroup.portlet.pfg import pfg
+
+from quintagroup.portlet.pfg.tests.base import TestCase
+
+
+from Products.CMFCore.utils import getToolByName
+
+class TestPFGPortlet(TestCase):
+
+    def afterSetUp(self):
+        self.setRoles(('Manager',))
+        self.portal.invokeFactory('FormFolder', 'test_form')
+
+    def testPortletTypeRegistered(self):
+        portlet = getUtility(IPortletType, name='quintagroup.portlet.pfg.PFGPortlet')
+        self.assertEquals(portlet.addview, 'quintagroup.portlet.pfg.PFGPortlet')
+
+    def testInterfaces(self):
+        portlet = pfg.Assignment(target_form=u"/test_form")
+        self.failUnless(IPortletAssignment.providedBy(portlet))
+        self.failUnless(IPortletDataProvider.providedBy(portlet.data))
+
+    def testInvokeAddview(self):
+        portlet = getUtility(IPortletType, name='quintagroup.portlet.pfg.PFGPortlet')
+        mapping = self.portal.restrictedTraverse('++contextportlets++plone.leftcolumn')
+        for m in mapping.keys():
+            del mapping[m]
+        addview = mapping.restrictedTraverse('+/' + portlet.addview)
+
+        addview.createAndAdd(data={'target_form' : u"/test_form"})
+
+        self.assertEquals(len(mapping), 1)
+        self.failUnless(isinstance(mapping.values()[0], pfg.Assignment))
+
+    def testInvokeEditView(self):
+        mapping = PortletAssignmentMapping()
+        request = self.folder.REQUEST
+
+        mapping['foo'] = pfg.Assignment(target_form=u"/test_form")
+        editview = getMultiAdapter((mapping['foo'], request), name='edit')
+        self.failUnless(isinstance(editview, pfg.EditForm))
+
+    def testRenderer(self):
+        context = self.folder
+        request = self.folder.REQUEST
+        view = self.folder.restrictedTraverse('@@plone')
+        manager = getUtility(IPortletManager, name='plone.rightcolumn', context=self.portal)
+        assignment = pfg.Assignment(target_form=u"/test_form")
+
+        renderer = getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
+        self.failUnless(isinstance(renderer, pfg.Renderer))
+
+class TestPFGPortletRenderer(TestCase):
+
+    def afterSetUp(self):
+        self.loginAsPortalOwner()
+        self.setRoles(('Manager',))
+        self.portal.invokeFactory('FormFolder', 'test_form')
+
+    def renderer(self, context=None, request=None, view=None, manager=None, assignment=None):
+        context = context or self.folder
+        request = request or self.folder.REQUEST
+        view = view or self.folder.restrictedTraverse('@@plone')
+        manager = manager or getUtility(IPortletManager, name='plone.rightcolumn', context=self.portal)
+        assignment = assignment or pfg.Assignment(target_form="/test_form")
+
+        return getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
+
+
+    def test_portletStyle(self):
+        renderer = self.renderer(context=self.portal,
+                                 request=self.portal.REQUEST,
+                                 assignment=pfg.Assignment(target_form="/test_form"))
+        renderer = renderer.__of__(self.portal)
+        renderer.update()
+
+        self.failUnless('Your E-Mail Address' in renderer.render())
+        self.failUnless('Subject' in renderer.render())
+        self.failUnless('Comments' in renderer.render())
+
+def test_suite():
+    from unittest import TestSuite, makeSuite
+    suite = TestSuite()
+    suite.addTest(makeSuite(TestPFGPortlet))
+    suite.addTest(makeSuite(TestPFGPortletRenderer))
+    return suite
Index: /quintagroup.portlet.pfg/trunk/setup.py
===================================================================
--- /quintagroup.portlet.pfg/trunk/setup.py	(revision 2815)
+++ /quintagroup.portlet.pfg/trunk/setup.py	(revision 2816)
@@ -25,4 +25,5 @@
       install_requires=[
           'setuptools',
+          'Products.PloneFormGen',
           # -*- Extra requirements: -*-
       ],
