def test_box_render_basic(self):

        with patch('il.portalinterlegis.browser.boxes.manager.get_template', get_template_stub):

            box = Box(IStubBox, 1)
            box.get_data = Mock(return_value={'var': 'XXXX'})
            context = object()
            self.assertMultiLineEqual('''
<div id="IStubBox_1">
  XXXX
</div>
'''.strip('\n'), box(context))
            box.get_data.assert_called_with(context)
    def test_using_box_form_creates_box_content(self):
        context = self.portal

        def use_box_form(supertitle, title, text, target, box):
            browser = self.layer.manager_browser()
            browser.open(self.url(box.form_name))
            browser.getControl(name='form.widgets.supertitle').value = supertitle
            browser.getControl(name='form.widgets.title').value = title
            browser.getControl(name='form.widgets.text').value = text
            # TODO: nao sei como testar um AutocompleteFieldWidget com o zope.testbrowser (tem javascript)
            # browser.getControl(label=u'Conteúdo relacionado').value = target
            browser.getControl(name='form.buttons.apply').click()

        box_1 = Box(ISuperTitleBox, 1)
        use_box_form('SUPERTIT_1', 'TIT_1', 'TEXT_1', 'ALVO_1', box_1)
        self.assertEqual(dict(supertitle='SUPERTIT_1', title='TIT_1', text='TEXT_1', target=None, image=None),
                         box_1.get_data(context))

        # a second one to test there is no mutual interference
        box_2 = Box(ISuperTitleBox, 2)
        use_box_form('SUPERTIT_2', 'TIT_2', 'TEXT_2', 'ALVO_2', box_2)
        self.assertEqual(dict(supertitle='SUPERTIT_2', title='TIT_2', text='TEXT_2', target=None, image=None),
                         box_2.get_data(context))
    def test_box_render_editable(self):
        with patch('il.portalinterlegis.browser.boxes.manager.get_template', get_template_stub):
            with patch('il.portalinterlegis.browser.boxes.manager.getSecurityManager') as security_mock:
                security_mock.checkPermission.return_value = True

                box = Box(IStubBox, 1)
                box.get_data = Mock(return_value={'var': 'XXXX'})
                context = object()
                self.assertMultiLineEqual('''
<div id="IStubBox_1" class ="editable-box" >
  XXXX
  <a class="editable-box-link-overlay" href="box_IStubBox_1">
    <img src="pencil_icon.png" width="16" height="16" alt="Editar esta caixa" />
  </a>
</div>
'''.strip('\n'), box(context))
                box.get_data.assert_called_with(context)