Skip to content

Commit 20f57c9

Browse files
committedNov 29, 2014
[composer] Make html tests text-free
Minimises cross platform rendering differences
1 parent 0d211e8 commit 20f57c9

File tree

22 files changed

+57
-11
lines changed

22 files changed

+57
-11
lines changed
 

‎tests/src/core/testqgscomposerhtml.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void TestQgsComposerHtml::sourceMode()
9191
htmlFrame->setFrameEnabled( true );
9292
htmlItem->addFrame( htmlFrame );
9393
htmlItem->setContentMode( QgsComposerHtml::ManualHtml );
94-
htmlItem->setHtml( QString( "<p style=\"font-family: %1\"><i>Test manual <b>html</b></i></p>" ).arg( mTestFont.family() ) );
94+
htmlItem->setHtml( QString( "<body style=\"margin: 10px;\"><div style=\"width: 100px; height: 50px; background-color: red;\"></div></body>" ) );
9595
htmlItem->loadHtml();
9696

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

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

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

135135
htmlItem->loadHtml();
136136

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

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

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

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

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

214214
//page2
215215
QgsCompositionChecker checker2( "composerhtml_smartbreaks2", mComposition );
216-
result = checker2.testComposition( mReport, 1 ) && result;
216+
result = checker2.testComposition( mReport, 1, 3000 ) && result;
217217

218218
mComposition->removeMultiFrame( htmlItem );
219219
delete htmlItem;

‎tests/src/python/test_qgscomposerhtml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def tearDown(self):
4747

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

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

125125
self.mComposition.removeMultiFrame( composerHtml )
Loading
Loading
-2.78 KB
Loading
6.05 KB
Loading
4.3 KB
Loading
5.8 KB
Loading
4.46 KB
Loading
5.8 KB
Loading
-3.68 KB
Loading

‎tests/testdata/test_html.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<html>
2+
<head>
3+
<style>
4+
body
5+
{
6+
background-color: transparent;
7+
margin: 6px;
8+
padding: 0px;
9+
}
10+
table
11+
{
12+
width: 300px;
13+
border-spacing: 6px;
14+
margin: 0px;
15+
padding: 0px;
16+
}
17+
table tr
18+
{
19+
height: 40px;
20+
}
21+
table td
22+
{
23+
border: 2px solid black;
24+
}
25+
tr.row1
26+
{
27+
background-color: red;
28+
}
29+
tr.row2
30+
{
31+
background-color: yellow;
32+
}
33+
</style>
34+
</head>
35+
<body>
36+
<table>
37+
<tbody>
38+
<tr class="row1"><td></td><td></td></tr>
39+
<tr class="row2"><td></td><td></td></tr>
40+
<tr class="row1"><td></td><td></td></tr>
41+
<tr class="row2"><td></td><td></td></tr>
42+
<tr class="row1"><td></td><td></td></tr>
43+
</tbody>
44+
</table>
45+
</body>
46+
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.