Exemplo n.º 1
0
 /**
  * @see ValueParserTestBase::validInputProvider
  */
 public function validInputProvider()
 {
     $gregorian = 'http://www.wikidata.org/entity/Q1985727';
     $julian = 'http://www.wikidata.org/entity/Q1985786';
     $julianOpts = new ParserOptions();
     $julianOpts->setOption(IsoTimestampParser::OPT_CALENDAR, $julian);
     $gregorianOpts = new ParserOptions();
     $gregorianOpts->setOption(IsoTimestampParser::OPT_CALENDAR, $gregorian);
     $prec10aOpts = new ParserOptions();
     $prec10aOpts->setOption(IsoTimestampParser::OPT_PRECISION, TimeValue::PRECISION_YEAR10);
     $precDayOpts = new ParserOptions();
     $precDayOpts->setOption(IsoTimestampParser::OPT_PRECISION, TimeValue::PRECISION_DAY);
     $precSecondOpts = new ParserOptions();
     $precSecondOpts->setOption(IsoTimestampParser::OPT_PRECISION, TimeValue::PRECISION_SECOND);
     $valid = array('+0000000000002013-07-16T00:00:00Z' => array('+2013-07-16T00:00:00Z', TimeValue::PRECISION_DAY), '+0000000000002013-07-00T00:00:00Z' => array('+2013-07-00T00:00:00Z', TimeValue::PRECISION_MONTH), '+0000000000002013-00-00T00:00:00Z' => array('+2013-00-00T00:00:00Z', TimeValue::PRECISION_YEAR), '+0000000000000000-00-00T00:00:00Z' => array('+0000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR, $julian), '+0000000000002000-00-00T00:00:00Z' => array('+2000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR), '+0000000000008000-00-00T00:00:00Z' => array('+8000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1K), '+0000000000020000-00-00T00:00:00Z' => array('+20000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR10K), '+0000000000200000-00-00T00:00:00Z' => array('+200000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR100K), '+0000000002000000-00-00T00:00:00Z' => array('+2000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1M), '+0000000020000000-00-00T00:00:00Z' => array('+20000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR10M), '+0000000200000000-00-00T00:00:00Z' => array('+200000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR100M), '+0000002000000000-00-00T00:00:00Z' => array('+2000000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1G), '+0000020000000000-00-00T00:00:00Z' => array('+20000000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1G), '+0000200000000000-00-00T00:00:00Z' => array('+200000000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1G), '+0002000000000000-00-00T00:00:00Z' => array('+2000000000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1G), '+0020000000000000-00-00T00:00:00Z' => array('+20000000000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1G), '+0200000000000000-00-00T00:00:00Z' => array('+200000000000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1G), '+2000000000000000-00-00T00:00:00Z' => array('+2000000000000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1G), '-2000000000000000-00-00T00:00:00Z' => array('-2000000000000000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR1G, $julian), '+0000000000002013-07-16T00:00:00Z (Gregorian)' => array('+2013-07-16T00:00:00Z', TimeValue::PRECISION_DAY), '+0000000000000000-01-01T00:00:00Z (Gregorian)' => array('+0000-01-01T00:00:00Z', TimeValue::PRECISION_DAY), '+0000000000002001-01-14T00:00:00Z (Julian)' => array('+2001-01-14T00:00:00Z', TimeValue::PRECISION_DAY, $julian), '+0000000000010000-01-01T00:00:00Z (Gregorian)' => array('+10000-01-01T00:00:00Z', TimeValue::PRECISION_DAY), '-0000000000000001-01-01T00:00:00Z (Gregorian)' => array('-0001-01-01T00:00:00Z', TimeValue::PRECISION_DAY, $gregorian), '-00000000001-01-01T00:00:00Z (Gregorian)' => array('-0001-01-01T00:00:00Z', TimeValue::PRECISION_DAY, $gregorian, $julianOpts), '-00000000001-01-01T00:00:00Z (Julian)' => array('-0001-01-01T00:00:00Z', TimeValue::PRECISION_DAY, $julian, $gregorianOpts), '-000001-01-01T00:00:00Z (Gregorian)' => array('-0001-01-01T00:00:00Z', TimeValue::PRECISION_DAY, $gregorian), '-1-01-01T00:00:00Z (Gregorian)' => array('-0001-01-01T00:00:00Z', TimeValue::PRECISION_DAY, $gregorian), '-1-01-02T00:00:00Z' => array('-0001-01-02T00:00:00Z', TimeValue::PRECISION_DAY, $gregorian, $gregorianOpts), '+2001-01-03T00:00:00Z' => array('+2001-01-03T00:00:00Z', TimeValue::PRECISION_DAY, $julian, $julianOpts), '-1-01-04T00:00:00Z' => array('-0001-01-04T00:00:00Z', TimeValue::PRECISION_YEAR10, $julian, $prec10aOpts), '-1-01-05T00:00:00Z' => array('-0001-01-05T00:00:00Z', TimeValue::PRECISION_DAY, $julian), '+1999-00-00T00:00:00Z' => array('+1999-00-00T00:00:00Z', TimeValue::PRECISION_YEAR), '+2000-00-00T00:00:00Z' => array('+2000-00-00T00:00:00Z', TimeValue::PRECISION_YEAR), '+2010-00-00T00:00:00Z' => array('+2010-00-00T00:00:00Z', TimeValue::PRECISION_YEAR), '2015-01-01T00:00:00Z' => array('+2015-01-01T00:00:00Z', TimeValue::PRECISION_DAY), '2015-01-01T00:00:00' => array('+2015-01-01T00:00:00Z', TimeValue::PRECISION_DAY), "−2015-01-01T00:00:00" => array('-2015-01-01T00:00:00Z', TimeValue::PRECISION_DAY, $julian), '2015-01-01T161718' => array('+0000000000002015-01-01T16:17:18Z', TimeValue::PRECISION_SECOND), '2015-01-01T1617' => array('+0000000000002015-01-01T16:17:00Z', TimeValue::PRECISION_MINUTE), '2015-01-01T00:00' => array('+2015-01-01T00:00:00Z', TimeValue::PRECISION_DAY), '2015-01-01' => array('+2015-01-01T00:00:00Z', TimeValue::PRECISION_DAY), '60-01-01' => array('+0060-01-01T00:00:00Z', TimeValue::PRECISION_DAY, $julian), '32-01-01' => array('+0032-01-01T00:00:00Z', TimeValue::PRECISION_DAY, $julian), '1-01-01T00:00' => array('+0001-01-01T00:00:00Z', TimeValue::PRECISION_DAY, $julian), '001-01-01' => array('+0001-01-01T00:00:00Z', TimeValue::PRECISION_DAY, $julian), '-01-02-03' => array('-0001-02-03T00:00:00Z', TimeValue::PRECISION_DAY, $julian), '+01-02-03' => array('+0001-02-03T00:00:00Z', TimeValue::PRECISION_DAY, $julian), '2015-01-00' => array('+2015-01-00T00:00:00Z', TimeValue::PRECISION_MONTH), '2015-00-00' => array('+2015-00-00T00:00:00Z', TimeValue::PRECISION_YEAR), '+2015-01-01T00:00:61Z' => array('+2015-01-01T00:00:61Z', TimeValue::PRECISION_SECOND), '+0000000000000012-12-00T00:00:00Z' => array('+0012-12-00T00:00:00Z', TimeValue::PRECISION_MONTH, $julian, $precDayOpts), '+2015-01-01T00:00:00Z' => array('+2015-01-01T00:00:00Z', TimeValue::PRECISION_SECOND, $gregorian, $precSecondOpts), '1583-01-01' => array('+1583-01-01T00:00:00Z', TimeValue::PRECISION_DAY, $gregorian), '1582-08-01' => array('+1582-08-01T00:00:00Z', TimeValue::PRECISION_DAY, $julian));
     $argLists = array();
     foreach ($valid as $key => $value) {
         $timestamp = $value[0];
         $precision = isset($value[1]) ? $value[1] : TimeValue::PRECISION_DAY;
         $calendarModel = isset($value[2]) ? $value[2] : $gregorian;
         $options = isset($value[3]) ? $value[3] : null;
         $argLists[] = array((string) $key, new TimeValue($timestamp, 0, 0, 0, $precision, $calendarModel), new IsoTimestampParser(new CalendarModelParser($options), $options));
     }
     return $argLists;
 }
 public function testDigitGroupSeparatorOption()
 {
     $options = new ParserOptions();
     $options->setOption(YearTimeParser::OPT_DIGIT_GROUP_SEPARATOR, '.');
     $parser = new YearTimeParser(null, $options);
     $timeValue = $parser->parse('-19.000');
     $this->assertSame('-19000-00-00T00:00:00Z', $timeValue->getTime());
 }
