Skip to content

Commit

Permalink
Install IRelatedItems behavior (fixes #294)
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed Sep 30, 2013
1 parent d20fc5d commit 6fb4bff
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
'plone.app.lockingbehavior',
'plone.app.referenceablebehavior',
'plone.app.registry',
'plone.app.relationfield',
'plone.app.stagingbehavior',
'plone.app.textfield',
'plone.app.tiles',
Expand Down
1 change: 1 addition & 0 deletions src/collective/cover/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<five:registerPackage package="." />
<includeDependencies package="." />
<include package="five.grok" />
<include package="plone.app.relationfield" />

<permission
id="collective.cover.CanExportLayout"
Expand Down
5 changes: 5 additions & 0 deletions src/collective/cover/profiles.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@
description="Link integrity on Rich Text tile references."
handler=".upgrades.issue_35"
/>
<genericsetup:upgradeStep
title="issue_294"
description="Install IRelatedItems behavior."
handler=".upgrades.issue_294"
/>
</genericsetup:upgradeSteps>

</configure>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<element value="plone.app.dexterity.behaviors.exclfromnav.IExcludeFromNavigation" />
<element value="plone.app.lockingbehavior.behaviors.ILocking" />
<element value="plone.app.referenceablebehavior.referenceable.IReferenceable" />
<element value="plone.app.relationfield.behavior.IRelatedItems" />
<element value="plone.app.stagingbehavior.interfaces.IStagingSupport" />
</property>

Expand Down
2 changes: 2 additions & 0 deletions src/collective/cover/tests/test_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ def test_export_permission(self):
setRoles(self.portal, TEST_USER_ID, ['Member'])
self.assertFalse(self.layout_edit.can_export_layout())
self.assertNotIn('<span>Export layout</span>', self.layout_edit())

# TODO: add test for plone.app.relationfield.behavior.IRelatedItems
24 changes: 23 additions & 1 deletion src/collective/cover/tests/test_upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_upgrade_to_5_registrations(self):
self.setup.setLastVersionForProfile(self.profile_id, u'4')
upgrades = self.setup.listUpgrades(self.profile_id)
self.assertEqual(len(upgrades), 1)
self.assertEqual(len(upgrades[0]), 6)
self.assertEqual(len(upgrades[0]), 7)

def _get_upgrade_step(self, title):
"""Get one of the upgrade steps from 4 to 5.
Expand Down Expand Up @@ -277,3 +277,25 @@ def test_register_alternate_view(self):
register_alternate_view(self.portal)
view_methods = portal_types['collective.cover.content'].view_methods
self.assertIn(u'standard', view_methods)

def test_issue_294(self):
# check if the upgrade step is registered
title = u'issue_294'
description = u"Install IRelatedItems behavior."
step = self._get_upgrade_step(title)
self.assertIsNotNone(step)
self.assertEqual(step['description'], description)

# remove behavior to simulate version 4 state
fti = getUtility(IDexterityFTI, name='collective.cover.content')
related_items = u'plone.app.relationfield.behavior.IRelatedItems'
behaviors = list(fti.behaviors)
behaviors.remove(related_items)
fti.behaviors = tuple(behaviors)
fti = getUtility(IDexterityFTI, name='collective.cover.content')
self.assertNotIn(related_items, fti.behaviors)

# and now run the upgrade step to validate the update
self._do_upgrade_step(step)
fti = getUtility(IDexterityFTI, name='collective.cover.content')
self.assertIn(related_items, fti.behaviors)
16 changes: 16 additions & 0 deletions src/collective/cover/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,19 @@ def issue_35(context, logger=None):
behaviors.append(referenceable)
fti.behaviors = tuple(behaviors)
logger.info("collective.cover objects are now referenceable.")


def issue_294(context, logger=None):
"""Install IRelatedItems behavior.
See: https://github.com/collective/collective.cover/issues/294
"""
if logger is None:
logger = logging.getLogger(PROJECTNAME)

fti = getUtility(IDexterityFTI, name='collective.cover.content')
related_items = u'plone.app.relationfield.behavior.IRelatedItems'
behaviors = list(fti.behaviors)
if related_items not in behaviors:
behaviors.append(related_items)
fti.behaviors = tuple(behaviors)
logger.info("IRelatedItems behavior was installed.")

0 comments on commit 6fb4bff

Please sign in to comment.