3ed983b01adf89e1be1dd1fbf2e6e63f0a49be35
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiEditPageTest.php
1 <?php
2
3 /**
4 * @group API
5 * @group Database
6 */
7 class ApiEditPageTest extends ApiTestCase {
8
9 function setUp() {
10 parent::setUp();
11 $this->doLogin();
12 }
13
14 function getTokens() {
15 return $this->getTokenList( self::$users['sysop'] );
16 }
17
18 function testEdit() {
19 $name = 'ApiEditPageTest_testEdit';
20
21 $tokenData = $this->getTokens();
22
23 if( !isset( $tokenData[0]['query']['pages'] ) ) {
24 $this->markTestIncomplete( "No edit token found" );
25 }
26
27 $keys = array_keys( $tokenData[0]['query']['pages'] );
28 $key = array_pop( $keys );
29 $pageinfo = $tokenData[0]['query']['pages'][$key];
30 $session = $tokenData[2];
31
32 // -----------------------------------------------------------------------
33
34 $data = $this->doApiRequest( array(
35 'action' => 'edit',
36 'title' => $name,
37 'text' => 'some text',
38 'token' => $pageinfo['edittoken'] ),
39 $session,
40 false,
41 self::$users['sysop']->user );
42
43 $this->assertArrayHasKey( 'edit', $data[0] );
44 $this->assertArrayHasKey( 'result', $data[0]['edit'] );
45 $this->assertEquals( 'Success', $data[0]['edit']['result'] );
46
47 $this->assertArrayHasKey( 'new', $data[0]['edit'] );
48 $this->assertArrayNotHasKey( 'nochange', $data[0]['edit'] );
49
50 $this->assertArrayHasKey( 'pageid', $data[0]['edit'] );
51 $this->assertArrayHasKey( 'contentmodel', $data[0]['edit'] );
52 $this->assertEquals( CONTENT_MODEL_WIKITEXT, $data[0]['edit']['contentmodel'] );
53
54 // -----------------------------------------------------------------------
55 $data = $this->doApiRequest( array(
56 'action' => 'edit',
57 'title' => $name,
58 'text' => 'some text',
59 'token' => $pageinfo['edittoken'] ),
60 $session,
61 false,
62 self::$users['sysop']->user );
63
64 $this->assertEquals( 'Success', $data[0]['edit']['result'] );
65
66 $this->assertArrayNotHasKey( 'new', $data[0]['edit'] );
67 $this->assertArrayHasKey( 'nochange', $data[0]['edit'] );
68
69 // -----------------------------------------------------------------------
70 $data = $this->doApiRequest( array(
71 'action' => 'edit',
72 'title' => $name,
73 'text' => 'different text',
74 'token' => $pageinfo['edittoken'] ),
75 $session,
76 false,
77 self::$users['sysop']->user );
78
79 $this->assertEquals( 'Success', $data[0]['edit']['result'] );
80
81 $this->assertArrayNotHasKey( 'new', $data[0]['edit'] );
82 $this->assertArrayNotHasKey( 'nochange', $data[0]['edit'] );
83
84 $this->assertArrayHasKey( 'oldrevid', $data[0]['edit'] );
85 $this->assertArrayHasKey( 'newrevid', $data[0]['edit'] );
86 $this->assertTrue( $data[0]['edit']['newrevid'] !== $data[0]['edit']['oldrevid'], "revision id should change after edit" );
87 }
88
89 function testEditAppend() {
90 $this->markTestIncomplete( "not yet implemented" );
91 }
92
93 function testEditSection() {
94 $this->markTestIncomplete( "not yet implemented" );
95 }
96
97 function testUndo() {
98 $this->markTestIncomplete( "not yet implemented" );
99 }
100
101 function testEditNonText() {
102 $this->markTestIncomplete( "not yet implemented" );
103 }
104 }