From: Marius Hoch Date: Thu, 18 Oct 2012 03:03:10 +0000 (+0200) Subject: Unit test for User::getEditCount X-Git-Tag: 1.31.0-rc.0~21930^2 X-Git-Url: http://git.cyclocoop.org/%27-%20%20.%20url_absolue%28find_in_path%28%27spip_style.css%27%29%29%20%20%20.%20url_absolue%28find_in_path%28%27prive/spip_style.css%27%29%29%20.%20%27?a=commitdiff_plain;h=e65eb02d3e1d5ad49b50f4c95d6f5d21fa40e80a;p=lhc%2Fweb%2Fwiklou.git Unit test for User::getEditCount Rather trivial test for User::getEditCount as suggested by Siebrand in https://gerrit.wikimedia.org/r/26457 This required adding the User in the test to DB, as the data is written to and read from the DB. Change-Id: Ic4e55c01247158315b759654b34fdbdf9a61db01 --- diff --git a/tests/phpunit/includes/UserTest.php b/tests/phpunit/includes/UserTest.php index 316e6f5a24..a788253297 100644 --- a/tests/phpunit/includes/UserTest.php +++ b/tests/phpunit/includes/UserTest.php @@ -162,4 +162,28 @@ class UserTest extends MediaWikiTestCase { 'Each user rights (core/extensions) has a corresponding right- message.' ); } + + /** + * Test User::editCount + */ + public function testEditCount() { + $user = User::newFromName( 'UnitTestUser' ); + $user->loadDefaults(); + $user->addToDatabase(); + + // let the user have a few (10) edits + $page = WikiPage::factory( Title::newFromText( 'UserTest_EditCount' ) ); + for( $i = 0; $i < 10; $i++ ) { + $page->doEdit( (string) $i, 'test', 0, false, $user ); + } + + $user->clearInstanceCache(); + $this->assertEquals( 10, $user->getEditCount(), 'After ten edits, the user edit count should be 10' ); + + // increase the edit count and clear the cache + $user->incEditCount(); + + $user->clearInstanceCache(); + $this->assertEquals( 11, $user->getEditCount(), 'After increasing the edit count manually, the user edit count should be 11' ); + } }