MediaWiki REL1_33
FormatJsonTest Class Reference

FormatJson. More...

Inheritance diagram for FormatJsonTest:
Collaboration diagram for FormatJsonTest:

Public Member Functions

 provideEmptyJsonKeyStrings ()
 
 provideParseStripComments ()
 
 provideStripComments ()
 
 testDecodeReturnType ()
 
 testEmptyJsonKeyArray ( $json, $expect, $php71Name)
 FormatJson::encode FormatJson::decode provideEmptyJsonKeyStrings.
 
 testEncodeAllOk ( $from, $to)
 provideEncodeAllOk
 
 testEncodeDefault ( $from, $to)
 provideEncodeDefault
 
 testEncodeFail ()
 
 testEncodePhpBug46944 ()
 
 testEncoderPrettyPrinting ( $pretty, $expectedIndent)
 provideEncoderPrettyPrinting
 
 testEncodeUtf8 ( $from, $to)
 provideEncodeUtf8
 
 testEncodeXmlMeta ( $from, $to)
 provideEncodeXmlMeta
 
 testParse ( $value)
 provideParse
 
 testParseErrors ( $value)
 provideParseErrors
 
 testParseStripComments ( $json, $expect)
 FormatJson::parse FormatJson::stripComments provideParseStripComments.
 
 testParseTryFixing ( $value, $expected, $jsoncParses=true, $expectedJsonc=null)
 provideParseTryFixing
 
 testStripComments ( $json, $expect)
 FormatJson::stripComments provideStripComments.
 
- Public Member Functions inherited from MediaWikiTestCase
 __construct ( $name=null, array $data=[], $dataName='')
 
 __destruct ()
 
 addDBData ()
 Stub.
 
 addDBDataOnce ()
 Stub.
 
 copyTestData (IDatabase $source, IDatabase $target)
 Copy test data from one database connection to another.
 
 dbPrefix ()
 
 getCliArg ( $offset)
 
 hideDeprecated ( $function)
 Don't throw a warning if $function is deprecated and called later.
 
 needsDB ()
 
 run (PHPUnit_Framework_TestResult $result=null)
 
 setCliArg ( $offset, $value)
 
 setContentLang ( $lang)
 
 setGroupPermissions ( $newPerms, $newKey=null, $newValue=null)
 Alters $wgGroupPermissions for the duration of the test.
 
 setupAllTestDBs ()
 Set up all test DBs.
 
 setUserLang ( $lang)
 
 testMediaWikiTestCaseParentSetupCalled ()
 Make sure MediaWikiTestCase extending classes have called their parent setUp method.
 
 usesTemporaryTables ()
 

Static Public Member Functions

static provideEncodeAllOk ()
 
static provideEncodeDefault ()
 
static provideEncoderPrettyPrinting ()
 
static provideEncodeUtf8 ()
 
static provideEncodeXmlMeta ()
 
static provideParse ()
 
static provideParseErrors ()
 
static provideParseTryFixing ()
 Test data for testParseTryFixing.
 
static toObject ( $value)
 Recursively convert arrays into stdClass.
 
- Static Public Member Functions inherited from MediaWikiTestCase
static getMutableTestUser ( $groups=[])
 Convenience method for getting a mutable test user.
 
static getTestPrefixFor (IDatabase $db)
 
static getTestSysop ()
 Convenience method for getting an immutable admin test user.
 
static getTestUser ( $groups=[])
 Convenience method for getting an immutable test user.
 
static installMockMwServices (Config $configOverrides=null)
 Creates a new "mock" MediaWikiServices instance, and installs it.
 
static listTables (IMaintainableDatabase $db)
 
static prepareServices (Config $bootstrapConfig)
 
static resetNonServiceCaches ()
 Resets some non-service singleton instances and other static caches.
 
static restoreMwServices ()
 Restores the original, non-mock MediaWikiServices instance.
 
static setUpBeforeClass ()
 
static setupTestDB (IMaintainableDatabase $db, $prefix)
 Creates an empty skeleton of the wiki database by cloning its structure to equivalent tables using the given $prefix.
 
