def test_multiple_selection(self):
     """The pattern_options key maximumSelectionSize shouldn't be
     set when the field allows multiple selections"""
     from plone.app.widgets.dx import RelatedItemsFieldWidget
     context = Mock(absolute_url=lambda: 'fake_url')
     context.portal_properties.site_properties\
         .getProperty.return_value = ['SomeType']
     field = List(
         __name__='selectfield',
         value_type=Choice(values=['one', 'two', 'three'])
     )
     widget = RelatedItemsFieldWidget(field, self.request)
     widget.context = context
     widget.update()
     base_args = widget._base_args()
     patterns_options = base_args['pattern_options']
     self.assertFalse('maximumSelectionSize' in patterns_options)
Example #2
0
 def test_fieldwidget(self):
     from plone.app.widgets.dx import RelatedItemsWidget
     from plone.app.widgets.dx import RelatedItemsFieldWidget
     field = Mock(__name__='field', title=u'', required=True)
     vocabulary = Mock()
     request = Mock()
     widget = RelatedItemsFieldWidget(field, vocabulary, request)
     self.assertTrue(isinstance(widget, RelatedItemsWidget))
     self.assertIs(widget.field, field)
     self.assertIs(widget.request, request)
Example #3
0
    def test_multiple_selection(self):
        """The pattern_options key maximumSelectionSize shouldn't be
        set when the field allows multiple selections"""
        from plone.app.widgets.dx import RelatedItemsFieldWidget
        from zope.schema.interfaces import ISource
        from zope.schema.vocabulary import VocabularyRegistry

        context = Mock(absolute_url=lambda: 'fake_url')
        context.portal_properties.site_properties\
            .getProperty.return_value = ['SomeType']
        field = List(
            __name__='selectfield',
            value_type=Choice(vocabulary='foobar')
        )
        widget = RelatedItemsFieldWidget(field, self.request)
        widget.context = context

        vocab = Mock()
        alsoProvides(vocab, ISource)
        with mock.patch.object(VocabularyRegistry, 'get', return_value=vocab):
            widget.update()
            base_args = widget._base_args()
        patterns_options = base_args['pattern_options']
        self.assertFalse('maximumSelectionSize' in patterns_options)
        self.assertEqual(
            patterns_options['vocabularyUrl'],
            '/@@getVocabulary?name=foobar&field=selectfield',
            )
Example #4
0
 def test_single_selection(self):
     """The pattern_options value for maximumSelectionSize should
     be 1 when the field only allows a single selection."""
     from plone.app.widgets.dx import RelatedItemsFieldWidget
     context = Mock(absolute_url=lambda: 'fake_url')
     context.portal_properties.site_properties\
         .getProperty.return_value = ['SomeType']
     field = Choice(
         __name__='selectfield',
         values=['one', 'two', 'three'],
     )
     widget = RelatedItemsFieldWidget(field, self.request)
     widget.context = context
     widget.update()
     base_args = widget._base_args()
     pattern_options = base_args['pattern_options']
     self.assertEquals(pattern_options.get('maximumSelectionSize', 0), 1)