Example #1
0
    def test_single_valued_empty(self):
        from plone.app.widgets.at import RelatedItemsWidget

        self.field.getName.return_value = 'fieldname'
        self.field.getAccessor.return_value = lambda: None
        self.field.multiValued = False
        self.context.portal_properties.site_properties\
            .getProperty.return_value = ['SomeType']

        widget = RelatedItemsWidget()

        self.assertEqual(
            {
                'name': 'fieldname',
                'value': '',
                'pattern': 'relateditems',
                'pattern_options': {
                    'folderTypes': ['SomeType'],
                    'homeText': u'Home',
                    'separator': ';',
                    'orderable': True,
                    'searchAllText': u'Entire site',
                    'searchText': u'Search',
                    'maximumSelectionSize': 1,
                    'vocabularyUrl': '/@@getVocabulary?name='
                                     'plone.app.vocabularies.Catalog'
                                     '&field=fieldname',
                },
            },
            widget._base_args(self.context, self.field, self.request),
        )
Example #2
0
    def test_multi_valued(self):
        from zope.event import notify
        from zope.interface import implements
        from zope.lifecycleevent import ObjectCreatedEvent
        from plone.uuid.interfaces import IUUID
        from plone.uuid.interfaces import IAttributeUUID
        from plone.app.widgets.at import RelatedItemsWidget

        class ExampleContent(object):
            implements(IAttributeUUID)

        obj1 = ExampleContent()
        obj2 = ExampleContent()
        notify(ObjectCreatedEvent(obj1))
        notify(ObjectCreatedEvent(obj2))

        self.field.getName.return_value = 'fieldname'
        self.field.getAccessor.return_value = lambda: [obj1, obj2]
        self.field.multiValued = True
        self.context.portal_properties.site_properties\
            .getProperty.return_value = ['SomeType']

        widget = RelatedItemsWidget()

        self.assertEqual(
            {
                'name': 'fieldname',
                'value': '{};{}'.format(IUUID(obj1), IUUID(obj2)),
                'pattern': 'relateditems',
                'pattern_options': {
                    'folderTypes': ['SomeType'],
                    'homeText':
                    u'Home',
                    'searchAllText':
                    u'Entire site',
                    'searchText':
                    u'Search',
                    'separator':
                    ';',
                    'orderable':
                    True,
                    'maximumSelectionSize':
                    -1,
                    'vocabularyUrl':
                    '/@@getVocabulary?name='
                    'plone.app.vocabularies.Catalog'
                    '&field=fieldname',
                },
            },
            widget._base_args(self.context, self.field, self.request),
        )
Example #3
0
    def test_multi_valued(self):
        from zope.event import notify
        from zope.interface import implements
        from zope.lifecycleevent import ObjectCreatedEvent
        from plone.uuid.interfaces import IUUID
        from plone.uuid.interfaces import IAttributeUUID
        from plone.app.widgets.at import RelatedItemsWidget

        class ExampleContent(object):
            implements(IAttributeUUID)

        obj1 = ExampleContent()
        obj2 = ExampleContent()
        notify(ObjectCreatedEvent(obj1))
        notify(ObjectCreatedEvent(obj2))

        self.field.getName.return_value = 'fieldname'
        self.field.getAccessor.return_value = lambda: [obj1, obj2]
        self.field.multiValued = True
        self.context.portal_properties.site_properties\
            .getProperty.return_value = ['SomeType']

        widget = RelatedItemsWidget()

        self.assertEqual(
            {
                'name': 'fieldname',
                'value': '{};{}'.format(IUUID(obj1), IUUID(obj2)),
                'pattern': 'relateditems',
                'pattern_options': {
                    'folderTypes': ['SomeType'],
                    'homeText': u'Home',
                    'searchAllText': u'Entire site',
                    'searchText': u'Search',
                    'separator': ';',
                    'orderable': True,
                    'maximumSelectionSize': -1,
                    'vocabularyUrl': '/@@getVocabulary?name='
                                     'plone.app.vocabularies.Catalog'
                                     '&field=fieldname',
                },
            },
            widget._base_args(self.context, self.field, self.request),
        )
Example #4
0
    def test_single_valued_empty(self):
        from plone.app.widgets.at import RelatedItemsWidget

        self.field.getName.return_value = 'fieldname'
        self.field.getAccessor.return_value = lambda: None
        self.field.multiValued = False
        self.context.portal_properties.site_properties\
            .getProperty.return_value = ['SomeType']

        widget = RelatedItemsWidget()

        self.assertEqual(
            {
                'name': 'fieldname',
                'value': '',
                'pattern': 'relateditems',
                'pattern_options': {
                    'folderTypes': ['SomeType'],
                    'homeText':
                    u'Home',
                    'separator':
                    ';',
                    'orderable':
                    True,
                    'searchAllText':
                    u'Entire site',
                    'searchText':
                    u'Search',
                    'maximumSelectionSize':
                    1,
                    'vocabularyUrl':
                    '/@@getVocabulary?name='
                    'plone.app.vocabularies.Catalog'
                    '&field=fieldname',
                },
            },
            widget._base_args(self.context, self.field, self.request),
        )