public function provideDataTypeValidation()
 {
     $latLonValue = new LatLongValue(0, 0);
     $wikidataUri = 'http://www.wikidata.org/entity/';
     $cases = array(array('wikibase-item', 'q8', false, 'Expected EntityId, string supplied'), array('wikibase-item', new StringValue('q8'), false, 'Expected EntityId, StringValue supplied'), array('wikibase-item', new EntityIdValue(new ItemId('q8')), true, 'existing entity'), array('wikibase-item', new EntityIdValue(new ItemId('q3')), false, 'missing entity'), array('wikibase-item', new EntityIdValue(new PropertyId('p8')), false, 'not an item'), array('wikibase-property', new EntityIdValue(new PropertyId('p8')), true, 'existing entity'), array('wikibase-property', new EntityIdValue(new ItemId('q8')), false, 'not a property'), array('wikibase-entity', new EntityIdValue(new PropertyId('p8')), true, 'existing entity'), array('wikibase-entity', new EntityIdValue(new ItemId('q8')), true, 'existing entity'), array('wikibase-entity', new EntityIdValue(new ItemId('q3')), false, 'missing entity'), array('wikibase-entity', new StringValue('q8'), false, 'Expected EntityId, StringValue supplied'), array('commonsMedia', 'Foo.jpg', false, 'StringValue expected, string supplied'), array('commonsMedia', new NumberValue(7), false, 'StringValue expected'), array('commonsMedia', new StringValue(''), false, 'empty string should be invalid'), array('commonsMedia', new StringValue(str_repeat('x', 237) . '.jpg'), false, 'name too long'), array('commonsMedia', new StringValue('Foo'), false, 'no file extension'), array('commonsMedia', new StringValue('Foo.a'), false, 'file extension to short'), array('commonsMedia', new StringValue('Foo.jpg'), true, 'this should be good'), array('commonsMedia', new StringValue("a\na.jpg"), false, 'illegal character: newline'), array('commonsMedia', new StringValue('a[a.jpg'), false, 'illegal character: square bracket'), array('commonsMedia', new StringValue('a]a.jpg'), false, 'illegal character: square bracket'), array('commonsMedia', new StringValue('a{a.jpg'), false, 'illegal character: curly bracket'), array('commonsMedia', new StringValue('a}a.jpg'), false, 'illegal character: curly bracket'), array('commonsMedia', new StringValue('a|a.jpg'), false, 'illegal character: pipe'), array('commonsMedia', new StringValue('Foo#bar.jpg'), false, 'illegal character: hash'), array('commonsMedia', new StringValue('Foo:bar.jpg'), false, 'illegal character: colon'), array('commonsMedia', new StringValue('Foo/bar.jpg'), false, 'illegal character: slash'), array('commonsMedia', new StringValue('Foo\\bar.jpg'), false, 'illegal character: backslash'), array('commonsMedia', new StringValue('Äöü.jpg'), true, 'Unicode support'), array('commonsMedia', new StringValue(' Foo.jpg'), false, 'media name with leading space'), array('commonsMedia', new StringValue('Foo.jpg '), false, 'media name with trailing space'), array('commonsMedia', new StringValue('Foo-NOT-FOUND.jpg'), false, 'file not found'), array('string', 'Foo', false, 'StringValue expected, string supplied'), array('string', new NumberValue(7), false, 'StringValue expected'), array('string', new StringValue(''), false, 'empty string should be invalid'), array('string', new StringValue('Foo'), true, 'simple string'), array('string', new StringValue('Äöü'), true, 'Unicode support'), array('string', new StringValue(str_repeat('x', 400)), true, 'long, but not too long'), array('string', new StringValue(str_repeat('x', 401)), false, 'too long'), array('string', new StringValue(' Foo'), false, 'string with leading space'), array('string', new StringValue('Foo '), false, 'string with trailing space'), array('time', 'Foo', false, 'TimeValue expected, string supplied'), array('time', new NumberValue(7), false, 'TimeValue expected'), array('time', new TimeValue('+2013-06-06T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_DAY, '1'), false, 'calendar: too short'), array('time', new TimeValue('+2013-06-06T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_DAY, $wikidataUri . 'Q' . str_repeat('6', 224)), false, 'calendar: too long'), array('time', new TimeValue('+2013-06-06T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_DAY, $wikidataUri . 'Q1985727'), true, 'calendar: URL'), array('time', new TimeValue('+2013-06-06T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_DAY, ' ' . $wikidataUri . 'Q1985727 '), false, 'calendar: untrimmed'), array('time', new TimeValue('+2013-06-06T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_DAY, ' javascript:alert(1)'), false, 'calendar: bad URL'), array('time', new TimeValue('+2013-06-06T11:22:33Z', 0, 0, 0, TimeValue::PRECISION_DAY, $wikidataUri . 'Q1985727'), false, 'time given to the second'), array('time', new TimeValue('+2013-06-06T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_SECOND, $wikidataUri . 'Q1985727'), false, 'precision: second'), array('globe-coordinate', 'Foo', false, 'GlobeCoordinateValue expected, string supplied'), array('globe-coordinate', new NumberValue(7), false, 'GlobeCoordinateValue expected'), array('globe-coordinate', new GlobeCoordinateValue($latLonValue, 1, $wikidataUri . 'Q2'), true, 'integer precision is valid'), array('globe-coordinate', new GlobeCoordinateValue($latLonValue, 0.2, $wikidataUri . 'Q2'), true, 'float precision is valid'), array('globe-coordinate', new GlobeCoordinateValue($latLonValue, null, $wikidataUri . 'Q2'), false, 'null precision is invalid'), array('globe-coordinate', new GlobeCoordinateValue($latLonValue, 1, ''), false, 'globe: empty string should be invalid'), array('globe-coordinate', new GlobeCoordinateValue($latLonValue, 1, $wikidataUri . 'Q' . str_repeat('6', 224)), false, 'globe: too long'), array('globe-coordinate', new GlobeCoordinateValue($latLonValue, 1, $wikidataUri . 'Q2'), true, 'globe: URL'), array('globe-coordinate', new GlobeCoordinateValue($latLonValue, 1, ' ' . $wikidataUri . 'Q2 '), false, 'globe: untrimmed'), array('globe-coordinate', new GlobeCoordinateValue($latLonValue, 1, ' javascript:alert(1) '), false, 'globe: bad URL scheme'), array('url', 'Foo', false, 'StringValue expected, string supplied'), array('url', new NumberValue(7), false, 'StringValue expected'), array('url', new StringValue('http://acme.com'), true, 'Simple HTTP URL'), array('url', new StringValue('https://acme.com'), true, 'Simple HTTPS URL'), array('url', new StringValue('ftp://acme.com'), true, 'Simple FTP URL'), array('url', new StringValue('http://acme.com/foo/bar?some=stuff#fragment'), true, 'Complex HTTP URL'), array('url', new StringValue('//bla'), false, 'Protocol-relative'), array('url', new StringValue('/bla/bla'), false, 'relative path'), array('url', new StringValue('just stuff'), false, 'just words'), array('url', new StringValue('javascript:alert("evil")'), false, 'JavaScript URL'), array('url', new StringValue('http://'), false, 'bad http URL'), array('url', new StringValue('http://' . str_repeat('x', 494)), false, 'URL too long'), array('url', new StringValue(' http://acme.com'), false, 'URL with leading space'), array('url', new StringValue('http://acme.com '), false, 'URL with trailing space'), array('quantity', QuantityValue::newFromNumber(5), true, 'Simple integer'), array('quantity', QuantityValue::newFromNumber(5, 'http://qudt.org/vocab/unit#Meter'), true, 'Vocabulary URI'), array('quantity', QuantityValue::newFromNumber(5, $wikidataUri . 'Q11573'), false, 'Wikidata URI'), array('quantity', QuantityValue::newFromNumber(5, '1'), true, '1 means unitless'), array('quantity', QuantityValue::newFromNumber(5, 'kittens'), false, 'Bad unit URI'), array('quantity', QuantityValue::newFromNumber('-11.234', '1', '-10', '-12'), true, 'decimal strings'), array('monolingualtext', new MonolingualTextValue('contentlanguage', 'text'), true, 'Simple value'), array('monolingualtext', new MonolingualTextValue('en', 'text'), false, 'Not a valid language'));
     return $cases;
 }
