Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4140427
MathMLRdfBuilderTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
MathMLRdfBuilderTest.php
View Options
<?php
use
DataValues\StringValue
;
use
MediaWiki\Extension\Math\MathMLRdfBuilder
;
use
MediaWiki\Extension\Math\Tests\MathMockHttpTrait
;
use
Wikibase\DataModel\Entity\NumericPropertyId
;
use
Wikibase\DataModel\Snak\PropertyValueSnak
;
use
Wikimedia\Purtle\NTriplesRdfWriter
;
use
Wikimedia\Rdbms\IDatabase
;
use
Wikimedia\Rdbms\LBFactory
;
/**
* Test the MathML RDF formatter
*
* @group Math
* @covers \MediaWiki\Extension\Math\MathMLRdfBuilder
* @author Moritz Schubotz (physikerwelt)
*/
class
MathMLRdfBuilderTest
extends
MediaWikiIntegrationTestCase
{
use
MathMockHttpTrait
;
private
const
ACME_PREFIX_URL
=
'http://acme/'
;
private
const
ACME_REF
=
'testing'
;
protected
function
setUp
():
void
{
$this
->
markTestSkippedIfExtensionNotLoaded
(
'WikibaseClient'
);
$db
=
$this
->
createMock
(
IDatabase
::
class
);
$db
->
method
(
'selectRow'
)->
willReturn
(
false
);
$lbFactory
=
$this
->
createMock
(
LBFactory
::
class
);
$lbFactory
->
method
(
'getReplicaDatabase'
)->
willReturn
(
$db
);
$this
->
setService
(
'DBLoadBalancerFactory'
,
$lbFactory
);
parent
::
setUp
();
}
/**
* @param string $test
* @return string
*/
private
function
makeCase
(
$test
)
{
$builder
=
new
MathMLRdfBuilder
();
$writer
=
new
NTriplesRdfWriter
();
$writer
->
prefix
(
'www'
,
"http://www/"
);
$writer
->
prefix
(
'acme'
,
self
::
ACME_PREFIX_URL
);
$writer
->
start
();
$writer
->
about
(
'www'
,
'Q1'
);
$snak
=
new
PropertyValueSnak
(
new
NumericPropertyId
(
'P1'
),
new
StringValue
(
$test
)
);
$builder
->
addValue
(
$writer
,
'acme'
,
self
::
ACME_REF
,
'DUMMY'
,
''
,
$snak
);
return
trim
(
$writer
->
drain
()
);
}
public
function
testValidInput
()
{
$this
->
setupGoodMathRestBaseMockHttp
();
$triples
=
$this
->
makeCase
(
'
\s
in x^2'
);
$this
->
assertStringContainsString
(
self
::
ACME_PREFIX_URL
.
self
::
ACME_REF
.
'> "<math'
,
$triples
);
$this
->
assertStringContainsString
(
'<mi>sin</mi>'
,
$triples
);
$this
->
assertStringContainsString
(
'<mn>2</mn>'
,
$triples
);
$this
->
assertStringContainsString
(
'^^<http://www.w3.org/1998/Math/MathML> .'
,
$triples
);
}
public
function
testInvalidInput
()
{
$this
->
setupBadMathRestBaseMockHttp
();
$triples
=
$this
->
makeCase
(
'
\s
in
\n
ewcommand'
);
$this
->
assertStringContainsString
(
'<math'
,
$triples
);
$this
->
assertStringContainsString
(
'unknown function'
,
$triples
);
$this
->
assertStringContainsString
(
'newcommand'
,
$triples
);
$this
->
assertStringContainsString
(
'^^<http://www.w3.org/1998/Math/MathML> .'
,
$triples
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 15:30 (3 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
14/95/102e870cc831e79910a589da3e61
Default Alt Text
MathMLRdfBuilderTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment