From eedb2b294b7d06e531b9267160d2fb9a4b436df5 Mon Sep 17 00:00:00 2001 From: Alexandre Boeglin <alex@nexedi.com> Date: Fri, 15 Sep 2006 13:35:42 +0000 Subject: [PATCH] check that getCategoryList called on a category does not append self if already included. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9997 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/CMFCategory/CategoryTool.py | 4 +++- product/CMFCategory/tests/testCMFCategory.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/product/CMFCategory/CategoryTool.py b/product/CMFCategory/CategoryTool.py index fde325d6dd..31bbb81985 100644 --- a/product/CMFCategory/CategoryTool.py +++ b/product/CMFCategory/CategoryTool.py @@ -1150,7 +1150,9 @@ class CategoryTool( UniqueObject, Folder, Base ): else: result = [] if getattr(context, 'isCategory', 0): - result.append(context.getRelativeUrl()) # Pure category is member of itself + category_url = context.getRelativeUrl() + if category_url not in result: + result.append(context.getRelativeUrl()) # Pure category is member of itself return result security.declareProtected( Permissions.ModifyPortalContent, '_setCategoryList' ) diff --git a/product/CMFCategory/tests/testCMFCategory.py b/product/CMFCategory/tests/testCMFCategory.py index c5cdd50ab5..88a6d76d03 100644 --- a/product/CMFCategory/tests/testCMFCategory.py +++ b/product/CMFCategory/tests/testCMFCategory.py @@ -595,6 +595,22 @@ class TestCMFCategory(ERP5TypeTestCase): self.tic() self.assert_(obj in [x.getObject() for x in test.getCategoryMemberValueList()]) + def test_18_getCategoryList(self, quiet=0, run=run_all_test): + """ + check that getCategoryList called on a category does not append self again + and again + """ + if not run: return + if not quiet: + message = 'Test getCategoryList on Category' + ZopeTestCase._print('\n ' + message) + LOG('Testing... ', 0, message) + portal = self.getPortal() + region_value = portal.portal_categories.resolveCategory('region/%s' % self.region1) + category_list = region_value.getCategoryList() + region_value.setCategoryList(category_list) + self.assertEqual(category_list, region_value.getCategoryList()) + if __name__ == '__main__': framework() else: -- 2.30.9