/**
  * @dataProvider queryErrorProvider
  */
 public function testGetFormattedErrorString($errors, $expected)
 {
     $query = $this->getMockBuilder('\\SMWQuery')->disableOriginalConstructor()->getMock();
     $query->expects($this->atLeastOnce())->method('getErrors')->will($this->returnValue($errors));
     $instance = new HtmlContentBuilder();
     $this->assertEquals($expected, $instance->getFormattedErrorString($query));
 }
Exemplo n.º 2
0
 /**
  * TODO: document
  */
 protected function makeHTMLResult()
 {
     global $wgOut;
     // TODO: hold into account $smwgAutocompleteInSpecialAsk
     $result = '';
     $res = null;
     $htmlContentBuilder = new HtmlContentBuilder();
     // build parameter strings for URLs, based on current settings
     $urlArgs['q'] = $this->m_querystring;
     $tmp_parray = array();
     foreach ($this->m_params as $key => $value) {
         if (!in_array($key, array('sort', 'order', 'limit', 'offset', 'title'))) {
             $tmp_parray[$key] = $value;
         }
     }
     $urlArgs['p'] = SMWInfolink::encodeParameters($tmp_parray);
     $printoutstring = '';
     $duration = 0;
     $navigation = '';
     $queryobj = null;
     /**
      * @var PrintRequest $printout
      */
     foreach ($this->m_printouts as $printout) {
         $printoutstring .= $printout->getSerialisation(true) . "\n";
     }
     if ($printoutstring !== '') {
         $urlArgs['po'] = $printoutstring;
     }
     if (array_key_exists('sort', $this->m_params)) {
         $urlArgs['sort'] = $this->m_params['sort'];
     }
     if (array_key_exists('order', $this->m_params)) {
         $urlArgs['order'] = $this->m_params['order'];
     }
     if ($this->getRequest()->getCheck('bTitle')) {
         $urlArgs['bTitle'] = $this->getRequest()->getVal('bTitle');
         $urlArgs['bMsg'] = $this->getRequest()->getVal('bMsg');
     }
     if ($this->m_querystring !== '') {
         // FIXME: this is a hack
         SMWQueryProcessor::addThisPrintout($this->m_printouts, $this->m_params);
         $params = SMWQueryProcessor::getProcessedParams($this->m_params, $this->m_printouts);
         $this->m_params['format'] = $params['format']->getValue();
         $this->params = $params;
         $queryobj = SMWQueryProcessor::createQuery($this->m_querystring, $params, SMWQueryProcessor::SPECIAL_PAGE, $this->m_params['format'], $this->m_printouts);
         /**
          * @var SMWQueryResult $res
          */
         // Determine query results
         $duration = microtime(true);
         $res = $this->getStoreFromParams($params)->getQueryResult($queryobj);
         $duration = number_format(microtime(true) - $duration, 4, '.', '');
         // Try to be smart for rss/ical if no description/title is given and we have a concept query:
         if ($this->m_params['format'] == 'rss') {
             $desckey = 'rssdescription';
             $titlekey = 'rsstitle';
         } elseif ($this->m_params['format'] == 'icalendar') {
             $desckey = 'icalendardescription';
             $titlekey = 'icalendartitle';
         } else {
             $desckey = false;
         }
         if ($desckey && $queryobj->getDescription() instanceof SMWConceptDescription && (!isset($this->m_params[$desckey]) || !isset($this->m_params[$titlekey]))) {
             $concept = $queryobj->getDescription()->getConcept();
             if (!isset($this->m_params[$titlekey])) {
                 $this->m_params[$titlekey] = $concept->getText();
             }
             if (!isset($this->m_params[$desckey])) {
                 // / @bug The current SMWStore will never return SMWConceptValue (an SMWDataValue) here; it might return SMWDIConcept (an SMWDataItem)
                 $dv = end(\SMW\StoreFactory::getStore()->getPropertyValues(SMWWikiPageValue::makePageFromTitle($concept), new SMW\DIProperty('_CONC')));
                 if ($dv instanceof SMWConceptValue) {
                     $this->m_params[$desckey] = $dv->getDocu();
                 }
             }
         }
         $printer = SMWQueryProcessor::getResultPrinter($this->m_params['format'], SMWQueryProcessor::SPECIAL_PAGE);
         $printer->setShowErrors(false);
         global $wgRequest;
         $hidequery = $wgRequest->getVal('eq') == 'no';
         if (!$printer->isExportFormat()) {
             if ($res->getCount() > 0) {
                 if ($this->m_editquery) {
                     $urlArgs['eq'] = 'yes';
                 } elseif ($hidequery) {
                     $urlArgs['eq'] = 'no';
                 }
                 $navigation = $this->getNavigationBar($res, $urlArgs);
                 $query_result = $printer->getResult($res, $params, SMW_OUTPUT_HTML);
                 if (is_array($query_result)) {
                     $result .= $query_result[0];
                 } else {
                     $result .= $query_result;
                 }
             } else {
                 $result = Html::element('div', array('class' => 'smw-callout smw-callout-info'), wfMessage('smw_result_noresults')->escaped());
             }
         }
     }
     // FileExport will override the header and cause issues during the unit
     // test when fetching the output stream therefore use the plain output
     if (defined('MW_PHPUNIT_TEST') && isset($printer) && $printer->isExportFormat()) {
         $result = $printer->getResult($res, $params, SMW_OUTPUT_FILE);
         $printer = null;
     }
     if (isset($printer) && $printer->isExportFormat()) {
         $wgOut->disable();
         /**
          * @var SMWIExportPrinter $printer
          */
         $printer->outputAsFile($res, $params);
     } else {
         if ($this->m_querystring) {
             $this->getOutput()->setHTMLtitle($this->m_querystring);
         } else {
             $this->getOutput()->setHTMLtitle(wfMessage('ask')->text());
         }
         $urlArgs['offset'] = $this->m_params['offset'];
         $urlArgs['limit'] = $this->m_params['limit'];
         $isFromCache = $res !== null ? $res->isFromCache() : false;
         $result = $this->getInputForm($printoutstring, wfArrayToCGI($urlArgs), $navigation, $duration, $isFromCache) . $htmlContentBuilder->getFormattedErrorString($queryobj) . $result;
         $this->getOutput()->addHTML($result);
     }
 }