From: daniel Date: Fri, 22 Jun 2012 22:04:09 +0000 (+0200) Subject: very basic test for ApiEditPage X-Git-Tag: 1.31.0-rc.0~22590 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=78b4f237ef868934e6c912a295836fa40a3ed718;p=lhc%2Fweb%2Fwiklou.git very basic test for ApiEditPage Based on the generic Api logging system in APITestCase. Change-Id: I28c0bd41f585cca199fdef9a78e60ef66625d37f --- diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php b/tests/phpunit/includes/api/ApiEditPageTest.php new file mode 100644 index 0000000000..5297d6daa7 --- /dev/null +++ b/tests/phpunit/includes/api/ApiEditPageTest.php @@ -0,0 +1,84 @@ +doLogin(); + } + + function testEdit( ) { + $name = 'ApiEditPageTest_testEdit'; + + // -- test new page -------------------------------------------- + $apiResult = $this->doApiRequestWithToken( array( + 'action' => 'edit', + 'title' => $name, + 'text' => 'some text', ) ); + $apiResult = $apiResult[0]; + + # Validate API result data + $this->assertArrayHasKey( 'edit', $apiResult ); + $this->assertArrayHasKey( 'result', $apiResult['edit'] ); + $this->assertEquals( 'Success', $apiResult['edit']['result'] ); + + $this->assertArrayHasKey( 'new', $apiResult['edit'] ); + $this->assertArrayNotHasKey( 'nochange', $apiResult['edit'] ); + + $this->assertArrayHasKey( 'pageid', $apiResult['edit'] ); + + // -- test existing page, no change ---------------------------- + $data = $this->doApiRequestWithToken( array( + 'action' => 'edit', + 'title' => $name, + 'text' => 'some text', ) ); + + $this->assertEquals( 'Success', $data[0]['edit']['result'] ); + + $this->assertArrayNotHasKey( 'new', $data[0]['edit'] ); + $this->assertArrayHasKey( 'nochange', $data[0]['edit'] ); + + // -- test existing page, with change -------------------------- + $data = $this->doApiRequestWithToken( array( + 'action' => 'edit', + 'title' => $name, + 'text' => 'different text' ) ); + + $this->assertEquals( 'Success', $data[0]['edit']['result'] ); + + $this->assertArrayNotHasKey( 'new', $data[0]['edit'] ); + $this->assertArrayNotHasKey( 'nochange', $data[0]['edit'] ); + + $this->assertArrayHasKey( 'oldrevid', $data[0]['edit'] ); + $this->assertArrayHasKey( 'newrevid', $data[0]['edit'] ); + $this->assertNotEquals( + $data[0]['edit']['newrevid'], + $data[0]['edit']['oldrevid'], + "revision id should change after edit" + ); + } + + function testEditAppend() { + $this->markTestIncomplete( "not yet implemented" ); + } + + function testEditSection() { + $this->markTestIncomplete( "not yet implemented" ); + } + + function testUndo() { + $this->markTestIncomplete( "not yet implemented" ); + } + + function testEditNonText() { + $this->markTestIncomplete( "not yet implemented" ); + } +} diff --git a/tests/phpunit/includes/api/ApiTestCase.php b/tests/phpunit/includes/api/ApiTestCase.php index 3b044ef94b..d6c48cbd73 100644 --- a/tests/phpunit/includes/api/ApiTestCase.php +++ b/tests/phpunit/includes/api/ApiTestCase.php @@ -85,10 +85,16 @@ abstract class ApiTestCase extends MediaWikiLangTestCase { * This is cheating a bit -- we grab a token in the correct format and then add it to the pseudo-session and to the * request, without actually requesting a "real" edit token * @param $params Array: key-value API params - * @param $session Array: session array + * @param $session Array|null: session array * @param $user User|null A User object for the context */ - protected function doApiRequestWithToken( Array $params, Array $session, User $user = null ) { + protected function doApiRequestWithToken( Array $params, Array $session = null, User $user = null ) { + global $wgRequest; + + if ( $session === null ) { + $session = $wgRequest->getSessionArray(); + } + if ( $session['wsToken'] ) { // add edit token to fake session $session['wsEditToken'] = $session['wsToken'];