5 * @author Matthew Flaschen
9 * @todo factor tests in this class into providers and test methods
12 class OutputPageTest
extends MediaWikiTestCase
{
13 const SCREEN_MEDIA_QUERY
= 'screen and (min-width: 982px)';
14 const SCREEN_ONLY_MEDIA_QUERY
= 'only screen and (min-width: 982px)';
17 * Tests a particular case of transformCssMedia, using the given input, globals,
18 * expected return, and message
20 * Asserts that $expectedReturn is returned.
22 * options['printableQuery'] - value of query string for printable, or omitted for none
23 * options['handheldQuery'] - value of query string for handheld, or omitted for none
24 * options['media'] - passed into the method under the same name
25 * options['expectedReturn'] - expected return value
26 * options['message'] - PHPUnit message for assertion
28 * @param array $args key-value array of arguments as shown above
30 protected function assertTransformCssMediaCase( $args ) {
32 if ( isset( $args['printableQuery'] ) ) {
33 $queryData['printable'] = $args['printableQuery'];
36 if ( isset( $args['handheldQuery'] ) ) {
37 $queryData['handheld'] = $args['handheldQuery'];
40 $fauxRequest = new FauxRequest( $queryData, false );
41 $this->setMWGlobals( array(
42 'wgRequest' => $fauxRequest,
45 $actualReturn = OutputPage
::transformCssMedia( $args['media'] );
46 $this->assertSame( $args['expectedReturn'], $actualReturn, $args['message'] );
50 * Tests print requests
51 * @covers OutputPage::transformCssMedia
53 public function testPrintRequests() {
54 $this->assertTransformCssMediaCase( array(
55 'printableQuery' => '1',
57 'expectedReturn' => null,
58 'message' => 'On printable request, screen returns null'
61 $this->assertTransformCssMediaCase( array(
62 'printableQuery' => '1',
63 'media' => self
::SCREEN_MEDIA_QUERY
,
64 'expectedReturn' => null,
65 'message' => 'On printable request, screen media query returns null'
68 $this->assertTransformCssMediaCase( array(
69 'printableQuery' => '1',
70 'media' => self
::SCREEN_ONLY_MEDIA_QUERY
,
71 'expectedReturn' => null,
72 'message' => 'On printable request, screen media query with only returns null'
75 $this->assertTransformCssMediaCase( array(
76 'printableQuery' => '1',
78 'expectedReturn' => '',
79 'message' => 'On printable request, media print returns empty string'
84 * Tests screen requests, without either query parameter set
85 * @covers OutputPage::transformCssMedia
87 public function testScreenRequests() {
88 $this->assertTransformCssMediaCase( array(
90 'expectedReturn' => 'screen',
91 'message' => 'On screen request, screen media type is preserved'
94 $this->assertTransformCssMediaCase( array(
95 'media' => 'handheld',
96 'expectedReturn' => 'handheld',
97 'message' => 'On screen request, handheld media type is preserved'
100 $this->assertTransformCssMediaCase( array(
101 'media' => self
::SCREEN_MEDIA_QUERY
,
102 'expectedReturn' => self
::SCREEN_MEDIA_QUERY
,
103 'message' => 'On screen request, screen media query is preserved.'
106 $this->assertTransformCssMediaCase( array(
107 'media' => self
::SCREEN_ONLY_MEDIA_QUERY
,
108 'expectedReturn' => self
::SCREEN_ONLY_MEDIA_QUERY
,
109 'message' => 'On screen request, screen media query with only is preserved.'
112 $this->assertTransformCssMediaCase( array(
114 'expectedReturn' => 'print',
115 'message' => 'On screen request, print media type is preserved'
120 * Tests handheld behavior
121 * @covers OutputPage::transformCssMedia
123 public function testHandheld() {
124 $this->assertTransformCssMediaCase( array(
125 'handheldQuery' => '1',
126 'media' => 'handheld',
127 'expectedReturn' => '',
128 'message' => 'On request with handheld querystring and media is handheld, returns empty string'
131 $this->assertTransformCssMediaCase( array(
132 'handheldQuery' => '1',
134 'expectedReturn' => null,
135 'message' => 'On request with handheld querystring and media is screen, returns null'