1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# -*- coding: utf-8 -*-
##############################################################################
# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
"""A unittest for erp5_web"""
import unittest
from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import getSecurityManager
def setLanguage(portal, language):
from Products.iHotfix import Context, get_ident, contexts
localizer = portal.Localizer
if not language in localizer.get_supported_languages():
localizer.add_language(language)
request = portal.REQUEST
request.environ['HTTP_ACCEPT_LANGUAGE'] = language
request.environ['PATH_INFO'] = '/'
context = Context(request)
contexts[get_ident()] = context
request.processInputs()
class TestWeb(ERP5TypeTestCase):
"""
Test for erp5_web
"""
run_all_test = 1
quiet = 1
def getBusinessTemplateList(self):
return ('erp5_base',
'erp5_dms_mysql_innodb_catalog',
'erp5_web',
)
def getTitle(self):
return "Web"
def createUser(self, name, role_list):
user_folder = self.getPortal().acl_users
user_folder._doAddUser(name, 'password', role_list, [])
def changeUser(self, name):
self.old_user = getSecurityManager().getUser()
user_folder = self.getPortal().acl_users
user = user_folder.getUserById(name).__of__(user_folder)
newSecurityManager(None, user)
def afterSetUp(self):
self.createUser('admin', ['Manager'])
self.createUser('erp5user', ['Auditor', 'Author'])
get_transaction().commit()
self.tic()
def beforeTearDown(self):
get_transaction().abort()
def clearModule(module):
module.manage_delObjects(list(module.objectIds()))
get_transaction().commit()
self.tic()
clearModule(self.portal.web_site_module)
clearModule(self.portal.web_page_module)
def testAccessWebPageByReference(self):
self.changeUser('admin')
site = self.portal.web_site_module.newContent(portal_type='Web Site',
id='site')
section = site.newContent(portal_type='Web Section', id='section')
get_transaction().commit()
self.tic()
section.setCriterionProperty('portal_type')
section.setCriterion('portal_type', max='', identity=['Web Page'], min='')
get_transaction().commit()
self.tic()
self.changeUser('erp5user')
page_en = self.portal.web_page_module.newContent(portal_type='Web Page')
page_en.edit(reference='my-first-web-page',
language='en',
version='1',
text_format='text/plain',
text_content='Hello, World!')
get_transaction().commit()
self.tic()
page_en.publish()
get_transaction().commit()
self.tic()
page_ja = self.portal.web_page_module.newContent(portal_type='Web Page')
page_ja.edit(reference='my-first-web-page',
language='ja',
version='1',
text_format='text/plain',
text_content='こんにちは、世界!')
get_transaction().commit()
self.tic()
page_ja.publish()
get_transaction().commit()
self.tic()
setLanguage(self.portal, 'en')
target = self.portal.restrictedTraverse('web_site_module/site/section/my-first-web-page')
self.assertEqual('Hello, World!', target.getTextContent())
setLanguage(self.portal, 'ja')
target = self.portal.restrictedTraverse('web_site_module/site/section/my-first-web-page')
self.assertEqual('こんにちは、世界!', target.getTextContent())
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestWeb))
return suite