static teardownTestDB ()
 Restores MediaWiki to using the table set (table prefix) it was using before setupTestDB() was called.
 
static wfResetOutputBuffersBarrier ( $buffer)
 Used as a marker to prevent wfResetOutputBuffers from breaking PHPUnit.
 

Static Private Member Functions

static getEncodeTestCases (array $unescapedGroups)
 Generate a set of test cases for a particular combination of encoder options.
 

Additional Inherited Members

- Public Attributes inherited from MediaWikiTestCase
const DB_PREFIX = 'unittest_'
 Table name prefixes.
 
const ORA_DB_PREFIX = 'ut_'
 
- Static Public Attributes inherited from MediaWikiTestCase
static TestUser[] $users
 
- Protected Member Functions inherited from MediaWikiTestCase
 addCoreDBData ()
 
 addTmpFiles ( $files)
 
 arrayWrap (array $elements)
 Utility method taking an array of elements and wrapping each element in its own array.
 
 assertArrayEquals (array $expected, array $actual, $ordered=false, $named=false)
 Assert that two arrays are equal.
 
 assertFileContains ( $fileName, $actualData, $createIfMissing=false, $msg='')
 Check whether file contains given data.
 
 assertHTMLEquals ( $expected, $actual, $msg='')
 Put each HTML element on its own line and then equals() the results.
 
 assertSelect ( $table, $fields, $condition, array $expectedRows, array $options=[], array $join_conds=[])
 Asserts that the given database query yields the rows given by $expectedRows.
 
 assertType ( $type, $actual, $message='')
 Asserts the type of the provided value.
 
 assertTypeOrValue ( $type, $actual, $value=false, $message='')
 Asserts that the provided variable is of the specified internal type or equals the $value argument.
 
 checkDbIsSupported ()
 
 checkPHPExtension ( $extName)
 Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
 
 editPage ( $pageName, $text, $summary='', $defaultNs=NS_MAIN)
 Edits or creates a page/revision.
 
 ensureMockDatabaseConnection (IDatabase $db)
 
 getDefaultWikitextNS ()
 Returns the ID of a namespace that defaults to Wikitext.
 
 getExistingTestPage ( $title=null)
 Returns a WikiPage representing an existing page.
 
 getNewTempDirectory ()
 obtains a new temporary directory
 
 getNewTempFile ()
 Obtains a new temporary file name.
 
 getNonexistingTestPage ( $title=null)
 Returns a WikiPage representing a non-existing page.
 
 getSchemaOverrides (IMaintainableDatabase $db)
 Stub.
 
 insertPage ( $pageName, $text='Sample page for unit test.', $namespace=null, User $user=null)
 Insert a new page.
 
 isTestInDatabaseGroup ()
 
 isWikitextNS ( $ns)
 Returns true if the given namespace defaults to Wikitext according to $wgNamespaceContentModels.
 
 markTestSkippedIfDbType ( $type)
 Skip the test if using the specified database type.
 
 markTestSkippedIfNoDiff3 ()
 Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped, if not ready.
 
 mergeMwGlobalArrayValue ( $name, $values)
 Merges the given values into a MW global array variable.
 
 objectAssociativeSort (array &$array)
 Does an associative sort that works for objects.
 
 overrideMwServices (Config $configOverrides=null, array $services=[])
 Stashes the global instance of MediaWikiServices, and installs a new one, allowing test cases to override settings and services.
 
 revisionDelete ( $rev, array $value=[Revision::DELETED_TEXT=> 1], $comment='')
 Revision-deletes a revision.
 
 setIniSetting ( $name, $value)
 Set an ini setting for the duration of the test.
 
 setLogger ( $channel, LoggerInterface $logger)
 Sets the logger for a specified channel, for the duration of the test.
 
 setMwGlobals ( $pairs, $value=null)
 Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
 
 setService ( $name, $object)
 Sets a service, maintaining a stashed version of the previous service to be restored in tearDown.
 
 setTemporaryHook ( $hookName, $handler)
 Create a temporary hook handler which will be reset by tearDown.
 
 setUp ()
 
 stashMwGlobals ( $globalKeys)
 Stashes the global, will be restored in tearDown()
 
 tearDown ()
 
 truncateTable ( $tableName, IDatabase $db=null)
 Empties the given table and resets any auto-increment counters.
 
