Index: /quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testCanonicalURL.py
===================================================================
--- /quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testCanonicalURL.py	(revision 1935)
+++ /quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testCanonicalURL.py	(revision 1936)
@@ -1,20 +1,16 @@
 import re
+from zope.interface import alsoProvides
 from zope.component import queryAdapter
 from zope.component import provideAdapter
+from zope.component import queryMultiAdapter
 from plone.indexer.decorator import indexer
-
-try:
-    from plone.indexer.decorator import indexer
-except ImportError:
-    IS_NEW = False
-    from Products.CMFPlone.CatalogTool import registerIndexableAttribute
-else:
-    IS_NEW = True
 
 from Products.CMFCore.interfaces import IContentish
 from Products.Archetypes.interfaces import IBaseContent
 
-from quintagroup.canonicalpath.interfaces import ICanonicalPath
-from quintagroup.seoptimizer.interfaces import ISEOCanonicalPath
+from quintagroup.canonicalpath.interfaces import ICanonicalLink
+from quintagroup.canonicalpath.adapters import PROPERTY_LINK as CANONICAL_PROPERTY
+from quintagroup.seoptimizer.browser.interfaces import IPloneSEOLayer
+# from quintagroup.seoptimizer.interfaces import ISEOCanonicalPath
 from base import *
 
@@ -51,5 +47,5 @@
         foundcurls = self.curl.findall(html)
 
-        qseo_url = self.mydoc.getProperty('qSEO_canonical','')
+        qseo_url = ICanonicalLink(self.mydoc).canonical_link
         self.assertTrue(qseo_url == mydoc_url_new,
            "Not set 'qSEO_canonical' property")
@@ -58,81 +54,18 @@
            foundcurls, mydoc_url_new))
 
-    def test_SEOCanonicalAdapterRegistration(self):
-        portal_seocanonical = queryAdapter(self.portal, interface=ISEOCanonicalPath)
-        self.assertTrue(portal_seocanonical is not None,
-            "Not registered ISEOCanonicalPath adapter")
-
-        mydoc_seocanonical = queryAdapter(self.mydoc, interface=ISEOCanonicalPath)
-        self.assertTrue(mydoc_seocanonical is not None,
-            "Not registered ISEOCanonicalPath adapter")
-
-    def test_canonicalAdapterRegistration(self):
-        canonical_portal = queryAdapter(self.portal, interface=ICanonicalPath)
-        self.assertTrue(canonical_portal is not None,
-            "Not registered ICanonicalPath adapter for portal root")
-
-        canonical_mydoc = queryAdapter(self.mydoc, interface=ICanonicalPath)
-        self.assertTrue(canonical_mydoc is not None,
-            "Not registered ICanonicalPath adapter for the documnent")
-
-    def test_canonicalAdapter(self):
-        purl = getToolByName(self.portal, 'portal_url')
-        mydoc_path_rel = '/'+'/'.join(purl.getRelativeContentPath(self.mydoc))
-
-        canonical = queryAdapter(self.mydoc, ISEOCanonicalPath)
-        cpath = canonical.canonical_path()
-        self.assertTrue(cpath == mydoc_path_rel,
-            "By canonical path adapter got: '%s', must be: '%s'" % (
-             cpath, mydoc_path_rel))
-
-        # Update canonical url property
-        mydoc_url_new = self.mydoc.absolute_url() + '.new'
-        self.publish(self.mydoc_path + '/@@seo-context-properties?' \
-            'seo_canonical_override=checked&seo_canonical=%s' \
-            '&form.submitted=1' % mydoc_url_new, self.basic_auth)
-
-        mydoc_path_rel_new = mydoc_path_rel + '.new'
-        newcpath = canonical.canonical_path()
-        self.assertTrue(newcpath == mydoc_path_rel_new,
-            "By canonical path adapter got: '%s', must be: '%s'" % (
-             newcpath, mydoc_path_rel_new))
-
-
-    def addIndexerOld(self):
-        def canonical_path(obj, **kwargs):
-            """Return canonical_path property for the object.
-            """
-            cpath = queryAdapter(obj, interface=ISEOCanonicalPath)
-            if cpath:
-                return cpath.canonical_path()
-            return None
-        registerIndexableAttribute("canonical_path", test_column)
-
-    def addIndexerNew(self):
-        @indexer(IContentish)
-        def canonical_path(obj, **kwargs):
-            """Return canonical_path property for the object.
-            """
-            cpath = queryAdapter(obj, interface=ISEOCanonicalPath)
-            if cpath:
-                return cpath.canonical_path()
-            return None
-
-        provideAdapter(canonical_path, name='canonical_path')
+    def test_defaultCanonical(self):
+        expect = self.mydoc.absolute_url()
+        cpath = ICanonicalLink(self.mydoc).canonical_link
+        self.assertTrue(cpath == expect,
+            "Default canonical link adapter return: '%s', must be: '%s'" % (
+             cpath, expect))
 
     def testCatalogUpdated(self):
         purl = getToolByName(self.portal, 'portal_url')
         catalog = getToolByName(self.portal, 'portal_catalog')
-        if IS_NEW:
-            self.addIndexerNew()
-        else:
-            self.addIndexerOld()
-        catalog.addColumn('canonical_path')
-
-        canonical = queryAdapter(self.mydoc, ISEOCanonicalPath)
-        cpath = canonical.canonical_path()
+        catalog.addColumn('canonical_link')
 
         # get catalog data before update
-        mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_path
+        mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_link
         self.assertTrue(not mydoc_catalog_canonical)
 
@@ -143,17 +76,34 @@
             '&form.submitted=1' % mydoc_url_new, self.basic_auth)
 
-        newcpath = canonical.canonical_path()
-        mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_path
+        newcpath = ICanonicalLink(self.mydoc).canonical_link
+        mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_link
         self.assertTrue(newcpath == mydoc_catalog_canonical,
             "canonical path get by adapter: '%s' not equals to cataloged one: '%s'" % (
              newcpath, mydoc_catalog_canonical))
 
+    def test_canonicalValidation(self):
+        wrong_canonical = 'wrong   canonical'
+        # Update canonical url property
+        html = self.publish(self.mydoc_path + '/@@seo-context-properties?' \
+               'seo_canonical_override=checked&seo_canonical=%s&' \
+               'form.submitted=1' % wrong_canonical, self.basic_auth).getBody()
+        self.assertTrue("wrong canonical url" in html,
+                        "Canonical url not validated")
+        
+    def test_delCanonical(self):
+        newcanonical = '/new_canonical'
+        ICanonicalLink(self.mydoc).canonical_link = newcanonical
 
-    def testSEOCanonicalAdapter4OFSFolder(self):
-        atct_tool = self.portal.portal_atct
-        seocan = queryAdapter(self.mydoc, ISEOCanonicalPath)
-        self.assertTrue(seocan is not None,
-            "seo canonical adapter not found for 'ATCT Tool'")
+        assert ICanonicalLink(self.mydoc).canonical_link == newcanonical
 
+        # remove canonical url customization
+        self.publish(self.mydoc_path + '/@@seo-context-properties?' \
+           'seo_canonical=%s&seo_canonical_override=&form.submitted=1' % newcanonical,
+            self.basic_auth)
+
+        mydoc_canonical = ICanonicalLink(self.mydoc).canonical_link
+        self.assertTrue(mydoc_canonical == self.mydoc.absolute_url(),
+            "Steel customized canonical url after remove customization") 
+        
 
 def test_suite():
