X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fphpunit%2Fincludes%2FPreferencesTest.php;h=4d3b195c3446dab3f78118245b0acf5ac2a8d976;hb=9aa1db75934c1bd270ef745b4cfc98a2cd9ca1f2;hp=d78c1e7dc07dd88dfea542f5f240511a155dbce5;hpb=03cd9495a4dac1c1cda738d52e74b553b977beb8;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/PreferencesTest.php b/tests/phpunit/includes/PreferencesTest.php index d78c1e7dc0..4d3b195c34 100644 --- a/tests/phpunit/includes/PreferencesTest.php +++ b/tests/phpunit/includes/PreferencesTest.php @@ -44,6 +44,7 @@ class PreferencesTest extends MediaWikiTestCase { /** * Placeholder to verify T36302 * @covers Preferences::profilePreferences + * @deprecated replaced by DefaultPreferencesFactoryTest::testEmailAuthentication() */ public function testEmailAuthenticationFieldWhenUserHasNoEmail() { $prefs = $this->prefsFor( 'noemail' ); @@ -56,6 +57,7 @@ class PreferencesTest extends MediaWikiTestCase { /** * Placeholder to verify T36302 * @covers Preferences::profilePreferences + * @deprecated replaced by DefaultPreferencesFactoryTest::testEmailAuthentication() */ public function testEmailAuthenticationFieldWhenUserEmailNotAuthenticated() { $prefs = $this->prefsFor( 'notauth' ); @@ -68,6 +70,7 @@ class PreferencesTest extends MediaWikiTestCase { /** * Placeholder to verify T36302 * @covers Preferences::profilePreferences + * @deprecated replaced by DefaultPreferencesFactoryTest::testEmailAuthentication() */ public function testEmailAuthenticationFieldWhenUserEmailIsAuthenticated() { $prefs = $this->prefsFor( 'auth' ); @@ -77,86 +80,11 @@ class PreferencesTest extends MediaWikiTestCase { $this->assertEquals( 'mw-email-authenticated', $prefs['emailauthentication']['cssclass'] ); } - /** - * Test that PreferencesFormPreSave hook has correct data: - * - user Object is passed - * - oldUserOptions contains previous user options (before save) - * - formData and User object have set up new properties - * - * @see https://phabricator.wikimedia.org/T169365 - * @covers Preferences::tryFormSubmit - */ - public function testPreferencesFormPreSaveHookHasCorrectData() { - $oldOptions = [ - 'test' => 'abc', - 'option' => 'old' - ]; - $newOptions = [ - 'test' => 'abc', - 'option' => 'new' - ]; - $configMock = new HashConfig( [ - 'HiddenPrefs' => [] - ] ); - $form = $this->getMockBuilder( PreferencesForm::class ) - ->disableOriginalConstructor() - ->getMock(); - - $userMock = $this->getMockBuilder( User::class ) - ->disableOriginalConstructor() - ->getMock(); - $userMock->method( 'getOptions' ) - ->willReturn( $oldOptions ); - $userMock->method( 'isAllowedAny' ) - ->willReturn( true ); - $userMock->method( 'isAllowed' ) - ->willReturn( true ); - - $userMock->expects( $this->exactly( 2 ) ) - ->method( 'setOption' ) - ->withConsecutive( - [ $this->equalTo( 'test' ), $this->equalTo( $newOptions[ 'test' ] ) ], - [ $this->equalTo( 'option' ), $this->equalTo( $newOptions[ 'option' ] ) ] - ); - - $form->expects( $this->any() ) - ->method( 'getModifiedUser' ) - ->willReturn( $userMock ); - - $form->expects( $this->any() ) - ->method( 'getContext' ) - ->willReturn( $this->context ); - - $form->expects( $this->any() ) - ->method( 'getConfig' ) - ->willReturn( $configMock ); - - $this->setTemporaryHook( 'PreferencesFormPreSave', function ( - $formData, $form, $user, &$result, $oldUserOptions ) - use ( $newOptions, $oldOptions, $userMock ) { - $this->assertSame( $userMock, $user ); - foreach ( $newOptions as $option => $value ) { - $this->assertSame( $value, $formData[ $option ] ); - } - foreach ( $oldOptions as $option => $value ) { - $this->assertSame( $value, $oldUserOptions[ $option ] ); - } - $this->assertEquals( true, $result ); - } - ); - - Preferences::tryFormSubmit( $newOptions, $form ); - } - /** Helper */ protected function prefsFor( $user_key ) { - $preferences = []; - Preferences::profilePreferences( + return Preferences::getPreferences( $this->prefUsers[$user_key], - $this->context, - $preferences + $this->context ); - - return $preferences; } }