Merge "Add Special:Login and Special:Logout as aliases."
[lhc/web/wiklou.git] / tests / phpunit / includes / RevisionStorageTest_ContentHandlerUseDB.php
1 <?php
2
3 /**
4 * @group ContentHandler
5 * @group Database
6 * ^--- important, causes temporary tables to be used instead of the real database
7 */
8 class RevisionTest_ContentHandlerUseDB extends RevisionStorageTest {
9
10 function setUp() {
11 $this->setMwGlobals( 'wgContentHandlerUseDB', false );
12
13 $dbw = wfGetDB( DB_MASTER );
14
15 $page_table = $dbw->tableName( 'page' );
16 $revision_table = $dbw->tableName( 'revision' );
17 $archive_table = $dbw->tableName( 'archive' );
18
19 if ( $dbw->fieldExists( $page_table, 'page_content_model' ) ) {
20 $dbw->query( "alter table $page_table drop column page_content_model" );
21 $dbw->query( "alter table $revision_table drop column rev_content_model" );
22 $dbw->query( "alter table $revision_table drop column rev_content_format" );
23 $dbw->query( "alter table $archive_table drop column ar_content_model" );
24 $dbw->query( "alter table $archive_table drop column ar_content_format" );
25 }
26
27 parent::setUp();
28 }
29
30 /**
31 * @covers Revision::selectFields
32 */
33 public function testSelectFields() {
34 $fields = Revision::selectFields();
35
36 $this->assertTrue( in_array( 'rev_id', $fields ), 'missing rev_id in list of fields' );
37 $this->assertTrue( in_array( 'rev_page', $fields ), 'missing rev_page in list of fields' );
38 $this->assertTrue( in_array( 'rev_timestamp', $fields ), 'missing rev_timestamp in list of fields' );
39 $this->assertTrue( in_array( 'rev_user', $fields ), 'missing rev_user in list of fields' );
40
41 $this->assertFalse( in_array( 'rev_content_model', $fields ), 'missing rev_content_model in list of fields' );
42 $this->assertFalse( in_array( 'rev_content_format', $fields ), 'missing rev_content_format in list of fields' );
43 }
44
45 /**
46 * @covers Revision::getContentModel
47 */
48 public function testGetContentModel() {
49 try {
50 $this->makeRevision( array( 'text' => 'hello hello.',
51 'content_model' => CONTENT_MODEL_JAVASCRIPT ) );
52
53 $this->fail( "Creating JavaScript content on a wikitext page should fail with "
54 . "\$wgContentHandlerUseDB disabled" );
55 } catch ( MWException $ex ) {
56 $this->assertTrue( true ); // ok
57 }
58 }
59
60
61 /**
62 * @covers Revision::getContentFormat
63 */
64 public function testGetContentFormat() {
65 try {
66 // @todo change this to test failure on using a non-standard (but supported) format
67 // for a content model supported in the given location. As of 1.21, there are
68 // no alternative formats for any of the standard content models that could be
69 // used for this though.
70
71 $this->makeRevision( array( 'text' => 'hello hello.',
72 'content_model' => CONTENT_MODEL_JAVASCRIPT,
73 'content_format' => 'text/javascript' ) );
74
75 $this->fail( "Creating JavaScript content on a wikitext page should fail with "
76 . "\$wgContentHandlerUseDB disabled" );
77 } catch ( MWException $ex ) {
78 $this->assertTrue( true ); // ok
79 }
80 }
81 }