- Static Protected Member Functions inherited from MediaWikiTestCase
static getExternalStoreDatabaseConnections ()
 Gets master database connections for all of the ExternalStoreDB stores configured in $wgDefaultExternalStore.
 
static isUsingExternalStoreDB ()
 Check whether ExternalStoreDB is being used.
 
static setupDatabaseWithTestPrefix (IMaintainableDatabase $db, $prefix=null)
 Setups a database with cloned tables using the given prefix.
 
static setupExternalStoreTestDBs ( $testPrefix=null)
 Clones the External Store database(s) for testing.
 
static stripStringKeys (&$r)
 Utility function for eliminating all string keys from an array.
 
- Protected Attributes inherited from MediaWikiTestCase
Database $db
 Primary database.
 
array $supportedDBs
 
array $tablesUsed = []
 

Detailed Description

FormatJson.

Definition at line 6 of file FormatJsonTest.php.

Member Function Documentation

◆ getEncodeTestCases()

static FormatJsonTest::getEncodeTestCases ( array  $unescapedGroups)
staticprivate

Generate a set of test cases for a particular combination of encoder options.

Parameters
array$unescapedGroupsList of character groups to leave unescaped
Returns
array Arrays of unencoded strings and corresponding encoded strings

Definition at line 336 of file FormatJsonTest.php.

References $name, and as.

Referenced by provideEncodeAllOk(), provideEncodeDefault(), provideEncodeUtf8(), and provideEncodeXmlMeta().

◆ provideEmptyJsonKeyStrings()

FormatJsonTest::provideEmptyJsonKeyStrings ( )

Definition at line 385 of file FormatJsonTest.php.

◆ provideEncodeAllOk()

static FormatJsonTest::provideEncodeAllOk ( )
static

Definition at line 93 of file FormatJsonTest.php.

References getEncodeTestCases().

◆ provideEncodeDefault()

static FormatJsonTest::provideEncodeDefault ( )
static

Definition at line 60 of file FormatJsonTest.php.

References getEncodeTestCases().

◆ provideEncoderPrettyPrinting()

static FormatJsonTest::provideEncoderPrettyPrinting ( )
static

Definition at line 8 of file FormatJsonTest.php.

◆ provideEncodeUtf8()

static FormatJsonTest::provideEncodeUtf8 ( )
static

Definition at line 71 of file FormatJsonTest.php.

References getEncodeTestCases().

◆ provideEncodeXmlMeta()

static FormatJsonTest::provideEncodeXmlMeta ( )
static

Definition at line 82 of file FormatJsonTest.php.

References getEncodeTestCases().

◆ provideParse()

static FormatJsonTest::provideParse ( )
static

Definition at line 135 of file FormatJsonTest.php.

References false, null, and true.

◆ provideParseErrors()

static FormatJsonTest::provideParseErrors ( )
static

Definition at line 255 of file FormatJsonTest.php.

◆ provideParseStripComments()

FormatJsonTest::provideParseStripComments ( )

Definition at line 308 of file FormatJsonTest.php.

References true.

◆ provideParseTryFixing()

static FormatJsonTest::provideParseTryFixing ( )
static

Test data for testParseTryFixing.

Some PHP interpreters use json-c rather than the JSON.org canonical parser to avoid being encumbered by the "shall be used for Good, not Evil" clause of the JSON.org parser's license. By default, json-c parses in a non-strict mode which allows trailing commas for array and object delarations among other things, so our JSON_ERROR_SYNTAX rescue block is not always triggered. It however isn't lenient in exactly the same ways as our TRY_FIXING mode, so the assertions in this test are a bit more complicated than they ideally would be:

