Skip to content

Commit

Permalink
Add tests for (multiple) image fields on content
Browse files Browse the repository at this point in the history
  • Loading branch information
laulaz committed Mar 30, 2016
1 parent 2647ce6 commit fb687a4
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/collective/autoscaling/profiles/testing/types.xml
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<object name="portal_types" meta_type="Plone Types Tool">
<property name="title">Controls the available content types in your portal</property>
<object name="dexterity_content_type_with_two_image_fields" meta_type="Dexterity FTI"/>
</object>
@@ -0,0 +1,60 @@
<?xml version="1.0"?>
<object name="dexterity_content_type_with_two_image_fields"
meta_type="Dexterity FTI" i18n:domain="plone"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">
<property name="title"
i18n:translate="">dexterity content type with two image fields</property>
<property name="description" i18n:translate="">None</property>
<property name="icon_expr">string:${portal_url}/document_icon.png</property>
<property
name="factory">dexterity_content_type_with_two_image_fields</property>
<property
name="add_view_expr">string:${folder_url}/++add++dexterity_content_type_with_two_image_fields</property>
<property name="link_target"></property>
<property name="immediate_view">view</property>
<property name="global_allow">True</property>
<property name="filter_content_types">True</property>
<property name="allowed_content_types"/>
<property name="allow_discussion">False</property>
<property name="default_view">view</property>
<property name="view_methods">
<element value="view"/>
</property>
<property name="default_view_fallback">False</property>
<property name="add_permission">cmf.AddPortalContent</property>
<property name="klass">plone.dexterity.content.Container</property>
<property name="behaviors">
<element value="plone.app.dexterity.behaviors.metadata.IDublinCore"/>
<element value="plone.app.content.interfaces.INameFromTitle"/>
<element value="plone.app.imagecropping.behaviors.IImageCroppingBehavior"/>
</property>
<property name="schema"></property>
<property
name="model_source">&lt;model xmlns:security="http://namespaces.plone.org/supermodel/security" xmlns:marshal="http://namespaces.plone.org/supermodel/marshal" xmlns:form="http://namespaces.plone.org/supermodel/form" xmlns="http://namespaces.plone.org/supermodel/schema"&gt;
&lt;schema&gt;
&lt;field name="first_image" type="plone.namedfile.field.NamedBlobImage"&gt;
&lt;description/&gt;
&lt;title&gt;First image&lt;/title&gt;
&lt;/field&gt;
&lt;field name="second_image" type="plone.namedfile.field.NamedBlobImage"&gt;
&lt;description/&gt;
&lt;title&gt;Second image&lt;/title&gt;
&lt;/field&gt;
&lt;/schema&gt;
&lt;/model&gt;</property>
<property name="model_file"></property>
<alias from="(Default)" to="(dynamic view)"/>
<alias from="edit" to="@@edit"/>
<alias from="sharing" to="@@sharing"/>
<alias from="view" to="(selected layout)"/>
<action title="View" action_id="view" category="object" condition_expr=""
description="" icon_expr="" link_target="" url_expr="string:${object_url}"
visible="True">
<permission value="View"/>
</action>
<action title="Edit" action_id="edit" category="object" condition_expr=""
description="" icon_expr="" link_target=""
url_expr="string:${object_url}/edit" visible="True">
<permission value="Modify portal content"/>
</action>
</object>
6 changes: 5 additions & 1 deletion src/collective/autoscaling/tests/library.py
Expand Up @@ -3,6 +3,7 @@
from cStringIO import StringIO
from plone import api
from plone.app.robotframework.remote import RemoteLibrary
from plone.namedfile.file import NamedBlobImage
import PIL.Image


