def test_widget_addform_url_on_addform(self):
        from plone.app.z3cform.widget import AjaxSelectWidget
        widget = AjaxSelectWidget(self.request)
        form = Mock(parentForm=None)
        from zope.interface import directlyProvides  # noqa
        from z3c.form.interfaces import IAddForm
        directlyProvides(form, IAddForm)  # noqa
        form.request = {'URL': 'http://addform_url'}
        widget.form = form
        self.assertEqual(
            {
                'name': None,
                'value': u'',
                'pattern': 'select2',
                'pattern_options': {'separator': ';'},
            },
            widget._base_args(),
        )
        widget.vocabulary = 'vocabulary1'
        self.assertEqual(
            {
                'name': None,
                'value': u'',
                'pattern': 'select2',
                'pattern_options': {
                    'separator': ';',
                    'vocabularyUrl':
                    'http://addform_url/@@getVocabulary?name=vocabulary1'}

            },
            widget._base_args(),
        )
Exemple #2
0
 def test_widget_addform_url_on_addform(self):
     from plone.app.z3cform.widget import AjaxSelectWidget
     widget = AjaxSelectWidget(self.request)
     form = Mock()
     from zope.interface import directlyProvides
     from z3c.form.interfaces import IAddForm
     directlyProvides(form, IAddForm)
     form.request = {'URL': 'http://addform_url'}
     widget.form = form
     self.assertEqual(
         {
             'name': None,
             'value': u'',
             'pattern': 'select2',
             'pattern_options': {
                 'separator': ';'
             },
         },
         widget._base_args(),
     )
     widget.vocabulary = 'vocabulary1'
     self.assertEqual(
         {
             'name': None,
             'value': u'',
             'pattern': 'select2',
             'pattern_options': {
                 'separator':
                 ';',
                 'vocabularyUrl':
                 'http://addform_url/@@getVocabulary?name=vocabulary1'
             }
         },
         widget._base_args(),
     )
Exemple #3
0
    def test_keywords_cannot_add(self):
        from plone.app.z3cform.widget import AjaxSelectWidget

        portal = self.layer['portal']
        widget = AjaxSelectWidget(self.request)
        widget.context = portal
        widget.vocabulary = 'plone.app.vocabularies.Keywords'
        self.assertEqual(widget._base_args()['pattern_options']['allowNewItems'], 'false')
    def test_keywords_cannot_add(self):
        from plone.app.z3cform.widget import AjaxSelectWidget

        portal = self.layer['portal']
        widget = AjaxSelectWidget(self.request)
        widget.context = portal
        widget.vocabulary = 'plone.app.vocabularies.Keywords'
        self.assertEqual(widget._base_args()['pattern_options'][
                         'allowNewItems'], 'false')
Exemple #5
0
    def test_keywords_can_add(self):
        from plone.app.z3cform.widget import AjaxSelectWidget

        portal = self.layer['portal']
        setRoles(portal, TEST_USER_ID, ['Manager'])
        widget = AjaxSelectWidget(self.request)
        widget.context = portal
        widget.vocabulary = 'plone.app.vocabularies.Keywords'
        self.assertEqual(widget._base_args()['pattern_options']['allowNewItems'], 'true')
    def test_keywords_can_add(self):
        from plone.app.z3cform.widget import AjaxSelectWidget

        portal = self.layer['portal']
        setRoles(portal, TEST_USER_ID, ['Manager'])
        widget = AjaxSelectWidget(self.request)
        widget.context = portal
        widget.vocabulary = 'plone.app.vocabularies.Keywords'
        self.assertEqual(widget._base_args()['pattern_options'][
                         'allowNewItems'], 'true')
    def test_widget(self):
        from plone.app.z3cform.widget import AjaxSelectWidget
        widget = AjaxSelectWidget(self.request)
        widget.update()
        self.assertEqual(
            {
                'name': None,
                'value': u'',
                'pattern': 'select2',
                'pattern_options': {'separator': ';'},
            },
            widget._base_args()
        )

        widget.vocabulary = 'example'
        self.assertEqual(
            widget._base_args(),
            {
                'name': None,
                'value': u'',
                'pattern': 'select2',
                'pattern_options': {
                    'vocabularyUrl': '/@@getVocabulary?name=example',
                    'separator': ';'
                },
            }
        )

        widget.value = 'three;two'
        self.assertEqual(
            widget._base_args(),
            {
                'name': None,
                'value': 'three;two',
                'pattern': 'select2',
                'pattern_options': {
                    'vocabularyUrl': '/@@getVocabulary?name=example',
                    'initialValues': {'three': u'Three', 'two': u'Two'},
                    'separator': ';'
                },
            }
        )