Optional third argument: true if json-c parses the value without intervention, false otherwise. Defaults to true.

Optional fourth argument: expected cannonical JSON serialization of json-c parsed result. Defaults to the second argument's value.

Definition at line 199 of file FormatJsonTest.php.

References false.

◆ provideStripComments()

FormatJsonTest::provideStripComments ( )

Definition at line 272 of file FormatJsonTest.php.

◆ testDecodeReturnType()

FormatJsonTest::testDecodeReturnType ( )

Definition at line 121 of file FormatJsonTest.php.

◆ testEmptyJsonKeyArray()

FormatJsonTest::testEmptyJsonKeyArray (   $json,
  $expect,
  $php71Name 
)

FormatJson::encode FormatJson::decode provideEmptyJsonKeyStrings.

Parameters
string$json

Decoding behavior with empty keys can be surprising. See https://phabricator.wikimedia.org/T206411

Definition at line 423 of file FormatJsonTest.php.

◆ testEncodeAllOk()

FormatJsonTest::testEncodeAllOk (   $from,
  $to 
)

provideEncodeAllOk

Definition at line 100 of file FormatJsonTest.php.

◆ testEncodeDefault()

FormatJsonTest::testEncodeDefault (   $from,
  $to 
)

provideEncodeDefault

Definition at line 67 of file FormatJsonTest.php.

◆ testEncodeFail()

FormatJsonTest::testEncodeFail ( )

Definition at line 112 of file FormatJsonTest.php.

◆ testEncodePhpBug46944()

FormatJsonTest::testEncodePhpBug46944 ( )

Definition at line 104 of file FormatJsonTest.php.

◆ testEncoderPrettyPrinting()

FormatJsonTest::testEncoderPrettyPrinting (   $pretty,
  $expectedIndent 
)

provideEncoderPrettyPrinting

Definition at line 23 of file FormatJsonTest.php.

◆ testEncodeUtf8()

FormatJsonTest::testEncodeUtf8 (   $from,
  $to 
)

provideEncodeUtf8

Definition at line 78 of file FormatJsonTest.php.

◆ testEncodeXmlMeta()

FormatJsonTest::testEncodeXmlMeta (   $from,
  $to 
)

provideEncodeXmlMeta

Definition at line 89 of file FormatJsonTest.php.

◆ testParse()

FormatJsonTest::testParse (   $value)

provideParse

Parameters
mixed$value

Definition at line 165 of file FormatJsonTest.php.

References $value, and toObject().

◆ testParseErrors()

FormatJsonTest::testParseErrors (   $value)

provideParseErrors

Parameters
mixed$value

Definition at line 266 of file FormatJsonTest.php.

References $value.

◆ testParseStripComments()

FormatJsonTest::testParseStripComments (   $json,
  $expect 
)

FormatJson::parse FormatJson::stripComments provideParseStripComments.

Parameters
string$json
mixed$expect

Definition at line 323 of file FormatJsonTest.php.

◆ testParseTryFixing()

FormatJsonTest::testParseTryFixing (   $value,
  $expected,
  $jsoncParses = true,
  $expectedJsonc = null 
)

provideParseTryFixing

Parameters
string$value
string | bool$expectedExpected result with strict parser
bool$jsoncParsesWill json-c parse this value without TRY_FIXING?
string | bool$expectedJsoncExpected result with lenient parser if different from the strict expectation

Definition at line 226 of file FormatJsonTest.php.

References $value, and null.

◆ testStripComments()

FormatJsonTest::testStripComments (   $json,
  $expect 
)

FormatJson::stripComments provideStripComments.

Parameters
string$json
string$expect

Definition at line 304 of file FormatJsonTest.php.

◆ toObject()

static FormatJsonTest::toObject (   $value)
static

Recursively convert arrays into stdClass.

Parameters
array | string | bool | int | float | null$value
Returns
stdClass|string|bool|int|float|null

Definition at line 157 of file FormatJsonTest.php.

References $value, and object.

Referenced by testParse().


The documentation for this class was generated from the following file: