Skip to content

Commit

Permalink
[composer] Make html tests text-free
Browse files Browse the repository at this point in the history
Minimises cross platform rendering differences
  • Loading branch information
nyalldawson committed Nov 29, 2014
1 parent 0d211e8 commit 20f57c9
Show file tree
Hide file tree
Showing 22 changed files with 57 additions and 11 deletions.
18 changes: 9 additions & 9 deletions tests/src/core/testqgscomposerhtml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );

Expand All @@ -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();

Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/src/python/test_qgscomposerhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 )
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions tests/testdata/test_html.html
Original file line number Diff line number Diff line change
@@ -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.