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