On Mon, Dec 25, 2017 at 12:00 PM, Tony Thomas <01tonytho...@gmail.com>
wrote:

> Came across a situation similar to [1] where I had to call submit()
> function of a FormSpecialPage during a unit test. We have something going
> on in the background, and $this->getUser() needs to return a valid user.
>
> Is there a way to mimic this context inside the unit test, so that I can
> manually set a $user in the unit test, and this would be used while
> performing inner operations ?
>

No need to mimic, you can just inject it (as long as the special page
correctly uses $this->getUser() & co instead of using globals, which is
usually not a problem with special pages) :

$specialPage = $this->newSpecialPage();
$context = new DerivativeContext( RequestContext::getMain() );
$context->setUser( $user );
$context->setRequest( ... );
$specialPage->setContext( $context );
$res = $specialPage->onSubmit( $input );
_______________________________________________
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to