Exemplo n.º 3
0
 /**
  * @return MonthNameUnlocalizer
  */
 public function getMonthNameUnlocalizer()
 {
     $languageCode = $this->options->getOption(ValueParser::OPT_LANG);
     if ($languageCode === self::CANONICAL_LANGUAGE_CODE) {
         $replacements = array();
     } else {
         $replacements = $this->monthNameProvider->getMonthNameReplacements($languageCode, self::CANONICAL_LANGUAGE_CODE);
     }
     return new MonthNameUnlocalizer($replacements);
 }
Exemplo n.º 4
0
 public function testSetAndGetOptions()
 {
     /**
      * @var StringValueParser $parser
      */
     $parser = $this->getInstance();
     $parser->setOptions(new ParserOptions());
     $this->assertEquals(new ParserOptions(), $parser->getOptions());
     $options = new ParserOptions();
     $options->setOption('~=[,,_,,]:3', '~=[,,_,,]:3');
     $parser->setOptions($options);
     $this->assertEquals($options, $parser->getOptions());
 }
 private function newTimeParserFactory($languageCode = 'en')
 {
     $options = new ParserOptions();
     $options->setOption(ValueParser::OPT_LANG, $languageCode);
     $monthNameProvider = $this->getMock('Wikibase\\Repo\\Parsers\\MonthNameProvider');
     $monthNameProvider->expects($this->any())->method('getMonthNameReplacements')->will($this->returnCallback(function ($languageCode, $baseLanguageCode) {
         $replacements = array();
         for ($i = 1; $i <= 12; $i++) {
             $canonical = $baseLanguageCode . 'Month' . $i;
             $replacements[$languageCode . 'Month' . $i] = $canonical;
             $replacements[$languageCode . 'Month' . $i . 'Gen'] = $canonical;
         }
         return $replacements;
     }));
     return new TimeParserFactory($options, $monthNameProvider);
 }
 /**
  * @return string
  */
 private function getDigitGroupSeparator()
 {
     $languageCode = $this->options->getOption(ValueParser::OPT_LANG);
     $language = Language::factory($languageCode);
     $separatorMap = $language->separatorTransformTable();
     $canonical = YearTimeParser::CANONICAL_DIGIT_GROUP_SEPARATOR;
     return isset($separatorMap[$canonical]) ? $separatorMap[$canonical] : $canonical;
 }
