MediaWiki  REL1_21
OutputPageTest.php
Go to the documentation of this file.
00001 <?php
00002 
00010 class OutputPageTest extends MediaWikiTestCase {
00011         const SCREEN_MEDIA_QUERY = 'screen and (min-width: 982px)';
00012         const SCREEN_ONLY_MEDIA_QUERY = 'only screen and (min-width: 982px)';
00013 
00029         protected function assertTransformCssMediaCase( $args ) {
00030                 $queryData = array();
00031                 if ( isset( $args['printableQuery'] ) ) {
00032                         $queryData['printable'] = $args['printableQuery'];
00033                 }
00034 
00035                 if ( isset( $args['handheldQuery'] ) ) {
00036                         $queryData['handheld'] = $args['handheldQuery'];
00037                 }
00038 
00039                 $fauxRequest = new FauxRequest( $queryData, false );
00040                 $this->setMWGlobals( array(
00041                         'wgRequest' => $fauxRequest,
00042                         'wgHandheldForIPhone' => $args['handheldForIPhone']
00043                 ) );
00044 
00045                 $actualReturn = OutputPage::transformCssMedia( $args['media'] );
00046                 $this->assertSame( $args['expectedReturn'], $actualReturn, $args['message'] );
00047         }
00048 
00058         protected function assertTransformCssMediaCaseWithBothHandheldForIPhone( $args ) {
00059                 $message = $args['message'];
00060                 foreach ( array( true, false ) as $handheldForIPhone ) {
00061                         $args['handheldForIPhone'] = $handheldForIPhone;
00062                         $stringHandheldForIPhone = var_export( $handheldForIPhone, true );
00063                         $args['message'] = "$message. \$wgHandheldForIPhone was $stringHandheldForIPhone";
00064                         $this->assertTransformCssMediaCase( $args );
00065                 }
00066         }
00067 
00071         public function testPrintRequests() {
00072                 $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array(
00073                         'printableQuery' => '1',
00074                         'media' => 'screen',
00075                         'expectedReturn' => null,
00076                         'message' => 'On printable request, screen returns null'
00077                 ) );
00078 
00079                 $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array(
00080                         'printableQuery' => '1',
00081                         'media' => self::SCREEN_MEDIA_QUERY,
00082                         'expectedReturn' => null,
00083                         'message' => 'On printable request, screen media query returns null'
00084                 ) );
00085 
00086                 $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array(
00087                         'printableQuery' => '1',
00088                         'media' => self::SCREEN_ONLY_MEDIA_QUERY,
00089                         'expectedReturn' => null,
00090                         'message' => 'On printable request, screen media query with only returns null'
00091                 ) );
00092 
00093                 $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array(
00094                         'printableQuery' => '1',
00095                         'media' => 'print',
00096                         'expectedReturn' => '',
00097                         'message' => 'On printable request, media print returns empty string'
00098                 ) );
00099         }
00100 
00104         public function testScreenRequests() {
00105                 $this->assertTransformCssMediaCase( array(
00106                         'handheldForIPhone' => false,
00107                         'media' => 'screen',
00108                         'expectedReturn' => 'screen',
00109                         'message' => 'On screen request, with handheldForIPhone false, screen media type is preserved'
00110                 ) );
00111 
00112                 $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array(
00113                         'media' => self::SCREEN_MEDIA_QUERY,
00114                         'expectedReturn' => self::SCREEN_MEDIA_QUERY,
00115                         'message' => 'On screen request, screen media query is preserved.'
00116                 ) );
00117 
00118                 $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array(
00119                         'media' => self::SCREEN_ONLY_MEDIA_QUERY,
00120                         'expectedReturn' => self::SCREEN_ONLY_MEDIA_QUERY,
00121                         'message' => 'On screen request, screen media query with only is preserved.'
00122                 ) );
00123 
00124                 $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array(
00125                         'media' => 'print',
00126                         'expectedReturn' => 'print',
00127                         'message' => 'On screen request, print media type is preserved'
00128                 ) );
00129         }
00130 
00134         public function testHandheld() {
00135                 $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array(
00136                         'handheldQuery' => '1',
00137                         'media' => 'handheld',
00138                         'expectedReturn' => '',
00139                         'message' => 'On request with handheld querystring and media is handheld, returns empty string'
00140                 ) );
00141 
00142                 $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array(
00143                         'handheldQuery' => '1',
00144                         'media' => 'screen',
00145                         'expectedReturn' => null,
00146                         'message' => 'On request with handheld querystring and media is screen, returns null'
00147                 ) );
00148 
00149                 // A bit counter-intuitively, $wgHandheldForIPhone should only matter if the query handheld is false or omitted
00150                 $this->assertTransformCssMediaCase( array(
00151                         'handheldQuery' => '0',
00152                         'media' => 'screen',
00153                         'handheldForIPhone' => true,
00154                         'expectedReturn' => 'screen and (min-device-width: 481px)',
00155                         'message' => 'With $wgHandheldForIPhone true, screen media type is transformed'
00156                 ) );
00157 
00158                 $this->assertTransformCssMediaCase( array(
00159                         'media' => 'handheld',
00160                         'handheldForIPhone' => true,
00161                         'expectedReturn' => 'handheld, only screen and (max-device-width: 480px)',
00162                         'message' => 'With $wgHandheldForIPhone true, handheld media type is transformed'
00163                 ) );
00164 
00165                 $this->assertTransformCssMediaCase( array(
00166                         'media' => 'handheld',
00167                         'handheldForIPhone' => false,
00168                         'expectedReturn' => 'handheld',
00169                         'message' => 'With $wgHandheldForIPhone false, handheld media type is preserved'
00170                 ) );
00171         }
00172 }