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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
##############################################################################
#
# Copyright (c) 2007 Nexedi SARL 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.
#
##############################################################################
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
# Needed in order to have a log file inside the current folder
os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log')
os.environ['EVENT_LOG_SEVERITY'] = '-300'
from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.CMFCore.utils import getToolByName
from AccessControl.SecurityManagement import newSecurityManager
from zLOG import LOG
import time
try:
from transaction import get as get_transaction
except ImportError:
pass
#
# Test Setting
#
INSTANCE_HOME = os.environ['INSTANCE_HOME']
bt5_path = os.path.join(INSTANCE_HOME, 'bt5')
# dependency order
target_business_templates = (
'erp5_base',
'erp5_trade',
'erp5_mysql_innodb_catalog',
'erp5_pdf_editor',
'erp5_pdf_style',
'erp5_pdm',
'erp5_accounting',
'erp5_apparel',
## 'erp5_banking_core',
## 'erp5_banking_cash',
## 'erp5_banking_check',
## 'erp5_banking_inventory',
'erp5_budget',
'erp5_commerce',
'erp5_consulting',
'erp5_crm',
'erp5_web',
'erp5_dms',
'erp5_forge',
'erp5_immobilisation',
'erp5_item',
'erp5_mrp',
'erp5_payroll',
'erp5_project',
)
class TestXHTML(ERP5TypeTestCase):
run_all_test = 1
def getTitle(self):
return "XHTML Test"
def getBusinessTemplateList(self):
""" """
return target_business_templates
def afterSetUp(self):
self.portal = self.getPortal()
self.login()
self.enableDefaultSitePreference()
def login(self, quiet=0, run=run_all_test):
uf = self.getPortal().acl_users
uf._doAddUser('seb', '', ['Manager'], [])
uf._doAddUser('ERP5TypeTestCase', '', ['Manager'], [])
user = uf.getUserById('seb').__of__(uf)
newSecurityManager(None, user)
def enableDefaultSitePreference(self):
portal_preferences = getToolByName(self.portal, 'portal_preferences')
portal_workflow = getToolByName(self.portal, 'portal_workflow')
default_site_preference = portal_preferences.default_site_preference
portal_workflow.doActionFor(default_site_preference, 'enable_action')
def validate_xhtml(source):
import popen2
stdout, stdin, stderr = popen2.popen3('/usr/bin/tidy -e -q -utf8')
stdin.write(source)
stdin.close()
for i in stderr:
data = i.split(' - ')
if len(data) >= 2:
if data[1].startswith('Error: '):
return False
return True
def makeTestMethod(module_id, portal_type, view_name):
def testMethod(self):
module = getattr(self.portal, module_id)
content = module.newContent(portal_type=portal_type)
view = getattr(content, view_name)
self.assert_(validate_xhtml(view()))
return testMethod
def addTestMethodDynamically():
from Products.ERP5.tests.utils import BusinessTemplateInfo
for i in target_business_templates:
business_template = os.path.join(bt5_path, '%s.bt5' % i)
business_template_info = BusinessTemplateInfo(business_template)
for module_id, module_portal_type in business_template_info.modules.items():
for portal_type in business_template_info.allowed_content_types.get(
module_portal_type, ()):
for action_information in business_template_info.actions[portal_type]:
if (action_information['category']=='object_view' and
action_information['visible']==1 and
action_information['text'].startswith('string:${object_url}/') and
len(action_information['text'].split('/'))==2):
view_name = action_information['text'].split('/')[-1]
method = makeTestMethod(module_id, portal_type, view_name)
method_name = 'test%s%s' % (portal_type, view_name)
setattr(TestXHTML, method_name, method)
addTestMethodDynamically()
if __name__ == '__main__':
framework()
else:
import unittest
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestXHTML))
return suite