test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / OutputPageTest.php
blob56bb0fcef2fedc728c1b297622ffd11d553ab60c
1 <?php
3 /**
5 * @author Matthew Flaschen
7 * @group Output
9 */
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)';
14 /**
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 ) {
29 $queryData = array();
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,
41 ) );
43 $actualReturn = OutputPage::transformCssMedia( $args['media'] );
44 $this->assertSame( $args['expectedReturn'], $actualReturn, $args['message'] );
47 /**
48 * Tests print requests
50 public function testPrintRequests() {
51 $this->assertTransformCssMediaCase( array(
52 'printableQuery' => '1',
53 'media' => 'screen',
54 'expectedReturn' => null,
55 'message' => 'On printable request, screen returns null'
56 ) );
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'
63 ) );
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'
70 ) );
72 $this->assertTransformCssMediaCase( array(
73 'printableQuery' => '1',
74 'media' => 'print',
75 'expectedReturn' => '',
76 'message' => 'On printable request, media print returns empty string'
77 ) );
80 /**
81 * Tests screen requests, without either query parameter set
83 public function testScreenRequests() {
84 $this->assertTransformCssMediaCase( array(
85 'media' => 'screen',
86 'expectedReturn' => 'screen',
87 'message' => 'On screen request, screen media type is preserved'
88 ) );
90 $this->assertTransformCssMediaCase( array(
91 'media' => 'handheld',
92 'expectedReturn' => 'handheld',
93 'message' => 'On screen request, handheld media type is preserved'
94 ) );
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.'
100 ) );
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.'
106 ) );
108 $this->assertTransformCssMediaCase( array(
109 'media' => 'print',
110 'expectedReturn' => 'print',
111 'message' => 'On screen request, print media type is preserved'
112 ) );
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'
124 ) );
126 $this->assertTransformCssMediaCase( array(
127 'handheldQuery' => '1',
128 'media' => 'screen',
129 'expectedReturn' => null,
130 'message' => 'On request with handheld querystring and media is screen, returns null'
131 ) );