vendor/Five/1.2b-r20590

view browser/tests/cps_test_localizer.txt @ 0:3673ed425f80

Vendor import of Five 1.2b+ (r20590)
author fguillaume
date Fri, 02 Dec 2005 20:25:42 +0000
parents
children
line source
1 Localizer languages
2 ===================
4 Before we start, we need to set up a manager user to be able to create
5 the portal:
7 >>> uf = self.folder.acl_users
8 >>> uf._doAddUser('manager', 'r00t', ['Manager'], [])
10 We need to 1) configure the Zope 3 i18n message catalogs, 2) make the
11 CPS portal traversable, 3) register the Localizer languagees adapter
12 and 4) register our test page:
14 >>> configure_zcml = """
15 ... <configure
16 ... xmlns="http://namespaces.zope.org/zope"
17 ... xmlns:browser="http://namespaces.zope.org/browser"
18 ... xmlns:five="http://namespaces.zope.org/five"
19 ... xmlns:i18n="http://namespaces.zope.org/i18n"
20 ... >
21 ... <configure package="Products.Five.tests">
22 ... <i18n:registerTranslations directory="locales" />
23 ... </configure>
24 ...
25 ... <five:traversable class="Products.CPSDefault.Portal.CPSDefaultSite" />
26 ...
27 ... <adapter
28 ... for="zope.publisher.interfaces.http.IHTTPRequest"
29 ... provides="zope.i18n.interfaces.IUserPreferredLanguages"
30 ... factory="Products.Five.i18n.LocalizerLanguages"
31 ... />
32 ...
33 ... <configure package="Products.Five.browser.tests">
34 ... <browser:page
35 ... for="*"
36 ... template="cps_test_localizer.pt"
37 ... name="cps_test_localizer.html"
38 ... permission="zope2.View"
39 ... />
40 ... </configure>
41 ... </configure>
42 ... """
43 >>> from Products.Five import zcml
44 >>> zcml.load_string(configure_zcml)
46 Create a CPS portal. We print an additional line before creating it
47 because PortalTransforms might print stuff to stdout and doctest
48 doesn't allow us to ellide a first line.
50 >>> print "Ignore lines after me"; print http(r"""
51 ... POST /test_folder_1_/manage_addProduct/CPSDefault/manage_addCPSDefaultSite HTTP/1.1
52 ... Authorization: Basic manager:r00t
53 ... Content-Length: 269
54 ... Content-Type: application/x-www-form-urlencoded
55 ...
56 ... id=cps&title=CPS+Portal&description=&manager_id=manager&manager_sn=CPS+manager&manager_givenName=Manager&manager_email=root%40localhost&manager_password=root&manager_password_confirmation=root&langs_list%3Alist=en&langs_list%3Alist=fr&langs_list%3Alist=de&submit=Create""")
57 Ignore lines after me
58 ...
59 HTTP/1.1 200 OK
60 ...
62 Now for some actual testing... Our test page is a simple ZPT
63 translating two messages from different domains. The first domain is
64 a Zope 3 style one, the second one comes from Localizer.
66 Both systems should yield the same default language (English) when no
67 language is specified whatsoever:
69 >>> print http(r"""
70 ... GET /test_folder_1_/cps/cps_test_localizer.html HTTP/1.1
71 ... """)
72 HTTP/1.1 200 OK
73 ...
74 <html>
75 <body>
76 <!-- fivetest is a Zope 3 style i18n domain, default is a Localizer domain -->
77 <p>This is a message</p>
78 <p>Object actions</p>
79 </body>
80 </html>
82 Both systems should honour the HTTP ``Accept-Language`` header in the
83 same way:
85 >>> print http(r"""
86 ... GET /test_folder_1_/cps/cps_test_localizer.html HTTP/1.1
87 ... Accept-Language: de
88 ... """)
89 HTTP/1.1 200 OK
90 ...
91 <html>
92 <body>
93 <!-- fivetest is a Zope 3 style i18n domain, default is a Localizer domain -->
94 <p>Dies ist eine Nachricht</p>
95 <p>Objekt Aktionen</p>
96 </body>
97 </html>
99 Both systems should also honour Localizer-specific ways of determining
100 the language, for example the ``LOCALIZER_LANGUAGE`` cookie:
102 >>> print http(r"""
103 ... GET /test_folder_1_/cps/cps_test_localizer.html HTTP/1.1
104 ... Accept-Language: de
105 ... Cookie: LOCALIZER_LANGUAGE=en
106 ... """)
107 HTTP/1.1 200 OK
108 ...
109 <html>
110 <body>
111 <!-- fivetest is a Zope 3 style i18n domain, default is a Localizer domain -->
112 <p>This is a message</p>
113 <p>Object actions</p>
114 </body>
115 </html>