Index: branches/REL1_18/phase3/tests/phpunit/MediaWikiTestCase.php |
— | — | @@ -4,11 +4,14 @@ |
5 | 5 | public $suite; |
6 | 6 | public $regex = ''; |
7 | 7 | public $runDisabled = false; |
8 | | - |
| 8 | + |
| 9 | + /** |
| 10 | + * @var DatabaseBase |
| 11 | + */ |
9 | 12 | protected $db; |
10 | | - protected $dbClone; |
11 | 13 | protected $oldTablePrefix; |
12 | 14 | protected $useTemporaryTables = true; |
| 15 | + private static $dbSetup = false; |
13 | 16 | |
14 | 17 | /** |
15 | 18 | * Table name prefixes. Oracle likes it shorter. |
— | — | @@ -43,28 +46,24 @@ |
44 | 47 | $this->db = wfGetDB( DB_MASTER ); |
45 | 48 | |
46 | 49 | $this->checkDbIsSupported(); |
47 | | - |
| 50 | + |
48 | 51 | $this->oldTablePrefix = $wgDBprefix; |
49 | | - |
50 | | - $this->destroyDB(); |
51 | | - |
52 | | - $this->initDB(); |
| 52 | + |
| 53 | + if( !self::$dbSetup ) { |
| 54 | + $this->initDB(); |
| 55 | + self::$dbSetup = true; |
| 56 | + } |
| 57 | + |
53 | 58 | $this->addCoreDBData(); |
54 | 59 | $this->addDBData(); |
55 | 60 | |
56 | 61 | parent::run( $result ); |
57 | | - |
58 | | - $this->destroyDB(); |
| 62 | + |
| 63 | + $this->resetDB(); |
59 | 64 | } else { |
60 | 65 | parent::run( $result ); |
61 | 66 | } |
62 | 67 | } |
63 | | - |
64 | | - function __destruct() { |
65 | | - if( $this->needsDB() ) { |
66 | | - $this->destroyDB(); |
67 | | - } |
68 | | - } |
69 | 68 | |
70 | 69 | function dbPrefix() { |
71 | 70 | return $this->db->getType() == 'oracle' ? self::ORA_DB_PREFIX : self::DB_PREFIX; |
— | — | @@ -109,61 +108,59 @@ |
110 | 109 | |
111 | 110 | private function initDB() { |
112 | 111 | global $wgDBprefix; |
113 | | - |
114 | | - $dbType = $this->db->getType(); |
115 | | - |
116 | 112 | if ( $wgDBprefix === $this->dbPrefix() ) { |
117 | 113 | throw new MWException( 'Cannot run unit tests, the database prefix is already "unittest_"' ); |
118 | 114 | } |
119 | 115 | |
120 | | - $tables = $this->listTables(); |
121 | | - |
122 | | - $this->dbClone = new CloneDatabase( $this->db, $tables, $this->dbPrefix() ); |
123 | | - $this->dbClone->useTemporaryTables( $this->useTemporaryTables ); |
124 | | - $this->dbClone->cloneTableStructure(); |
125 | | - |
126 | | - if ( $dbType == 'oracle' ) |
| 116 | + $dbClone = new CloneDatabase( $this->db, $this->listTables(), $this->dbPrefix() ); |
| 117 | + $dbClone->useTemporaryTables( $this->useTemporaryTables ); |
| 118 | + $dbClone->cloneTableStructure(); |
| 119 | + |
| 120 | + if ( $this->db->getType() == 'oracle' ) { |
127 | 121 | $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' ); |
128 | 122 | |
129 | | - if ( $dbType == 'oracle' ) { |
130 | 123 | # Insert 0 user to prevent FK violations |
131 | | - |
132 | 124 | # Anonymous user |
133 | 125 | $this->db->insert( 'user', array( |
134 | 126 | 'user_id' => 0, |
135 | 127 | 'user_name' => 'Anonymous' ) ); |
136 | 128 | } |
137 | | - |
138 | 129 | } |
139 | | - |
| 130 | + |
| 131 | + /** |
| 132 | + * Empty all tables so they can be repopulated for tests |
| 133 | + */ |
| 134 | + private function resetDB() { |
| 135 | + if( $this->db ) { |
| 136 | + foreach( $this->listTables() as $tbl ) { |
| 137 | + if( $tbl == 'interwiki' || $tbl == 'user' ) continue; |
| 138 | + $this->db->delete( $tbl, '*', __METHOD__ ); |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + |
140 | 143 | protected function destroyDB() { |
141 | | - |
142 | | - if ( $this->useTemporaryTables ) { |
| 144 | + if ( $this->useTemporaryTables || is_null( $this->db ) ) { |
143 | 145 | # Don't need to do anything |
144 | | - //return; |
145 | | - //Temporary tables seem to be broken ATM, delete anyway |
146 | | - } |
147 | | - |
148 | | - if( is_null( $this->db ) ) { |
149 | 146 | return; |
150 | 147 | } |
151 | | - |
| 148 | + |
152 | 149 | $tables = $this->db->listTables( $this->dbPrefix(), __METHOD__ ); |
153 | | - |
| 150 | + |
154 | 151 | foreach ( $tables as $table ) { |
155 | 152 | try { |
156 | 153 | $sql = $this->db->getType() == 'oracle' ? "DROP TABLE $table CASCADE CONSTRAINTS PURGE" : "DROP TABLE `$table`"; |
157 | 154 | $this->db->query( $sql, __METHOD__ ); |
158 | | - } catch( Exception $e ) { |
159 | | - } |
| 155 | + } catch( MWException $mwe ) {} |
160 | 156 | } |
161 | | - |
| 157 | + |
162 | 158 | if ( $this->db->getType() == 'oracle' ) |
163 | 159 | $this->db->query( 'BEGIN FILL_WIKI_INFO; END;', __METHOD__ ); |
164 | | - |
| 160 | + |
165 | 161 | CloneDatabase::changePrefix( $this->oldTablePrefix ); |
166 | 162 | } |
167 | 163 | |
| 164 | + |
168 | 165 | function __call( $func, $args ) { |
169 | 166 | static $compatibility = array( |
170 | 167 | 'assertInternalType' => 'assertType', |
— | — | @@ -193,7 +190,7 @@ |
194 | 191 | |
195 | 192 | protected function listTables() { |
196 | 193 | global $wgDBprefix; |
197 | | - |
| 194 | + |
198 | 195 | $tables = $this->db->listTables( $wgDBprefix, __METHOD__ ); |
199 | 196 | $tables = array_map( array( __CLASS__, 'unprefixTable' ), $tables ); |
200 | 197 | |
Property changes on: branches/REL1_18/phase3/tests/phpunit/MediaWikiTestCase.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
201 | 198 | Merged /branches/REL1_17/phase3/tests/phpunit/MediaWikiTestCase.php:r81445,81448 |
202 | 199 | Merged /branches/sqlite/tests/phpunit/MediaWikiTestCase.php:r58211-58321 |
203 | 200 | Merged /trunk/phase3/tests/phpunit/MediaWikiTestCase.php:r87632,87636,87640,87644,88231-88232,88755,88769,89099,89108,89301,89479-89480,90602,90612,90618,90626,90630-90631,90637,90655,90657,90666,90812 |
204 | 201 | Merged /branches/new-installer/phase3/tests/phpunit/MediaWikiTestCase.php:r43664-66004 |
205 | 202 | Merged /branches/REL1_15/phase3/tests/phpunit/MediaWikiTestCase.php:r51646 |
Index: branches/REL1_18/phase3/tests/phpunit/includes/XmlJsTest.php |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | <?php |
3 | | -class XmlJs extends PHPUnit_Framework_TestCase { |
| 3 | +class XmlJs extends MediaWikiTestCase { |
4 | 4 | public function testConstruction() { |
5 | 5 | $obj = new XmlJsCode( null ); |
6 | 6 | $this->assertNull( $obj->value ); |
Index: branches/REL1_18/phase3/tests/phpunit/includes/MWNamespaceTest.php |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | * Generated by PHPUnit on 2011-02-20 at 21:01:55. |
12 | 12 | * |
13 | 13 | */ |
14 | | -class MWNamespaceTest extends PHPUnit_Framework_TestCase { |
| 14 | +class MWNamespaceTest extends MediaWikiTestCase { |
15 | 15 | /** |
16 | 16 | * @var MWNamespace |
17 | 17 | */ |
Index: branches/REL1_18/phase3/tests/phpunit/includes/parser/MagicVariableTest.php |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | */ |
14 | 14 | |
15 | 15 | /** */ |
16 | | -class MagicVariableTest extends PHPUnit_Framework_TestCase { |
| 16 | +class MagicVariableTest extends MediaWikiTestCase { |
17 | 17 | /** Will contains a parser object*/ |
18 | 18 | private $testParser = null; |
19 | 19 | |
Index: branches/REL1_18/phase3/tests/phpunit/includes/api/ApiWatchTest.php |
— | — | @@ -5,6 +5,7 @@ |
6 | 6 | /** |
7 | 7 | * @group Database |
8 | 8 | * @group Destructive |
| 9 | + * @todo This test suite is severly broken and need a full review |
9 | 10 | */ |
10 | 11 | class ApiWatchTest extends ApiTestSetup { |
11 | 12 | |
— | — | @@ -17,11 +18,13 @@ |
18 | 19 | return $this->getTokenList( $this->sysopUser ); |
19 | 20 | } |
20 | 21 | |
| 22 | + /** |
| 23 | + * @group Broken |
| 24 | + */ |
21 | 25 | function testWatchEdit() { |
22 | 26 | |
23 | 27 | $data = $this->getTokens(); |
24 | 28 | |
25 | | - $this->markTestIncomplete( "Broken" ); |
26 | 29 | $keys = array_keys( $data[0]['query']['pages'] ); |
27 | 30 | $key = array_pop( $keys ); |
28 | 31 | $pageinfo = $data[0]['query']['pages'][$key]; |
— | — | @@ -68,12 +71,13 @@ |
69 | 72 | return $data; |
70 | 73 | } |
71 | 74 | |
72 | | - |
| 75 | + /** |
| 76 | + * @group Broken |
| 77 | + */ |
73 | 78 | function testWatchProtect() { |
74 | 79 | |
75 | 80 | $data = $this->getTokens(); |
76 | 81 | |
77 | | - $this->markTestIncomplete( "Broken" ); |
78 | 82 | $keys = array_keys( $data[0]['query']['pages'] ); |
79 | 83 | $key = array_pop( $keys ); |
80 | 84 | $pageinfo = $data[0]['query']['pages'][$key]; |
— | — | @@ -125,6 +129,7 @@ |
126 | 130 | |
127 | 131 | /** |
128 | 132 | * @depends testGetRollbackToken |
| 133 | + * @group Broken |
129 | 134 | */ |
130 | 135 | function testWatchRollback( $data ) { |
131 | 136 | $keys = array_keys( $data[0]['query']['pages'] ); |
— | — | @@ -142,7 +147,7 @@ |
143 | 148 | if( $ue->getCodeString() == 'onlyauthor' ) { |
144 | 149 | $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" ); |
145 | 150 | } else { |
146 | | - $this->fail( "Received error " . $ue->getCodeString() ); |
| 151 | + $this->fail( "Received error '" . $ue->getCodeString() . "'" ); |
147 | 152 | } |
148 | 153 | } |
149 | 154 | |
— | — | @@ -150,12 +155,13 @@ |
151 | 156 | $this->assertArrayHasKey( 'title', $data[0]['rollback'] ); |
152 | 157 | } |
153 | 158 | |
154 | | - |
| 159 | + /** |
| 160 | + * @group Broken |
| 161 | + */ |
155 | 162 | function testWatchDelete() { |
156 | 163 | |
157 | 164 | $data = $this->getTokens(); |
158 | 165 | |
159 | | - $this->markTestIncomplete( "Broken" ); |
160 | 166 | $keys = array_keys( $data[0]['query']['pages'] ); |
161 | 167 | $key = array_pop( $keys ); |
162 | 168 | $pageinfo = $data[0]['query']['pages'][$key]; |
Property changes on: branches/REL1_18/phase3/tests/phpunit/includes/api/ApiWatchTest.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
163 | 169 | Merged /branches/REL1_17/phase3/tests/phpunit/includes/api/ApiWatchTest.php:r81445,81448 |
164 | 170 | Merged /branches/sqlite/tests/phpunit/includes/api/ApiWatchTest.php:r58211-58321 |
165 | 171 | Merged /trunk/phase3/tests/phpunit/includes/api/ApiWatchTest.php:r87632,87636,87640,87644,88231-88232,88769,89099,89108,89182,89301,89479-89480,90602,90612,90618,90626,90630-90631,90637,90655,90657,90666,90812 |
166 | 172 | Merged /branches/new-installer/phase3/tests/phpunit/includes/api/ApiWatchTest.php:r43664-66004 |
167 | 173 | Merged /branches/REL1_15/phase3/tests/phpunit/includes/api/ApiWatchTest.php:r51646 |
Index: branches/REL1_18/phase3/tests/phpunit/includes/api/ApiBlockTest.php |
— | — | @@ -27,9 +27,7 @@ |
28 | 28 | $user->saveSettings(); |
29 | 29 | } |
30 | 30 | } |
31 | | - |
32 | 31 | |
33 | | - |
34 | 32 | function testMakeNormalBlock() { |
35 | 33 | |
36 | 34 | $data = $this->getTokens(); |
Index: branches/REL1_18/phase3/tests/phpunit/suites/ExtensionsTestSuite.php |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | * Needed to avoid warnings like 'No tests found in class "ExtensionsTestSuite".' |
28 | 28 | * when no extensions with tests are used. |
29 | 29 | */ |
30 | | -class DummyExtensionsTest extends PHPUnit_Framework_TestCase { |
| 30 | +class DummyExtensionsTest extends MediaWikiTestCase { |
31 | 31 | public function testNothing() { |
32 | 32 | |
33 | 33 | } |
Index: branches/REL1_18/phase3/tests/phpunit/phpunit.php |
— | — | @@ -51,13 +51,10 @@ |
52 | 52 | } |
53 | 53 | |
54 | 54 | require_once( 'PHPUnit/Runner/Version.php' ); |
55 | | -if( version_compare( PHPUnit_Runner_Version::id(), '3.5.0', '>=' ) ) { |
56 | | - # PHPUnit 3.5.0 introduced a nice autoloader based on class name |
57 | | - require_once( 'PHPUnit/Autoload.php' ); |
58 | | -} else { |
59 | | - # Keep the old pre PHPUnit 3.5.0 behaviour for compatibility |
60 | | - require_once( 'PHPUnit/TextUI/Command.php' ); |
| 55 | +if( version_compare( PHPUnit_Runner_Version::id(), '3.5.0', '<' ) ) { |
| 56 | + die( 'PHPUnit 3.5 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" ); |
61 | 57 | } |
| 58 | +require_once( 'PHPUnit/Autoload.php' ); |
62 | 59 | |
63 | 60 | require_once( "$IP/tests/TestsAutoLoader.php" ); |
64 | 61 | MediaWikiPHPUnitCommand::main(); |
Property changes on: branches/REL1_18/phase3/tests/phpunit/phpunit.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
65 | 62 | Merged /branches/new-installer/phase3/tests/phpunit/phpunit.php:r43664-66004 |
66 | 63 | Merged /branches/REL1_15/phase3/tests/phpunit/phpunit.php:r51646 |
67 | 64 | Merged /branches/REL1_17/phase3/tests/phpunit/phpunit.php:r81445,81448 |
68 | 65 | Merged /branches/sqlite/tests/phpunit/phpunit.php:r58211-58321 |
69 | 66 | Merged /trunk/phase3/tests/phpunit/phpunit.php:r87632,87636,87640,87644,87839,88231-88232,88769,89099,89108,89301,89479-89480,90602,90612,90618,90626,90630-90631,90637,90655,90657,90666,90812 |
Property changes on: branches/REL1_18/phase3/tests/phpunit |
___________________________________________________________________ |
Modified: svn:mergeinfo |
70 | 67 | Merged /trunk/phase3/tests/phpunit:r88769,89301 |