Expand All @@ -14,7 +15,10 @@ def image_dimensions_of(self, image_url):
"""
portal = api.portal.get()
image = portal.restrictedTraverse(image_url)
data = image.image.data
if isinstance(image, NamedBlobImage):
data = image.data
else:
data = image.image.data
imageFile = StringIO(data)
image = PIL.Image.open(imageFile)
return image.size
Expand Down
67 changes: 53 additions & 14 deletions src/collective/autoscaling/tests/robot/keywords.robot
Expand Up @@ -6,6 +6,8 @@ ${TEST_FOLDER} = ${PLONE_URL}/${TEST_FOLDER_ID}

*** Keywords ***

# Settings

I am logged in as a ${role}
Enable autologin as ${role}
Go to ${PLONE_URL}
Expand All @@ -18,6 +20,22 @@ I access collective.autoscaling settings
Click link link=Autoscaling
Page Should Contain Lets you change the settings of images autoscaling feature.

I choose to show message to user
Select Checkbox id=form.show_message
Click Button Save

I disabled autoscaling
Unselect Checkbox id=form.is_enabled
Click Button Save

I change settings to width '${setting_width}' and height '${setting_height}'
Input text name=form.image_max_width ${setting_width}
Input text name=form.image_max_height ${setting_height}
Click Button Save


# Content manipulation

I upload a big image called '${title}'
Go to ${TEST_FOLDER}
Open Add New Menu
Expand All @@ -29,29 +47,50 @@ I upload a big image called '${title}'
Wait Until Page Contains Item created
Page Should Contain Item created

image '${content-id}' is scaled down
I create a content called '${title}' with two image fields using image '${image}'
Go to ${TEST_FOLDER}
Open Add New Menu
Click Link link=dexterity content type with two image fields
Input text name=form.widgets.IDublinCore.title ${title}
Choose File name=form.widgets.first_image ${PATH_TO_TEST_FILES}/${image}
Choose File name=form.widgets.second_image ${PATH_TO_TEST_FILES}/${image}
Click Button Save
Wait Until Page Contains Item created
Page Should Contain Item created

I delete the image '${content-id}'
Delete image ${TEST_FOLDER_ID}/${content-id}


# Checks

image '${content-id}' is scaled down to width '${setting_width}' and height '${setting_height}' and size '${size}'
Go to ${TEST_FOLDER}/${content-id}/view
Page Should Contain Size: 47KB
Page Should Contain Size: ${size}
${size} = image dimensions of ${TEST_FOLDER_ID}/${content-id}
${width} = Get From List ${size} 0
${height} = Get From List ${size} 1
Should Be Equal As Strings ${width} 1200
Should Be Equal As Strings ${height} 600
Should Be Equal As Strings ${width} ${setting_width}
Should Be Equal As Strings ${height} ${setting_height}

I choose to show message to user
Select Checkbox id=form.show_message
Click Button Save
both images are scaled down for content '${title}' to width '${setting_width}' and height '${setting_height}'
${size} = image dimensions of ${TEST_FOLDER_ID}/${title}/first_image
${width} = Get From List ${size} 0
${height} = Get From List ${size} 1
Should Be Equal As Strings ${width} ${setting_width}
Should Be Equal As Strings ${height} ${setting_height}
${size} = image dimensions of ${TEST_FOLDER_ID}/${title}/second_image
${width} = Get From List ${size} 0
${height} = Get From List ${size} 1
Should Be Equal As Strings ${width} ${setting_width}
Should Be Equal As Strings ${height} ${setting_height}

information message is shown
information message for one image is shown
Page Should Contain One image has been resized on this content.

I disabled autoscaling
Unselect Checkbox id=form.is_enabled
Click Button Save
information message for multiples images ('${nb}') is shown
Page Should Contain ${nb} images have been resized on this content.

image '${content-id}' is not scaled down
Go to ${TEST_FOLDER}/${content-id}/view
Page Should Contain Size: 64KB

I delete the image '${content-id}'
Delete image ${TEST_FOLDER_ID}/${content-id}
24 changes: 21 additions & 3 deletions src/collective/autoscaling/tests/robot/test_scaling.robot
Expand Up @@ -18,7 +18,7 @@ Test Teardown Close all browsers
Scenario: When I upload an image it is scaled down automatically
Given I am logged in as a Manager
When I upload a big image called 'big-image.png'
Then image 'big-image.png' is scaled down
Then image 'big-image.png' is scaled down to width '1200' and height '600' and size '47KB'
And I delete the image 'big-image.png'

Scenario: I see an information message if it is activated in settings
Expand All @@ -27,7 +27,25 @@ Scenario: I see an information message if it is activated in settings
And I access collective.autoscaling settings
And I choose to show message to user
And I upload a big image called 'big-image.png'
Then information message is shown
Then information message for one image is shown
And I delete the image 'big-image.png'

Scenario: When I upload images on fields they are scaled down automatically
Given I am logged in as a Manager
When I go to the control panel
And I access collective.autoscaling settings
And I choose to show message to user
When I create a content called 'doc' with two image fields using image 'big-image.png'
Then both images are scaled down for content 'doc' to width '1200' and height '600'
And information message for multiples images ('2') is shown

Scenario: When I upload an image it is scaled down to new settings
Given I am logged in as a Manager
When I go to the control panel
And I access collective.autoscaling settings
And I change settings to width '400' and height '800'
And I upload a big image called 'big-image.png'
Then image 'big-image.png' is scaled down to width '400' and height '200' and size '14KB'
And I delete the image 'big-image.png'

Scenario: If the addon is not enabled, no image are scaled down automatically
Expand All @@ -36,5 +54,5 @@ Scenario: If the addon is not enabled, no image are scaled down automatically
And I access collective.autoscaling settings
And I disabled autoscaling
And I upload a big image called 'big-image.png'
Then image 'big-image.png' is not scaled down
Then image 'big-image.png' is not scaled down
And I delete the image 'big-image.png'

0 comments on commit fb687a4

Please sign in to comment.