Skip to content
Permalink
Browse files

[composer] Make html tests text-free

Minimises cross platform rendering differences
  • Loading branch information
nyalldawson committed Nov 29, 2014
1 parent 0d211e8 commit 20f57c90d99ceacff1bfe07fd44b9beb14a7f171
Showing with 57 additions and 11 deletions.
  1. +9 −9 tests/src/core/testqgscomposerhtml.cpp
  2. +2 −2 tests/src/python/test_qgscomposerhtml.py
  3. BIN ..._images/expected_composerhtml_expressions_disabled/expected_composerhtml_expressions_disabled.png
  4. BIN ...ol_images/expected_composerhtml_expressions_enabled/expected_composerhtml_expressions_enabled.png
  5. BIN tests/testdata/control_images/expected_composerhtml_manual/expected_composerhtml_manual.png
  6. BIN ...ta/control_images/expected_composerhtml_multiframe1/default/expected_composerhtml_multiframe1.png
  7. BIN ...s/testdata/control_images/expected_composerhtml_multiframe1/expected_composerhtml_multiframe1.png
  8. BIN ...ta/control_images/expected_composerhtml_multiframe1/precise/expected_composerhtml_multiframe1.png
  9. BIN ...ta/control_images/expected_composerhtml_multiframe2/default/expected_composerhtml_multiframe2.png
  10. BIN ...s/testdata/control_images/expected_composerhtml_multiframe2/expected_composerhtml_multiframe2.png
  11. BIN ...ta/control_images/expected_composerhtml_multiframe2/precise/expected_composerhtml_multiframe2.png
  12. BIN .../control_images/expected_composerhtml_smartbreaks1/default/expected_composerhtml_smartbreaks1.png
  13. BIN ...testdata/control_images/expected_composerhtml_smartbreaks1/expected_composerhtml_smartbreaks1.png
  14. BIN .../control_images/expected_composerhtml_smartbreaks1/precise/expected_composerhtml_smartbreaks1.png
  15. BIN .../control_images/expected_composerhtml_smartbreaks2/default/expected_composerhtml_smartbreaks2.png
  16. BIN ...testdata/control_images/expected_composerhtml_smartbreaks2/expected_composerhtml_smartbreaks2.png
  17. BIN .../control_images/expected_composerhtml_smartbreaks2/precise/expected_composerhtml_smartbreaks2.png
  18. BIN tests/testdata/control_images/expected_composerhtml_table/default/expected_composerhtml_table.png
  19. BIN tests/testdata/control_images/expected_composerhtml_table/expected_composerhtml_table.png
  20. BIN tests/testdata/control_images/expected_composerhtml_table/precise/expected_composerhtml_table.png
  21. BIN ...data/control_images/expected_composerhtml_userstylesheet/expected_composerhtml_userstylesheet.png
  22. +46 −0 tests/testdata/test_html.html
@@ -91,7 +91,7 @@ void TestQgsComposerHtml::sourceMode()
htmlFrame->setFrameEnabled( true );
htmlItem->addFrame( htmlFrame );
htmlItem->setContentMode( QgsComposerHtml::ManualHtml );
htmlItem->setHtml( QString( "<p style=\"font-family: %1\"><i>Test manual <b>html</b></i></p>" ).arg( mTestFont.family() ) );
htmlItem->setHtml( QString( "<body style=\"margin: 10px;\"><div style=\"width: 100px; height: 50px; background-color: red;\"></div></body>" ) );
htmlItem->loadHtml();

QgsCompositionChecker checker( "composerhtml_manual", mComposition );
@@ -108,10 +108,10 @@ void TestQgsComposerHtml::userStylesheets()
htmlFrame->setFrameEnabled( true );
htmlItem->addFrame( htmlFrame );
htmlItem->setContentMode( QgsComposerHtml::ManualHtml );
htmlItem->setHtml( QString( "<p style=\"font-family: %1\"><i>Test user stylesheets <b>html</b></i></p>" ).arg( mTestFont.family() ) );
htmlItem->setHtml( QString( "<body style=\"margin: 10px;\"><div style=\"width: 100px; height: 50px; background-color: red;\"></div></body>" ) );

//set user stylesheet
htmlItem->setUserStylesheet( QString( "b { color: red; } i { color: green; }" ) );
htmlItem->setUserStylesheet( QString( "div { background-color: green !important; }" ) );
//setting user stylesheet enabled automatically loads html
htmlItem->setUserStylesheetEnabled( true );

@@ -130,7 +130,7 @@ void TestQgsComposerHtml::evalExpressions()
htmlItem->addFrame( htmlFrame );
htmlItem->setContentMode( QgsComposerHtml::ManualHtml );
htmlItem->setEvaluateExpressions( true );
htmlItem->setHtml( QString( "<p style=\"font-family: %1\">Test expressions = <i>[% 1 + 2 + 3%]</i></p>" ).arg( mTestFont.family() ) );
htmlItem->setHtml( QString( "<body style=\"margin: 10px;\"><div style=\"width: [% 10 * 10 %]px; height: [% 30 + 20 %]px; background-color: [% 'yel' || 'low' %];\"></div></body>" ) );