Exemple #8
0
    def test_widget(self):
        from plone.app.z3cform.widget import AjaxSelectWidget
        widget = AjaxSelectWidget(self.request)
        widget.update()
        self.assertEqual(
            {
                'name': None,
                'value': u'',
                'pattern': 'select2',
                'pattern_options': {'separator': ';'},
            },
            widget._base_args()
        )

        widget.vocabulary = 'example'
        self.assertEqual(
            widget._base_args(),
            {
                'name': None,
                'value': u'',
                'pattern': 'select2',
                'pattern_options': {
                    'vocabularyUrl': '/@@getVocabulary?name=example',
                    'separator': ';'
                },
            }
        )

        widget.value = 'three;two'
        self.assertEqual(
            widget._base_args(),
            {
                'name': None,
                'value': 'three;two',
                'pattern': 'select2',
                'pattern_options': {
                    'vocabularyUrl': '/@@getVocabulary?name=example',
                    'initialValues': {'three': u'Three', 'two': u'Two'},
                    'separator': ';'
                },
            }
        )
 def test_widget_tuple_orderable(self):
     from plone.app.z3cform.widget import AjaxSelectWidget
     widget = AjaxSelectWidget(self.request)
     widget.field = Tuple(__name__='selectfield')
     self.assertEqual(
         {
             'name': None,
             'value': u'',
             'pattern': 'select2',
             'pattern_options': {'orderable': True, 'separator': ';'},
         },
         widget._base_args(),
     )
Exemple #10
0
 def test_widget_tuple_orderable(self):
     from plone.app.z3cform.widget import AjaxSelectWidget
     widget = AjaxSelectWidget(self.request)
     widget.field = Tuple(__name__='selectfield')
     self.assertEqual(
         {
             'name': None,
             'value': u'',
             'pattern': 'select2',
             'pattern_options': {'orderable': True, 'separator': ';'},
         },
         widget._base_args(),
     )
 def test_widget_choice(self):
     from plone.app.z3cform.widget import AjaxSelectWidget
     from zope.schema.interfaces import ISource
     widget = AjaxSelectWidget(self.request)
     source = Mock()
     alsoProvides(source, ISource)
     widget.field = Choice(__name__='choicefield', source=source)
     widget.name = 'choicefield'
     self.assertEqual(
         {
             'name': 'choicefield',
             'value': u'',
             'pattern': 'select2',
             'pattern_options': {
                 'separator': ';',
                 'maximumSelectionSize': 1,
                 'vocabularyUrl':
                 'http://127.0.0.1/++widget++choicefield/@@getSource',
                 },
         },
         widget._base_args(),
     )
Exemple #12
0
 def test_widget_choice(self):
     from plone.app.z3cform.widget import AjaxSelectWidget
     from zope.schema.interfaces import ISource
     widget = AjaxSelectWidget(self.request)
     source = Mock()
     alsoProvides(source, ISource)
     widget.field = Choice(__name__='choicefield', source=source)
     widget.name = 'choicefield'
     self.assertEqual(
         {
             'name': 'choicefield',
             'value': u'',
             'pattern': 'select2',
             'pattern_options': {
                 'separator': ';',
                 'maximumSelectionSize': 1,
                 'allowNewItems': 'false',
                 'vocabularyUrl':
                 'http://127.0.0.1/++widget++choicefield/@@getSource',
                 },
         },
         widget._base_args(),
     )