/** * Tests a particular case of transformCssMedia, using the given input, globals, * expected return, and message * * Asserts that $expectedReturn is returned. * * options['printableQuery'] - value of query string for printable, or omitted for none * options['handheldQuery'] - value of query string for handheld, or omitted for none * options['handheldForIPhone'] - value of the $wgHandheldForIPhone global * options['media'] - passed into the method under the same name * options['expectedReturn'] - expected return value * options['message'] - PHPUnit message for assertion * * @param array $args key-value array of arguments as shown above */ protected function assertTransformCssMediaCase($args) { $queryData = array(); if (isset($args['printableQuery'])) { $queryData['printable'] = $args['printableQuery']; } if (isset($args['handheldQuery'])) { $queryData['handheld'] = $args['handheldQuery']; } $fauxRequest = new FauxRequest($queryData, false); $this->setMWGlobals(array('wgRequest' => $fauxRequest, 'wgHandheldForIPhone' => $args['handheldForIPhone'])); $actualReturn = OutputPage::transformCssMedia($args['media']); $this->assertSame($args['expectedReturn'], $actualReturn, $args['message']); }
/** * Combines an associative array mapping media type to CSS into a * single stylesheet with "@media" blocks. * * @param array $stylePairs Array keyed by media type containing (arrays of) CSS strings * @return array */ public static function makeCombinedStyles(array $stylePairs) { $out = array(); foreach ($stylePairs as $media => $styles) { // ResourceLoaderFileModule::getStyle can return the styles // as a string or an array of strings. This is to allow separation in // the front-end. $styles = (array) $styles; foreach ($styles as $style) { $style = trim($style); // Don't output an empty "@media print { }" block (bug 40498) if ($style !== '') { // Transform the media type based on request params and config // The way that this relies on $wgRequest to propagate request params is slightly evil $media = OutputPage::transformCssMedia($media); if ($media === '' || $media == 'all') { $out[] = $style; } elseif (is_string($media)) { $out[] = "@media {$media} {\n" . str_replace("\n", "\n\t", "\t" . $style) . "}"; } // else: skip } } } return $out; }
/** * Combines an associative array mapping media type to CSS into a * single stylesheet with @media blocks. * * @param $styles Array: List of CSS strings keyed by media type * * @return string */ public static function makeCombinedStyles(array $styles) { $out = ''; foreach ($styles as $media => $style) { // Transform the media type based on request params and config // The way that this relies on $wgRequest to propagate request params is slightly evil $media = OutputPage::transformCssMedia($media); if ($media === null) { // Skip } elseif ($media === '' || $media == 'all') { // Don't output invalid or frivolous @media statements $out .= "{$style}\n"; } else { $out .= "@media {$media} {\n" . str_replace("\n", "\n\t", "\t" . $style) . "\n}\n"; } } return $out; }