r102595 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102594‎ | r102595 | r102596 >
Date:23:11, 9 November 2011
Author:gicode
Status:ok (Comments)
Tags:
Comment:
Move tests that have likely never been executed. Now they will be executed.

It might be a good idea to have a commit hook or similar to catch these.

You can find candidates for renaming with this command:
$ find tests/phpunit/includes/ -name '*.php' | grep -Ev 'Test.php$' | xargs grep -l MediaWikiTestCase
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/GlobalFunctions/wfShorthandToInteger.php (deleted) (history)
  • /trunk/phase3/tests/phpunit/includes/GlobalFunctions/wfShorthandToIntegerTest.php (added) (history)
  • /trunk/phase3/tests/phpunit/includes/parser/TagHooks.php (deleted) (history)
  • /trunk/phase3/tests/phpunit/includes/parser/TagHooksTest.php (added) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/parser/TagHooks.php
@@ -1,77 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * @group Parser
6 - */
7 -class TagHookTest extends MediaWikiTestCase {
8 -
9 - public static function provideValidNames() {
10 - return array( array( 'foo' ), array( 'foo-bar' ), array( 'foo_bar' ), array( 'FOO-BAR' ), array( 'foo bar' ) );
11 - }
12 -
13 - public static function provideBadNames() {
14 - return array( array( "foo<bar" ), array( "foo>bar" ), array( "foo\nbar" ), array( "foo\rbar" ) );
15 - }
16 -
17 - /**
18 - * @dataProvider provideValidNames
19 - */
20 - function testTagHooks( $tag ) {
21 - global $wgParserConf;
22 - $parser = new Parser( $wgParserConf );
23 -
24 - $parser->setHook( $tag, array( $this, 'tagCallback' ) );
25 - $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
26 - $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
27 -
28 - $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
29 - }
30 -
31 - /**
32 - * @dataProvider provideBadNames
33 - * @expectedException MWException
34 - */
35 - function testBadTagHooks( $tag ) {
36 - global $wgParserConf;
37 - $parser = new Parser( $wgParserConf );
38 -
39 - $parser->setHook( $tag, array( $this, 'tagCallback' ) );
40 - $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
41 - $this->fail('Exception not thrown.');
42 - }
43 -
44 - /**
45 - * @dataProvider provideValidNames
46 - */
47 - function testFunctionTagHooks( $tag ) {
48 - global $wgParserConf;
49 - $parser = new Parser( $wgParserConf );
50 -
51 - $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), 0 );
52 - $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
53 - $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
54 -
55 - $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
56 - }
57 -
58 - /**
59 - * @dataProvider provideBadNames
60 - * @expectedException MWException
61 - */
62 - function testBadFunctionTagHooks( $tag ) {
63 - global $wgParserConf;
64 - $parser = new Parser( $wgParserConf );
65 -
66 - $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), SFH_OBJECT_ARGS );
67 - $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
68 - $this->fail('Exception not thrown.');
69 - }
70 -
71 - function tagCallback( $text, $params, $parser ) {
72 - return str_rot13( $text );
73 - }
74 -
75 - function functionTagCallback( &$parser, $frame, $code, $attribs ) {
76 - return str_rot13( $code );
77 - }
78 -}
Index: trunk/phase3/tests/phpunit/includes/parser/TagHooksTest.php
@@ -0,0 +1,77 @@
 2+<?php
 3+
 4+/**
 5+ * @group Parser
 6+ */
 7+class TagHookTest extends MediaWikiTestCase {
 8+
 9+ public static function provideValidNames() {
 10+ return array( array( 'foo' ), array( 'foo-bar' ), array( 'foo_bar' ), array( 'FOO-BAR' ), array( 'foo bar' ) );
 11+ }
 12+
 13+ public static function provideBadNames() {
 14+ return array( array( "foo<bar" ), array( "foo>bar" ), array( "foo\nbar" ), array( "foo\rbar" ) );
 15+ }
 16+
 17+ /**
 18+ * @dataProvider provideValidNames
 19+ */
 20+ function testTagHooks( $tag ) {
 21+ global $wgParserConf;
 22+ $parser = new Parser( $wgParserConf );
 23+
 24+ $parser->setHook( $tag, array( $this, 'tagCallback' ) );
 25+ $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
 26+ $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
 27+
 28+ $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
 29+ }
 30+
 31+ /**
 32+ * @dataProvider provideBadNames
 33+ * @expectedException MWException
 34+ */
 35+ function testBadTagHooks( $tag ) {
 36+ global $wgParserConf;
 37+ $parser = new Parser( $wgParserConf );
 38+
 39+ $parser->setHook( $tag, array( $this, 'tagCallback' ) );
 40+ $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
 41+ $this->fail('Exception not thrown.');
 42+ }
 43+
 44+ /**
 45+ * @dataProvider provideValidNames
 46+ */
 47+ function testFunctionTagHooks( $tag ) {
 48+ global $wgParserConf;
 49+ $parser = new Parser( $wgParserConf );
 50+
 51+ $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), 0 );
 52+ $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
 53+ $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
 54+
 55+ $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
 56+ }
 57+
 58+ /**
 59+ * @dataProvider provideBadNames
 60+ * @expectedException MWException
 61+ */
 62+ function testBadFunctionTagHooks( $tag ) {
 63+ global $wgParserConf;
 64+ $parser = new Parser( $wgParserConf );
 65+
 66+ $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), SFH_OBJECT_ARGS );
 67+ $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
 68+ $this->fail('Exception not thrown.');
 69+ }
 70+
 71+ function tagCallback( $text, $params, $parser ) {
 72+ return str_rot13( $text );
 73+ }
 74+
 75+ function functionTagCallback( &$parser, $frame, $code, $attribs ) {
 76+ return str_rot13( $code );
 77+ }
 78+}
