Exemplo n.º 1
0
 public function testFormatterDoesNotThrowAnyWarnings()
 {
     $warnings = 0;
     try {
         $this->formatter->format('<html lang="en" dir="ltr"><head><title>My Website</title></head><body class="homepage"><div class="container"><h1 class="h1-title">H1 Title</h1><div class="body-content">Body Content</div></div></body></html>');
     } catch (\PHPUnit_Framework_Error_Warning $exception) {
         $warnings++;
     }
     $this->assertEquals(0, $warnings, 'Failed to assert that the formatter does not throw any exceptions');
 }
Exemplo n.º 2
0
 public function format($src)
 {
     $this->lineNumbers = false;
     $this->height = 0;
     $this->inline = true;
     return parent::format($src);
 }
Exemplo n.º 3
0
 /**
  * @dataProvider getHtmlData
  * @covers HtmlFormatter::getText
  */
 public function testTransform($input, $expected, $callback = false)
 {
     $input = self::normalize($input);
     $formatter = new HtmlFormatter(HtmlFormatter::wrapHTML($input));
     if ($callback) {
         $callback($formatter);
     }
     $formatter->filterContent();
     $html = $formatter->getText();
     $this->assertValidHtmlSnippet($html);
     $this->assertEquals(self::normalize($expected), self::normalize($html));
 }
Exemplo n.º 4
0
 /**
  * Replace Special:ApiHelp links with links to api.php
  *
  * @param string $html
  * @param string|null $helptitle Title to link to rather than api.php, must contain '$1'
  * @param array $localModules Keys are modules to link within the current page, values are ignored
  * @return string
  */
 public static function fixHelpLinks($html, $helptitle = null, $localModules = array())
 {
     $formatter = new HtmlFormatter($html);
     $doc = $formatter->getDoc();
     $xpath = new DOMXPath($doc);
     $nodes = $xpath->query('//a[@href][not(contains(@class,\'apihelp-linktrail\'))]');
     foreach ($nodes as $node) {
         $href = $node->getAttribute('href');
         do {
             $old = $href;
             $href = rawurldecode($href);
         } while ($old !== $href);
         if (preg_match('!Special:ApiHelp/([^&/|#]+)((?:#.*)?)!', $href, $m)) {
             if (isset($localModules[$m[1]])) {
                 $href = $m[2] === '' ? '#' . $m[1] : $m[2];
             } elseif ($helptitle !== null) {
                 $href = Title::newFromText(str_replace('$1', $m[1], $helptitle) . $m[2])->getFullURL();
             } else {
                 $href = wfAppendQuery(wfScript('api'), array('action' => 'help', 'modules' => $m[1])) . $m[2];
             }
             $node->setAttribute('href', $href);
             $node->removeAttribute('title');
         }
     }
     return $formatter->getText();
 }
Exemplo n.º 5
0
 public function getDoc()
 {
     $this->hasDoc = true;
     return parent::getDoc();
 }
 /**
  * Performs final transformations to mobile format and returns resulting HTML
  *
  * @param DOMElement|string|null $element ID of element to get HTML from or
  *   false to get it from the whole tree
  * @return string Processed HTML
  */
 public function getText($element = null)
 {
     if ($this->mainPage) {
         $element = $this->parseMainPage($this->getDoc());
     }
     $html = parent::getText($element);
     return $html;
 }
Exemplo n.º 7
0
 function ParseCSS($String)
 {
     do {
         $sReturn = $String;
         $String = str_replace('\\', '', HtmlFormatter::DecodeEntities($String));
         $String = preg_replace(array('%/\\*(.*?)\\*/%si', '/expression\\(/i'), array('', '('), $String);
         $String = preg_replace_callback('/((behavior|-moz-binding)(?>\\s*):(?>\\s*))?url\\((?>\\s*)(((["\'`])(.*?)\\5)|((?>[^)]+)))/si', create_function('$m', 'if(isset($m[7]))$t=7;else $t=6;' . 'return (\'url(\'.$m[5].HtmlFormatter::EscapeQuotes(HtmlFormatter::ParseProtocol($m[$t])).$m[5]);'), $String);
     } while ($sReturn != $String);
     return $sReturn;
 }
 /**
  * {@inheritDoc}
  */
 public function formatBatch(array $records)
 {
     return parent::formatBatch(array_reverse($records));
 }
Exemplo n.º 9
0
 /**
  * @covers Phossa\Shared\Message\Formatter\HtmlFormatter::formatMessage
  * @dataProvider dataProvider
  */
 public function testFormatMessage($template, $arguments, $expect)
 {
     $this->assertEquals($expect, $this->object->formatMessage($template, $arguments));
 }