Skip to content

Commit

Permalink
Merge pull request #380 from plone/maurits-plone-app-content-conditional
Browse files Browse the repository at this point in the history
Make the dependency on plone.app.content conditional.
  • Loading branch information
mauritsvanrees authored Nov 2, 2023
2 parents a8a8ae5 + d4ebbe1 commit 669e1e7
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ commit-id = "55bda5c9"

[pyproject]
codespell_ignores = "hove"
dependencies_ignores = "['plone.app.relationfield', 'plone.directives.form', 'plone.directives.dexterity', 'five.grok', 'plone.app.intid', 'plone.contentrules', 'plone.schema', 'z3c.relationfield']"
dependencies_ignores = "['plone.app.content', 'plone.app.relationfield', 'plone.directives.form', 'plone.directives.dexterity', 'five.grok', 'plone.app.intid', 'plone.contentrules', 'plone.schema', 'z3c.relationfield']"

[flake8]
extra_lines = """
Expand Down
3 changes: 3 additions & 0 deletions news/3858.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Make the dependency on ``plone.app.content`` conditional.
This is for ``INameFromTitle``, which we want to move to ``plone.base``.
[maurits]
38 changes: 23 additions & 15 deletions plone/app/dexterity/behaviors/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,31 @@
for="plone.dexterity.interfaces.IDexterityContent"
/>

<!-- Title-to-id -->
<plone:behavior
name="plone.namefromtitle"
title="Name from title"
description="Automatically generate short URL name for content based on its initial title"
provides="plone.app.content.interfaces.INameFromTitle"
/>
<configure zcml:condition="installed plone.app.content">
<!-- Title-to-id -->
<!-- Note: we must keep `plone.app.content.interfaces.INameFromTitle` as
`provides`, instead of the new location in `plone.base`,
as long as we want to avoid breaking sites that have the old interface
in the behaviors list of a portal_type, instead of the named behavior.
See https://github.com/plone/plone.app.dexterity/pull/379
-->
<plone:behavior
name="plone.namefromtitle"
title="Name from title"
description="Automatically generate short URL name for content based on its initial title"
provides="plone.app.content.interfaces.INameFromTitle"
/>

<!-- File-name-to-id -->
<plone:behavior
name="plone.namefromfilename"
title="Name from file name"
description="Automatically generate short URL name for content based on its primary field file name"
provides=".filename.INameFromFileName"
/>
<!-- File-name-to-id -->
<plone:behavior
name="plone.namefromfilename"
title="Name from file name"
description="Automatically generate short URL name for content based on its primary field file name"
provides=".filename.INameFromFileName"
/>

<adapter factory=".filename.NameFromFileName" />
<adapter factory=".filename.NameFromFileName" />
</configure>

<!-- Navigation root -->
<plone:behavior
Expand Down
47 changes: 0 additions & 47 deletions plone/app/dexterity/tests/namefromtitle.txt

This file was deleted.

1 change: 0 additions & 1 deletion plone/app/dexterity/tests/test_doctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
tests = (
"discussion.txt",
"editing.rst",
"namefromtitle.txt",
"metadata.txt",
"nextprevious.txt",
"filename.txt",
Expand Down
84 changes: 84 additions & 0 deletions plone/app/dexterity/tests/test_namefromtitle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from plone.app.dexterity.testing import DEXTERITY_FUNCTIONAL_TESTING
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.app.testing import TEST_USER_NAME
from plone.app.testing import TEST_USER_PASSWORD
from plone.dexterity.fti import DexterityFTI
from plone.testing.zope import Browser

import transaction
import unittest


def add_dinosaur_type(portal, behavior_name):
fti = DexterityFTI("dinosaur")
portal.portal_types._setObject("dinosaur", fti)
fti.klass = "plone.dexterity.content.Container"
fti.filter_content_types = False
fti.behaviors = (
behavior_name,
"plone.basic",
)
return fti


class NameFromTitleFunctionalTest(unittest.TestCase):
"""Test name-from-title using named behavior."""

layer = DEXTERITY_FUNCTIONAL_TESTING
behavior_name = "plone.namefromtitle"

def setUp(self):
app = self.layer["app"]
self.portal = self.layer["portal"]
self.request = self.layer["request"]
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.portal_url = self.portal.absolute_url()

# Say we have a 'Dinosaur' content type:
self.fti = add_dinosaur_type(self.portal, self.behavior_name)

transaction.commit()
self.browser = Browser(app)
self.browser.handleErrors = False
self.browser.addHeader(
"Authorization",
"Basic {}:{}".format(
TEST_USER_NAME,
TEST_USER_PASSWORD,
),
)

def test_create(self):
self.browser.open(f"{self.portal_url}/++add++dinosaur")
self.browser.getControl("Title").value = "Brachiosaurus"
self.browser.getControl("Save").click()
self.assertEqual(self.browser.url, f"{self.portal_url}/brachiosaurus/view")

# Does it still work if we are adding content within a container?
self.browser.open(f"{self.portal_url}/brachiosaurus/++add++dinosaur")
self.browser.getControl("Title").value = "Baby Brachiosaurus"
self.browser.getControl("Save").click()
self.assertEqual(
self.browser.url,
f"{self.portal_url}/brachiosaurus/baby-brachiosaurus/view",
)


class PloneAppContentNameFromTitleFunctionalTest(NameFromTitleFunctionalTest):
"""Test name-from-title using old plone.app.content behavior interface."""

behavior_name = "plone.app.content.interfaces.INameFromTitle"


# We could test that you can use the new interface location as behavior name,
# but this fails, and this is fine: it was never supported.
# In all cases the named behavior is recommended.
#
# class PloneBaseNameFromTitleFunctionalTest(NameFromTitleFunctionalTest):
# """Test name-from-title using new plone.base behavior interface."""
# behavior_name = "plone.base.interfaces.INameFromTitle"


def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Zope = [
'Products.CMFCore', 'Products.CMFDynamicViewFTI',
]
python-dateutil = ['dateutil']
ignore-packages = ['plone.app.relationfield', 'plone.directives.form', 'plone.directives.dexterity', 'five.grok', 'plone.app.intid', 'plone.contentrules', 'plone.schema', 'z3c.relationfield']
ignore-packages = ['plone.app.content', 'plone.app.relationfield', 'plone.directives.form', 'plone.directives.dexterity', 'five.grok', 'plone.app.intid', 'plone.contentrules', 'plone.schema', 'z3c.relationfield']

##
# Add extra configuration options in .meta.toml:
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
# Plone/Zope core
"lxml",
"plone.base",
"plone.app.content",
"plone.app.uuid",
"plone.app.z3cform>=1.1.0",
"plone.autoform>=1.1",
Expand Down

0 comments on commit 669e1e7

Please sign in to comment.