Property changes on: trunk/phase3/tests/phpunit/includes/parser/TagHooksTest.php
___________________________________________________________________
Added: svn:eol-style
179 + native
Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/wfShorthandToInteger.php
@@ -1,28 +0,0 @@
2 -<?php
3 -
4 -class wfShorthandToIntegerTest extends MediaWikiTestCase {
5 - /**
6 - * @dataProvider provideABunchOfShorthands
7 - */
8 - function testWfShorthandToInteger( $input, $output, $description ) {
9 - $this->assertEquals(
10 - wfShorthandToInteger( $input ),
11 - $output,
12 - $description
13 - );
14 - }
15 -
16 - function provideABunchOfShorthands() {
17 - return array(
18 - array( '', -1, 'Empty string' ),
19 - array( ' ', -1, 'String of spaces' ),
20 - array( '1G', 1024 * 1024 * 1024, 'One gig uppercased' ),
21 - array( '1g', 1024 * 1024 * 1024, 'One gig lowercased' ),
22 - array( '1M', 1024 * 1024, 'One meg uppercased' ),
23 - array( '1m', 1024 * 1024, 'One meg lowercased' ),
24 - array( '1K', 1024, 'One kb uppercased' ),
25 - array( '1k', 1024, 'One kb lowercased' ),
26 - );
27 - }
28 -
29 -}
Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/wfShorthandToIntegerTest.php
@@ -0,0 +1,28 @@
 2+<?php
 3+
 4+class wfShorthandToIntegerTest extends MediaWikiTestCase {
 5+ /**
 6+ * @dataProvider provideABunchOfShorthands
 7+ */
 8+ function testWfShorthandToInteger( $input, $output, $description ) {
 9+ $this->assertEquals(
 10+ wfShorthandToInteger( $input ),
 11+ $output,
 12+ $description
 13+ );
 14+ }
 15+
 16+ function provideABunchOfShorthands() {
 17+ return array(
 18+ array( '', -1, 'Empty string' ),
 19+ array( ' ', -1, 'String of spaces' ),
 20+ array( '1G', 1024 * 1024 * 1024, 'One gig uppercased' ),
 21+ array( '1g', 1024 * 1024 * 1024, 'One gig lowercased' ),
 22+ array( '1M', 1024 * 1024, 'One meg uppercased' ),
 23+ array( '1m', 1024 * 1024, 'One meg lowercased' ),
 24+ array( '1K', 1024, 'One kb uppercased' ),
 25+ array( '1k', 1024, 'One kb lowercased' ),
 26+ );
 27+ }
 28+
 29+}
Property changes on: trunk/phase3/tests/phpunit/includes/GlobalFunctions/wfShorthandToIntegerTest.php
___________________________________________________________________
Added: svn:eol-style
130 + native

Sign-offs

UserFlagDate
Hasharinspected16:16, 10 November 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r102661Minor tweaks to r102595: remove echo that clutters output, etcdemon15:20, 10 November 2011
r102719Add test to catch the problem fixed in r102595....gicode23:45, 10 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r80024Add tests for parser tag hooks.platonides18:37, 11 January 2011
r99960Initial tests for wfShorthandToInteger(). Definitely needs moredemon18:35, 16 October 2011

Comments

#Comment by Hashar (talk | contribs)   16:17, 10 November 2011

Well spotted thanks! And you even kept the history :-)

Status & tagging log