Back to index

plone3  3.1.7
test_languagetool.py
Go to the documentation of this file.
00001 from Products.PloneTestCase import PloneTestCase
00002 
00003 PloneTestCase.setupPloneSite()
00004 from Products.PloneLanguageTool import LanguageTool
00005 
00006 class TestLanguageToolExists(PloneTestCase.PloneTestCase):
00007 
00008     def afterSetUp(self):
00009         self.id = LanguageTool.id
00010 
00011     def testLanguageToolExists(self):
00012         self.failUnless(self.id in self.portal.objectIds())
00013 
00014 
00015 class TestLanguageToolSettings(PloneTestCase.PloneTestCase):
00016 
00017     def afterSetUp(self):
00018         self.id = LanguageTool.id
00019         self.ltool = self.portal._getOb(self.id)
00020 
00021     def testLanguageToolType(self):
00022         self.failUnless(self.ltool.meta_type == LanguageTool.meta_type)
00023 
00024     def testSetLanguageSettings(self):
00025         defaultLanguage = 'de'
00026         supportedLanguages = ['en','de','no']
00027         self.ltool.manage_setLanguageSettings(defaultLanguage, supportedLanguages,
00028                                    setCookieN=False, setRequestN=False,
00029                                    setPathN=False, setForcelanguageUrls=False,
00030                                    setAllowContentLanguageFallback=True,
00031                                    setUseCombinedLanguageCodes=True,
00032                                    startNeutral=False, displayFlags=False)
00033 
00034         self.failUnless(self.ltool.getDefaultLanguage()==defaultLanguage)
00035         self.failUnless(self.ltool.getSupportedLanguages()==supportedLanguages)
00036         self.failUnless(self.ltool.use_cookie_negotiation==False)
00037         self.failUnless(self.ltool.use_request_negotiation==False)
00038         self.failUnless(self.ltool.use_path_negotiation==False)
00039         self.failUnless(self.ltool.force_language_urls==False)
00040         self.failUnless(self.ltool.allow_content_language_fallback==True)
00041         self.failUnless(self.ltool.use_combined_language_codes==True)
00042         self.failUnless(self.ltool.startNeutral()==False)
00043         self.failUnless(self.ltool.showFlags()==False)
00044 
00045 
00046 class TestLanguageTool(PloneTestCase.PloneTestCase):
00047 
00048     def afterSetUp(self):
00049         self.id = LanguageTool.id
00050         self.ltool = self.portal._getOb(self.id)
00051 
00052     def testLanguageSettings(self):
00053         defaultLanguage = 'de'
00054         supportedLanguages = ['en','de','no']
00055         self.ltool.manage_setLanguageSettings(defaultLanguage, supportedLanguages,
00056                                               setUseCombinedLanguageCodes=False)
00057         self.failUnless(self.ltool.getDefaultLanguage()==defaultLanguage)
00058         self.failUnless(self.ltool.getSupportedLanguages()==supportedLanguages)
00059 
00060     def testSupportedLanguages(self):
00061         defaultLanguage = 'de'
00062         supportedLanguages = ['en','de','no']
00063         self.ltool.manage_setLanguageSettings(defaultLanguage, supportedLanguages)
00064         self.failUnless(self.ltool.getSupportedLanguages()==supportedLanguages)
00065 
00066         self.ltool.removeSupportedLanguages(supportedLanguages)
00067         self.failUnless(self.ltool.getSupportedLanguages()==[])
00068 
00069         for lang in supportedLanguages:
00070             self.ltool.addSupportedLanguage(lang)
00071         self.failUnless(self.ltool.getSupportedLanguages()==supportedLanguages)
00072 
00073     def testDefaultLanguage(self):
00074         supportedLanguages = ['de','no']
00075 
00076         self.ltool.manage_setLanguageSettings('no', supportedLanguages)
00077         self.failUnless(self.ltool.getSupportedLanguages()==supportedLanguages)
00078         self.failUnless(self.ltool.getDefaultLanguage()=='no')
00079 
00080         # default not in supported languages, should set to first supported
00081         self.ltool.manage_setLanguageSettings('nl', supportedLanguages)
00082 
00083         self.failUnless(self.ltool.getSupportedLanguages()==supportedLanguages)
00084         self.failUnless(self.ltool.getDefaultLanguage()=='de')
00085 
00086     def testAvailableLanguage(self):
00087         defaultLanguage = 'de'
00088         supportedLanguages = ['en','de','no']
00089         self.ltool.manage_setLanguageSettings(defaultLanguage, supportedLanguages)
00090         availableLanguages = self.ltool.getAvailableLanguageInformation()
00091         for lang in availableLanguages:
00092             if lang in supportedLanguages:
00093                 self.failUnless(availableLanguages[lang]['selected'] == True)
00094 
00095 
00096 def test_suite():
00097     from unittest import TestSuite, makeSuite
00098     suite = TestSuite()
00099     suite.addTest(makeSuite(TestLanguageToolExists))
00100     suite.addTest(makeSuite(TestLanguageToolSettings))
00101     suite.addTest(makeSuite(TestLanguageTool))
00102     return suite