2012-06-25 14:09:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2012-08-29 13:14:49 +00:00
|
|
|
* @group Editing
|
2012-06-25 14:09:08 +00:00
|
|
|
* @group API
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
|
|
|
|
class ApiEditPageTest extends ApiTestCase {
|
|
|
|
|
|
|
|
|
|
function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
$this->doLogin();
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 13:14:49 +00:00
|
|
|
function getTokens() {
|
|
|
|
|
return $this->getTokenList( self::$users['sysop'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testEdit() {
|
2012-06-25 14:09:08 +00:00
|
|
|
$name = 'ApiEditPageTest_testEdit';
|
|
|
|
|
|
2012-08-29 13:14:49 +00:00
|
|
|
$tokenData = $this->getTokens();
|
|
|
|
|
|
|
|
|
|
if( !isset( $tokenData[0]['query']['pages'] ) ) {
|
|
|
|
|
$this->markTestIncomplete( "No edit token found" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$keys = array_keys( $tokenData[0]['query']['pages'] );
|
|
|
|
|
$key = array_pop( $keys );
|
|
|
|
|
$pageinfo = $tokenData[0]['query']['pages'][$key];
|
|
|
|
|
$session = $tokenData[2];
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
$data = $this->doApiRequest( array(
|
2012-06-25 14:09:08 +00:00
|
|
|
'action' => 'edit',
|
|
|
|
|
'title' => $name,
|
2012-08-29 13:14:49 +00:00
|
|
|
'text' => 'some text',
|
|
|
|
|
'token' => $pageinfo['edittoken'] ),
|
|
|
|
|
$session,
|
|
|
|
|
false,
|
|
|
|
|
self::$users['sysop']->user );
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'edit', $data[0] );
|
|
|
|
|
$this->assertArrayHasKey( 'result', $data[0]['edit'] );
|
|
|
|
|
$this->assertEquals( 'Success', $data[0]['edit']['result'] );
|
2012-08-29 08:07:10 +00:00
|
|
|
|
2012-08-29 13:14:49 +00:00
|
|
|
$this->assertArrayHasKey( 'new', $data[0]['edit'] );
|
|
|
|
|
$this->assertArrayNotHasKey( 'nochange', $data[0]['edit'] );
|
2012-06-25 14:09:08 +00:00
|
|
|
|
2012-08-29 13:14:49 +00:00
|
|
|
$this->assertArrayHasKey( 'pageid', $data[0]['edit'] );
|
|
|
|
|
$this->assertArrayHasKey( 'contentmodel', $data[0]['edit'] );
|
|
|
|
|
$this->assertEquals( CONTENT_MODEL_WIKITEXT, $data[0]['edit']['contentmodel'] );
|
2012-06-25 14:09:08 +00:00
|
|
|
|
2012-08-29 13:14:49 +00:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
$data = $this->doApiRequest( array(
|
2012-06-25 14:09:08 +00:00
|
|
|
'action' => 'edit',
|
|
|
|
|
'title' => $name,
|
2012-08-29 13:14:49 +00:00
|
|
|
'text' => 'some text',
|
|
|
|
|
'token' => $pageinfo['edittoken'] ),
|
|
|
|
|
$session,
|
|
|
|
|
false,
|
|
|
|
|
self::$users['sysop']->user );
|
2012-06-25 14:09:08 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( 'Success', $data[0]['edit']['result'] );
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey( 'new', $data[0]['edit'] );
|
|
|
|
|
$this->assertArrayHasKey( 'nochange', $data[0]['edit'] );
|
|
|
|
|
|
2012-08-29 13:14:49 +00:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
$data = $this->doApiRequest( array(
|
2012-06-25 14:09:08 +00:00
|
|
|
'action' => 'edit',
|
|
|
|
|
'title' => $name,
|
2012-08-29 13:14:49 +00:00
|
|
|
'text' => 'different text',
|
|
|
|
|
'token' => $pageinfo['edittoken'] ),
|
|
|
|
|
$session,
|
|
|
|
|
false,
|
|
|
|
|
self::$users['sysop']->user );
|
2012-06-25 14:09:08 +00:00
|
|
|
|
|
|
|
|
$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'] );
|
2012-08-29 13:14:49 +00:00
|
|
|
$this->assertTrue( $data[0]['edit']['newrevid'] !== $data[0]['edit']['oldrevid'], "revision id should change after edit" );
|
2012-06-25 14:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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" );
|
|
|
|
|
}
|
|
|
|
|
}
|