Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4111762
RestTestTrait.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
RestTestTrait.php
View Options
<?php
namespace
MediaWiki\Tests\Rest
;
use
MediaWiki\Config\ServiceOptions
;
use
MediaWiki\MainConfigNames
;
use
MediaWiki\Rest\BasicAccess\StaticBasicAuthorizer
;
use
MediaWiki\Rest\Module\Module
;
use
MediaWiki\Rest\Reporter\PHPErrorReporter
;
use
MediaWiki\Rest\RequestData
;
use
MediaWiki\Rest\ResponseFactory
;
use
MediaWiki\Rest\Router
;
use
MediaWiki\Rest\Validator\Validator
;
use
MediaWiki\Tests\Rest\Handler\SessionHelperTestTrait
;
use
MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait
;
use
Psr\Container\ContainerInterface
;
use
Wikimedia\ObjectCache\EmptyBagOStuff
;
use
Wikimedia\ObjectFactory\ObjectFactory
;
/**
* A trait providing utility function for testing the REST framework.
* This trait is intended to be used on subclasses of MediaWikiUnitTestCase
* or MediaWikiIntegrationTestCase.
*
* @stable to use
*/
trait
RestTestTrait
{
use
SessionHelperTestTrait
;
use
MockAuthorityTrait
;
/**
* @param array $params Constructor parameters, as an associative array.
* In addition to the actual parameters, the following pseudo-parameters
* are supported:
* - 'config': an associative array of configuration variables, used
* to construct the 'options' parameter.
* - 'request': A request object, used to construct the 'validator' parameter.
* @return Router
*/
private
function
newRouter
(
array
$params
=
[]
)
{
$responseFactory
=
new
ResponseFactory
(
[]
);
$responseFactory
->
setShowExceptionDetails
(
true
);
$objectFactory
=
new
ObjectFactory
(
$this
->
getMockForAbstractClass
(
ContainerInterface
::
class
)
);
$authority
=
$params
[
'authority'
]
??
$this
->
mockAnonUltimateAuthority
();
$config
=
(
$params
[
'config'
]
??
[]
)
+
[
MainConfigNames
::
CanonicalServer
=>
'https://wiki.example.com'
,
MainConfigNames
::
InternalServer
=>
'http://api.local:8080'
,
MainConfigNames
::
RestPath
=>
'/rest'
,
MainConfigNames
::
ScriptPath
=>
'/w'
,
MainConfigNames
::
RightsUrl
=>
'https://rights.url'
,
MainConfigNames
::
RightsText
=>
'your rights'
,
MainConfigNames
::
EmergencyContact
=>
'admin@test.test'
,
MainConfigNames
::
Sitename
=>
'Test Site'
,
];
$request
=
$params
[
'request'
]
??
new
RequestData
();
return
new
Router
(
$params
[
'routeFiles'
]
??
[
MW_INSTALL_PATH
.
'/tests/phpunit/unit/includes/Rest/testRoutes.json'
],
$params
[
'extraRoutes'
]
??
[],
$params
[
'options'
]
??
new
ServiceOptions
(
Router
::
CONSTRUCTOR_OPTIONS
,
$config
),
$params
[
'cacheBag'
]
??
new
EmptyBagOStuff
(),
$params
[
'responseFactory'
]
??
$responseFactory
,
$params
[
'basicAuth'
]
??
new
StaticBasicAuthorizer
(),
$params
[
'authority'
]
??
$authority
,
$params
[
'objectFactory'
]
??
$objectFactory
,
$params
[
'validator'
]
??
new
Validator
(
$objectFactory
,
$request
,
$authority
),
$params
[
'errorReporter'
]
??
new
PHPErrorReporter
(),
$params
[
'hookContainer'
]
??
$this
->
createHookContainer
(),
$params
[
'session'
]
??
$this
->
getSession
(
true
)
);
}
/**
* @since 1.43
* @param array $params Constructor parameters for Module and Router, as an associative array.
* @return Module
*/
private
function
newModule
(
array
$params
)
{
$objectFactory
=
new
ObjectFactory
(
$this
->
getMockForAbstractClass
(
ContainerInterface
::
class
)
);
$authority
=
$params
[
'authority'
]
??
$this
->
mockAnonUltimateAuthority
();
$request
=
$params
[
'request'
]
??
new
RequestData
();
$module
=
$this
->
getMockBuilder
(
Module
::
class
)
->
setConstructorArgs
(
[
$params
[
'router'
]
??
$this
->
newRouter
(
$params
),
$params
[
'pathPrefix'
]
??
'mock'
,
$params
[
'responseFactory'
]
??
new
ResponseFactory
(
[]
),
$params
[
'basicAuth'
]
??
new
StaticBasicAuthorizer
(),
$params
[
'objectFactory'
]
??
$objectFactory
,
$params
[
'restValidator'
]
??
new
Validator
(
$objectFactory
,
$request
,
$authority
),
$params
[
'errorReporter'
]
??
new
PHPErrorReporter
()
]
)
->
onlyMethods
(
[]
)
->
getMockForAbstractClass
();
return
$module
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 22:31 (4 h, 54 m ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
31/79/2cfc76942223efb188d8a6536dc4
Default Alt Text
RestTestTrait.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment