Merge "Fix more UnitTests for databases that do not use integer timestamps"
[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 var $saveContentHandlerNoDB = null;
10
11 function setUp() {
12 global $wgContentHandlerUseDB;
13
14 $this->saveContentHandlerNoDB = $wgContentHandlerUseDB;
15
16 $wgContentHandlerUseDB = false;
17
18 $dbw = wfGetDB( DB_MASTER );
19
20 $page_table = $dbw->tableName( 'page' );
21 $revision_table = $dbw->tableName( 'revision' );
22 $archive_table = $dbw->tableName( 'archive' );
23
24 if ( $dbw->fieldExists( $page_table, 'page_content_model' ) ) {
25 $dbw->query( "alter table $page_table drop column page_content_model" );
26 $dbw->query( "alter table $revision_table drop column rev_content_model" );
27 $dbw->query( "alter table $revision_table drop column rev_content_format" );
28 $dbw->query( "alter table $archive_table drop column ar_content_model" );
29 $dbw->query( "alter table $archive_table drop column ar_content_format" );
30 }
31
32 parent::setUp();
33 }
34
35 function tearDown() {
36 global $wgContentHandlerUseDB;
37
38 parent::tearDown();
39
40 $wgContentHandlerUseDB = $this->saveContentHandlerNoDB;
41 }
42
43 /**
44 * @covers Revision::selectFields
45 */
46 public function testSelectFields() {
47 $fields = Revision::selectFields();
48
49 $this->assertTrue( in_array( 'rev_id', $fields ), 'missing rev_id in list of fields' );
50 $this->assertTrue( in_array( 'rev_page', $fields ), 'missing rev_page in list of fields' );
51 $this->assertTrue( in_array( 'rev_timestamp', $fields ), 'missing rev_timestamp in list of fields' );
52 $this->assertTrue( in_array( 'rev_user', $fields ), 'missing rev_user in list of fields' );
53
54 $this->assertFalse( in_array( 'rev_content_model', $fields ), 'missing rev_content_model in list of fields' );
55 $this->assertFalse( in_array( 'rev_content_format', $fields ), 'missing rev_content_format in list of fields' );
56 }
57
58 /**
59 * @covers Revision::getContentModel
60 */
61 public function testGetContentModel() {
62 try {
63 $this->makeRevision( array( 'text' => 'hello hello.',
64 'content_model' => CONTENT_MODEL_JAVASCRIPT ) );
65
66 $this->fail( "Creating JavaScript content on a wikitext page should fail with "
67 . "\$wgContentHandlerUseDB disabled" );
68 } catch ( MWException $ex ) {
69 $this->assertTrue( true ); // ok
70 }
71 }
72
73
74 /**
75 * @covers Revision::getContentFormat
76 */
77 public function testGetContentFormat() {
78 try {
79 //@todo: change this to test failure on using a non-standard (but supported) format
80 // for a content model supported in the given location. As of 1.21, there are
81 // no alternative formats for any of the standard content models that could be
82 // used for this though.
83
84 $this->makeRevision( array( 'text' => 'hello hello.',
85 'content_model' => CONTENT_MODEL_JAVASCRIPT,
86 'content_format' => 'text/javascript' ) );
87
88 $this->fail( "Creating JavaScript content on a wikitext page should fail with "
89 . "\$wgContentHandlerUseDB disabled" );
90 } catch ( MWException $ex ) {
91 $this->assertTrue( true ); // ok
92 }
93 }
94
95 }