Commit 2889c4bd authored by Alain Takoudjou's avatar Alain Takoudjou

Correctly cleanup path for category setter

parent e62b1932
......@@ -1148,6 +1148,24 @@ class TestCMFCategory(ERP5TypeTestCase):
self.assertEqual(list(related), [person.getRelativeUrl()])
person._setTest1Value(a)
self.assertEqual(list(related), [])
def test_Category_setCategoryValue(self):
# Test all case of setting categories values
region_value = self.portal.portal_categories.resolveCategory('region/europe')
region_value2 = self.portal.portal_categories.resolveCategory('region/europe/west')
self.assertNotEqual(None,region_value)
self.assertNotEqual(None,region_value2)
p1 = self.getPersonModule()._getOb(self.id1)
p1.setRegionValue(region_value)
person = self.getPersonModule().newContent(region_value=region_value2)
self.tic()
self.assertEqual(p1.getRegion(), 'europe')
self.assertTrue('region/europe' in p1.getCategoryList())
self.assertEqual(person.getRegion(), 'europe/west')
self.assertTrue('region/europe/west' in person.getCategoryList())
def test_suite():
......
......@@ -1818,9 +1818,10 @@ class Base( CopyContainer,
def _setValue(self, id, target, spec=(), filter=None, portal_type=(), keep_default=1,
checked_permission=None):
getRelativeUrl = self.getPortalObject().portal_url.getRelativeUrl
def cleanupCategory(path):
# prevent duplicating base categories and storing "portal_categories/"
for start_string in ("%s/" % id, "portal_categories/"):
for start_string in ( "portal_categories/", "%s/" % id):
if path.startswith(start_string):
path = path[len(start_string):]
return path
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment