示例#1
0
    def test_widget(self):
        from plone.app.widgets.dx import SelectWidget
        widget = SelectWidget(self.request)
        widget.field = Choice(
            __name__='selectfield',
            values=['one', 'two', 'three']
        )
        widget.terms = widget.field.vocabulary
        self.assertEqual(
            {
                'multiple': False,
                'name': None,
                'pattern_options': {},
                'pattern': 'select2',
                'value': (),
                'items': [
                    ('one', 'one'),
                    ('two', 'two'),
                    ('three', 'three')
                ]
            },
            widget._base_args(),
        )

        widget.multiple = True
        self.assertEqual(
            {
                'multiple': True,
                'name': None,
                'pattern_options': {'separator': ';', 'multiple': True},
                'pattern': 'select2',
                'value': (),
                'items': [
                    ('one', 'one'),
                    ('two', 'two'),
                    ('three', 'three')
                ]
            },
            widget._base_args(),
        )

        widget.value = 'one'
        self.assertEqual(
            {
                'multiple': True,
                'name': None,
                'pattern_options': {'separator': ';', 'multiple': True},
                'pattern': 'select2',
                'value': ('one'),
                'items': [
                    ('one', 'one'),
                    ('two', 'two'),
                    ('three', 'three')
                ]
            },
            widget._base_args(),
        )
示例#2
0
 def test_widget_set_not_orderable(self):
     from plone.app.widgets.dx import SelectWidget
     widget = SelectWidget(self.request)
     # A set is not orderable
     widget.field = Set(
         __name__='selectfield',
         value_type=Choice(values=['one', 'two', 'three'])
     )
     widget.terms = widget.field.value_type.vocabulary
     self.assertEqual(
         {
             'multiple': True,
             'name': None,
             'pattern_options': {
                 'multiple': True, 'separator': ';'},
             'pattern': 'select2',
             'value': (),
             'items': [
                 ('one', 'one'),
                 ('two', 'two'),
                 ('three', 'three')
             ]
         },
         widget._base_args(),
     )