Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the search in folder that is set as default item of the parent folder #66

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion collective/searchandreplace/searchreplaceutility.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def make_catalog_query_args(context, findWhat, searchSubFolders, onlySearchableT
if context.isPrincipiaFolderish and not searchSubFolders:
query["depth"] = 1
container = aq_parent(context)
if isDefaultPage(container, context) and searchSubFolders:
if isDefaultPage(container, context) and not context.isPrincipiaFolderish and searchSubFolders:
query["query"] = "/".join(container.getPhysicalPath())
catalog_query_args = dict(path=query)
if settings().restrict_searchable_types:
Expand Down
80 changes: 80 additions & 0 deletions collective/searchandreplace/tests/test_matchcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from plone.app.testing import TEST_USER_ID
from zope.component import getUtility

from collective.searchandreplace.searchreplaceutility import make_catalog_query_args

import unittest


Expand Down Expand Up @@ -54,6 +56,84 @@ def testOneMatch(self):
self.assertEqual(len(results), 1)



class TestPath(unittest.TestCase):
layer = SEARCH_REPLACE_INTEGRATION_LAYER

def setUp(self):
self.portal = self.layer["portal"]
self.srutil = getUtility(ISearchReplaceUtility)

def testPathItem(self):
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.portal.invokeFactory("Document", "doc1")
doc1 = getattr(self.portal, "doc1")

catalog_query_args = make_catalog_query_args(context=doc1, findWhat="Find", searchSubFolders=True, onlySearchableText=False)
path = catalog_query_args["path"]["query"]
self.assertEqual(path, '/plone/doc1')

def testPathItemNoSubFolders(self):
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.portal.invokeFactory("Document", "doc1")
doc1 = getattr(self.portal, "doc1")

catalog_query_args = make_catalog_query_args(context=doc1, findWhat="Find", searchSubFolders=False, onlySearchableText=False)
path = catalog_query_args["path"]["query"]
self.assertEqual(path, '/plone/doc1')

def testPathFolder(self):
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.portal.invokeFactory("Folder", "mainfolder")
mainfolder = getattr(self.portal, "mainfolder")

catalog_query_args = make_catalog_query_args(context=mainfolder, findWhat="Find", searchSubFolders=True, onlySearchableText=False)
path = catalog_query_args["path"]["query"]
self.assertEqual(path, '/plone/mainfolder')

def testPathFolderNoSubFolders(self):
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.portal.invokeFactory("Folder", "mainfolder")
mainfolder = getattr(self.portal, "mainfolder")

catalog_query_args = make_catalog_query_args(context=mainfolder, findWhat="Find", searchSubFolders=False, onlySearchableText=False)
path = catalog_query_args["path"]["query"]
self.assertEqual(path, '/plone/mainfolder')

def testPathItemDefaultView(self):
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.portal.invokeFactory("Document", "index_html")

catalog_query_args = make_catalog_query_args(context=self.portal.index_html, findWhat="Find", searchSubFolders=True, onlySearchableText=False)
path = catalog_query_args["path"]["query"]
self.assertEqual(path, '/plone')

def testPathItemDefaultViewNoSubFolders(self):
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.portal.invokeFactory("Document", "index_html")

catalog_query_args = make_catalog_query_args(context=self.portal.index_html, findWhat="Find", searchSubFolders=False, onlySearchableText=False)
path = catalog_query_args["path"]["query"]
self.assertEqual(path, '/plone/index_html')

def testPathFolderDefaultView(self):
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.portal.invokeFactory("Folder", "index_html")

catalog_query_args = make_catalog_query_args(context=self.portal.index_html, findWhat="Find", searchSubFolders=True, onlySearchableText=False)
path = catalog_query_args["path"]["query"]
self.assertEqual(path, '/plone/index_html')

def testPathFolderDefaultViewNoSubFolders(self):
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.portal.invokeFactory("Folder", "index_html")

catalog_query_args = make_catalog_query_args(context=self.portal.index_html, findWhat="Find", searchSubFolders=False, onlySearchableText=False)
path = catalog_query_args["path"]["query"]
self.assertEqual(path, '/plone/index_html')



class TestMultipleMatchCase(unittest.TestCase):
"""Ensure that multiple matches work."""

Expand Down
Loading