diff --git a/src/InputCheck/LocalChecker.php b/src/InputCheck/LocalChecker.php index 9ed5c444b..46ea30c7c 100644 --- a/src/InputCheck/LocalChecker.php +++ b/src/InputCheck/LocalChecker.php @@ -21,13 +21,13 @@ class LocalChecker extends BaseChecker { */ public function __construct( $tex = '', $type = 'tex' ) { parent::__construct( $tex ); - if ( $type !== 'tex' ) { - // this type check will be refactored with the introduction of chem-types: - // see: https://phabricator.wikimedia.org/T321262 + if ( $type === 'tex' || $type === 'chem' || $type === 'inline-tex' ) { + $this->texVC = new TexVC(); + $options = $type === 'chem' ? [ "usemhchem" => true ] : null; + $this->result = $this->texVC->check( $tex, $options ); + } else { throw new InvalidArgumentException( "Non supported type passed to LocalChecker: " . $type ); } - $this->texVC = new TexVC(); - $this->result = $this->texVC->check( $tex ); } /** diff --git a/tests/phpunit/InputCheck/LocalCheckerTest.php b/tests/phpunit/InputCheck/LocalCheckerTest.php index 2e8a42bcd..aa324afd8 100644 --- a/tests/phpunit/InputCheck/LocalCheckerTest.php +++ b/tests/phpunit/InputCheck/LocalCheckerTest.php @@ -24,14 +24,24 @@ class LocalCheckerTest extends MediaWikiIntegrationTestCase { $this->assertSame( '\\sin x^{2}', $checker->getValidTex() ); } - public function testValidType() { + public function testValidTypeTex() { $checker = new LocalChecker( '\sin x^2', 'tex' ); $this->assertTrue( $checker->isValid() ); } + public function testValidTypeChem() { + $checker = new LocalChecker( '{\\displaystyle {\\ce {\\cdot OHNO_{2}}}}', 'chem' ); + $this->assertTrue( $checker->isValid() ); + } + + public function testValidTypeInline() { + $checker = new LocalChecker( '{\\textstyle \\log2 }', 'inline-tex' ); + $this->assertTrue( $checker->isValid() ); + } + public function testInvalidType() { $this->expectException( InvalidArgumentException::class ); - new LocalChecker( '\sin x^2', 'chem' ); + new LocalChecker( '\sin x^2', 'INVALIDTYPE' ); } public function testInvalid() {