Exemplo n.º 7
0
 /**
  * @dataProvider conflictingUnitOptionProvider
  */
 public function testConflictingUnitOption($value, $unit)
 {
     $options = new ParserOptions();
     $options->setOption(QuantityParser::OPT_UNIT, $unit);
     $parser = $this->getQuantityParser($options);
     $this->setExpectedException('ValueParsers\\ParseException');
     $parser->parse($value);
 }
Exemplo n.º 8
0
 /**
  * @see ValueParserTestBase::getInstance
  *
  * @return CalendarModelParser
  */
 protected function getInstance()
 {
     $options = new ParserOptions();
     $options->setOption(CalendarModelParser::OPT_CALENDAR_MODEL_URIS, array('Localized' => 'Unlocalized'));
     return new CalendarModelParser($options);
 }
 /**
  * @param string|null $optionsParam
  *
  * @return ParserOptions
  */
 private function getOptionsObject($optionsParam)
 {
     $parserOptions = new ParserOptions();
     $parserOptions->setOption(ValueParser::OPT_LANG, $this->getLanguage()->getCode());
     if (is_string($optionsParam) && $optionsParam !== '') {
         $options = json_decode($optionsParam, true);
         if (!is_array($options)) {
             $this->errorReporter->dieError('Malformed options parameter', 'malformed-options');
         }
         foreach ($options as $name => $value) {
             $parserOptions->setOption($name, $value);
         }
     }
     return $parserOptions;
 }
 public function testDefaultOption()
 {
     $options = array('foo' => 42, 'bar' => 4.2, 'baz' => array('o_O', false, null, '42' => 42, array()));
     $parserOptions = new ParserOptions($options);
     foreach ($options as $option => $value) {
         $parserOptions->defaultOption($option, 9001);
         $this->assertEquals(serialize($value), serialize($parserOptions->getOption($option)), 'Defaulting a set option should not affect its value');
     }
     $defaults = array('N' => 42, 'y' => 4.2, 'a' => false, 'n' => array('42' => 42, array('')));
     foreach ($defaults as $option => $value) {
         $parserOptions->defaultOption($option, $value);
         $this->assertEquals(serialize($value), serialize($parserOptions->getOption($option)), 'Defaulting a not set option should affect its value');
     }
 }
 /**
  * Shortcut to $this->options->defaultOption.
  *
  * @since 0.1
  *
  * @param string $option
  * @param mixed $default
  */
 protected final function defaultOption($option, $default)
 {
     $this->options->defaultOption($option, $default);
 }