def create_demo_content(self):
        """Create a portal structure which we can test against.
        Plone (portal root)
        |-- image
        |-- about
            |-- team
            `-- contact
        """
        portal = self.layer["portal"]

        self.about = api.content.create(
            container=portal,
            type="Folder",
            id="about",
            title=u"About",
        )
        self.team = api.content.create(
            container=self.about,
            type="Document",
            id="team",
            title=u"Team",
        )
        self.contact = api.content.create(
            container=self.about,
            type="Document",
            id="contact",
            title=u"Contact",
        )
        self.image = api.content.create(
            container=portal,
            type="Image",
            title=u"Image",
            id="image",
            image=NamedImage(dummy.Image(), "image/gif", u"test.gif"),
        )
Esempio n. 2
0
 def testClearImageTitle(self):
     # Test for http://dev.plone.org/plone/ticket/3303
     # Should be able to clear Image title
     self.folder.invokeFactory('Image', id='image', title='Foo',
                               file=dummy.Image())
     self.assertEqual(self.folder.image.Title(), 'Foo')
     self.folder.image.image_edit(title='')
     self.assertEqual(self.folder.image.Title(), '')
Esempio n. 3
0
    def test_filters(self):
        try:
            from plone.scale.scale import scaleImage
            scaleImage   # pyflakes
        except ImportError:
            print "scaling images not available. skipping test"
            return

        # Let's turn these filters on first.
        tinymce_utility = getUtility(ITinyMCE)
        tinymce_utility.link_using_uids = True
        tinymce_utility.allow_captioned_images = True

        # To test the settings, we'll need an image.
        self.portal.invokeFactory('Image', id='image.jpg', title="Image", file=dummy.Image())
        image = getattr(self.portal, 'image.jpg')
        image.setDescription('My caption')
        image.reindexObject()
        UID = image.UID()

        # Let's transform some text/html to text/x-html-safe, which should trigger the
        # filters.
        text = """
<html>
   <head></head>
   <body>
       <img src="resolveuid/%s/image_thumb" class="image-left captioned" width="200" alt="My alt text" />
       <p><img src="/image.jpg" class="image-right captioned" width="200" style="border-width:1px" /></p>
       <pre>This is line 1
             This is line 2</pre>
   </body>
</html>""" % UID
        transformed_text = self.portal.portal_transforms.convertTo('text/x-html-safe', text, mimetype='text/html', context=self.portal)

        # The UID reference should be converted to an absolute url, and a caption should be added.
        self.assertEqual(unicode(transformed_text).replace(' ', ''), u"""
<dl style="width:200px;" class="image-left captioned">
<dt><img src="http://nohost/plone/image.jpg/image_thumb" alt="My alt text" title="Image" height="16" width="200" /></dt>
 <dd class="image-caption" style="width:200px;">My caption</dd>
</dl>
<p><dl style="width:200px;" class="image-right captioned">
<dt><img src="http://nohost/plone/image.jpg/image" alt="Image" title="Image" height="16" width="200" style="border-width:1px" /></dt>
 <dd class="image-caption" style="width:200px;">My caption</dd>
</dl></p>
<pre>This is line 1
      This is line 2</pre>
""".replace(' ', ''))
        # Now turn off the settings.
        tinymce_utility.link_using_uids = False
        tinymce_utility.allow_captioned_images = False

        # Now the filters should not be applied.

        transformed_text_2 = self.portal.portal_transforms.convertTo('text/x-html-safe', text, mimetype='text/html', context=self.portal)
        self.assertNotEqual(unicode(transformed_text_2).replace(' ', ''), unicode(transformed_text).replace(' ', ''))
Esempio n. 4
0
 def testEditFormatMetadataOfImage(self):
     # Test fix for http://dev.plone.org/plone/ticket/1323
     self.folder.invokeFactory('Image', id='image')
     self.folder.image.edit(file=dummy.Image('foo.zip'))
     self.assertEqual(self.folder.image.Format(), 'application/zip')
     self.assertEqual('application/zip',
                      self.folder.image.getImage().content_type)
     # Changing the format should be reflected in content_type property
     self.utils.editMetadata(self.folder.image, format='image/gif')
     self.assertEqual(self.folder.image.Format(), 'image/gif')
     self.assertEqual('image/gif',
                      self.folder.image.getImage().content_type)
Esempio n. 5
0
 def testInvokeAddview(self):
     portlet = getUtility(IPortletType, name='collective.portlet.rich.RichPortlet')
     mapping = self.portal.restrictedTraverse('++contextportlets++plone.leftcolumn')
     for m in mapping.keys():
         del mapping[m]
     addview = mapping.restrictedTraverse('+/' + portlet.addview)
     
     #TODO: clean the dummy.Image() up
     data = {
         'target_title_image' : dummy.Image(), 
         'title' : u"test title", 
         'text' : u"test text", 
         'links' : [u'http://www.plone.org:Link title 1:Link description 1', u'http://www.python.org:Link title 2:Link description 2'],
     }
     addview.createAndAdd(data=data)
     
     self.assertEquals(len(mapping), 1)
     self.failUnless(isinstance(mapping.values()[0], richportlet.Assignment))
 def testImagePatch(self):
     # Is it ok to remove the imagePatch? Probably not as we
     # don't want the border attribute ...
     self.folder.invokeFactory('Image', id='foo', file=dummy.Image())
     endswith = ' alt="" title="" height="16" width="16" />'
     self.assertEqual(self.folder.foo.tag()[-len(endswith):], endswith)
Esempio n. 7
0
 def testMemberPortrait(self):
     self.portal_member.setPortrait(dummy.Image())
     self.assertEqual(self.portal_member.getPortrait().data, dummy.GIF)
     self.assertEqual(self.portal_member.getPortrait(),
                      self.getUser().getProperty('portrait'))
 def testImageEdit(self):
     self.folder.invokeFactory('Image', id='image')
     self.folder.image.edit(file=dummy.Image())
     self.assertEqual(str(self.folder.image.data), dummy.GIF)
 def testImageCreate(self):
     self.folder.invokeFactory(
         'Image', id='image', image=NamedImage(dummy.Image()))
     self.assertEqual(self.folder.image.image.data, dummy.GIF)
Esempio n. 10
0
 def testUploadImage(self):
     self.folder[self.image_id].image_edit(file=dummy.Image('fred.gif'))
     self.assertTrue('fred.gif' in self.folder)
Esempio n. 11
0
 def afterSetUp(self):
     self.folder.invokeFactory('File', id='file')
     self.folder.file.file_edit(file=dummy.File('foo.pdf'))
     self.folder.invokeFactory('Image', id='image')
     self.folder.image.image_edit(file=dummy.Image('foo.gif'))
Esempio n. 12
0
 def afterSetUp(self):
     self.folder.invokeFactory('File', id='file', file=dummy.File())
     self.folder.invokeFactory('Image', id='image', file=dummy.Image())
 def testUploadImage(self):
     self.folder[self.image_id].image_edit(file=dummy.Image('fred.gif'))
     self.failUnless('fred.gif' in self.folder)