Exemplo n.º 2
0
 public function testFormatWithFormatString()
 {
     $formatter = $this->getQuantityFormatter(null, '<$2>$1');
     $value = QuantityValue::newFromNumber('+5', 'USD');
     $formatted = $formatter->format($value);
     $this->assertSame('<USD>5', $formatted);
 }
 public function provideApiRequest()
 {
     $november11 = new TimeValue('+2013-11-11T01:02:03Z', 0, 0, 0, TimeValue::PRECISION_DAY, 'http://acme.test');
     $november = new TimeValue('+2013-11-10T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_MONTH, 'http://acme.test');
     $wordSeparator = wfMessage('word-separator')->text();
     $deletedItem = wfMessage('wikibase-deletedentity-item')->inLanguage('en')->text();
     return array(array(new StringValue('test'), null, null, null, '/^test$/'), array($november11, null, null, null, '/^11 November 2013$/'), array($november, null, null, null, '/^November 2013$/'), array(new StringValue('http://acme.test'), 'string', SnakFormatter::FORMAT_PLAIN, null, '@^http://acme\\.test$@'), array(new StringValue('http://acme.test'), 'string', SnakFormatter::FORMAT_WIKI, null, '@^http&#58;//acme\\.test$@'), array(new StringValue('http://acme.test'), 'url', SnakFormatter::FORMAT_PLAIN, null, '@^http://acme\\.test$@'), array(QuantityValue::newFromNumber('+12.33', '1'), 'quantity', SnakFormatter::FORMAT_PLAIN, array('lang' => 'de'), '@^12,33$@'), array(new StringValue('http://acme.test'), 'url', SnakFormatter::FORMAT_WIKI, null, '@^http://acme\\.test$@'), array(new StringValue('example.jpg'), 'commonsMedia', SnakFormatter::FORMAT_HTML, null, '@commons\\.wikimedia\\.org\\/wiki\\/File:Example\\.jpg@'), array(new EntityIdValue(new ItemId('Q404')), 'wikibase-item', SnakFormatter::FORMAT_HTML, null, '/^Q404' . $wordSeparator . '<span class="wb-entity-undefinedinfo">\\(' . preg_quote($deletedItem, '/') . '\\)<\\/span>$/'), array(new EntityIdValue(new ItemId('Q23')), 'wikibase-item', SnakFormatter::FORMAT_HTML, null, '/^<a title="[^"]*Q23" href="[^"]+Q23">George Washington<\\/a>$/'), array(new EntityIdValue(new ItemId('Q23')), 'wikibase-item', SnakFormatter::FORMAT_HTML, array('lang' => 'de-ch'), '/^<a title="[^"]*Q23" href="[^"]+Q23" lang="en">George Washington<\\/a>' . '<sup class="wb-language-fallback-indicator">[^<>]+<\\/sup>$/'));
 }
Exemplo n.º 4
0
 /**
  * @dataProvider applyUnitOptionProvider
  */
 public function testGivenHtmlCharacters_formatEscapesHtmlCharacters(FormatterOptions $options = null, $unit, $expected)
 {
     $decimalFormatter = $this->getMock('ValueFormatters\\DecimalFormatter');
     $decimalFormatter->expects($this->any())->method('format')->will($this->returnValue('<b>+2</b>'));
     $formatter = $this->getQuantityHtmlFormatter($options, $decimalFormatter);
     $formatted = $formatter->format(QuantityValue::newFromNumber('+2', $unit));
     $this->assertSame($expected, $formatted);
 }
Exemplo n.º 5
0
 /**
  * @see ValueParserTestBase::validInputProvider
  */
 public function validInputProvider()
 {
     $amounts = array('0' => QuantityValue::newFromNumber(0, '1', 1, -1), '-0' => QuantityValue::newFromNumber(0, '1', 1, -1), '-00.00' => QuantityValue::newFromNumber('+0.00', '1', '+0.01', '-0.01'), '+00.00' => QuantityValue::newFromNumber('+0.00', '1', '+0.01', '-0.01'), '0001' => QuantityValue::newFromNumber(1, '1', 2, 0), '+01' => QuantityValue::newFromNumber(1, '1', 2, 0), '-1' => QuantityValue::newFromNumber(-1, '1', 0, -2), '+42' => QuantityValue::newFromNumber(42, '1', 43, 41), ' -  42' => QuantityValue::newFromNumber(-42, '1', -41, -43), '9001' => QuantityValue::newFromNumber(9001, '1', 9002, 9000), '.5' => QuantityValue::newFromNumber('+0.5', '1', '+0.6', '+0.4'), '-.125' => QuantityValue::newFromNumber('-0.125', '1', '-0.124', '-0.126'), '3.' => QuantityValue::newFromNumber(3, '1', 4, 2), ' 3 ' => QuantityValue::newFromNumber(3, '1', 4, 2), '2.125' => QuantityValue::newFromNumber('+2.125', '1', '+2.126', '+2.124'), '2.1250' => QuantityValue::newFromNumber('+2.1250', '1', '+2.1251', '+2.1249'), '1.4e-2' => QuantityValue::newFromNumber('+0.014', '1', '+0.015', '+0.013'), '1.4e3' => QuantityValue::newFromNumber('+1400', '1', '+1500', '+1300'), '1.4e3!m' => QuantityValue::newFromNumber('+1400', 'm', '+1400', '+1400'), '1.4e3m2' => QuantityValue::newFromNumber('+1400', 'm2', '+1500', '+1300'), '1.4ev' => QuantityValue::newFromNumber('+1.4', 'ev', '+1.5', '+1.3'), '1.4e' => QuantityValue::newFromNumber('+1.4', 'e', '+1.5', '+1.3'), '12e3e4' => QuantityValue::newFromNumber('+12000', 'e4', '+13000', '+11000'), '0.004e3' => QuantityValue::newFromNumber('+4', '1', '+5', '+3'), '0.004e-3' => QuantityValue::newFromNumber('+0.000004', '1', '+0.000005', '+0.000003'), '4000e3' => QuantityValue::newFromNumber('+4000000', '1', '+4001000', '+3999000'), '4000e-3' => QuantityValue::newFromNumber('+4.000', '1', '+4.001', '+3.999'), '0!' => QuantityValue::newFromNumber(0, '1', 0, 0), '10.003!' => QuantityValue::newFromNumber('+10.003', '1', '+10.003', '+10.003'), '-200!' => QuantityValue::newFromNumber(-200, '1', -200, -200), '0~' => QuantityValue::newFromNumber(0, '1', 1, -1), '10.003~' => QuantityValue::newFromNumber('+10.003', '1', '+10.004', '+10.002'), '-200~' => QuantityValue::newFromNumber(-200, '1', -199, -201), '5.3 +/- 0.2' => QuantityValue::newFromNumber('+5.3', '1', '+5.5', '+5.1'), '5.3+-0.2' => QuantityValue::newFromNumber('+5.3', '1', '+5.5', '+5.1'), '5.3 ±0.2' => QuantityValue::newFromNumber('+5.3', '1', '+5.5', '+5.1'), '5.3 +/- +0.2' => QuantityValue::newFromNumber('+5.3', '1', '+5.5', '+5.1'), '5.3+-+0.2' => QuantityValue::newFromNumber('+5.3', '1', '+5.5', '+5.1'), '5.3e3 +/- 0.2e2' => QuantityValue::newFromNumber('+5300', '1', '+5320', '+5280'), '2e-2+/-1.1e-1' => QuantityValue::newFromNumber('+0.02', '1', '+0.13', '-0.09'), '5.3 +/- -0.2' => QuantityValue::newFromNumber('+5.3', '1', '+5.5', '+5.1'), '5.3+--0.2' => QuantityValue::newFromNumber('+5.3', '1', '+5.5', '+5.1'), '5.3 ±-0.2' => QuantityValue::newFromNumber('+5.3', '1', '+5.5', '+5.1'), '5.3+-0.2cm' => QuantityValue::newFromNumber('+5.3', 'cm', '+5.5', '+5.1'), '10.003! km' => QuantityValue::newFromNumber('+10.003', 'km', '+10.003', '+10.003'), '-200~ %  ' => QuantityValue::newFromNumber(-200, '%', -199, -201), '100003 m³' => QuantityValue::newFromNumber(100003, 'm³', 100004, 100002), '3.±-0.2µ' => QuantityValue::newFromNumber('+3', 'µ', '+3.2', '+2.8'), '+00.20 Å' => QuantityValue::newFromNumber('+0.20', 'Å', '+0.21', '+0.19'));
     $argLists = array();
     foreach ($amounts as $amount => $expected) {
         //NOTE: PHP may "helpfully" have converted $amount to an integer. Yay.
         $argLists[] = array(strval($amount), $expected);
     }
     return $argLists;
 }
 public function testGivenHtmlCharacters_formatEscapesHtmlCharacters()
 {
     $unitFormatter = $this->getMock('ValueFormatters\\NumberLocalizer');
     $unitFormatter->expects($this->any())->method('localizeNumber')->will($this->returnValue('<a>+2</a>'));
     $formatter = $this->newFormatter($unitFormatter);
     $value = QuantityValue::newFromNumber('+2', '<a>m</a>', '+2', '+2');
     $html = $formatter->format($value);
     $this->assertNotContains('<a>', $html);
     $this->assertContains('&lt;a&gt;', $html);
     $this->assertNotContains('&amp;', $html);
 }
Exemplo n.º 7
0
 public function transformProvider()
 {
     $identity = function (DecimalValue $value) {
         return $value;
     };
     $square = function (DecimalValue $value) {
         $v = $value->getValueFloat();
         return new DecimalValue($v * $v * $v);
     };
     $scale = function (DecimalValue $value, $factor) {
         return new DecimalValue($value->getValueFloat() * $factor);
     };
     return array(0 => array(QuantityValue::newFromNumber('+10', '1', '+11', '+9'), $identity, QuantityValue::newFromNumber('+10', '?', '+11', '+9')), 1 => array(QuantityValue::newFromNumber('-0.5', '1', '-0.4', '-0.6'), $identity, QuantityValue::newFromNumber('-0.5', '?', '-0.4', '-0.6')), 2 => array(QuantityValue::newFromNumber('+0', '1', '+1', '-1'), $square, QuantityValue::newFromNumber('+0', '?', '+1', '-1')), 3 => array(QuantityValue::newFromNumber('+10', '1', '+11', '+9'), $square, QuantityValue::newFromNumber('+1000', '?', '+1300', '+700')), 4 => array(QuantityValue::newFromNumber('+0.5', '1', '+0.6', '+0.4'), $scale, QuantityValue::newFromNumber('+0.25', '?', '+0.3', '+0.2'), 0.5), 10 => array(QuantityValue::newFromNumber('+100', '1', '+100', '+100'), $scale, QuantityValue::newFromNumber('+12825.0', '?', '+12825.0', '+12825.0'), 128.25), 11 => array(QuantityValue::newFromNumber('+100', '1', '+110', '+90'), $scale, QuantityValue::newFromNumber('+330', '?', '+370', '+300'), 3.3333), 12 => array(QuantityValue::newFromNumber('+100', '1', '+100.1', '+99.9'), $scale, QuantityValue::newFromNumber('+333.3', '?', '+333.7', '+333.0'), 3.3333), 13 => array(QuantityValue::newFromNumber('+100', '1', '+100.01', '+99.99'), $scale, QuantityValue::newFromNumber('+333.33', '?', '+333.36', '+333.30'), 3.3333));
 }
 public function provideAddValue()
 {
     $value = QuantityValue::newFromNumber('+23.5', '1', '+23.6', '+23.4');
     $snak = new PropertyValueSnak(new PropertyId('P7'), $value);
     return array('simple' => array($snak, false, array('<http://www/Q1> <http://acme/statement/P7> "+23.5"^^<http://www.w3.org/2001/XMLSchema#decimal> .')), 'complex' => array($snak, true, array('<http://www/Q1> ' . '<http://acme/statement/P7> ' . '"+23.5"^^<http://www.w3.org/2001/XMLSchema#decimal> .', '<http://www/Q1> ' . '<http://acme/statement/value/P7> ' . '<http://acme/value/1ac4bb05a87bfd5fde2740bbb6941533> .', '<http://acme/value/1ac4bb05a87bfd5fde2740bbb6941533> ' . '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ' . '<http://acme/onto/QuantityValue> .', '<http://acme/value/1ac4bb05a87bfd5fde2740bbb6941533> ' . '<http://acme/onto/quantityAmount> ' . '"+23.5"^^<http://www.w3.org/2001/XMLSchema#decimal> .', '<http://acme/value/1ac4bb05a87bfd5fde2740bbb6941533> ' . '<http://acme/onto/quantityUpperBound> ' . '"+23.6"^^<http://www.w3.org/2001/XMLSchema#decimal> .', '<http://acme/value/1ac4bb05a87bfd5fde2740bbb6941533> ' . '<http://acme/onto/quantityLowerBound> ' . '"+23.4"^^<http://www.w3.org/2001/XMLSchema#decimal> .', '<http://acme/value/1ac4bb05a87bfd5fde2740bbb6941533> ' . '<http://acme/onto/quantityUnit> ' . '<http://www.wikidata.org/entity/Q199> .')));
 }
 public function entityIdProvider()
 {
     $set1 = new StatementList();
     $this->addStatement($set1, 'Q1');
     $set2 = new StatementList();
     $this->addStatement($set2, 'Q20');
     $this->addStatement($set2, 'Q21');
     $set2->addNewStatement(new PropertyValueSnak(1, QuantityValue::newFromNumber(1, self::UNIT_PREFIX . 'Q22')));
     $siteLinks = new SiteLinkList();
     $siteLinks->addNewSiteLink('siteId', 'pageName', array(new ItemId('Q1')));
     return array(array(new StatementList(), null, array()), array($set1, null, array('P1', 'Q1')), array(new StatementList(), $siteLinks, array('Q1')), array($set1, $siteLinks, array('P1', 'Q1')), array($set2, null, array('P1', 'Q20', 'Q21', 'Q22')), array($set2, $siteLinks, array('P1', 'Q20', 'Q21', 'Q22', 'Q1')));
 }
 public function provideNewFormatter()
 {
     return array('plain string' => array('String', SnakFormatter::FORMAT_PLAIN, $this->newFormatterOptions(), new StringValue('foo bar'), '@^foo bar$@'), 'wikitext string' => array('String', SnakFormatter::FORMAT_WIKI, $this->newFormatterOptions(), new StringValue('foo[bar]'), '@^foo&#91;bar&#93;$@'), 'html string' => array('String', SnakFormatter::FORMAT_HTML, $this->newFormatterOptions(), new StringValue('foo<bar>'), '@^foo&lt;bar&gt;$@'), 'plain bad value' => array('UnDeserializableValue', SnakFormatter::FORMAT_PLAIN, $this->newFormatterOptions(), new UnDeserializableValue('foo bar', 'xyzzy', 'broken'), '@invalid@'), 'plain url' => array('Url', SnakFormatter::FORMAT_PLAIN, $this->newFormatterOptions(), new StringValue('http://acme.com/'), '@^http://acme\\.com/$@'), 'wikitext url' => array('Url', SnakFormatter::FORMAT_WIKI, $this->newFormatterOptions(), new StringValue('http://acme.com/'), '@^http://acme\\.com/$@'), 'html url' => array('Url', SnakFormatter::FORMAT_HTML, $this->newFormatterOptions(), new StringValue('http://acme.com/'), '@^.*href="http://acme.com/".*$@'), 'plain item label (with language fallback)' => array('EntityId', SnakFormatter::FORMAT_PLAIN, $this->newFormatterOptions('de-ch'), new EntityIdValue(new ItemId('Q5')), '@^Name für Q5$@'), 'item link (with entity lookup)' => array('EntityId', SnakFormatter::FORMAT_HTML, $this->newFormatterOptions(), new EntityIdValue(new ItemId('Q5')), '/^<a\\b[^>]* href="[^"]*\\bQ5">Label for Q5<\\/a>.*$/', 'wikibase-item'), 'property link (with entity lookup)' => array('EntityId', SnakFormatter::FORMAT_HTML, $this->newFormatterOptions(), new EntityIdValue(new PropertyId('P5')), '/^<a\\b[^>]* href="[^"]*\\bP5">Label for P5<\\/a>.*$/', 'wikibase-property'), 'plain commons media' => array('CommonsMedia', SnakFormatter::FORMAT_PLAIN, $this->newFormatterOptions(), new StringValue('Example.jpg'), '@^Example.jpg$@'), 'html commons link' => array('CommonsMedia', SnakFormatter::FORMAT_HTML, $this->newFormatterOptions(), new StringValue('Example.jpg'), '@^<a class="extiw" href="//commons\\.wikimedia\\.org/wiki/File:Example\\.jpg">Example\\.jpg</a>$@', 'commonsMedia'), 'plain coordinate' => array('GlobeCoordinate', SnakFormatter::FORMAT_PLAIN, $this->newFormatterOptions(), new GlobeCoordinateValue(new LatLongValue(-55.755786, 37.25633), 0.25), '@^55°45\'S, 37°15\'E$@'), 'coordinate details' => array('GlobeCoordinate', SnakFormatter::FORMAT_HTML_DIFF, $this->newFormatterOptions('de'), new GlobeCoordinateValue(new LatLongValue(-55.755786, 37.25633), 0.25), '@^.*55° 45\', 37° 15\'.*$@'), 'localized quantity' => array('Quantity', SnakFormatter::FORMAT_PLAIN, $this->newFormatterOptions('de'), QuantityValue::newFromNumber('+123456.789'), '@^123\\.456,789$@'), 'quantity details' => array('Quantity', SnakFormatter::FORMAT_HTML_DIFF, $this->newFormatterOptions('de'), QuantityValue::newFromNumber('+123456.789'), '@^.*123\\.456,789.*$@'), 'a month in 1980' => array('Time', SnakFormatter::FORMAT_PLAIN, $this->newFormatterOptions(), new TimeValue('+1980-05-01T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_MONTH, 'http://www.wikidata.org/entity/Q1985727'), '/^May 1980$/'), 'a gregorian day in 1520' => array('Time', SnakFormatter::FORMAT_HTML, $this->newFormatterOptions(), new TimeValue('+1520-05-01T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_DAY, 'http://www.wikidata.org/entity/Q1985727'), '/^1 May 1520<sup class="wb-calendar-name">Gregorian<\\/sup>$/'), 'a julian day in 1980' => array('Time', SnakFormatter::FORMAT_HTML_DIFF, $this->newFormatterOptions(), new TimeValue('+1980-05-01T00:00:00Z', 0, 0, 0, TimeValue::PRECISION_DAY, 'http://www.wikidata.org/entity/Q1985786'), '/^.*>1 May 1980<sup class="wb-calendar-name">Julian<\\/sup>.*$/'), 'text in english' => array('Monolingual', SnakFormatter::FORMAT_PLAIN, $this->newFormatterOptions('en'), new MonolingualTextValue('en', 'Hello World'), '/^Hello World$/'), 'text in german' => array('Monolingual', SnakFormatter::FORMAT_HTML, $this->newFormatterOptions('en'), new MonolingualTextValue('de', 'Hallo Welt'), '/^.*lang="de".*?>Hallo Welt<.*Deutsch.*$/'));
 }
Exemplo n.º 11
0
 /**
  * Returns the rounding exponent based on the given $quantity
  * and the @see QuantityFormatter::OPT_APPLY_ROUNDING option.
  *
  * @param QuantityValue $quantity
  *
  * @return int
  */
 private function getRoundingExponent(QuantityValue $quantity)
 {
     if ($this->options->getOption(self::OPT_APPLY_ROUNDING) === true) {
         // round to the order of uncertainty
         return $quantity->getOrderOfUncertainty();
     } elseif ($this->options->getOption(self::OPT_APPLY_ROUNDING) === false) {
         // to keep all digits, use the negative length of the fractional part
         return -strlen($quantity->getAmount()->getFractionalPart());
     } else {
         return (int) $this->options->getOption(self::OPT_APPLY_ROUNDING);
     }
 }