[424] | 1 | import re |
---|
| 2 | import string |
---|
| 3 | import urllib |
---|
[1475] | 4 | from cStringIO import StringIO |
---|
[424] | 5 | from zope.component import getMultiAdapter |
---|
| 6 | from Products.Five import zcml, fiveconfigure |
---|
| 7 | from Testing.ZopeTestCase import installPackage, hasPackage |
---|
| 8 | from Products.PloneTestCase import PloneTestCase |
---|
| 9 | from Products.CMFCore.utils import getToolByName |
---|
| 10 | from Products.CMFCore.permissions import ManagePortal |
---|
| 11 | from Products.CMFQuickInstallerTool.InstalledProduct import InstalledProduct |
---|
| 12 | from AccessControl.SecurityManagement import newSecurityManager, noSecurityManager |
---|
| 13 | |
---|
| 14 | import quintagroup.seoptimizer |
---|
| 15 | from quintagroup.seoptimizer.config import * |
---|
| 16 | |
---|
| 17 | zcml.load_site() |
---|
| 18 | zcml.load_config('overrides.zcml', quintagroup.seoptimizer) |
---|
| 19 | zcml.load_config('configure.zcml', quintagroup.seoptimizer) |
---|
| 20 | PRODUCT = 'quintagroup.seoptimizer' |
---|
| 21 | installPackage(PRODUCT) |
---|
| 22 | props = {'stop_words':STOP_WORDS, 'fields':FIELDS, 'additional_keywords': []} |
---|
| 23 | |
---|
| 24 | custom_metatags = [{'meta_name' : 'metatag1', |
---|
| 25 | 'meta_content' : 'metatag1value'}, |
---|
| 26 | {'meta_name' : 'metatag2', |
---|
[1269] | 27 | 'meta_content' : 'metatag2value'}, |
---|
| 28 | {'meta_name' : 'metatag3', |
---|
| 29 | 'meta_content' : ''} |
---|
| 30 | ] |
---|
[1313] | 31 | view_metatags = ['DC.creator', 'DC.format', 'DC.date.modified', 'DC.date.created', 'DC.type', |
---|
| 32 | 'DC.distribution', 'description', 'keywords', 'robots', 'distribution'] |
---|
[424] | 33 | |
---|
[1269] | 34 | global_custom_metatags = {'default_custom_metatags':'metatag1|global_metatag1value\nmetatag4|global_metatag4value'} |
---|
| 35 | |
---|
[424] | 36 | configlets = ({'id':'qSEOptimizer', |
---|
| 37 | 'name':'Search Engine Optimizer', |
---|
| 38 | 'action':'string:${portal_url}/seo-controlpanel', |
---|
| 39 | 'condition':'', |
---|
| 40 | 'category':'Products', |
---|
| 41 | 'visible':1, |
---|
| 42 | 'appId':'qSEOptimizer', |
---|
| 43 | 'permission':ManagePortal},) |
---|
| 44 | |
---|
| 45 | qSEO_CONTENT = ['File','Document','News Item'] |
---|
| 46 | qSEO_FOLDER = [] |
---|
| 47 | qSEO_TYPES = qSEO_CONTENT + qSEO_FOLDER |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | PloneTestCase.setupPloneSite() |
---|
| 51 | |
---|
| 52 | class TestBeforeInstall(PloneTestCase.FunctionalTestCase): |
---|
| 53 | |
---|
| 54 | def afterSetUp(self): |
---|
| 55 | self.basic_auth = 'mgr:mgrpw' |
---|
| 56 | self.portal_path = '/%s' % self.portal.absolute_url(1) |
---|
| 57 | |
---|
| 58 | def testAccessPortalRootAnonymous(self): |
---|
| 59 | response = self.publish(self.portal_path) |
---|
| 60 | self.assertEqual(response.getStatus(), 200) |
---|
| 61 | |
---|
| 62 | def testAccessPortalRootAuthenticated(self): |
---|
| 63 | response = self.publish(self.portal_path, self.basic_auth) |
---|
| 64 | self.assertEqual(response.getStatus(), 200) |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | class TestInstallation(PloneTestCase.PloneTestCase): |
---|
| 68 | |
---|
| 69 | def afterSetUp(self): |
---|
| 70 | self.properties = getToolByName(self.portal, 'portal_properties') |
---|
| 71 | self.qi = self.portal.portal_quickinstaller |
---|
| 72 | self.qi.installProduct(PRODUCT) |
---|
| 73 | |
---|
| 74 | def testAddingPropertySheet(self): |
---|
| 75 | """ Test adding property sheet to portal_properties tool """ |
---|
| 76 | self.failUnless(hasattr(self.properties.aq_base, PROPERTY_SHEET)) |
---|
| 77 | |
---|
| 78 | def testAddingPropertyFields(self): |
---|
| 79 | """ Test adding property field to portal_properties.maps_properties sheet """ |
---|
| 80 | map_sheet = self.properties[PROPERTY_SHEET] |
---|
| 81 | for key, value in props.items(): |
---|
| 82 | self.failUnless(map_sheet.hasProperty(key) and list(map_sheet.getProperty(key)) == value) |
---|
| 83 | |
---|
| 84 | def test_configlet_install(self): |
---|
| 85 | configTool = getToolByName(self.portal, 'portal_controlpanel', None) |
---|
| 86 | self.assert_(PRODUCT in [a.getId() for a in configTool.listActions()], 'Configlet not found') |
---|
| 87 | |
---|
| 88 | def test_actions_install(self): |
---|
| 89 | portal_types = getToolByName(self.portal, 'portal_types') |
---|
| 90 | for ptype in portal_types.objectValues(): |
---|
| 91 | try: |
---|
| 92 | #for Plone-2.5 and higher |
---|
| 93 | acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions()) |
---|
| 94 | action = acts and acts[0] or None |
---|
| 95 | except AttributeError: |
---|
| 96 | action = ptype.getActionById('seo_properties', default=None ) |
---|
| 97 | |
---|
| 98 | if ptype.getId() in qSEO_TYPES: |
---|
| 99 | self.assert_(action, 'Action for %s not found' % ptype.getId()) |
---|
| 100 | else: |
---|
| 101 | self.assert_(not action, 'Action found for %s' % ptype.getId()) |
---|
| 102 | |
---|
| 103 | def test_skins_install(self): |
---|
| 104 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
| 105 | |
---|
| 106 | for skin in skinstool.getSkinSelections(): |
---|
| 107 | path = skinstool.getSkinPath(skin) |
---|
| 108 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 109 | self.assert_(PRODUCT in path, 'qSEOptimizer layer not found in %s' %skin) |
---|
| 110 | |
---|
| 111 | def test_versionedskin_install(self): |
---|
| 112 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
| 113 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
| 114 | plone_version = mtool.getFileSystemVersion() |
---|
| 115 | if plone_version < "3": |
---|
| 116 | for skin in skinstool.getSkinSelections(): |
---|
| 117 | path = skinstool.getSkinPath(skin) |
---|
| 118 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 119 | self.assert_(PRODUCT+'/%s' % plone_version in path, 'qSEOptimizer versioned layer not found in %s' %skin) |
---|
| 120 | |
---|
| 121 | def test_actions_uninstall(self): |
---|
| 122 | self.qi.uninstallProducts([PRODUCT]) |
---|
| 123 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
| 124 | portal_types = getToolByName(self.portal, 'portal_types') |
---|
| 125 | for ptype in portal_types.objectValues(): |
---|
| 126 | try: |
---|
| 127 | #for Plone-2.5 and higher |
---|
| 128 | acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions()) |
---|
| 129 | action = acts and acts[0] or None |
---|
| 130 | except AttributeError: |
---|
| 131 | action = ptype.getActionById('seo_properties', default=None ) |
---|
| 132 | |
---|
| 133 | self.assert_(not action, 'Action for %s found after uninstallation' % ptype.getId()) |
---|
| 134 | |
---|
| 135 | def test_skins_uninstall(self): |
---|
| 136 | self.qi.uninstallProducts([PRODUCT]) |
---|
| 137 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
| 138 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
| 139 | |
---|
| 140 | for skin in skinstool.getSkinSelections(): |
---|
| 141 | path = skinstool.getSkinPath(skin) |
---|
| 142 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 143 | self.assert_(not PRODUCT in path, 'qSEOptimizer layer found in %s after uninstallation' %skin) |
---|
| 144 | |
---|
| 145 | def test_versionedskin_uninstall(self): |
---|
| 146 | self.qi.uninstallProducts([PRODUCT]) |
---|
| 147 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
| 148 | skinstool=getToolByName(self.portal, 'portal_skins') |
---|
| 149 | mtool = getToolByName(self.portal, 'portal_migration') |
---|
| 150 | plone_version = mtool.getFileSystemVersion() |
---|
| 151 | |
---|
| 152 | for skin in skinstool.getSkinSelections(): |
---|
| 153 | path = skinstool.getSkinPath(skin) |
---|
| 154 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 155 | self.assert_(not PRODUCT+'/%s' % plone_version in path, 'qSEOptimizer versioned layer found in %s after uninstallation' %skin) |
---|
| 156 | |
---|
| 157 | def test_configlet_uninstall(self): |
---|
| 158 | self.qi.uninstallProducts([PRODUCT]) |
---|
| 159 | self.assertNotEqual(self.qi.isProductInstalled(PRODUCT), True,'qSEOptimizer is already installed') |
---|
| 160 | |
---|
| 161 | configTool = getToolByName(self.portal, 'portal_controlpanel', None) |
---|
| 162 | self.assert_(not PRODUCT in [a.getId() for a in configTool.listActions()], 'Configlet found after uninstallation') |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | class TestResponse(PloneTestCase.FunctionalTestCase): |
---|
| 166 | |
---|
| 167 | def afterSetUp(self): |
---|
| 168 | self.qi = self.portal.portal_quickinstaller |
---|
| 169 | self.qi.installProduct(PRODUCT) |
---|
[1475] | 170 | self.sp = self.portal.portal_properties.seo_properties |
---|
| 171 | self.pu = self.portal.plone_utils |
---|
| 172 | self.basic_auth = 'portal_manager:secret' |
---|
[424] | 173 | |
---|
[1475] | 174 | uf = self.app.acl_users |
---|
| 175 | uf.userFolderAddUser('portal_manager', 'secret', ['Manager'], []) |
---|
| 176 | user = uf.getUserById('portal_manager') |
---|
| 177 | if not hasattr(user, 'aq_base'): |
---|
| 178 | user = user.__of__(uf) |
---|
| 179 | newSecurityManager(None, user) |
---|
[424] | 180 | |
---|
| 181 | '''Preparation for functional testing''' |
---|
| 182 | my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
| 183 | my_doc = self.portal['my_doc'] |
---|
[1475] | 184 | self.canonurl = 'http://nohost/plone/test.html' |
---|
[1269] | 185 | self.sp.manage_changeProperties(**global_custom_metatags) |
---|
[1475] | 186 | abs_path = "/%s" % my_doc.absolute_url(1) |
---|
| 187 | self.form_data = {'seo_description': 'it is description', 'seo_keywords_override:int': 1, 'seo_custommetatags_override:int': 1, |
---|
| 188 | 'seo_robots_override:int': 1, 'seo_robots': 'ALL', 'seo_description_override:int': 1, 'seo_canonical_override:int': 1, |
---|
| 189 | 'seo_keywords:list': 'keyword1', 'seo_html_comment': 'no comments', |
---|
| 190 | 'seo_title_override:int': 1, 'seo_title': 'hello world', 'seo_html_comment_override:int': 1, |
---|
| 191 | 'seo_distribution_override:int': 1, 'seo_distribution': 'Global', 'seo_canonical': self.canonurl, 'form.submitted:int': 1} |
---|
| 192 | st = '' |
---|
| 193 | for d in custom_metatags: |
---|
| 194 | st += '&seo_custommetatags.meta_name:records=%s&seo_custommetatags.meta_content:records=%s' % (d['meta_name'],d['meta_content']) |
---|
| 195 | self.publish(path=abs_path+'/@@seo-context-properties', basic=self.basic_auth, request_method='POST', stdin=StringIO(urllib.urlencode(self.form_data)+st)) |
---|
| 196 | #self.publish(abs_path+'/@@seo-context-properties?%s' % urllib.urlencode(self.form_data), self.basic_auth) |
---|
[424] | 197 | |
---|
| 198 | wf_tool = self.portal.portal_workflow |
---|
| 199 | wf_tool.doActionFor(my_doc, 'publish') |
---|
| 200 | |
---|
[1269] | 201 | self.abs_path = abs_path |
---|
| 202 | self.my_doc = my_doc |
---|
[424] | 203 | self.html = self.publish(abs_path, self.basic_auth).getBody() |
---|
| 204 | |
---|
[1052] | 205 | # now setup page with title equal to plone site's title |
---|
| 206 | my_doc2 = self.portal.invokeFactory('Document', id='my_doc2') |
---|
| 207 | my_doc2 = self.portal['my_doc2'] |
---|
| 208 | my_doc2.update(title=self.portal.Title()) |
---|
| 209 | wf_tool.doActionFor(my_doc2, 'publish') |
---|
| 210 | abs_path2 = "/%s" % my_doc2.absolute_url(1) |
---|
| 211 | self.html2 = self.publish(abs_path2, self.basic_auth).getBody() |
---|
| 212 | |
---|
[424] | 213 | def testTitle(self): |
---|
| 214 | m = re.match('.*<title>\\s*hello world\\s*</title>', self.html, re.S|re.M) |
---|
| 215 | self.assert_(m, 'Title not set in') |
---|
| 216 | |
---|
[1052] | 217 | def testTitleDuplication(self): |
---|
| 218 | """If we are not overriding page title and current page title equals title of the plone site |
---|
| 219 | then there should be no concatenation of both titles. Only one should be displayed. |
---|
| 220 | """ |
---|
| 221 | m = re.match('.*<title>\\s*%s\\s*</title>' % self.portal.Title(), self.html2, re.S|re.M) |
---|
| 222 | self.assert_(m, 'Title is not set correctly, perhaps it is duplicated with plone site title') |
---|
| 223 | |
---|
[424] | 224 | def testDescription(self): |
---|
| 225 | m = re.match('.*<meta name="description" content="it is description" />', self.html, re.S|re.M) |
---|
[1313] | 226 | if not m: |
---|
| 227 | m = re.match('.*<meta content="it is description" name="description" />', self.html, re.S|re.M) |
---|
[424] | 228 | self.assert_(m, 'Description not set in') |
---|
| 229 | |
---|
| 230 | def testKeywords(self): |
---|
[1475] | 231 | m = re.match('.*<meta name="keywords" content="keyword1" />', self.html, re.S|re.M) |
---|
[1313] | 232 | if not m: |
---|
[1475] | 233 | m = re.match('.*<meta content="keyword1" name="keywords" />', self.html, re.S|re.M) |
---|
[424] | 234 | self.assert_(m, 'Keywords not set in') |
---|
| 235 | |
---|
| 236 | def testRobots(self): |
---|
| 237 | m = re.match('.*<meta name="robots" content="ALL" />', self.html, re.S|re.M) |
---|
[1313] | 238 | if not m: |
---|
| 239 | m = re.match('.*<meta content="ALL" name="robots" />', self.html, re.S|re.M) |
---|
[424] | 240 | self.assert_(m, 'Robots not set in') |
---|
| 241 | |
---|
| 242 | def testDistribution(self): |
---|
| 243 | m = re.match('.*<meta name="distribution" content="Global" />', self.html, re.S|re.M) |
---|
[1313] | 244 | if not m: |
---|
| 245 | m = re.match('.*<meta content="Global" name="distribution" />', self.html, re.S|re.M) |
---|
[424] | 246 | self.assert_(m, 'Distribution not set in') |
---|
| 247 | |
---|
| 248 | def testHTMLComments(self): |
---|
| 249 | m = re.match('.*<!--\\s*no comments\\s*-->', self.html, re.S|re.M) |
---|
| 250 | self.assert_(m, 'Comments not set in') |
---|
| 251 | |
---|
| 252 | def testTagsOrder(self): |
---|
[1313] | 253 | mtop = self.sp.getProperty('metatags_order') |
---|
| 254 | metatags_order = [t.split(' ')[0] for t in mtop if len(t.split(' '))==2 and t.split(' ')[0] in view_metatags] |
---|
| 255 | m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), self.html, re.S|re.M) |
---|
[424] | 256 | self.assert_(m, "Meta tags order not supported.") |
---|
| 257 | |
---|
[1313] | 258 | mtop = list(mtop) |
---|
| 259 | mtop.reverse() |
---|
| 260 | metatags_order = [t.split(' ')[0] for t in mtop if len(t.split(' '))==2 and t.split(' ')[0] in view_metatags] |
---|
| 261 | m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), self.html, re.S|re.M) |
---|
| 262 | self.assertFalse(m, "Meta tags order not supported.") |
---|
| 263 | |
---|
| 264 | self.sp.manage_changeProperties(**{'metatags_order':tuple(mtop)}) |
---|
| 265 | html = self.publish(self.abs_path, self.basic_auth).getBody() |
---|
| 266 | m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), self.html, re.S|re.M) |
---|
| 267 | self.assertFalse(m, "Meta tags order not supported.") |
---|
| 268 | |
---|
| 269 | m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), html, re.S|re.M) |
---|
| 270 | self.assert_(m, "Meta tags order not supported.") |
---|
| 271 | |
---|
| 272 | |
---|
[424] | 273 | def testCustomMetaTags(self): |
---|
| 274 | for tag in custom_metatags: |
---|
| 275 | m = re.search('<meta name="%(meta_name)s" content="%(meta_content)s" />' % tag, self.html, re.S|re.M) |
---|
[1313] | 276 | if not m: |
---|
| 277 | m = re.search('<meta content="%(meta_content)s" name="%(meta_name)s" />' % tag, self.html, re.S|re.M) |
---|
[1269] | 278 | if tag['meta_content']: |
---|
| 279 | self.assert_(m, "Custom meta tag %s not applied." % tag['meta_name']) |
---|
| 280 | else: |
---|
| 281 | self.assert_(not m, "Meta tag %s has no content, but is present in the page." % tag['meta_name']) |
---|
| 282 | m = re.search('<meta name="metatag4" content="global_metatag4value" />' , self.html, re.S|re.M) |
---|
[1313] | 283 | if not m: |
---|
| 284 | m = re.search('<meta content="global_metatag4value" name="metatag4" />' , self.html, re.S|re.M) |
---|
[1269] | 285 | self.assert_(m, "Global custom meta tag %s not applied." % 'metatag4') |
---|
[424] | 286 | |
---|
[1269] | 287 | def testDeleteCustomMetaTags(self): |
---|
| 288 | self.sp.manage_changeProperties(**{'default_custom_metatags':'metatag1|global_metatag1value'}) |
---|
| 289 | my_doc = self.my_doc |
---|
[1475] | 290 | self.form_data = {'seo_custommetatags': custom_metatags, 'seo_custommetatags_override:int': 0, 'form.submitted:int': 1} |
---|
| 291 | self.publish(path=self.abs_path+'/@@seo-context-properties', basic=self.basic_auth, request_method='POST', stdin=StringIO(urllib.urlencode(self.form_data))) |
---|
[1269] | 292 | html = self.publish(self.abs_path, self.basic_auth).getBody() |
---|
| 293 | m = re.search('<meta name="metatag4" content="global_metatag4value" />' , html, re.S|re.M) |
---|
[1313] | 294 | if not m: |
---|
| 295 | m = re.search('<meta content="global_metatag4value" name="metatag4" />' , html, re.S|re.M) |
---|
[1269] | 296 | self.assert_(not m, "Global custom meta tag %s is prosent in the page." % 'metatag4') |
---|
| 297 | m = re.search('<meta name="metatag1" content="global_metatag1value" />' , html, re.S|re.M) |
---|
[1313] | 298 | if not m: |
---|
| 299 | m = re.search('<meta content="global_metatag1value" name="metatag1" />' , html, re.S|re.M) |
---|
[1475] | 300 | self.assert_(m, "Global custom meta tag %s not applied." % 'metatag1') |
---|
[1269] | 301 | |
---|
[898] | 302 | def testCanonical(self): |
---|
| 303 | m = re.match('.*<link rel="canonical" href="%s" />' % self.canonurl, self.html, re.S|re.M) |
---|
| 304 | self.assert_(m, self.canonurl) |
---|
| 305 | |
---|
| 306 | def testDefaultCanonical(self): |
---|
| 307 | """Default canonical url mast add document absolute_url |
---|
| 308 | """ |
---|
| 309 | # Delete custom canonical url |
---|
| 310 | my_doc = self.portal['my_doc'] |
---|
| 311 | my_doc._delProperty(id='qSEO_canonical') |
---|
| 312 | # Get document without customized canonical url |
---|
| 313 | abs_path = "/%s" % my_doc.absolute_url(1) |
---|
| 314 | self.html = self.publish(abs_path, self.basic_auth).getBody() |
---|
| 315 | |
---|
| 316 | my_url = my_doc.absolute_url() |
---|
| 317 | m = re.match('.*<link rel="canonical" href="%s" />' % my_url, self.html, re.S|re.M) |
---|
| 318 | self.assert_(m, my_url) |
---|
| 319 | |
---|
[424] | 320 | class TestAdditionalKeywords(PloneTestCase.FunctionalTestCase): |
---|
| 321 | |
---|
| 322 | def afterSetUp(self): |
---|
| 323 | self.qi = self.portal.portal_quickinstaller |
---|
| 324 | self.qi.installProduct(PRODUCT) |
---|
| 325 | self.sp = self.portal.portal_properties.seo_properties |
---|
| 326 | self.pu = self.portal.plone_utils |
---|
| 327 | |
---|
| 328 | self.basic_auth = 'portal_manager:secret' |
---|
| 329 | uf = self.app.acl_users |
---|
| 330 | uf.userFolderAddUser('portal_manager', 'secret', ['Manager'], []) |
---|
| 331 | user = uf.getUserById('portal_manager') |
---|
| 332 | if not hasattr(user, 'aq_base'): |
---|
| 333 | user = user.__of__(uf) |
---|
| 334 | newSecurityManager(None, user) |
---|
| 335 | |
---|
| 336 | '''Preparation for functional testing''' |
---|
| 337 | self.my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
| 338 | self.my_doc = self.portal['my_doc'] |
---|
| 339 | |
---|
| 340 | def test_additional_keywords_in_configlet(self): |
---|
| 341 | quoted_keywords = urllib.quote('foo\nbar') |
---|
| 342 | path = self.portal.id+'/@@seo-controlpanel?additionalKeywords:lines=%s&form.submitted=1'%quoted_keywords |
---|
| 343 | self.publish(path, self.basic_auth) |
---|
| 344 | self.assertEqual(self.sp.additional_keywords, ('foo', 'bar')) |
---|
| 345 | self.publish(self.portal.id+'/@@seo-controlpanel?form.submitted=1', self.basic_auth) |
---|
| 346 | self.assertEqual(self.sp.additional_keywords, ()) |
---|
| 347 | |
---|
| 348 | def test_listMetaTags_empty(self): |
---|
| 349 | metatags = self.pu.listMetaTags(self.my_doc) |
---|
| 350 | self.assert_('keywords' not in metatags) |
---|
| 351 | |
---|
| 352 | def test_listMetaTags_one(self): |
---|
| 353 | self.my_doc.manage_addProperty('qSEO_keywords', ('foo',), 'lines') |
---|
| 354 | self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) |
---|
[1313] | 355 | m = re.match('.*<meta\ content="foo"\ name="keywords"\ />', self.html, re.S|re.M) |
---|
| 356 | if not m: |
---|
| 357 | m = re.match('.*<meta\ name="keywords"\ content="foo"\ />', self.html, re.S|re.M) |
---|
[424] | 358 | self.assert_(m, "No 'foo' keyword find") |
---|
| 359 | |
---|
| 360 | def test_listMetaTags_two(self): |
---|
| 361 | self.my_doc.manage_addProperty('qSEO_keywords', ('foo', 'bar'), 'lines') |
---|
| 362 | self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) |
---|
[1313] | 363 | m = re.match('.*<meta\ content="foo, bar"\ name="keywords"\ />', self.html, re.S|re.M) |
---|
| 364 | if not m: |
---|
| 365 | m = re.match('.*<meta\ name="keywords"\ content="foo, bar"\ />', self.html, re.S|re.M) |
---|
[424] | 366 | self.assert_(m, "No 'foo, bar' keyword find") |
---|
| 367 | |
---|
| 368 | def test_additional_keywords_in_listMetaTags_empty(self): |
---|
| 369 | self.sp.additional_keywords = ('foo',) |
---|
| 370 | metatags = self.pu.listMetaTags(self.my_doc) |
---|
| 371 | self.assert_('keywords' not in metatags) |
---|
| 372 | |
---|
| 373 | def test_additional_keywords_in_listMetaTags_one(self): |
---|
| 374 | self.my_doc.setText('<p>foo</p>') |
---|
| 375 | self.sp.additional_keywords = ('foo',) |
---|
| 376 | self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) |
---|
[1313] | 377 | m = re.match('.*<meta\ content="foo"\ name="keywords"\ />', self.html, re.S|re.M) |
---|
| 378 | if not m: |
---|
| 379 | m = re.match('.*<meta\ name="keywords"\ content="foo"\ />', self.html, re.S|re.M) |
---|
[424] | 380 | self.assert_(m, "No 'foo' keyword find") |
---|
| 381 | |
---|
| 382 | def test_additional_keywords_in_listMetaTags_two(self): |
---|
| 383 | self.my_doc.setText('<p>foo bar</p>') |
---|
| 384 | self.sp.additional_keywords = ('foo', 'bar') |
---|
| 385 | self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) |
---|
[1313] | 386 | m = re.match('.*<meta\ content="foo, bar"\ name="keywords"\ />', self.html, re.S|re.M) |
---|
| 387 | if not m: |
---|
| 388 | m = re.match('.*<meta\ name="keywords"\ content="foo, bar"\ />', self.html, re.S|re.M) |
---|
[424] | 389 | self.assert_(m, "No 'foo, bar' keyword find") |
---|
| 390 | |
---|
| 391 | def test_additional_keywords_in_listMetaTags_merge(self): |
---|
| 392 | self.my_doc.setText('<p>foo bar</p>') |
---|
| 393 | self.sp.additional_keywords = ('foo', 'bar') |
---|
| 394 | self.my_doc.manage_addProperty('qSEO_keywords', ('baz',), 'lines') |
---|
| 395 | self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) |
---|
[1475] | 396 | m = re.findall('.*(<meta\s+(?:content="(?:(?:baz|bar|foo),\s*(?:baz|foo|bar),\s*(?:baz|foo|bar)"\s*)|(?:name="keywords"\s*)){2}/>)', self.html, re.S|re.M) |
---|
[424] | 397 | self.assert_(m, "No 'foo, bar, baz' keyword find") |
---|
| 398 | |
---|
| 399 | |
---|
| 400 | class TestExposeDCMetaTags(PloneTestCase.FunctionalTestCase): |
---|
| 401 | |
---|
| 402 | def afterSetUp(self): |
---|
| 403 | self.qi = self.portal.portal_quickinstaller |
---|
| 404 | self.sp = self.portal.portal_properties.site_properties |
---|
| 405 | self.qi.installProduct(PRODUCT) |
---|
| 406 | self.basic_auth = 'portal_manager:secret' |
---|
| 407 | uf = self.app.acl_users |
---|
| 408 | uf.userFolderAddUser('portal_manager', 'secret', ['Manager'], []) |
---|
| 409 | user = uf.getUserById('portal_manager') |
---|
| 410 | if not hasattr(user, 'aq_base'): |
---|
| 411 | user = user.__of__(uf) |
---|
| 412 | newSecurityManager(None, user) |
---|
| 413 | |
---|
| 414 | '''Preparation for functional testing''' |
---|
| 415 | self.my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
| 416 | self.my_doc = self.portal['my_doc'] |
---|
| 417 | |
---|
| 418 | def test_exposeDCMetaTags_in_configletOn(self): |
---|
| 419 | path = self.portal.id+'/@@seo-controlpanel?exposeDCMetaTags=True&form.submitted=1' |
---|
| 420 | self.publish(path, self.basic_auth) |
---|
| 421 | self.assert_(self.sp.exposeDCMetaTags) |
---|
| 422 | |
---|
| 423 | def test_exposeDCMetaTags_in_configletOff(self): |
---|
| 424 | self.publish(self.portal.id+'/@@seo-controlpanel?form.submitted=1', self.basic_auth) |
---|
| 425 | self.assert_(not self.sp.exposeDCMetaTags) |
---|
| 426 | |
---|
| 427 | def test_exposeDCMetaTagsPropertyOff(self): |
---|
| 428 | self.sp.manage_changeProperties(exposeDCMetaTags = False) |
---|
| 429 | self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) |
---|
[1313] | 430 | m1 = re.match('.*<meta\ name="DC.format"\ content=".*?"\ />', self.html, re.S|re.M) |
---|
| 431 | if not m1: |
---|
| 432 | m1 = re.match('.*<meta content=".*?" name="DC.format" />', self.html, re.S|re.M) |
---|
| 433 | m2 = re.match('.*<meta name="DC.distribution" content=".*?" />', self.html, re.S|re.M) |
---|
| 434 | if not m2: |
---|
| 435 | m2 = re.match('.*<meta content=".*?" name="DC.distribution" />', self.html, re.S|re.M) |
---|
| 436 | m = m1 or m2 |
---|
[424] | 437 | self.assert_(not m, 'DC meta tags avaliable when exposeDCMetaTags=False') |
---|
| 438 | |
---|
| 439 | def test_exposeDCMetaTagsPropertyOn(self): |
---|
| 440 | self.sp.manage_changeProperties(exposeDCMetaTags = True) |
---|
| 441 | self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) |
---|
[1313] | 442 | m1 = re.match('.*<meta\ content=".*?"\ name="DC.format"\ />', self.html, re.S|re.M) |
---|
| 443 | if not m1: |
---|
| 444 | m1 = re.match('.*<meta\ name="DC.format"\ content=".*?"\ />', self.html, re.S|re.M) |
---|
| 445 | m2 = re.match('.*<meta\ content=".*?"\ name="DC.type"\ />', self.html, re.S|re.M) |
---|
| 446 | if not m2: |
---|
| 447 | m2 = re.match('.*<meta\ name="DC.type"\ content=".*?"\ />', self.html, re.S|re.M) |
---|
| 448 | m = m1 and m2 |
---|
[424] | 449 | self.assert_(m, 'DC meta tags not avaliable when createManager=True') |
---|
| 450 | |
---|
| 451 | |
---|
[950] | 452 | class TestMetaTagsDuplication(PloneTestCase.FunctionalTestCase): |
---|
[424] | 453 | |
---|
[950] | 454 | def afterSetUp(self): |
---|
| 455 | self.qi = self.portal.portal_quickinstaller |
---|
| 456 | self.basic_auth = 'portal_manager:secret' |
---|
| 457 | uf = self.app.acl_users |
---|
| 458 | uf.userFolderAddUser('portal_manager', 'secret', ['Manager'], []) |
---|
| 459 | user = uf.getUserById('portal_manager') |
---|
| 460 | if not hasattr(user, 'aq_base'): |
---|
| 461 | user = user.__of__(uf) |
---|
| 462 | newSecurityManager(None, user) |
---|
| 463 | |
---|
| 464 | '''Preparation for functional testing''' |
---|
| 465 | self.my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
| 466 | self.my_doc = self.portal['my_doc'] |
---|
| 467 | self.my_doc.update(description="Document description") |
---|
| 468 | |
---|
| 469 | def test_GeneratorMeta(self): |
---|
| 470 | # Get document without customized canonical url |
---|
| 471 | abs_path = "/%s" % self.my_doc.absolute_url(1) |
---|
| 472 | regen = re.compile('<meta\s+[^>]*name=\"generator\"[^>]*>', re.S|re.M) |
---|
| 473 | |
---|
| 474 | # Before product installation |
---|
| 475 | html = self.publish(abs_path, self.basic_auth).getBody() |
---|
| 476 | lengen = len(regen.findall(html)) |
---|
| 477 | self.assert_(lengen==1, "There is %d generator meta tag(s) " \ |
---|
| 478 | "before seoptimizer installation" % lengen) |
---|
| 479 | |
---|
| 480 | # # After PRODUCT installation |
---|
| 481 | # self.qi.installProduct(PRODUCT) |
---|
| 482 | # html = self.publish(abs_path, self.basic_auth).getBody() |
---|
| 483 | # lengen = len(regen.findall(html)) |
---|
| 484 | # self.assert_(lengen==1, "There is %d generator meta tag(s) " \ |
---|
| 485 | # "after seoptimizer installation" % lengen) |
---|
| 486 | |
---|
| 487 | def test_DescriptionMeta(self): |
---|
| 488 | # Get document without customized canonical url |
---|
| 489 | abs_path = "/%s" % self.my_doc.absolute_url(1) |
---|
| 490 | regen = re.compile('<meta\s+[^>]*name=\"description\"[^>]*>', re.S|re.M) |
---|
| 491 | |
---|
| 492 | # Before product installation |
---|
| 493 | html = self.publish(abs_path, self.basic_auth).getBody() |
---|
| 494 | lendesc = len(regen.findall(html)) |
---|
| 495 | self.assert_(lendesc==1, "There is %d DESCRIPTION meta tag(s) " \ |
---|
| 496 | "before seoptimizer installation" % lendesc) |
---|
| 497 | |
---|
| 498 | # # After PRODUCT installation |
---|
| 499 | # self.qi.installProduct(PRODUCT) |
---|
| 500 | # html = self.publish(abs_path, self.basic_auth).getBody() |
---|
| 501 | # lendesc = len(regen.findall(html)) |
---|
| 502 | # self.assert_(lendesc==1, "There is %d DESCRIPTION meta tag(s) " \ |
---|
| 503 | # "after seoptimizer installation" % lendesc) |
---|
| 504 | |
---|
[959] | 505 | class TestBaseURL(PloneTestCase.FunctionalTestCase): |
---|
[950] | 506 | |
---|
[959] | 507 | def afterSetUp(self): |
---|
| 508 | self.qi = self.portal.portal_quickinstaller |
---|
| 509 | self.qi.installProduct(PRODUCT) |
---|
| 510 | #self.portal.changeSkin('Plone Default') |
---|
| 511 | |
---|
| 512 | self.basic_auth = 'portal_manager:secret' |
---|
| 513 | uf = self.app.acl_users |
---|
| 514 | uf.userFolderAddUser('portal_manager', 'secret', ['Manager'], []) |
---|
| 515 | user = uf.getUserById('portal_manager') |
---|
| 516 | if not hasattr(user, 'aq_base'): |
---|
| 517 | user = user.__of__(uf) |
---|
| 518 | newSecurityManager(None, user) |
---|
| 519 | |
---|
| 520 | def test_notFolderBaseURL(self): |
---|
| 521 | my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
| 522 | my_doc = self.portal['my_doc'] |
---|
| 523 | regen = re.compile('<base\s+[^>]*href=\"([^\"]*)\"[^>]*>', re.S|re.M) |
---|
[1475] | 524 | |
---|
[959] | 525 | path = "/%s" % my_doc.absolute_url(1) |
---|
| 526 | html = self.publish(path, self.basic_auth).getBody() |
---|
| 527 | burls = regen.findall(html) |
---|
[1475] | 528 | |
---|
[959] | 529 | mydocurl = my_doc.absolute_url() |
---|
| 530 | self.assert_(not [1 for burl in burls if not burl==mydocurl], |
---|
| 531 | "Wrong BASE URL for document: %s, all must be: %s" % (burls, mydocurl)) |
---|
| 532 | |
---|
| 533 | def test_folderBaseURL(self): |
---|
| 534 | my_fldr = self.portal.invokeFactory('Folder', id='my_fldr') |
---|
| 535 | my_fldr = self.portal['my_fldr'] |
---|
| 536 | regen = re.compile('<base\s+[^>]*href=\"([^\"]*)\"[^>]*>', re.S|re.M) |
---|
| 537 | |
---|
| 538 | path = "/%s" % my_fldr.absolute_url(1) |
---|
| 539 | html = self.publish(path, self.basic_auth).getBody() |
---|
| 540 | burls = regen.findall(html) |
---|
| 541 | |
---|
| 542 | myfldrurl = my_fldr.absolute_url() + '/' |
---|
| 543 | self.assert_(not [1 for burl in burls if not burl==myfldrurl], |
---|
| 544 | "Wrong BASE URL for folder: %s , all must be : %s" % (burls, myfldrurl)) |
---|
| 545 | |
---|
[1458] | 546 | |
---|
| 547 | class TestBugs(PloneTestCase.FunctionalTestCase): |
---|
| 548 | |
---|
| 549 | def afterSetUp(self): |
---|
| 550 | self.qi = self.portal.portal_quickinstaller |
---|
| 551 | self.qi.installProduct(PRODUCT) |
---|
| 552 | #self.portal.changeSkin('Plone Default') |
---|
| 553 | |
---|
| 554 | self.basic_auth = 'portal_manager:secret' |
---|
| 555 | uf = self.app.acl_users |
---|
| 556 | uf.userFolderAddUser('portal_manager', 'secret', ['Manager'], []) |
---|
| 557 | user = uf.getUserById('portal_manager') |
---|
| 558 | if not hasattr(user, 'aq_base'): |
---|
| 559 | user = user.__of__(uf) |
---|
| 560 | newSecurityManager(None, user) |
---|
| 561 | |
---|
| 562 | def test_modification_date(self): |
---|
| 563 | """ Modification date changing on SEO properties edit """ |
---|
| 564 | my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
| 565 | my_doc = self.portal['my_doc'] |
---|
| 566 | |
---|
| 567 | md_before = my_doc.modification_date |
---|
[1475] | 568 | abs_path = "/%s" % my_doc.absolute_url(1) |
---|
| 569 | form_data = {'seo_title': 'New Title', 'seo_title_override:int': 1, 'form.submitted:int': 1} |
---|
| 570 | self.publish(path=abs_path+'/@@seo-context-properties', basic=self.basic_auth, request_method='POST', stdin=StringIO(urllib.urlencode(form_data))) |
---|
[1458] | 571 | md_after = my_doc.modification_date |
---|
| 572 | self.assertNotEqual(md_before, md_after) |
---|
| 573 | |
---|
[1475] | 574 | |
---|
[950] | 575 | TESTS = [TestBeforeInstall, |
---|
| 576 | TestInstallation, |
---|
| 577 | TestResponse, |
---|
| 578 | TestExposeDCMetaTags, |
---|
| 579 | TestAdditionalKeywords, |
---|
| 580 | TestMetaTagsDuplication, |
---|
[959] | 581 | TestBaseURL, |
---|
[1458] | 582 | TestBugs, |
---|
[950] | 583 | ] |
---|
| 584 | |
---|
[424] | 585 | def test_suite(): |
---|
| 586 | from unittest import TestSuite, makeSuite |
---|
| 587 | suite = TestSuite() |
---|
| 588 | for suite_class in TESTS: |
---|
| 589 | suite.addTest(makeSuite(suite_class)) |
---|
| 590 | |
---|
| 591 | return suite |
---|
| 592 | |
---|
| 593 | if __name__ == '__main__': |
---|
| 594 | framework() |
---|