4
4
default_password
5
5
import re
6
6
from Products .CMFCore .utils import getToolByName
7
+ from quintagroup .canonicalpath .adapters import PROPERTY_LINK \
8
+ as CANONICAL_PROPERTY
7
9
8
10
9
11
class TestCanonicalURL (FunctionalTestCase ):
@@ -19,14 +21,59 @@ def afterSetUp(self):
19
21
'[^>]*href\s*=\s*\" ([^\" ]*)\" [^>]*>' ,
20
22
re .S | re .M )
21
23
22
- def test_CanonicalURL (self ):
24
+ def test_NoCanonicalURL (self ):
23
25
html = self .publish (self .mydoc_path , self .basic_auth ).getBody ()
24
26
foundcurls = self .curl .findall (html )
25
- mydoc_url = self .mydoc .absolute_url ()
27
+ assert not self .mydoc .hasProperty (CANONICAL_PROPERTY )
28
+ self .assertTrue (not foundcurls , "CANONICAL URL found, " \
29
+ "but object hasn't '%s' property" % CANONICAL_PROPERTY )
26
30
27
- self .assertTrue ([1 for curl in foundcurls if curl == mydoc_url ],
31
+ def test_CanonicalProperty (self ):
32
+ self .assertTrue (not self .mydoc .hasProperty (CANONICAL_PROPERTY ),
33
+ 'Canonical URL property is present in new document.' )
34
+
35
+ def test_CanonicalPropertyEnable (self ):
36
+ curl = '/newcanonical'
37
+ res = self .publish (self .mydoc_path + '/@@seo-context-properties?' \
38
+ 'seo_canonical=%s&seo_canonical_override=checked&' \
39
+ 'form.submitted=1&form.button.Save=Save' % curl ,
40
+ self .basic_auth ).getBody ()
41
+
42
+ self .assertTrue (self .mydoc .hasProperty (CANONICAL_PROPERTY ),
43
+ 'Overriding Canonical URL enabled,' \
44
+ 'but object hasn\' t canonical url property' )
45
+
46
+ self .assertTrue (self .mydoc .getProperty (CANONICAL_PROPERTY ) == curl ,
47
+ "Wrong Canonical URL for document: %s, all must be: %s"
48
+ % (self .mydoc .getProperty (CANONICAL_PROPERTY ), curl ))
49
+
50
+ def test_CanonicalPropertyDisable (self ):
51
+ curl = '/newcanonical'
52
+ self .mydoc .manage_addProperty (CANONICAL_PROPERTY , curl ,
53
+ 'string' )
54
+
55
+ assert self .mydoc .getProperty (CANONICAL_PROPERTY ) == curl
56
+
57
+ res = self .publish (self .mydoc_path + '/@@seo-context-properties?' \
58
+ 'seo_canonical=%s&seo_canonical_override=&' \
59
+ 'form.submitted=1&form.button.Save=Save' % curl ,
60
+ self .basic_auth ).getBody ()
61
+
62
+ self .assertTrue (not self .mydoc .hasProperty (CANONICAL_PROPERTY ),
63
+ 'Overriding Canonical URL disabled,' \
64
+ 'but canonical link is present in object properties' )
65
+
66
+ def test_CanonicalUrlPresent (self ):
67
+ self .mydoc .manage_addProperty (CANONICAL_PROPERTY , self .mydoc_path ,
68
+ 'string' )
69
+ assert self .mydoc .hasProperty (CANONICAL_PROPERTY )
70
+
71
+ html = self .publish (self .mydoc_path , self .basic_auth ).getBody ()
72
+ foundcurls = self .curl .findall (html )
73
+
74
+ self .assertTrue ([1 for curl in foundcurls if curl == self .mydoc_path ],
28
75
"Wrong CANONICAL URL for document: %s, all must be: %s" % (
29
- foundcurls , mydoc_url ))
76
+ foundcurls , self . mydoc_path ))
30
77
31
78
def test_updateCanonicalURL (self ):
32
79
mydoc_url_new = self .mydoc .absolute_url () + '.new'
0 commit comments