Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F2751095
EventLoggingExtensionFunctionsTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
EventLoggingExtensionFunctionsTest.php
View Options
<?php
/**
* PHP Unit tests for top-level ('ef-*') functions in EventLogging
* extension.
*
* @file
* @ingroup Extensions
*
* @author Ori Livneh <ori@wikimedia.org>
*/
use
MediaWiki\Extension\EventLogging\EventLogging
;
use
MediaWiki\Extension\EventLogging\Libs\JsonSchemaValidation\JsonSchemaException
;
/**
* @group EventLogging
* @covers \MediaWiki\Extension\EventLogging\EventLogging::schemaValidate
*/
class
EventLoggingExtensionFunctionsTest
extends
MediaWikiIntegrationTestCase
{
/** @var array a basic JSON schema, decoded to associative array. */
private
static
$validSchema
=
[
'properties'
=>
[
'valid'
=>
[
'type'
=>
'boolean'
,
'required'
=>
true
,
],
'action'
=>
[
'type'
=>
'string'
,
'enum'
=>
[
'delete'
,
'edit'
,
'history'
,
'protect'
,
'purge'
,
'submit'
,
'view'
,
],
],
]
];
/** @var array conforms to $validSchema. */
private
static
$validObject
=
[
'valid'
=>
true
,
'action'
=>
'history'
];
/** @var array does not conform to $validSchema. */
private
static
$invalidObject
=
[
'valid'
=>
true
,
'action'
=>
'cache'
];
/**
* Tests validation of objects against schema.
* EventLogging uses Rob Lanphier's JSON Schema Validation Library,
* which comes with a set of unit tests for verifying the handling
* of various edge cases. Accordingly, this test is designed to
* perform only a basic, high-level sanity-check on object and
* schema validation.
*
* @covers \MediaWiki\Extension\EventLogging\EventLogging::schemaValidate
*/
public
function
testSchemaValidate
()
{
$this
->
assertTrue
(
EventLogging
::
schemaValidate
(
self
::
$validObject
,
self
::
$validSchema
),
'EventLogging::schemaValidate() returns true when object validates successfully.'
);
$this
->
assertTrue
(
EventLogging
::
schemaValidate
(
self
::
$validSchema
),
'EventLogging::schemaValidate() defaults to validating against the schema schema.'
);
}
/**
* Tests invalidation of objects that deviate from schema.
* @covers \MediaWiki\Extension\EventLogging\EventLogging::schemaValidate
*/
public
function
testSchemaInvalidate
()
{
$this
->
expectException
(
JsonSchemaException
::
class
);
EventLogging
::
schemaValidate
(
self
::
$invalidObject
,
self
::
$validSchema
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Jul 3, 17:51 (1 d, 3 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
3c/22/21c5a83af08215d55afb5f07430a
Default Alt Text
EventLoggingExtensionFunctionsTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment