Back to index

plone3  3.1.7
test_Favorite.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit tests for Favorites.
00014 
00015 $Id: test_Favorite.py 77113 2007-06-26 20:36:26Z yuppie $
00016 """
00017 
00018 import unittest
00019 import Testing
00020 
00021 from zope.component import getSiteManager
00022 from zope.testing.cleanup import cleanUp
00023 
00024 from Products.CMFCore.interfaces import ISiteRoot
00025 from Products.CMFCore.testing import ConformsToContent
00026 from Products.CMFCore.tests.base.dummy import DummySite
00027 from Products.CMFCore.tests.base.dummy import DummyTool
00028 
00029 
00030 class FavoriteTests(ConformsToContent, unittest.TestCase):
00031 
00032     def _getTargetClass(self):
00033         from Products.CMFDefault.Favorite import Favorite
00034 
00035         return Favorite
00036 
00037     def _makeOne(self, *args, **kw):
00038         return self._getTargetClass()(*args, **kw)
00039 
00040     def setUp(self):
00041         sm = getSiteManager()
00042         self.site = DummySite('site')
00043         sm.registerUtility(self.site, ISiteRoot)
00044         self.site._setObject( 'portal_membership', DummyTool() )
00045         self.site._setObject( 'portal_url', DummyTool() )
00046 
00047     def tearDown(self):
00048         cleanUp()
00049 
00050     def test_z3interfaces(self):
00051         from zope.interface.verify import verifyClass
00052         from Products.CMFDefault.interfaces import IFavorite
00053         from Products.CMFDefault.interfaces import ILink
00054         from Products.CMFDefault.interfaces import IMutableFavorite
00055         from Products.CMFDefault.interfaces import IMutableLink
00056 
00057         verifyClass(IFavorite, self._getTargetClass())
00058         verifyClass(ILink, self._getTargetClass())
00059         verifyClass(IMutableFavorite, self._getTargetClass())
00060         verifyClass(IMutableLink, self._getTargetClass())
00061 
00062     def test_Empty( self ):
00063         utool = self.site.portal_url
00064         f = self.site._setObject('foo', self._makeOne('foo'))
00065 
00066         self.assertEqual( f.getId(), 'foo' )
00067         self.assertEqual( f.Title(), '' )
00068         self.assertEqual( f.Description(), '' )
00069         self.assertEqual( f.getRemoteUrl(), utool.root )
00070         self.assertEqual( f.getObject(), self.site )
00071         self.assertEqual( f.getIcon(), self.site.getIcon() )
00072         self.assertEqual( f.getIcon(1), self.site.getIcon(1) )
00073 
00074     def test_CtorArgs( self ):
00075         utool = self.site.portal_url
00076         self.assertEqual( self._makeOne( 'foo'
00077                                        , title='Title'
00078                                        ).Title(), 'Title' )
00079 
00080         self.assertEqual( self._makeOne( 'bar'
00081                                        , description='Description'
00082                                        ).Description(), 'Description' )
00083 
00084         baz = self.site._setObject('foo',
00085                                 self._makeOne('baz', remote_url='portal_url'))
00086         self.assertEqual( baz.getObject(), utool )
00087         self.assertEqual( baz.getRemoteUrl()
00088                         , '%s/portal_url' % utool.root )
00089         self.assertEqual( baz.getIcon(), utool.getIcon() )
00090 
00091     def test_edit( self ):
00092         utool = self.site.portal_url
00093         f = self.site._setObject('foo', self._makeOne('foo'))
00094         f.edit( 'portal_url' )
00095         self.assertEqual( f.getObject(), utool )
00096         self.assertEqual( f.getRemoteUrl()
00097                         , '%s/portal_url' % utool.root )
00098         self.assertEqual( f.getIcon(), utool.getIcon() )
00099 
00100     def test_editEmpty( self ):
00101         utool = self.site.portal_url
00102         f = self.site._setObject('gnnn', self._makeOne('gnnn'))
00103         f.edit( '' )
00104         self.assertEqual( f.getObject(), self.site )
00105         self.assertEqual( f.getRemoteUrl(), utool.root )
00106         self.assertEqual( f.getIcon(), self.site.getIcon() )
00107 
00108 
00109 def test_suite():
00110     return unittest.TestSuite((
00111         unittest.makeSuite(FavoriteTests),
00112         ))
00113 
00114 if __name__ == '__main__':
00115     unittest.main(defaultTest='test_suite')