5 * @author Matthew Flaschen
10 class OutputPageTest
extends MediaWikiTestCase
{
11 const SCREEN_MEDIA_QUERY
= 'screen and (min-width: 982px)';
12 const SCREEN_ONLY_MEDIA_QUERY
= 'only screen and (min-width: 982px)';
15 * Tests a particular case of transformCssMedia, using the given input, globals,
16 * expected return, and message
18 * Asserts that $expectedReturn is returned.
20 * options['printableQuery'] - value of query string for printable, or omitted for none
21 * options['handheldQuery'] - value of query string for handheld, or omitted for none
22 * options['media'] - passed into the method under the same name
23 * options['expectedReturn'] - expected return value
24 * options['message'] - PHPUnit message for assertion
26 * @param array $args key-value array of arguments as shown above
28 protected function assertTransformCssMediaCase( $args ) {
30 if ( isset( $args['printableQuery'] ) ) {
31 $queryData['printable'] = $args['printableQuery'];
34 if ( isset( $args['handheldQuery'] ) ) {
35 $queryData['handheld'] = $args['handheldQuery'];
38 $fauxRequest = new FauxRequest( $queryData, false );
39 $this->setMWGlobals( array(
40 'wgRequest' => $fauxRequest,
43 $actualReturn = OutputPage
::transformCssMedia( $args['media'] );
44 $this->assertSame( $args['expectedReturn'], $actualReturn, $args['message'] );
48 * Tests print requests
50 public function testPrintRequests() {
51 $this->assertTransformCssMediaCase( array(
52 'printableQuery' => '1',
54 'expectedReturn' => null,
55 'message' => 'On printable request, screen returns null'
58 $this->assertTransformCssMediaCase( array(
59 'printableQuery' => '1',
60 'media' => self
::SCREEN_MEDIA_QUERY
,
61 'expectedReturn' => null,
62 'message' => 'On printable request, screen media query returns null'
65 $this->assertTransformCssMediaCase( array(
66 'printableQuery' => '1',
67 'media' => self
::SCREEN_ONLY_MEDIA_QUERY
,
68 'expectedReturn' => null,
69 'message' => 'On printable request, screen media query with only returns null'
72 $this->assertTransformCssMediaCase( array(
73 'printableQuery' => '1',
75 'expectedReturn' => '',
76 'message' => 'On printable request, media print returns empty string'
81 * Tests screen requests, without either query parameter set
83 public function testScreenRequests() {
84 $this->assertTransformCssMediaCase( array(
86 'expectedReturn' => 'screen',
87 'message' => 'On screen request, screen media type is preserved'
90 $this->assertTransformCssMediaCase( array(
91 'media' => 'handheld',
92 'expectedReturn' => 'handheld',
93 'message' => 'On screen request, handheld media type is preserved'
96 $this->assertTransformCssMediaCase( array(
97 'media' => self
::SCREEN_MEDIA_QUERY
,
98 'expectedReturn' => self
::SCREEN_MEDIA_QUERY
,
99 'message' => 'On screen request, screen media query is preserved.'
102 $this->assertTransformCssMediaCase( array(
103 'media' => self
::SCREEN_ONLY_MEDIA_QUERY
,
104 'expectedReturn' => self
::SCREEN_ONLY_MEDIA_QUERY
,
105 'message' => 'On screen request, screen media query with only is preserved.'
108 $this->assertTransformCssMediaCase( array(
110 'expectedReturn' => 'print',
111 'message' => 'On screen request, print media type is preserved'
116 * Tests handheld behavior
118 public function testHandheld() {
119 $this->assertTransformCssMediaCase( array(
120 'handheldQuery' => '1',
121 'media' => 'handheld',
122 'expectedReturn' => '',
123 'message' => 'On request with handheld querystring and media is handheld, returns empty string'
126 $this->assertTransformCssMediaCase( array(
127 'handheldQuery' => '1',
129 'expectedReturn' => null,
130 'message' => 'On request with handheld querystring and media is screen, returns null'