From 91e194556c52d2f354344f930419eef2dd6267f0 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 4 Sep 2013 05:51:59 +0200 Subject: Update to MediaWiki 1.21.2 --- tests/phpunit/includes/OutputPageTest.php | 172 ++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 tests/phpunit/includes/OutputPageTest.php (limited to 'tests/phpunit/includes/OutputPageTest.php') diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php new file mode 100644 index 00000000..4084fb17 --- /dev/null +++ b/tests/phpunit/includes/OutputPageTest.php @@ -0,0 +1,172 @@ +setMWGlobals( array( + 'wgRequest' => $fauxRequest, + 'wgHandheldForIPhone' => $args['handheldForIPhone'] + ) ); + + $actualReturn = OutputPage::transformCssMedia( $args['media'] ); + $this->assertSame( $args['expectedReturn'], $actualReturn, $args['message'] ); + } + + /** + * Tests a case of transformCssMedia with both values of wgHandheldForIPhone. + * Used to verify that behavior is orthogonal to that option. + * + * If the value of wgHandheldForIPhone should matter, use assertTransformCssMediaCase. + * + * @param array $args key-value array of arguments as shown in assertTransformCssMediaCase. + * Will be mutated. + */ + protected function assertTransformCssMediaCaseWithBothHandheldForIPhone( $args ) { + $message = $args['message']; + foreach ( array( true, false ) as $handheldForIPhone ) { + $args['handheldForIPhone'] = $handheldForIPhone; + $stringHandheldForIPhone = var_export( $handheldForIPhone, true ); + $args['message'] = "$message. \$wgHandheldForIPhone was $stringHandheldForIPhone"; + $this->assertTransformCssMediaCase( $args ); + } + } + + /** + * Tests print requests + */ + public function testPrintRequests() { + $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array( + 'printableQuery' => '1', + 'media' => 'screen', + 'expectedReturn' => null, + 'message' => 'On printable request, screen returns null' + ) ); + + $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array( + 'printableQuery' => '1', + 'media' => self::SCREEN_MEDIA_QUERY, + 'expectedReturn' => null, + 'message' => 'On printable request, screen media query returns null' + ) ); + + $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array( + 'printableQuery' => '1', + 'media' => self::SCREEN_ONLY_MEDIA_QUERY, + 'expectedReturn' => null, + 'message' => 'On printable request, screen media query with only returns null' + ) ); + + $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array( + 'printableQuery' => '1', + 'media' => 'print', + 'expectedReturn' => '', + 'message' => 'On printable request, media print returns empty string' + ) ); + } + + /** + * Tests screen requests, without either query parameter set + */ + public function testScreenRequests() { + $this->assertTransformCssMediaCase( array( + 'handheldForIPhone' => false, + 'media' => 'screen', + 'expectedReturn' => 'screen', + 'message' => 'On screen request, with handheldForIPhone false, screen media type is preserved' + ) ); + + $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array( + 'media' => self::SCREEN_MEDIA_QUERY, + 'expectedReturn' => self::SCREEN_MEDIA_QUERY, + 'message' => 'On screen request, screen media query is preserved.' + ) ); + + $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array( + 'media' => self::SCREEN_ONLY_MEDIA_QUERY, + 'expectedReturn' => self::SCREEN_ONLY_MEDIA_QUERY, + 'message' => 'On screen request, screen media query with only is preserved.' + ) ); + + $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array( + 'media' => 'print', + 'expectedReturn' => 'print', + 'message' => 'On screen request, print media type is preserved' + ) ); + } + + /** + * Tests handheld and wgHandheldForIPhone behavior + */ + public function testHandheld() { + $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array( + 'handheldQuery' => '1', + 'media' => 'handheld', + 'expectedReturn' => '', + 'message' => 'On request with handheld querystring and media is handheld, returns empty string' + ) ); + + $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array( + 'handheldQuery' => '1', + 'media' => 'screen', + 'expectedReturn' => null, + 'message' => 'On request with handheld querystring and media is screen, returns null' + ) ); + + // A bit counter-intuitively, $wgHandheldForIPhone should only matter if the query handheld is false or omitted + $this->assertTransformCssMediaCase( array( + 'handheldQuery' => '0', + 'media' => 'screen', + 'handheldForIPhone' => true, + 'expectedReturn' => 'screen and (min-device-width: 481px)', + 'message' => 'With $wgHandheldForIPhone true, screen media type is transformed' + ) ); + + $this->assertTransformCssMediaCase( array( + 'media' => 'handheld', + 'handheldForIPhone' => true, + 'expectedReturn' => 'handheld, only screen and (max-device-width: 480px)', + 'message' => 'With $wgHandheldForIPhone true, handheld media type is transformed' + ) ); + + $this->assertTransformCssMediaCase( array( + 'media' => 'handheld', + 'handheldForIPhone' => false, + 'expectedReturn' => 'handheld', + 'message' => 'With $wgHandheldForIPhone false, handheld media type is preserved' + ) ); + } +} -- cgit v1.2.3-54-g00ecf