Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7417116
SpecialCreateAccountTest.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
SpecialCreateAccountTest.php
View Options
<?php
use
HtmlFormatter\HtmlFormatter
;
use
MediaWiki\Auth\AbstractPreAuthenticationProvider
;
use
MediaWiki\Auth\AuthenticationRequest
;
use
MediaWiki\Context\DerivativeContext
;
use
MediaWiki\Context\IContextSource
;
use
MediaWiki\Context\RequestContext
;
use
MediaWiki\MainConfigNames
;
use
MediaWiki\Request\FauxRequest
;
use
MediaWiki\SpecialPage\SpecialPage
;
use
MediaWiki\Specials\SpecialCreateAccount
;
/**
* @covers \MediaWiki\Specials\SpecialCreateAccount
* @group Database
*/
class
SpecialCreateAccountTest
extends
SpecialPageTestBase
{
/**
* @inheritDoc
*/
protected
function
newSpecialPage
(
?
IContextSource
$context
=
null
)
{
$services
=
$this
->
getServiceContainer
();
$context
??=
RequestContext
::
getMain
();
$page
=
new
SpecialCreateAccount
(
$services
->
getAuthManager
(),
$services
->
getFormatterFactory
()
);
$page
->
setContext
(
$context
);
$context
->
setTitle
(
$page
->
getPageTitle
()
);
return
$page
;
}
public
function
testCheckPermissions
()
{
$readOnlyMode
=
$this
->
getServiceContainer
()->
getReadOnlyMode
();
$readOnlyMode
->
setReason
(
'Test'
);
$this
->
expectException
(
ErrorPageError
::
class
);
$specialPage
=
$this
->
newSpecialPage
();
$specialPage
->
checkPermissions
();
}
/**
* Regression test for T360717 -- missing hidden fields from Special:CreateAccount
*/
public
function
testHiddenField
()
{
$config
=
$this
->
getServiceContainer
()->
getMainConfig
()->
get
(
MainConfigNames
::
AuthManagerConfig
);
$config
[
'preauth'
][
'MockAuthProviderWithHiddenField'
]
=
[
'class'
=>
MockAuthProviderWithHiddenField
::
class
];
$this
->
overrideConfigValue
(
MainConfigNames
::
AuthManagerConfig
,
$config
);
$specialPage
=
$this
->
newSpecialPage
();
$specialPage
->
execute
(
null
);
$html
=
$specialPage
->
getOutput
()->
getHTML
();
$this
->
assertStringContainsString
(
'<input id="mw-input-captchaId" name="captchaId" type="hidden" value="T360717">'
,
$html
);
}
public
function
testShouldShowTemporaryPasswordAndCreationReasonFieldsForRegisteredUser
():
void
{
$user
=
$this
->
getTestUser
()->
getUser
();
$context
=
new
DerivativeContext
(
RequestContext
::
getMain
()
);
$context
->
setUser
(
$user
);
$specialPage
=
$this
->
newSpecialPage
(
$context
);
$specialPage
->
execute
(
null
);
$doc
=
self
::
getOutputHtml
(
$specialPage
);
$this
->
assertNotNull
(
$doc
->
getElementById
(
'wpReason'
)
);
$this
->
assertNotNull
(
$doc
->
getElementById
(
'wpCreateaccountMail'
)
);
}
public
function
testShouldNotShowTemporaryPasswordAndCreationReasonFieldsForTempUser
():
void
{
$req
=
new
FauxRequest
();
$tempUser
=
$this
->
getServiceContainer
()
->
getTempUserCreator
()
->
create
(
null
,
$req
)
->
getUser
();
$context
=
new
DerivativeContext
(
RequestContext
::
getMain
()
);
$context
->
setUser
(
$tempUser
);
$specialPage
=
$this
->
newSpecialPage
(
$context
);
$specialPage
->
execute
(
null
);
$doc
=
self
::
getOutputHtml
(
$specialPage
);
$this
->
assertNull
(
$doc
->
getElementById
(
'wpReason'
),
'Temporary users should not have to provide a reason for their account creation (T328718)'
);
$this
->
assertNull
(
$doc
->
getElementById
(
'wpCreateaccountMail'
),
'Temporary users should not have the option to have a temporary password sent on signup (T328718)'
);
}
/**
* Convenience function to get the parsed DOM of the HTML generated by the given special page.
* @param SpecialPage $page
* @return DOMDocument
*/
private
static
function
getOutputHtml
(
SpecialPage
$page
):
DOMDocument
{
$html
=
HtmlFormatter
::
wrapHTML
(
$page
->
getOutput
()->
getHTML
()
);
return
(
new
HtmlFormatter
(
$html
)
)->
getDoc
();
}
}
class
MockAuthRequestWithHiddenField
extends
AuthenticationRequest
{
public
function
getFieldInfo
()
{
return
[
'captchaId'
=>
[
'type'
=>
'hidden'
,
'value'
=>
'T360717'
,
'label'
=>
''
,
'help'
=>
''
,
],
];
}
}
class
MockAuthProviderWithHiddenField
extends
AbstractPreAuthenticationProvider
{
public
function
getAuthenticationRequests
(
$action
,
array
$options
)
{
return
[
new
MockAuthRequestWithHiddenField
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 03:08 (1 d, 9 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
94/00/3fd3f39f41ee967d2ab13b2237b7
Default Alt Text
SpecialCreateAccountTest.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment