Back to index

plone3  3.1.7
test_atlink.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """
00020 """
00021 
00022 __author__ = 'Christian Heimes <tiran@cheimes.de>'
00023 __docformat__ = 'restructuredtext'
00024 
00025 from Testing import ZopeTestCase # side effect import. leave it here.
00026 from Products.ATContentTypes.tests import atcttestcase, atctftestcase
00027 
00028 import transaction
00029 from Products.CMFCore.permissions import View
00030 from Products.CMFCore.permissions import ModifyPortalContent
00031 from Products.Archetypes.interfaces.layer import ILayerContainer
00032 from Products.Archetypes.atapi import *
00033 
00034 from Products.ATContentTypes.content.link import ATLink
00035 from Products.ATContentTypes.interfaces import IATLink
00036 from Interface.Verify import verifyObject
00037 
00038 # z3 imports
00039 from Products.ATContentTypes.interface import IATLink as Z3IATLink
00040 from zope.interface.verify import verifyObject as Z3verifyObject
00041 
00042 URL='http://www.example.org/'
00043 
00044 def editATCT(obj):
00045     obj.setTitle('Test Title')
00046     obj.setDescription('Test description')
00047     obj.setRemoteUrl(URL)
00048 
00049 tests = []
00050 
00051 class TestSiteATLink(atcttestcase.ATCTTypeTestCase):
00052 
00053     klass = ATLink
00054     portal_type = 'Link'
00055     title = 'Link'
00056     meta_type = 'ATLink'
00057     icon = 'link_icon.gif'
00058 
00059     def test_implementsATLink(self):
00060         iface = IATLink
00061         self.failUnless(iface.isImplementedBy(self._ATCT))
00062         self.failUnless(verifyObject(iface, self._ATCT))
00063 
00064     def test_implementsATLink(self):
00065         iface = Z3IATLink
00066         self.failUnless(Z3verifyObject(iface, self._ATCT))
00067 
00068     def testLink(self):
00069         obj = self._ATCT
00070 
00071         url = 'http://www.example.org/'
00072         obj.setRemoteUrl(url)
00073         self.failUnlessEqual(obj.getRemoteUrl(), url)
00074 
00075         url = 'false:url'
00076         obj.setRemoteUrl(url)
00077         self.failUnlessEqual(obj.getRemoteUrl(), url)
00078 
00079     def testLinkSanitizesOutput(self):
00080         obj = self._ATCT
00081 
00082         url = 'javascript:alert("test")'
00083         obj.setRemoteUrl(url)
00084         self.failUnlessEqual(obj.getRemoteUrl(),
00085                              'javascript:alert%28%22test%22%29')
00086         # Keep question marks and ampersands intact, please.
00087         url = 'http://something.sane/f.php?p1=value&p2=value'
00088         obj.setRemoteUrl(url)
00089         self.failUnlessEqual(obj.getRemoteUrl(),
00090                              'http://something.sane/f.php?p1=value&p2=value')
00091 
00092     def test_edit(self):
00093         new = self._ATCT
00094         editATCT(new)
00095 
00096     def test_get_size(self):
00097         atct = self._ATCT
00098         editATCT(atct)
00099         self.failUnlessEqual(atct.get_size(), len(URL))
00100 
00101 tests.append(TestSiteATLink)
00102 
00103 class TestATLinkFields(atcttestcase.ATCTFieldTestCase):
00104 
00105     def afterSetUp(self):
00106         atcttestcase.ATCTFieldTestCase.afterSetUp(self)
00107         self._dummy = self.createDummy(klass=ATLink)
00108 
00109     def test_remoteUrlField(self):
00110         dummy = self._dummy
00111         field = dummy.getField('remoteUrl')
00112 
00113         self.failUnless(ILayerContainer.isImplementedBy(field))
00114         self.failUnless(field.required == 1, 'Value is %s' % field.required)
00115         self.failUnless(field.default == 'http://', 'Value is %s' % str(field.default))
00116         self.failUnless(field.searchable == 1, 'Value is %s' % field.searchable)
00117         self.failUnless(field.vocabulary == (),
00118                         'Value is %s' % str(field.vocabulary))
00119         self.failUnless(field.enforceVocabulary == 0,
00120                         'Value is %s' % field.enforceVocabulary)
00121         self.failUnless(field.multiValued == 0,
00122                         'Value is %s' % field.multiValued)
00123         self.failUnless(field.isMetadata == 0, 'Value is %s' % field.isMetadata)
00124         self.failUnless(field.accessor == 'getRemoteUrl',
00125                         'Value is %s' % field.accessor)
00126         self.failUnless(field.mutator == 'setRemoteUrl',
00127                         'Value is %s' % field.mutator)
00128         self.failUnless(field.read_permission == View,
00129                         'Value is %s' % field.read_permission)
00130         self.failUnless(field.write_permission == ModifyPortalContent,
00131                         'Value is %s' % field.write_permission)
00132         self.failUnless(field.generateMode == 'veVc',
00133                         'Value is %s' % field.generateMode)
00134         self.failUnless(field.force == '', 'Value is %s' % field.force)
00135         self.failUnless(field.type == 'string', 'Value is %s' % field.type)
00136         self.failUnless(isinstance(field.storage, AttributeStorage),
00137                         'Value is %s' % type(field.storage))
00138         self.failUnless(field.getLayerImpl('storage') == AttributeStorage(),
00139                         'Value is %s' % field.getLayerImpl('storage'))
00140         self.failUnless(ILayerContainer.isImplementedBy(field))
00141         self.failUnless(field.validators == (),
00142                         'Value is %s' % str(field.validators))
00143         self.failUnless(isinstance(field.widget, StringWidget),
00144                         'Value is %s' % id(field.widget))
00145         vocab = field.Vocabulary(dummy)
00146         self.failUnless(isinstance(vocab, DisplayList),
00147                         'Value is %s' % type(vocab))
00148         self.failUnless(tuple(vocab) == (), 'Value is %s' % str(tuple(vocab)))
00149         self.failUnless(field.primary == 1, 'Value is %s' % field.primary)
00150 
00151 tests.append(TestATLinkFields)
00152 
00153 class TestATLinkFunctional(atctftestcase.ATCTIntegrationTestCase):
00154     
00155     portal_type = 'Link'
00156     views = ('link_view', )
00157 
00158 tests.append(TestATLinkFunctional)
00159 
00160 import unittest
00161 def test_suite():
00162     suite = unittest.TestSuite()
00163     for test in tests:
00164         suite.addTest(unittest.makeSuite(test))
00165     return suite