80 e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
80 e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
81 e.eid = 'A' |
81 e.eid = 'A' |
82 form = EntityFieldsForm(self.request(login=u'toto'), None, entity=e) |
82 form = EntityFieldsForm(self.request(login=u'toto'), None, entity=e) |
83 field = StringField(name='login', eidparam=True) |
83 field = StringField(name='login', eidparam=True) |
84 form.append_field(field) |
84 form.append_field(field) |
85 form.form_build_context({}) |
85 form.build_context({}) |
86 self.assertEquals(form.form_field_display_value(field, {}), 'toto') |
86 self.assertEquals(form.form_field_display_value(field, {}), 'toto') |
87 |
87 |
88 |
88 |
89 def test_linkto_field_duplication(self): |
89 def test_linkto_field_duplication(self): |
90 e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
90 e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
135 trcomment_format=u'text/plain') |
135 trcomment_format=u'text/plain') |
136 |
136 |
137 # fields tests ############################################################ |
137 # fields tests ############################################################ |
138 |
138 |
139 def _render_entity_field(self, name, form): |
139 def _render_entity_field(self, name, form): |
140 form.form_build_context({}) |
140 form.build_context({}) |
141 renderer = FormRenderer(self.req) |
141 renderer = FormRenderer(self.req) |
142 return form.field_by_name(name).render(form, renderer) |
142 return form.field_by_name(name).render(form, renderer) |
143 |
143 |
144 def _test_richtextfield(self, expected): |
144 def _test_richtextfield(self, expected): |
145 class RTFForm(EntityFieldsForm): |
145 class RTFForm(EntityFieldsForm): |
169 |
169 |
170 def test_filefield(self): |
170 def test_filefield(self): |
171 class FFForm(EntityFieldsForm): |
171 class FFForm(EntityFieldsForm): |
172 data = FileField(format_field=StringField(name='data_format', max_length=50), |
172 data = FileField(format_field=StringField(name='data_format', max_length=50), |
173 encoding_field=StringField(name='data_encoding', max_length=20)) |
173 encoding_field=StringField(name='data_encoding', max_length=20)) |
174 file = self.add_entity('File', name=u"pouet.txt", data_encoding=u'UTF-8', |
174 file = self.add_entity('File', data_name=u"pouet.txt", data_encoding=u'UTF-8', |
175 data=Binary('new widgets system')) |
175 data=Binary('new widgets system')) |
176 form = FFForm(self.req, redirect_path='perdu.com', entity=file) |
176 form = FFForm(self.req, redirect_path='perdu.com', entity=file) |
177 self.assertTextEquals(self._render_entity_field('data', form), |
177 self.assertTextEquals(self._render_entity_field('data', form), |
178 '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="1" type="file" value="" /> |
178 '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="1" type="file" value="" /> |
179 <a href="javascript: toggleVisibility('data:%(eid)s-advanced')" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a> |
179 <a href="javascript: toggleVisibility('data:%(eid)s-advanced')" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a> |
193 encoding_field=StringField(name='data_encoding', max_length=20)) |
193 encoding_field=StringField(name='data_encoding', max_length=20)) |
194 def form_field_encoding(self, field): |
194 def form_field_encoding(self, field): |
195 return 'ascii' |
195 return 'ascii' |
196 def form_field_format(self, field): |
196 def form_field_format(self, field): |
197 return 'text/plain' |
197 return 'text/plain' |
198 file = self.add_entity('File', name=u"pouet.txt", data_encoding=u'UTF-8', |
198 file = self.add_entity('File', data_name=u"pouet.txt", data_encoding=u'UTF-8', |
199 data=Binary('new widgets system')) |
199 data=Binary('new widgets system')) |
200 form = EFFForm(self.req, redirect_path='perdu.com', entity=file) |
200 form = EFFForm(self.req, redirect_path='perdu.com', entity=file) |
201 self.assertTextEquals(self._render_entity_field('data', form), |
201 self.assertTextEquals(self._render_entity_field('data', form), |
202 '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="1" type="file" value="" /> |
202 '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="1" type="file" value="" /> |
203 <a href="javascript: toggleVisibility('data:%(eid)s-advanced')" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a> |
203 <a href="javascript: toggleVisibility('data:%(eid)s-advanced')" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a> |