Ensure users are able to edit the page after changing the content model
[lhc/web/wiklou.git] / tests / parser / DbTestRecorder.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Testing
20 */
21
22 class DbTestRecorder extends DbTestPreviewer {
23 public $version;
24
25 /**
26 * Set up result recording; insert a record for the run with the date
27 * and all that fun stuff
28 */
29 function start() {
30 $this->db->begin( __METHOD__ );
31
32 if ( !$this->db->tableExists( 'testrun' )
33 || !$this->db->tableExists( 'testitem' )
34 ) {
35 print "WARNING> `testrun` table not found in database. Trying to create table.\n";
36 $this->db->sourceFile( $this->db->patchPath( 'patch-testrun.sql' ) );
37 echo "OK, resuming.\n";
38 }
39
40 parent::start();
41
42 $this->db->insert( 'testrun',
43 [
44 'tr_date' => $this->db->timestamp(),
45 'tr_mw_version' => $this->version,
46 'tr_php_version' => PHP_VERSION,
47 'tr_db_version' => $this->db->getServerVersion(),
48 'tr_uname' => php_uname()
49 ],
50 __METHOD__ );
51 if ( $this->db->getType() === 'postgres' ) {
52 $this->curRun = $this->db->currentSequenceValue( 'testrun_id_seq' );
53 } else {
54 $this->curRun = $this->db->insertId();
55 }
56 }
57
58 /**
59 * Record an individual test item's success or failure to the db
60 *
61 * @param string $test
62 * @param bool $result
63 */
64 function record( $test, $subtest, $result ) {
65 parent::record( $test, $subtest, $result );
66
67 $this->db->insert( 'testitem',
68 [
69 'ti_run' => $this->curRun,
70 'ti_name' => $this->getName( $test, $subtest ),
71 'ti_success' => $result ? 1 : 0,
72 ],
73 __METHOD__ );
74 }
75
76 /**
77 * Commit transaction and clean up for result recording
78 */
79 function end() {
80 $this->db->commit( __METHOD__ );
81 parent::end();
82 }
83 }
84