r109230 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109229‎ | r109230 | r109231 >
Date:22:09, 17 January 2012
Author:amire80
Status:ok
Tags:i18nreview 
Comment:
Started writing tests for applying web fonts to body (set( font )). Changed literal font names to names from mw.webfonts.config.
Modified paths:
  • /trunk/extensions/WebFonts/tests/qunit/ext.webfonts.tests.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WebFonts/tests/qunit/ext.webfonts.tests.js
@@ -6,17 +6,41 @@
77 ok( mw.webfonts, 'mw.webfonts is defined' );
88 } );
99
 10+test( '-- Web font application to body', function() {
 11+ expect( 4 );
 12+
 13+ var invalidFont = 'NonExistingFont';
 14+ assertTrue( mw.webfonts.set( invalidFont ) === undefined, 'A non-existent font is not initialized' );
 15+ // TODO: test that the right thing was written to the log
 16+
 17+ var $body = $( 'body' );
 18+ var bodyLang = $body.attr( 'lang' );
 19+ var oldConfig = {
 20+ fontFamily: $body.css( 'font-family' ),
 21+ fontSize: $body.css( 'font-size' )
 22+ };
 23+ var teluguFont = mw.webfonts.config.languages.te[0]
 24+ $body.attr( 'lang', 'te' );
 25+
 26+ ok( mw.webfonts.set( teluguFont ), 'Attempted to load a Telugu font for the whole page' );
 27+ deepEqual( oldConfig, mw.webfonts.oldconfig, 'Previous body css was saved properly' );
 28+
 29+ // Restore <body>
 30+ $body.attr( 'lang', bodyLang );
 31+ ok( mw.webfonts.reset(), 'Reset body after testing font application' );
 32+} );
 33+
1034 test( '-- Dynamic font loading', function() {
1135 expect( 7 );
1236
13 - var validFontName = 'Lohit Devanagari';
 37+ var validFontName = mw.webfonts.config.languages.hi[0];
1438 mw.webfonts.fonts = [];
1539 var cssRulesLength = document.styleSheets.length;
16 - assertTrue( mw.webfonts.addFont( validFontName ) , 'Add a Devanagari font' );
 40+ assertTrue( mw.webfonts.addFont( validFontName ), 'Add a Devanagari font' );
1741 assertTrue( $.inArray( validFontName, mw.webfonts.fonts ) >= 0 , 'Devanagari font loaded' );
1842 assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'New css rule added to the document' );
1943 var loadedFontsSize = mw.webfonts.fonts.length;
20 - assertTrue( mw.webfonts.addFont( validFontName ) , 'Add the Devanagari font again' );
 44+ assertTrue( mw.webfonts.addFont( validFontName ), 'Add the Devanagari font again' );
2145 assertTrue( loadedFontsSize === mw.webfonts.fonts.length , 'A font that is already loaded is not loaded again' );
2246 assertFalse( mw.webfonts.addFont( 'Some non-existing font' ), 'addFont returns false if the font was not found' );
2347 assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'Loading the font does not add new css rules' );
@@ -33,19 +57,19 @@
3458 wgPageContentLanguage: "en",
3559 } );
3660
37 - ok( $( 'body' ).append( "<p class='webfonts-testing-lang-attr'>Some content</p>"), ' A element for testing lang-based loading was appended to <body>' );
 61+ ok( $( 'body' ).append( "<p class='webfonts-testing-lang-attr'>Some content</p>"), 'An element for testing lang-based loading was appended to body' );
3862 $testElement = $( 'p.webfonts-testing-lang-attr' )
3963 assertTrue( $testElement !== [], 'The test element is defined' );
4064
4165 ok( mw.webfonts.loadFontsForLangAttr(), 'Attempted to load fonts for the lang attribute' );
4266 assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr class since there is no lang attribute' );
4367
44 - ok( $testElement.attr( 'lang' , 'en' ) , 'The lang attribute of the test element was set to en (English)' );
 68+ ok( $testElement.attr( 'lang' , 'en' ), 'The lang attribute of the test element was set to en (English)' );
4569 ok( mw.webfonts.loadFontsForLangAttr(), 'Attempted to load fonts for the lang attribute en' );
4670 assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The test element has no webfonts-lang-attr class since en lang has no fonts available' );
4771
48 - var tamilFont = 'Lohit Tamil';
49 - ok( $testElement.attr( 'lang' , 'ta' ) , 'Set lang attribute to ta (Tamil)' );
 72+ var tamilFont = mw.webfonts.config.languages.ta[0];
 73+ ok( $testElement.attr( 'lang' , 'ta' ), 'Set lang attribute to ta (Tamil)' );
5074 ok( mw.webfonts.loadFontsForLangAttr(), 'Attempted to load fonts for the lang attribute ta' );
5175 assertTrue( $testElement.hasClass( 'webfonts-lang-attr' ), 'The test element has webfonts-lang-attr class' );
5276 assertTrue( $.inArray( tamilFont, mw.webfonts.fonts ) >= 0 , 'Tamil font loaded' );
@@ -54,14 +78,14 @@
5579 ok( mw.webfonts.reset(), 'Reset webfonts' );
5680 assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr since we reset it' );
5781
58 - ok( $testElement.remove(), 'The test element was removed from <body>' );
 82+ ok( $testElement.remove(), 'The test element was removed from body' );
5983 } );
6084
6185 test( '-- Dynamic font loading based on font-family style attribute', function() {
6286 expect( 14 )
6387
6488 mw.webfonts.fonts = [];
65 - ok( $( 'body' ).append( "<p class='webfonts-testing-font-family-style'>Some content</p>" ), 'An element for testing font-family loading was appended to <body>' );
 89+ ok( $( 'body' ).append( "<p class='webfonts-testing-font-family-style'>Some content</p>" ), 'An element for testing font-family loading was appended to body' );
6690 var $testElement = $( 'p.webfonts-testing-font-family-style' );
6791 assertTrue( $testElement !== [], 'The test element is defined' );
6892
@@ -79,12 +103,12 @@
80104 assertTrue( $.inArray( invalidFont, mw.webfonts.fonts ) === -1 , 'Font not loaded since it is not existing, including fallback fonts' );
81105 assertFalse( isFontFaceLoaded( invalidFont ), 'No new css rule added to the document since the font does not exist' );
82106
83 - var malayalamFont = 'AnjaliOldLipi';
 107+ var malayalamFont = mw.webfonts.config.languages.ml[0];
84108 $testElement.attr( 'style', 'font-family: ' + invalidFont + ', ' + malayalamFont + fallbackFonts );
85109 assertTrue( $.inArray( malayalamFont, mw.webfonts.fonts ) === -1 , 'Fallback font not loaded yet' );
86110 ok( mw.webfonts.loadFontsForFontFamilyStyle(), 'Loading fonts from font-family' );
87111 assertTrue( $.inArray( malayalamFont, mw.webfonts.fonts ) >= 0 , 'A fallback font was loaded' );
88 - assertTrue( isFontFaceLoaded( malayalamFont ) , 'New css rule added to the document for fallback font' );
 112+ assertTrue( isFontFaceLoaded( malayalamFont ), 'New css rule added to the document for fallback font' );
89113
90114 ok( $testElement.remove() );
91115 } );

Sign-offs

UserFlagDate
Nikerabbitinspected06:43, 18 January 2012
Nikerabbittested06:43, 18 January 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r111374[WebFonts tests] Refactor / fix breakage...krinkle14:49, 13 February 2012

Status & tagging log