htmlItem->loadHtml();

@@ -149,7 +149,7 @@ void TestQgsComposerHtml::evalExpressionsOff()
htmlItem->addFrame( htmlFrame );
htmlItem->setContentMode( QgsComposerHtml::ManualHtml );
htmlItem->setEvaluateExpressions( false );
htmlItem->setHtml( QString( "<p style=\"font-family: %1\">Test expressions = <i>[% 1 + 2 + 3%]</i></p>" ).arg( mTestFont.family() ) );
htmlItem->setHtml( QString( "<body style=\"margin: 10px;\"><div style=\"width: [% 10 * 10 %]px; height: [% 30 + 20 %]px; background-color: [% 'yel' || 'low' %];\"></div></body>" ) );
htmlItem->loadHtml();

QgsCompositionChecker checker( "composerhtml_expressions_disabled", mComposition );
@@ -165,7 +165,7 @@ void TestQgsComposerHtml::table()
QgsComposerFrame* htmlFrame = new QgsComposerFrame( mComposition, htmlItem, 0, 0, 100, 200 );
htmlFrame->setFrameEnabled( true );
htmlItem->addFrame( htmlFrame );
htmlItem->setUrl( QUrl( QString( "file:///%1" ).arg( QString( TEST_DATA_DIR ) + QDir::separator() + "html_table.html" ) ) );
htmlItem->setUrl( QUrl( QString( "file:///%1" ).arg( QString( TEST_DATA_DIR ) + QDir::separator() + "test_html.html" ) ) );

QgsCompositionChecker checker( "composerhtml_table", mComposition );
bool result = checker.testComposition( mReport );
@@ -183,7 +183,7 @@ void TestQgsComposerHtml::tableMultiFrame()
htmlItem->setUseSmartBreaks( false );

//page1
htmlItem->setUrl( QUrl( QString( "file:///%1" ).arg( QString( TEST_DATA_DIR ) + QDir::separator() + "html_table.html" ) ) );
htmlItem->setUrl( QUrl( QString( "file:///%1" ).arg( QString( TEST_DATA_DIR ) + QDir::separator() + "test_html.html" ) ) );
htmlItem->frame( 0 )->setFrameEnabled( true );
QgsCompositionChecker checker1( "composerhtml_multiframe1", mComposition );
bool result = checker1.testComposition( mReport );
@@ -206,14 +206,14 @@ void TestQgsComposerHtml::htmlMultiFrameSmartBreak()
htmlItem->setUseSmartBreaks( true );

//page1
htmlItem->setUrl( QUrl( QString( "file:///%1" ).arg( QString( TEST_DATA_DIR ) + QDir::separator() + "html_table.html" ) ) );
htmlItem->setUrl( QUrl( QString( "file:///%1" ).arg( QString( TEST_DATA_DIR ) + QDir::separator() + "test_html.html" ) ) );
htmlItem->frame( 0 )->setFrameEnabled( true );
QgsCompositionChecker checker1( "composerhtml_smartbreaks1", mComposition );
bool result = checker1.testComposition( mReport );

//page2
QgsCompositionChecker checker2( "composerhtml_smartbreaks2", mComposition );
result = checker2.testComposition( mReport, 1 ) && result;
result = checker2.testComposition( mReport, 1, 3000 ) && result;

mComposition->removeMultiFrame( htmlItem );
delete htmlItem;
@@ -47,7 +47,7 @@ def tearDown(self):

def htmlUrl(self):
"""Helper to get the url of the html doc."""
myPath = os.path.join(TEST_DATA_DIR, "html_table.html")
myPath = os.path.join(TEST_DATA_DIR, "test_html.html")
myUrl = QUrl("file:///" + myPath)
return myUrl

@@ -119,7 +119,7 @@ def testHtmlSmartBreaks(self):
print "Checking page 2"
myPage = 1
checker2 = QgsCompositionChecker('composerhtml_smartbreaks2', self.mComposition)
myTestResult, myMessage = checker2.testComposition( myPage )
myTestResult, myMessage = checker2.testComposition( myPage, 3000 )
assert myTestResult, myMessage

self.mComposition.removeMultiFrame( composerHtml )
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,46 @@
<html>
<head>
<style>
body
{
background-color: transparent;
margin: 6px;
padding: 0px;
}
table
{
width: 300px;
border-spacing: 6px;
margin: 0px;
padding: 0px;
}
table tr
{
height: 40px;
}
table td
{
border: 2px solid black;
}
tr.row1
{
background-color: red;
}
tr.row2
{
background-color: yellow;
}
</style>
</head>
<body>
<table>
<tbody>
<tr class="row1"><td></td><td></td></tr>
<tr class="row2"><td></td><td></td></tr>
<tr class="row1"><td></td><td></td></tr>
<tr class="row2"><td></td><td></td></tr>
<tr class="row1"><td></td><td></td></tr>
</tbody>
</table>
</body>
</html>

0 comments on commit 20f57c9

Please sign in to comment.
You can’t perform that action at this time.