5 from mx.DateTime import now |
5 from mx.DateTime import now |
6 NOW = now() |
6 NOW = now() |
7 from logilab.common.testlib import unittest_main |
7 from logilab.common.testlib import unittest_main |
8 from cubicweb.devtools.apptest import EnvBasedTC |
8 from cubicweb.devtools.apptest import EnvBasedTC |
9 |
9 |
|
10 from cubicweb.common.mttransforms import HAS_TAL |
10 from cubicweb.web.widgets import widget, AutoCompletionWidget |
11 from cubicweb.web.widgets import widget, AutoCompletionWidget |
11 |
12 |
12 |
13 |
13 class WidgetsTC(EnvBasedTC): |
14 class WidgetsTC(EnvBasedTC): |
14 |
15 |
39 entity = self.etype_instance('State') |
40 entity = self.etype_instance('State') |
40 entity.eid = 'X' |
41 entity.eid = 'X' |
41 entity |
42 entity |
42 self.assertEquals(w.required(entity), False) |
43 self.assertEquals(w.required(entity), False) |
43 self.assertEquals(w.render(entity), '') |
44 self.assertEquals(w.render(entity), '') |
|
45 if HAS_TAL: |
|
46 tal_format = u'\n<option value="text/cubicweb-page-template" >text/cubicweb-page-template</option>' |
|
47 else: |
|
48 tal_format = u'' |
44 self.assertTextEquals(w.edit_render(entity), |
49 self.assertTextEquals(w.edit_render(entity), |
45 u'''<input type="hidden" name="edits-description:X" value="__cubicweb_internal_field__"/> |
50 u'''<input type="hidden" name="edits-description:X" value="__cubicweb_internal_field__"/> |
46 <input type="hidden" name="edits-description_format:X" value="__cubicweb_internal_field__"/> |
51 <input type="hidden" name="edits-description_format:X" value="__cubicweb_internal_field__"/> |
47 |
52 |
48 <select name="description_format:X" id="description_format:X" tabindex="0"> |
53 <select name="description_format:X" id="description_format:X" tabindex="0"> |
49 <option value="text/rest" >text/rest</option> |
54 <option value="text/rest" >text/rest</option> |
50 <option value="text/html" selected="selected">text/html</option> |
55 <option value="text/html" selected="selected">text/html</option> |
51 <option value="text/plain" >text/plain</option> |
56 <option value="text/plain" >text/plain</option>%s |
52 <option value="text/cubicweb-page-template" >text/cubicweb-page-template</option> |
57 </select><br/><textarea onkeypress="autogrow(this)" name="description:X" accesskey="d" cols="80" id="description:X" rows="20" tabindex="1"></textarea>''' % tal_format) |
53 </select><br/><textarea onkeypress="autogrow(this)" name="description:X" accesskey="d" cols="80" id="description:X" rows="20" tabindex="1"></textarea>''') |
|
54 |
58 |
55 def test_textarea_widget_previous_value(self): |
59 def test_textarea_widget_previous_value(self): |
56 self.add_entity('EProperty', pkey=u'ui.fckeditor', value=u'') |
60 self.add_entity('EProperty', pkey=u'ui.fckeditor', value=u'') |
57 self.commit() |
61 self.commit() |
58 w = self.get_widget('State', 'description', 'String') |
62 w = self.get_widget('State', 'description', 'String') |
60 req.data['formvalues'] = {'description:X': 'a description'} |
64 req.data['formvalues'] = {'description:X': 'a description'} |
61 entity = self.etype_instance('State', req) |
65 entity = self.etype_instance('State', req) |
62 entity.eid = 'X' |
66 entity.eid = 'X' |
63 self.assertEquals(w.required(entity), False) |
67 self.assertEquals(w.required(entity), False) |
64 self.assertEquals(w.render(entity), '') |
68 self.assertEquals(w.render(entity), '') |
|
69 if HAS_TAL: |
|
70 tal_format = u'\n<option value="text/cubicweb-page-template" >text/cubicweb-page-template</option>' |
|
71 else: |
|
72 tal_format = u'' |
65 self.assertTextEquals(w.edit_render(entity), |
73 self.assertTextEquals(w.edit_render(entity), |
66 u'''<input type="hidden" name="edits-description:X" value="__cubicweb_internal_field__"/> |
74 u'''<input type="hidden" name="edits-description:X" value="__cubicweb_internal_field__"/> |
67 <input type="hidden" name="edits-description_format:X" value="__cubicweb_internal_field__"/> |
75 <input type="hidden" name="edits-description_format:X" value="__cubicweb_internal_field__"/> |
68 |
76 |
69 <select name="description_format:X" id="description_format:X" tabindex="0"> |
77 <select name="description_format:X" id="description_format:X" tabindex="0"> |
70 <option value="text/rest" >text/rest</option> |
78 <option value="text/rest" >text/rest</option> |
71 <option value="text/html" selected="selected">text/html</option> |
79 <option value="text/html" selected="selected">text/html</option> |
72 <option value="text/plain" >text/plain</option> |
80 <option value="text/plain" >text/plain</option>%s |
73 <option value="text/cubicweb-page-template" >text/cubicweb-page-template</option> |
81 </select><br/><textarea onkeypress="autogrow(this)" name="description:X" accesskey="d" cols="80" id="description:X" rows="20" tabindex="1">a description</textarea>''' % tal_format) |
74 </select><br/><textarea onkeypress="autogrow(this)" name="description:X" accesskey="d" cols="80" id="description:X" rows="20" tabindex="1">a description</textarea>''') |
|
75 |
82 |
76 def test_fckeditor_widget(self): |
83 def test_fckeditor_widget(self): |
77 w = self.get_widget('State', 'description', 'String') |
84 w = self.get_widget('State', 'description', 'String') |
78 req = self.request() |
85 req = self.request() |
79 entity = self.etype_instance('State', req) |
86 entity = self.etype_instance('State', req) |