mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-27 17:01:07 +00:00
Add separate database table for LaTeXML (step 2)
Currently the PNG and the LaTeXML rendering mode use a common table in the database. If both rendering modes are allowed in a wiki simultaneously this causes problems, because the fields are continuously overwritten. This change creates the new database table defined in step 1. Bug: 65522 Change-Id: I5f125d36b83776ca6f75ff014dc9095d0a737a35
This commit is contained in:
parent
ed570661de
commit
972cee0f98
|
@ -209,6 +209,7 @@ class MathHooks {
|
|||
* @return bool
|
||||
*/
|
||||
static function onLoadExtensionSchemaUpdates( $updater = null ) {
|
||||
global $wgMathValidModes;
|
||||
if ( is_null( $updater ) ) {
|
||||
throw new MWException( 'Math extension is only necessary in 1.18 or above' );
|
||||
}
|
||||
|
@ -218,17 +219,24 @@ class MathHooks {
|
|||
$type = $updater->getDB()->getType();
|
||||
|
||||
if ( in_array( $type, $map ) ) {
|
||||
$sql = dirname( __FILE__ ) . '/db/math.' . $type . '.sql';
|
||||
$updater->addExtensionTable( 'math', $sql );
|
||||
$sql = dirname( __FILE__ ) . '/db/math.' . $type . '.sql';
|
||||
$updater->addExtensionTable( 'math', $sql );
|
||||
if ( in_array( MW_MATH_LATEXML, $wgMathValidModes ) ) {
|
||||
if ( in_array( $type, array( 'mysql', 'sqlite', 'postgres' ) ) ) {
|
||||
$sql = dirname( __FILE__ ) . '/db/mathlatexml.' . $type . '.sql';
|
||||
$updater->addExtensionTable( 'mathlatexml', $sql );
|
||||
} else {
|
||||
throw new MWException( "Math extension does not currently support $type database for LaTeXML." );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new MWException( "Math extension does not currently support $type database." );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add 'math' table to the list of tables that need to be copied to
|
||||
* Add 'math' and 'mathlatexml' tables to the list of tables that need to be copied to
|
||||
* temporary tables for parser tests to run.
|
||||
*
|
||||
* @param array $tables
|
||||
|
@ -236,7 +244,7 @@ class MathHooks {
|
|||
*/
|
||||
static function onParserTestTables( &$tables ) {
|
||||
$tables[] = 'math';
|
||||
|
||||
$tables[] = 'mathlatexml';
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Test the database access and core functionallity of MathRenderer.
|
||||
* Test the database access and core functionality of MathRenderer.
|
||||
*
|
||||
* @group Math
|
||||
* @group Database //Used by needsDB
|
||||
|
@ -8,35 +8,32 @@
|
|||
class MathDatabaseTest extends MediaWikiTestCase {
|
||||
var $renderer;
|
||||
const SOME_TEX = "a+b";
|
||||
const SOME_HTML = "a<sub>b</sub>";
|
||||
const SOME_MATHML = "iℏ∂tΨ=H^Ψ<mrow><\ci>";
|
||||
const SOME_LOG = "Sample Log Text.";
|
||||
const SOME_STATUSCODE = 2;
|
||||
const SOME_TIMESTAMP = 1272509157;
|
||||
const SOME_VALIDXML = true;
|
||||
const SOME_HTML = "a<sub>b</sub> and so on";
|
||||
const SOME_MATHML = "iℏ∂_tΨ=H^Ψ<mrow><\ci>";
|
||||
const SOME_CONSERVATIVENESS = 2;
|
||||
const SOME_OUTPUTHASH = 'C65c884f742c8591808a121a828bc09f8<';
|
||||
const NUM_BASIC_FIELDS = 5;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* creates a new database connection and a new math renderer
|
||||
* TODO: Check if there is a way to get database access without creating
|
||||
* the connection to the datbase explictly
|
||||
* the connection to the database explicitly
|
||||
* function addDBData() {
|
||||
* $this->tablesUsed[] = 'math';
|
||||
* }
|
||||
* was not sufficant.
|
||||
* was not sufficient.
|
||||
*/
|
||||
protected function setup() {
|
||||
global $wgDebugMath;
|
||||
parent::setUp();
|
||||
// TODO:figure out why this is neccessary
|
||||
// TODO: figure out why this is necessary
|
||||
$this->db = wfGetDB( DB_MASTER );
|
||||
// Create a new instance of MathSource
|
||||
$this->renderer = $this->getMockForAbstractClass( 'MathRenderer', array ( self::SOME_TEX ) );
|
||||
$this->renderer = new MathTexvc( self::SOME_TEX );
|
||||
$this->tablesUsed[] = 'math';
|
||||
self::setupTestDB( $this->db, "mathtest" );
|
||||
|
||||
$wgDebugMath = FALSE;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks the tex and hash functions
|
||||
* @covers MathRenderer::getInputHash()
|
||||
|
@ -47,50 +44,39 @@ class MathDatabaseTest extends MediaWikiTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Helper function to set the current state of the sample renderer istance to the test values
|
||||
* Helper function to set the current state of the sample renderer instance to the test values
|
||||
*/
|
||||
public function setValues() {
|
||||
// set some values
|
||||
$this->renderer->setTex( self::SOME_TEX );
|
||||
$this->renderer->setHtml( self::SOME_HTML );
|
||||
$this->renderer->setMathml( self::SOME_MATHML );
|
||||
$this->renderer->setHtml( self::SOME_HTML );
|
||||
}
|
||||
/**
|
||||
* Checks database access. Writes an etry and reads it back.
|
||||
* @convers MathRenderer::writeDatabaseEntry()
|
||||
* @convers MathRenderer::readDatabaseEntry()
|
||||
* Checks database access. Writes an entry and reads it back.
|
||||
* @covers MathRenderer::writeDatabaseEntry()
|
||||
* @covers MathRenderer::readDatabaseEntry()
|
||||
*/
|
||||
public function testDBBasics() {
|
||||
// ;
|
||||
$this->setValues();
|
||||
|
||||
$this->renderer->writeToDatabase();
|
||||
|
||||
$renderer2 = $this->getMockForAbstractClass( 'MathRenderer', array ( self::SOME_TEX ) );
|
||||
$renderer2->readFromDatabase();
|
||||
$this->renderer->writeToDatabase( $this->db );
|
||||
$renderer2 = new MathTexvc( self::SOME_TEX );
|
||||
$this->assertTrue( $renderer2->readFromDatabase(), 'Reading from database failed' );
|
||||
// comparing the class object does now work due to null values etc.
|
||||
// $this->assertEquals($this->renderer,$renderer2);
|
||||
$this->assertEquals( $this->renderer->getTex(), $renderer2->getTex(), "test if tex is the same" );
|
||||
$this->assertEquals( $this->renderer->getMathml(), $renderer2->getMathml(), "Check MathML encoding" );
|
||||
$this->assertEquals( $this->renderer->getHtml(), $renderer2->getHtml() );
|
||||
$this->assertEquals( $this->renderer->getHtml(), $renderer2->getHtml(), 'test if HTML is the same' );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks the creation of the math table without debugging endabled.
|
||||
* Checks the creation of the math table without debugging enabled.
|
||||
* @covers MathHooks::onLoadExtensionSchemaUpdates
|
||||
*/
|
||||
public function testBasicCreateTable() {
|
||||
if ( $this->db->getType() === 'sqlite' ) {
|
||||
$this->markTestSkipped( "SQLite has global indices. We cannot " .
|
||||
"create the `unitest_math` table, its math_inputhash index " .
|
||||
"would conflict with the one from the real `math` table."
|
||||
);
|
||||
}
|
||||
global $wgDebugMath;
|
||||
public function testCreateTable() {
|
||||
$this->setMwGlobals( 'wgMathValidModes', array( MW_MATH_PNG ) );
|
||||
$this->db->dropTable( "math", __METHOD__ );
|
||||
$wgDebugMath = false;
|
||||
$dbu = DatabaseUpdater::newForDB( $this->db );
|
||||
$dbu->doUpdates( array( "extensions" ) );
|
||||
$this->expectOutputRegex( '/(.*)Creating math table(.*)/' );
|
||||
|
@ -100,5 +86,4 @@ class MathDatabaseTest extends MediaWikiTestCase {
|
|||
$row = $res->fetchRow();
|
||||
$this->assertEquals( count( $row ), 2 * self::NUM_BASIC_FIELDS );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
84
tests/MathLaTeXMLDatabaseTest.php
Normal file
84
tests/MathLaTeXMLDatabaseTest.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/**
|
||||
* Test the database access and core functionality of MathRenderer.
|
||||
*
|
||||
* @group Math
|
||||
* @group Database (Used by needsDB)
|
||||
*/
|
||||
class MathLaTeXMLDatabaseTest extends MediaWikiTestCase {
|
||||
var $renderer;
|
||||
const SOME_TEX = "a+b";
|
||||
const SOME_HTML = "a<sub>b</sub>";
|
||||
const SOME_MATHML = "iℏ∂_tΨ=H^Ψ<mrow><\ci>";
|
||||
const SOME_LOG = "Sample Log Text.";
|
||||
const SOME_TIMESTAMP = 1272509157;
|
||||
const SOME_SVG = "<?xml </svg >>%%LIKE;'\" DROP TABLE math;";
|
||||
|
||||
|
||||
/**
|
||||
* creates a new database connection and a new math renderer
|
||||
* TODO: Check if there is a way to get database access without creating
|
||||
* the connection to the database explicitly
|
||||
* function addDBData() {
|
||||
* $this->tablesUsed[] = 'math';
|
||||
* }
|
||||
* was not sufficient.
|
||||
*/
|
||||
protected function setup() {
|
||||
parent::setUp();
|
||||
// TODO: figure out why this is necessary
|
||||
$this->db = wfGetDB( DB_MASTER );
|
||||
// Create a new instance of MathSource
|
||||
$this->renderer = new MathLaTeXML( self::SOME_TEX );
|
||||
self::setupTestDB( $this->db, "mathtest" );
|
||||
}
|
||||
/**
|
||||
* Checks the tex and hash functions
|
||||
* @covers MathRenderer::getInputHash()
|
||||
*/
|
||||
public function testInputHash() {
|
||||
$expectedhash = $this->db->encodeBlob( pack( "H32", md5( self::SOME_TEX ) ) );
|
||||
$this->assertEquals( $expectedhash, $this->renderer->getInputHash() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to set the current state of the sample renderer instance to the test values
|
||||
*/
|
||||
public function setValues() {
|
||||
// set some values
|
||||
$this->renderer->setTex( self::SOME_TEX );
|
||||
$this->renderer->setMathml( self::SOME_MATHML );
|
||||
}
|
||||
/**
|
||||
* Checks database access. Writes an entry and reads it back.
|
||||
* @covers MathRenderer::writeDatabaseEntry()
|
||||
* @covers MathRenderer::readDatabaseEntry()
|
||||
*/
|
||||
public function testDBBasics() {
|
||||
$this->setValues();
|
||||
$this->renderer->writeToDatabase();
|
||||
|
||||
$renderer2 = $this->renderer = new MathLaTeXML( self::SOME_TEX );
|
||||
$renderer2->readFromDatabase();
|
||||
// comparing the class object does now work due to null values etc.
|
||||
$this->assertEquals( $this->renderer->getTex(), $renderer2->getTex(), "test if tex is the same" );
|
||||
$this->assertEquals( $this->renderer->getMathml(), $renderer2->getMathml(), "Check MathML encoding" );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks the creation of the math table without debugging enabled.
|
||||
* @covers MathHooks::onLoadExtensionSchemaUpdates
|
||||
*/
|
||||
public function testCreateTable() {
|
||||
$this->setMwGlobals( 'wgMathValidModes', array( MW_MATH_LATEXML ) );
|
||||
$this->db->dropTable( "mathlatexml", __METHOD__ );
|
||||
$dbu = DatabaseUpdater::newForDB( $this->db );
|
||||
$dbu->doUpdates( array( "extensions" ) );
|
||||
$this->expectOutputRegex( '/(.*)Creating mathlatexml table(.*)/' );
|
||||
$res = $this->db->select( "mathlatexml", "*" );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue