MediaWiki  REL1_22
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 
00028     protected function assertTransformCssMediaCase( $args ) {
00029         $queryData = array();
00030         if ( isset( $args['printableQuery'] ) ) {
00031             $queryData['printable'] = $args['printableQuery'];
00032         }
00033 
00034         if ( isset( $args['handheldQuery'] ) ) {
00035             $queryData['handheld'] = $args['handheldQuery'];
00036         }
00037 
00038         $fauxRequest = new FauxRequest( $queryData, false );
00039         $this->setMWGlobals( array(
00040             'wgRequest' => $fauxRequest,
00041         ) );
00042 
00043         $actualReturn = OutputPage::transformCssMedia( $args['media'] );
00044         $this->assertSame( $args['expectedReturn'], $actualReturn, $args['message'] );
00045     }
00046 
00050     public function testPrintRequests() {
00051         $this->assertTransformCssMediaCase( array(
00052             'printableQuery' => '1',
00053             'media' => 'screen',
00054             'expectedReturn' => null,
00055             'message' => 'On printable request, screen returns null'
00056         ) );
00057 
00058         $this->assertTransformCssMediaCase( array(
00059             'printableQuery' => '1',
00060             'media' => self::SCREEN_MEDIA_QUERY,
00061             'expectedReturn' => null,
00062             'message' => 'On printable request, screen media query returns null'
00063         ) );
00064 
00065         $this->assertTransformCssMediaCase( array(
00066             'printableQuery' => '1',
00067             'media' => self::SCREEN_ONLY_MEDIA_QUERY,
00068             'expectedReturn' => null,
00069             'message' => 'On printable request, screen media query with only returns null'
00070         ) );
00071 
00072         $this->assertTransformCssMediaCase( array(
00073             'printableQuery' => '1',
00074             'media' => 'print',
00075             'expectedReturn' => '',
00076             'message' => 'On printable request, media print returns empty string'
00077         ) );
00078     }
00079 
00083     public function testScreenRequests() {
00084         $this->assertTransformCssMediaCase( array(
00085             'media' => 'screen',
00086             'expectedReturn' => 'screen',
00087             'message' => 'On screen request, screen media type is preserved'
00088         ) );
00089 
00090         $this->assertTransformCssMediaCase( array(
00091             'media' => 'handheld',
00092             'expectedReturn' => 'handheld',
00093             'message' => 'On screen request, handheld media type is preserved'
00094         ) );
00095 
00096         $this->assertTransformCssMediaCase( array(
00097             'media' => self::SCREEN_MEDIA_QUERY,
00098             'expectedReturn' => self::SCREEN_MEDIA_QUERY,
00099             'message' => 'On screen request, screen media query is preserved.'
00100         ) );
00101 
00102         $this->assertTransformCssMediaCase( array(
00103             'media' => self::SCREEN_ONLY_MEDIA_QUERY,
00104             'expectedReturn' => self::SCREEN_ONLY_MEDIA_QUERY,
00105             'message' => 'On screen request, screen media query with only is preserved.'
00106         ) );
00107 
00108         $this->assertTransformCssMediaCase( array(
00109             'media' => 'print',
00110             'expectedReturn' => 'print',
00111             'message' => 'On screen request, print media type is preserved'
00112         ) );
00113     }
00114 
00118     public function testHandheld() {
00119         $this->assertTransformCssMediaCase( array(
00120             'handheldQuery' => '1',
00121             'media' => 'handheld',
00122             'expectedReturn' => '',
00123             'message' => 'On request with handheld querystring and media is handheld, returns empty string'
00124         ) );
00125 
00126         $this->assertTransformCssMediaCase( array(
00127             'handheldQuery' => '1',
00128             'media' => 'screen',
00129             'expectedReturn' => null,
00130             'message' => 'On request with handheld querystring and media is screen, returns null'
00131         ) );
00132     }
00133 }