Example #1
0
    def test_defaults(self):
        from plone.app.widgets.base import TextareaWidget

        widget = TextareaWidget('example1', name="example2")
        self.assertEqual(
            widget.render(),
            u'<textarea class="pat-example1" name="example2"></textarea>')

        self.assertEqual(widget.name, 'example2')
        self.assertEqual(widget.klass, 'pat-example1')
        self.assertEqual(widget.value, '')
Example #2
0
    def test_defaults(self):
        from plone.app.widgets.base import TextareaWidget

        widget = TextareaWidget('example1', name="example2")
        self.assertEqual(
            widget.render(),
            u'<textarea class="pat-example1" name="example2"></textarea>')

        self.assertEqual(widget.name, 'example2')
        self.assertEqual(widget.klass, 'pat-example1')
        self.assertEqual(widget.value, '')
Example #3
0
    def test_set_value(self):
        from plone.app.widgets.base import TextareaWidget

        widget = TextareaWidget('example1', name="example2", value='example3')
        self.assertEqual(
            widget.render(), u'<textarea class="pat-example1" name="example2">'
            'example3'
            '</textarea>')

        self.assertEqual(widget.value, 'example3')

        widget.value = 'example4'
        self.assertEqual(
            widget.render(), u'<textarea class="pat-example1" name="example2">'
            'example4'
            '</textarea>')

        del widget.value
        self.assertEqual(
            widget.render(),
            u'<textarea class="pat-example1" name="example2"></textarea>')
Example #4
0
    def test_set_value(self):
        from plone.app.widgets.base import TextareaWidget

        widget = TextareaWidget('example1', name="example2", value='example3')
        self.assertEqual(
            widget.render(),
            u'<textarea class="pat-example1" name="example2">'
            'example3'
            '</textarea>')

        self.assertEqual(widget.value, 'example3')

        widget.value = 'example4'
        self.assertEqual(
            widget.render(),
            u'<textarea class="pat-example1" name="example2">'
            'example4'
            '</textarea>')

        del widget.value
        self.assertEqual(
            widget.render(),
            u'<textarea class="pat-example1" name="example2"></textarea>')
Example #5
0
    def test_setting_patterns_options(self):
        from plone.app.widgets.base import TextareaWidget

        widget = TextareaWidget('example1',
                                name='example2',
                                pattern_options={
                                    'option1': 'value1',
                                    'option2': 'value2',
                                })

        html = widget.render()
        # the order of options is non-deterministic
        result1 = u'<textarea class="pat-example1" name="example2" data-pat-example1="{&quot;option1&quot;: &quot;value1&quot;, &quot;option2&quot;: &quot;value2&quot;}"></textarea>'  # noqa: E501
        result2 = u'<textarea class="pat-example1" name="example2" data-pat-example1="{&quot;option2&quot;: &quot;value2&quot;, &quot;option1&quot;: &quot;value1&quot;}"></textarea>'  # noqa: E501
        self.assertIn(html, [result1, result2])
Example #6
0
    def test_setting_patterns_options(self):
        from plone.app.widgets.base import TextareaWidget

        widget = TextareaWidget('example1',
                                name='expample2',
                                pattern_options={
                                    'option1': 'value1',
                                    'option2': 'value2',
                                })

        self.assertEqual(
            widget.render(), '<textarea class="pat-example1" name="expample2" '
            'data-pat-example1="{'
            '&quot;option2&quot;: &quot;value2&quot;, '
            '&quot;option1&quot;: &quot;value1&quot;}">'
            '</textarea>')
Example #7
0
    def test_setting_patterns_options(self):
        from plone.app.widgets.base import TextareaWidget

        widget = TextareaWidget(
            'example1',
            name='example2',
            pattern_options={
                'option1': 'value1',
                'option2': 'value2',
            })

        html = widget.render()
        # the order of options is non-deterministic
        result1 = u'<textarea class="pat-example1" name="example2" data-pat-example1="{&quot;option1&quot;: &quot;value1&quot;, &quot;option2&quot;: &quot;value2&quot;}"></textarea>'  # noqa: E501
        result2 = u'<textarea class="pat-example1" name="example2" data-pat-example1="{&quot;option2&quot;: &quot;value2&quot;, &quot;option1&quot;: &quot;value1&quot;}"></textarea>'  # noqa: E501
        self.assertIn(html, [result1, result2])
Example #8
0
    def test_setting_patterns_options(self):
        from plone.app.widgets.base import TextareaWidget

        widget = TextareaWidget(
            'example1',
            name='expample2',
            pattern_options={
                'option1': 'value1',
                'option2': 'value2',
            })

        self.assertEqual(
            widget.render(),
            '<textarea class="pat-example1" name="expample2" '
            'data-pat-example1="{'
            '&quot;option2&quot;: &quot;value2&quot;, '
            '&quot;option1&quot;: &quot;value1&quot;}">'
            '</textarea>')