Beispiel #1
0
 /**
  * @dataProvider getCases
  */
 public function testParseCoordinates($parts, $result, $globe = 'earth')
 {
     $formatted = '"' . implode($parts, '|') . '"';
     $s = GeoData::parseCoordinates($parts, $globe);
     $val = $s->value;
     if ($result === false) {
         $this->assertFalse($s->isGood(), "Parsing of {$formatted} was expected to fail");
     } else {
         $msg = $s->isGood() ? '' : $s->getWikiText();
         $this->assertTrue($s->isGood(), "Parsing of {$formatted} was expected to succeed, but it failed: {$msg}");
         $this->assertTrue($val->equalsTo($result), "Parsing of {$formatted} was expected to yield something close to" . " ({$result->lat}, {$result->lon}), but yielded ({$val->lat}, {$val->lon})");
     }
 }
 /**
  * #coordinates parser function callback
  * 
  * @param Parser $parser
  * @param PPFrame $frame
  * @param Array $args
  * @return Mixed
  */
 public function coordinates($parser, $frame, $args)
 {
     if ($parser != $this->parser) {
         throw new MWException(__METHOD__ . '() called by wrong parser');
     }
     $this->output = $parser->getOutput();
     if (!isset($this->output->geoData)) {
         $this->output->geoData = new CoordinatesOutput();
     }
     $this->unnamed = array();
     $this->named = array();
     $first = trim($frame->expand(array_shift($args)));
     $this->addArg($first);
     foreach ($args as $arg) {
         $bits = $arg->splitArg();
         $value = trim($frame->expand($bits['value']));
         if ($bits['index'] === '') {
             $this->named[trim($frame->expand($bits['name']))] = $value;
         } else {
             $this->addArg($value);
         }
     }
     $this->parseTagArgs();
     $status = GeoData::parseCoordinates($this->unnamed, $this->named['globe']);
     if ($status->isGood()) {
         $coord = $status->value;
         $status = $this->applyTagArgs($coord);
         if ($status->isGood()) {
             $status = $this->applyCoord($coord);
             if ($status->isGood()) {
                 return '';
             }
         }
     }
     $parser->addTrackingCategory('geodata-broken-tags-category');
     $errorText = $this->errorText($status);
     if ($errorText == '<>') {
         // Error that doesn't require a message,
         // can't think of a better way to pass this condition
         return '';
     }
     return array("<span class=\"error\">{$errorText}</span>", 'noparse' => false);
 }