MediaWiki  master
FormatJsonTest.php
Go to the documentation of this file.
1 <?php
2 
7 
26  public static function provideParseTryFixing() {
27  return [
28  [ "[,]", '[]', false ],
29  [ "[ , ]", '[]', false ],
30  [ "[ , }", false ],
31  [ '[1],', false, true, '[1]' ],
32  [ "[1,]", '[1]' ],
33  [ "[1\n,]", '[1]' ],
34  [ "[1,\n]", '[1]' ],
35  [ "[1,]\n", '[1]' ],
36  [ "[1\n,\n]\n", '[1]' ],
37  [ '["a,",]', '["a,"]' ],
38  [ "[[1,]\n,[2,\n],[3\n,]]", '[[1],[2],[3]]' ],
39  // I wish we could parse this, but would need quote parsing
40  [ '[[1,],[2,],[3,]]', false, true, '[[1],[2],[3]]' ],
41  [ '[1,,]', false, false, '[1]' ],
42  ];
43  }
44 
53  public function testParseTryFixing(
54  $value, $expected,
55  $jsoncParses = true, $expectedJsonc = null
56  ) {
57  // PHP5 results are always expected to have isGood() === false
58  $expectedGoodStatus = false;
59 
60  // Check to see if json parser allows trailing commas
61  if ( json_decode( '[1,]' ) !== null ) {
62  // Use json-c specific expected result if provided
63  $expected = ( $expectedJsonc === null ) ? $expected : $expectedJsonc;
64  // If json-c parses the value natively, expect isGood() === true
65  $expectedGoodStatus = $jsoncParses;
66  }
67 
69  $this->assertInstanceOf( Status::class, $st );
70  if ( $expected === false ) {
71  $this->assertFalse( $st->isOK(), 'Expected isOK() == false' );
72  } else {
73  $this->assertSame( $expectedGoodStatus, $st->isGood(),
74  'Expected isGood() == ' . ( $expectedGoodStatus ? 'true' : 'false' )
75  );
76  $this->assertTrue( $st->isOK(), 'Expected isOK == true' );
77  $val = FormatJson::encode( $st->getValue(), false, FormatJson::ALL_OK );
78  $this->assertEquals( $expected, $val );
79  }
80  }
81 
82 }
FormatJson.
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
testParseTryFixing( $value, $expected, $jsoncParses=true, $expectedJsonc=null)
provideParseTryFixing
const ALL_OK
Skip escaping as many characters as reasonably possible.
Definition: FormatJson.php:55
$value
static encode( $value, $pretty=false, $escaping=0)
Returns the JSON representation of a value.
Definition: FormatJson.php:115
const TRY_FIXING
If set, attempt to fix invalid JSON.
Definition: FormatJson.php:70
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
static provideParseTryFixing()
Test data for testParseTryFixing.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
static parse( $value, $options=0)
Decodes a JSON string.
Definition: FormatJson.php:188