11from collections .abc import Generator
22from plone import api
33from plone .api .exc import InvalidParameterError
4- from plone .app .testing .interfaces import SITE_OWNER_NAME
54from plone .dexterity .fti import DexterityFTI
65from Products .CMFPlone .Portal import PloneSite
76
@@ -14,13 +13,36 @@ def portal(app_class, create_site, answers) -> Generator[PloneSite]:
1413 yield site
1514
1615
17- class TestWikiPage :
18- portal_type : str = "WikiPage"
16+ @pytest .fixture (scope = "class" )
17+ def portal_type () -> str :
18+ return "WikiPage"
19+
20+
21+ @pytest .fixture (scope = "class" )
22+ def container (portal , content_factory ):
23+ """Return the container used to create the content instance under test."""
24+ payload = {
25+ "type" : "Workspace" ,
26+ "id" : "my-workspace" ,
27+ }
28+ return content_factory (portal , payload )
29+
30+
31+ @pytest .fixture (scope = "class" )
32+ def payload (portal_type ) -> dict :
33+ return {
34+ "type" : portal_type ,
35+ "id" : "my-other-wiki-page" ,
36+ "title" : "My other wiki page" ,
37+ "description" : "Description of my other wiki page" ,
38+ }
39+
1940
41+ class TestWikiPage :
2042 @pytest .fixture (autouse = True )
21- def _setup (self , portal , get_fti ) -> None :
43+ def _setup (self , portal , get_fti , portal_type ) -> None :
2244 self .portal = portal
23- self .fti : DexterityFTI = get_fti (self . portal_type )
45+ self .fti : DexterityFTI = get_fti (portal_type )
2446
2547 @pytest .mark .parametrize (
2648 "attr,expected" ,
@@ -44,8 +66,9 @@ def test_fti(self, attr: str, expected):
4466 assert isinstance (self .fti , DexterityFTI )
4567 assert getattr (self .fti , attr ) == expected
4668
47- def test_behaviors (self ):
48- assert self .fti .behaviors == (
69+ @pytest .mark .parametrize (
70+ "idx,behavior" ,
71+ enumerate ((
4972 "plone.basic" ,
5073 "volto.preview_image_link" ,
5174 "plone.categorization" ,
@@ -63,27 +86,43 @@ def test_behaviors(self):
6386 "plone.locking" ,
6487 "plone.translatable" ,
6588 "kitconcept.intranet.clm" ,
66- )
89+ )),
90+ )
91+ def test_behaviors (self , idx , behavior ):
92+ assert self .fti .behaviors [idx ] == behavior
6793
68- def test_wikipage_requires_workspace_container (self ):
69- with api .env .adopt_user (SITE_OWNER_NAME ):
94+ def test_wikipage_requires_workspace_container (
95+ self , site_owner_name , content_factory , portal_type , payload
96+ ):
97+ with api .env .adopt_user (site_owner_name ):
7098 with pytest .raises (InvalidParameterError ):
71- api .content .create (
72- container = self .portal ,
73- type = self .portal_type ,
74- title = "Root Wiki Page" ,
75- )
76-
77- workspace = api .content .create (
78- container = self .portal ,
79- type = "Workspace" ,
80- title = "Team Workspace" ,
81- )
82- page = api .content .create (
83- container = workspace ,
84- type = self .portal_type ,
85- title = "Workspace Wiki Page" ,
99+ content_factory (self .portal , payload )
100+
101+ workspace = content_factory (
102+ self .portal ,
103+ {"type" : "Workspace" , "title" : "Team Workspace" },
86104 )
105+ page = content_factory (workspace , payload )
87106
88- assert page .portal_type == self . portal_type
107+ assert page .portal_type == portal_type
89108 assert page .aq_parent == workspace
109+
110+ def test_versionable (self , portal_type , versionable_content_types ):
111+ assert portal_type in versionable_content_types
112+
113+ def test_create_initial_version_after_adding (self , last_version , content_instance ):
114+ version = last_version (content_instance )
115+ assert version .comment .default == "Initial version"
116+ assert version .version_id == 0
117+
118+ def test_create_version_on_save (
119+ self , notify_modified , history , last_version , content_instance
120+ ):
121+ with api .env .adopt_roles (["Manager" ]):
122+ content_instance .title = "Wiki Redux"
123+ notify_modified (content_instance )
124+ history_data = history (content_instance )
125+ assert len (history_data ) == 2 # Initial + modified version
126+ version = last_version (content_instance )
127+ assert version .comment is None
128+ assert version .version_id == 1
0 commit comments