/**
* @group API
+ * @group Database
*/
class ApiOptionsTest extends MediaWikiLangTestCase {
private $mTested, $mUserMock, $mContext, $mSession;
+ private $mOldGetPreferencesHooks = false;
+
private static $Success = array( 'options' => 'success' );
protected function setUp() {
->disableOriginalConstructor()
->getMock();
+ // Set up groups
+ $this->mUserMock->expects( $this->any() )
+ ->method( 'getEffectiveGroups' )->will( $this->returnValue( array( '*', 'user')) );
+
// Create a new context
$this->mContext = new DerivativeContext( new RequestContext() );
+ $this->mContext->getContext()->setTitle( Title::newFromText( 'Test' ) );
$this->mContext->setUser( $this->mUserMock );
$main = new ApiMain( $this->mContext );
$this->mSession = array();
$this->mTested = new ApiOptions( $main, 'options' );
+
+ global $wgHooks;
+ if ( !isset( $wgHooks['GetPreferences'] ) ) {
+ $wgHooks['GetPreferences'] = array();
+ }
+ $this->mOldGetPreferencesHooks = $wgHooks['GetPreferences'];
+ $wgHooks['GetPreferences'][] = array( $this, 'hookGetPreferences' );
+ }
+
+ protected function tearDown() {
+ global $wgHooks;
+
+ if ( $this->mOldGetPreferencesHooks !== false ) {
+ $wgHooks['GetPreferences'] = $this->mOldGetPreferencesHooks;
+ $this->mOldGetPreferencesHooks = false;
+ }
+
+ parent::tearDown();
+ }
+
+ public function hookGetPreferences( $user, &$preferences ) {
+ foreach ( array( 'name', 'willBeNull', 'willBeEmpty', 'willBeHappy' ) as $k ) {
+ $preferences[$k] = array(
+ 'type' => 'text',
+ 'section' => 'test',
+ 'label' => ' ',
+ );
+ }
+
+ return true;
}
private function getSampleRequest( $custom = array() ) {
$this->fail( "UsageException was not thrown" );
}
- /**
- * @group Broken
- */
public function testReset() {
$this->mUserMock->expects( $this->once() )
->method( 'resetOptions' );
$this->assertEquals( self::$Success, $response );
}
- /**
- * @group Broken
- */
public function testOptionWithValue() {
$this->mUserMock->expects( $this->never() )
->method( 'resetOptions' );
$this->assertEquals( self::$Success, $response );
}
- /**
- * @group Broken
- */
public function testOptionResetValue() {
$this->mUserMock->expects( $this->never() )
->method( 'resetOptions' );
$this->assertEquals( self::$Success, $response );
}
- /**
- * @group Broken
- */
public function testChange() {
$this->mUserMock->expects( $this->never() )
->method( 'resetOptions' );
$this->mUserMock->expects( $this->at( 1 ) )
+ ->method( 'getOptions' );
+
+ $this->mUserMock->expects( $this->at( 2 ) )
->method( 'setOption' )
->with( $this->equalTo( 'willBeNull' ), $this->equalTo( null ) );
- $this->mUserMock->expects( $this->at( 2 ) )
+ $this->mUserMock->expects( $this->at( 3 ) )
+ ->method( 'getOptions' );
+
+ $this->mUserMock->expects( $this->at( 4 ) )
->method( 'setOption' )
->with( $this->equalTo( 'willBeEmpty' ), $this->equalTo( '' ) );
- $this->mUserMock->expects( $this->at( 3 ) )
+ $this->mUserMock->expects( $this->at( 5 ) )
+ ->method( 'getOptions' );
+
+ $this->mUserMock->expects( $this->at( 6 ) )
->method( 'setOption' )
->with( $this->equalTo( 'willBeHappy' ), $this->equalTo( 'Happy' ) );
$this->assertEquals( self::$Success, $response );
}
- /**
- * @group Broken
- */
public function testResetChangeOption() {
$this->mUserMock->expects( $this->once() )
->method( 'resetOptions' );
$this->mUserMock->expects( $this->at( 2 ) )
+ ->method( 'getOptions' );
+
+ $this->mUserMock->expects( $this->at( 3 ) )
->method( 'setOption' )
->with( $this->equalTo( 'willBeHappy' ), $this->equalTo( 'Happy' ) );
- $this->mUserMock->expects( $this->at( 3 ) )
+ $this->mUserMock->expects( $this->at( 4 ) )
+ ->method( 'getOptions' );
+
+ $this->mUserMock->expects( $this->at( 5 ) )
->method( 'setOption' )
->with( $this->equalTo( 'name' ), $this->equalTo( 'value' ) );