I'm trying to test a parser tag extension with phpunit and have run into a strange problem. Whenever my extension calls $parser->recursiveTagParse(), the unit test blows up in Parser.php, complaining that $parser->mOptions is a non-object.
The tag callback looks pretty normal:
static function render($input, $argv, $parser, $frame) { // ... $parser->recursiveTagParse("something"); // ... }
and I have unit tests that call render()directly:
public function testMyTag() { global $wgParser; $this->assertEqual(MyTag::render("some text", array(), $wgParser, false)); }
(I don't like using $wgParser here, and maybe that's the root of my problems?) The tag works perfectly in the browser. Just not when unit-testing on the command line.
The blowup occurs in Parser.php::replaceVariables, when it calls $this->mOptions->getMaxIncludeSize().
Any advice appreciated!! Thanks, DanB
On Thu, Nov 1, 2012 at 6:11 PM, Daniel Barrett danb@vistaprint.com wrote:
I'm trying to test a parser tag extension with phpunit and have run into a strange problem. Whenever my extension calls $parser->recursiveTagParse(), the unit test blows up in Parser.php, complaining that $parser->mOptions is a non-object.
The tag callback looks pretty normal:
static function render($input, $argv, $parser, $frame) { // ... $parser->recursiveTagParse("something"); // ... }
and I have unit tests that call render()directly:
public function testMyTag() { global $wgParser; $this->assertEqual(MyTag::render("some text", array(), $wgParser, false)); }
(I don't like using $wgParser here, and maybe that's the root of my problems?) The tag works perfectly in the browser. Just not when unit-testing on the command line.
The blowup occurs in Parser.php::replaceVariables, when it calls $this->mOptions->getMaxIncludeSize().
Any advice appreciated!! Thanks, DanB
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
You're calling the recursiveTagParse while the parser is not in a "parsing" state.
The easiest way to do this is to have some text "yadda yadda<mytag>foo</mytag>" and pass it to $wgParser->parse, and have the parser being the thing calling your callback. (If you're going to do that approach you can even use older style parser tests text file with $wgParserTestFiles if you wanted as its basically doing the same thing)
You can also work around this (I believe anyhow) by doing something complicated with Parser->startExternalParse first and then doing what you are doing, but I've never really used that method and am not sure how it works.
Hope that helps, -bawolff
bawolff wrote:
You're calling the recursiveTagParse while the parser is not in a "parsing" state.
Thanks for the explanation.
The easiest way to do this is to have some text "yadda yadda<mytag>foo</mytag>" and pass it to $wgParser->parse
I tried this:
$this->assertEquals($wgParser->parse("<mytag>foo</mytag>", Title:newFromText("some page"), new ParserOptions), 'the output here');
but parse() produces weird artifacts like <!--LINK 2:3--> in the output, which are not predictable as unit test output. Any suggestions to prevent this?
DanB
Use a file with a format like parserTests.txt You then register it with $wgParserTestFiles. See Cite for an example.
wikitech-l@lists.wikimedia.org