From 63601400e476c6cf43d985f3e7b9864681695ed4 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 18 Jan 2013 16:46:04 +0100 Subject: Update to MediaWiki 1.20.2 this update includes: * adjusted Arch Linux skin * updated FluxBBAuthPlugin * patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024 --- tests/phpunit/includes/libs/CSSJanusTest.php | 560 +++++++++++++++++++++ tests/phpunit/includes/libs/CSSMinTest.php | 142 ++++++ .../includes/libs/GenericArrayObjectTest.php | 245 +++++++++ .../includes/libs/JavaScriptMinifierTest.php | 66 ++- 4 files changed, 991 insertions(+), 22 deletions(-) create mode 100644 tests/phpunit/includes/libs/CSSJanusTest.php create mode 100644 tests/phpunit/includes/libs/CSSMinTest.php create mode 100644 tests/phpunit/includes/libs/GenericArrayObjectTest.php (limited to 'tests/phpunit/includes/libs') diff --git a/tests/phpunit/includes/libs/CSSJanusTest.php b/tests/phpunit/includes/libs/CSSJanusTest.php new file mode 100644 index 00000000..54f66077 --- /dev/null +++ b/tests/phpunit/includes/libs/CSSJanusTest.php @@ -0,0 +1,560 @@ +assertEquals( $transformedA, $cssB, 'Test A-B transformation' ); + + $transformedB = CSSJanus::transform( $cssB ); + $this->assertEquals( $transformedB, $cssA, 'Test B-A transformation' ); + + // If no B version is provided, it means + // the output should equal the input. + } else { + $transformedA = CSSJanus::transform( $cssA ); + $this->assertEquals( $transformedA, $cssA, 'Nothing was flipped' ); + } + } + + /** + * @dataProvider provideTransformAdvancedCases + */ + function testTransformAdvanced( $code, $expectedOutput, $options = array() ) { + $swapLtrRtlInURL = isset( $options['swapLtrRtlInURL'] ) ? $options['swapLtrRtlInURL'] : false; + $swapLeftRightInURL = isset( $options['swapLeftRightInURL'] ) ? $options['swapLeftRightInURL'] : false; + + $flipped = CSSJanus::transform( $code, $swapLtrRtlInURL, $swapLeftRightInURL ); + + $this->assertEquals( $expectedOutput, $flipped, + 'Test flipping, options: url-ltr-rtl=' . ($swapLtrRtlInURL ? 'true' : 'false') + . ' url-left-right=' . ($swapLeftRightInURL ? 'true' : 'false') + ); + } + /** + * @dataProvider provideTransformBrokenCases + * @group Broken + */ + function testTransformBroken( $code, $expectedOutput ) { + $flipped = CSSJanus::transform( $code ); + + $this->assertEquals( $expectedOutput, $flipped, 'Test flipping' ); + } + + /** + * These transform cases are tested *in both directions* + * No need to declare a principle twice in both directions here. + */ + function provideTransformCases() { + return array( + // Property keys + array( + '.foo { left: 0; }', + '.foo { right: 0; }' + ), + // Guard against partial keys + // (CSS currently doesn't have flippable properties + // that contain the direction as part of the key without + // dash separation) + array( + '.foo { alright: 0; }' + ), + array( + '.foo { balleft: 0; }' + ), + + // Dashed property keys + array( + '.foo { padding-left: 0; }', + '.foo { padding-right: 0; }' + ), + array( + '.foo { margin-left: 0; }', + '.foo { margin-right: 0; }' + ), + array( + '.foo { border-left: 0; }', + '.foo { border-right: 0; }' + ), + + // Double-dashed property keys + array( + '.foo { border-left-color: red; }', + '.foo { border-right-color: red; }' + ), + array( + // Includes unknown properties? + '.foo { x-left-y: 0; }', + '.foo { x-right-y: 0; }' + ), + + // Multi-value properties + array( + '.foo { padding: 0; }' + ), + array( + '.foo { padding: 0 1px; }' + ), + array( + '.foo { padding: 0 1px 2px; }' + ), + array( + '.foo { padding: 0 1px 2px 3px; }', + '.foo { padding: 0 3px 2px 1px; }' + ), + + // Shorthand / Four notation + array( + '.foo { padding: .25em 15px 0pt 0ex; }', + '.foo { padding: .25em 0ex 0pt 15px; }' + ), + array( + '.foo { margin: 1px -4px 3px 2px; }', + '.foo { margin: 1px 2px 3px -4px; }' + ), + array( + '.foo { padding: 0 15px .25em 0; }', + '.foo { padding: 0 0 .25em 15px; }' + ), + array( + '.foo { padding: 1px 4.1grad 3px 2%; }', + '.foo { padding: 1px 2% 3px 4.1grad; }' + ), + array( + '.foo { padding: 1px 2px 3px auto; }', + '.foo { padding: 1px auto 3px 2px; }' + ), + array( + '.foo { padding: 1px inherit 3px auto; }', + '.foo { padding: 1px auto 3px inherit; }' + ), + array( + '.foo { border-radius: .25em 15px 0pt 0ex; }', + '.foo { border-radius: .25em 0ex 0pt 15px; }' + ), + array( + '.foo { x-unknown: a b c d; }' + ), + array( + '.foo barpx 0 2% { opacity: 0; }' + ), + array( + '#settings td p strong' + ), + array( + # Not sure how 4+ values should behave, + # testing to make sure changes are detected + '.foo { x-unknown: 1 2 3 4 5; }', + '.foo { x-unknown: 1 4 3 2 5; }', + ), + array( + '.foo { x-unknown: 1 2 3 4 5 6; }', + '.foo { x-unknown: 1 4 3 2 5 6; }', + ), + + // Shorthand / Three notation + array( + '.foo { margin: 1em 0 .25em; }' + ), + array( + '.foo { margin:-1.5em 0 -.75em; }' + ), + + // Shorthand / Two notation + array( + '.foo { padding: 1px 2px; }' + ), + + // Shorthand / One notation + array( + '.foo { padding: 1px; }' + ), + + // Direction + // Note: This differs from the Python implementation, + // see also CSSJanus::fixDirection for more info. + array( + '.foo { direction: ltr; }', + '.foo { direction: rtl; }' + ), + array( + '.foo { direction: rtl; }', + '.foo { direction: ltr; }' + ), + array( + 'input { direction: ltr; }', + 'input { direction: rtl; }' + ), + array( + 'input { direction: rtl; }', + 'input { direction: ltr; }' + ), + array( + 'body { direction: ltr; }', + 'body { direction: rtl; }' + ), + array( + '.foo, body, input { direction: ltr; }', + '.foo, body, input { direction: rtl; }' + ), + array( + 'body { padding: 10px; direction: ltr; }', + 'body { padding: 10px; direction: rtl; }' + ), + array( + 'body { direction: ltr } .myClass { direction: ltr }', + 'body { direction: rtl } .myClass { direction: rtl }' + ), + + // Left/right values + array( + '.foo { float: left; }', + '.foo { float: right; }' + ), + array( + '.foo { text-align: left; }', + '.foo { text-align: right; }' + ), + array( + '.foo { -x-unknown: left; }', + '.foo { -x-unknown: right; }' + ), + // Guard against selectors that look flippable + array( + '.column-left { width: 0; }' + ), + array( + 'a.left { width: 0; }' + ), + array( + 'a.leftification { width: 0; }' + ), + array( + 'a.ltr { width: 0; }' + ), + array( + #
+ '.a-ltr.png { width: 0; }' + ), + array( + # + 'foo-ltr[attr="x"] { width: 0; }' + ), + array( + 'div.left > span.right+span.left { width: 0; }' + ), + array( + '.thisclass .left .myclass { width: 0; }' + ), + array( + '.thisclass .left .myclass #myid { width: 0; }' + ), + + // Cursor values (east/west) + array( + '.foo { cursor: e-resize; }', + '.foo { cursor: w-resize; }' + ), + array( + '.foo { cursor: se-resize; }', + '.foo { cursor: sw-resize; }' + ), + array( + '.foo { cursor: ne-resize; }', + '.foo { cursor: nw-resize; }' + ), + + // Background + array( + '.foo { background-position: top left; }', + '.foo { background-position: top right; }' + ), + array( + '.foo { background: url(/foo/bar.png) top left; }', + '.foo { background: url(/foo/bar.png) top right; }' + ), + array( + '.foo { background: url(/foo/bar.png) top left no-repeat; }', + '.foo { background: url(/foo/bar.png) top right no-repeat; }' + ), + array( + '.foo { background: url(/foo/bar.png) no-repeat top left; }', + '.foo { background: url(/foo/bar.png) no-repeat top right; }' + ), + array( + '.foo { background: #fff url(/foo/bar.png) no-repeat top left; }', + '.foo { background: #fff url(/foo/bar.png) no-repeat top right; }' + ), + array( + '.foo { background-position: 100% 40%; }', + '.foo { background-position: 0% 40%; }' + ), + array( + '.foo { background-position: 23% 0; }', + '.foo { background-position: 77% 0; }' + ), + array( + '.foo { background-position: 23% auto; }', + '.foo { background-position: 77% auto; }' + ), + array( + '.foo { background-position-x: 23%; }', + '.foo { background-position-x: 77%; }' + ), + array( + '.foo { background-position-y: 23%; }', + '.foo { background-position-y: 23%; }' + ), + array( + '.foo { background:url(../foo.png) no-repeat 75% 50%; }', + '.foo { background:url(../foo.png) no-repeat 25% 50%; }' + ), + array( + '.foo { background: 10% 20% } .bar { background: 40% 30% }', + '.foo { background: 90% 20% } .bar { background: 60% 30% }' + ), + + // Multiple rules + array( + 'body { direction: rtl; float: right; } .foo { direction: ltr; float: right; }', + 'body { direction: ltr; float: left; } .foo { direction: rtl; float: left; }', + ), + + // Duplicate properties + array( + '.foo { float: left; float: right; float: left; }', + '.foo { float: right; float: left; float: right; }', + ), + + // Preserve comments + array( + '/* left /* right */left: 10px', + '/* left /* right */right: 10px' + ), + array( + '/*left*//*left*/left: 10px', + '/*left*//*left*/right: 10px' + ), + array( + '/* Going right is cool */ .foo { width: 0 }', + ), + array( + "/* padding-right 1 2 3 4 */\n#test { width: 0}\n/*right*/" + ), + array( + "/** Two line comment\n * left\n \*/\n#test {width: 0}" + ), + + // @noflip annotation + array( + // before selector (single) + '/* @noflip */ div { float: left; }' + ), + array( + // before selector (multiple) + '/* @noflip */ div, .notme { float: left; }' + ), + array( + // inside selector + 'div, /* @noflip */ .foo { float: left; }' + ), + array( + // after selector + 'div, .notme /* @noflip */ { float: left; }' + ), + array( + // before multiple rules + '/* @noflip */ div { float: left; } .foo { float: left; }', + '/* @noflip */ div { float: left; } .foo { float: right; }' + ), + array( + // after multiple rules + '.foo { float: left; } /* @noflip */ div { float: left; }', + '.foo { float: right; } /* @noflip */ div { float: left; }' + ), + array( + // before multiple properties + 'div { /* @noflip */ float: left; text-align: left; }', + 'div { /* @noflip */ float: left; text-align: right; }' + ), + array( + // after multiple properties + 'div { float: left; /* @noflip */ text-align: left; }', + 'div { float: right; /* @noflip */ text-align: left; }' + ), + + // Guard against css3 stuff + array( + 'background-image: -moz-linear-gradient(#326cc1, #234e8c);' + ), + array( + 'background-image: -webkit-gradient(linear, 100% 0%, 0% 0%, from(#666666), to(#ffffff));' + ), + + // CSS syntax / white-space variations + // spaces, no spaces, tabs, new lines, omitting semi-colons + array( + ".foo { left: 0; }", + ".foo { right: 0; }" + ), + array( + ".foo{ left: 0; }", + ".foo{ right: 0; }" + ), + array( + ".foo{ left: 0 }", + ".foo{ right: 0 }" + ), + array( + ".foo{left:0 }", + ".foo{right:0 }" + ), + array( + ".foo{left:0}", + ".foo{right:0}" + ), + array( + ".foo { left : 0 ; }", + ".foo { right : 0 ; }" + ), + array( + ".foo\n { left : 0 ; }", + ".foo\n { right : 0 ; }" + ), + array( + ".foo\n { \nleft : 0 ; }", + ".foo\n { \nright : 0 ; }" + ), + array( + ".foo\n { \n left : 0 ; }", + ".foo\n { \n right : 0 ; }" + ), + array( + ".foo\n { \n left\n : 0; }", + ".foo\n { \n right\n : 0; }" + ), + array( + ".foo \n { \n left\n : 0; }", + ".foo \n { \n right\n : 0; }" + ), + array( + ".foo\n{\nleft\n:\n0;}", + ".foo\n{\nright\n:\n0;}" + ), + array( + ".foo\n.bar {\n\tleft: 0;\n}", + ".foo\n.bar {\n\tright: 0;\n}" + ), + array( + ".foo\t{\tleft\t:\t0;}", + ".foo\t{\tright\t:\t0;}" + ), + ); + } + + /** + * These cases are tested in one way only (format: actual, expected, msg). + * If both ways can be tested, either put both versions in here or move + * it to provideTransformCases(). + */ + function provideTransformAdvancedCases() { + $bgPairs = array( + # [ - _ . ] <-> [ left right ltr rtl ] + 'foo.jpg' => 'foo.jpg', + 'left.jpg' => 'right.jpg', + 'ltr.jpg' => 'rtl.jpg', + + 'foo-left.png' => 'foo-right.png', + 'foo_left.png' => 'foo_right.png', + 'foo.left.png' => 'foo.right.png', + + 'foo-ltr.png' => 'foo-rtl.png', + 'foo_ltr.png' => 'foo_rtl.png', + 'foo.ltr.png' => 'foo.rtl.png', + + 'left-foo.png' => 'right-foo.png', + 'left_foo.png' => 'right_foo.png', + 'left.foo.png' => 'right.foo.png', + + 'ltr-foo.png' => 'rtl-foo.png', + 'ltr_foo.png' => 'rtl_foo.png', + 'ltr.foo.png' => 'rtl.foo.png', + + 'foo-ltr-left.gif' => 'foo-rtl-right.gif', + 'foo_ltr_left.gif' => 'foo_rtl_right.gif', + 'foo.ltr.left.gif' => 'foo.rtl.right.gif', + 'foo-ltr_left.gif' => 'foo-rtl_right.gif', + 'foo_ltr.left.gif' => 'foo_rtl.right.gif', + ); + $provider = array(); + foreach ( $bgPairs as $left => $right ) { + # By default '-rtl' and '-left' etc. are not touched, + # Only when the appropiate parameter is set. + $provider[] = array( + ".foo { background: url(images/$left); }", + ".foo { background: url(images/$left); }" + ); + $provider[] = array( + ".foo { background: url(images/$right); }", + ".foo { background: url(images/$right); }" + ); + $provider[] = array( + ".foo { background: url(images/$left); }", + ".foo { background: url(images/$right); }", + array( + 'swapLtrRtlInURL' => true, + 'swapLeftRightInURL' => true, + ) + ); + $provider[] = array( + ".foo { background: url(images/$right); }", + ".foo { background: url(images/$left); }", + array( + 'swapLtrRtlInURL' => true, + 'swapLeftRightInURL' => true, + ) + ); + } + + return $provider; + } + + /** + * Cases that are currently failing, but + * should be looked at in the future as enhancements and/or bug fix + */ + function provideTransformBrokenCases() { + return array( + // Guard against partial keys + array( + '.foo { leftxx: 0; }', + '.foo { leftxx: 0; }' + ), + array( + '.foo { rightxx: 0; }', + '.foo { rightxx: 0; }' + ), + + // Guard against selectors that look flippable + array( + # + 'foo-left-x[attr="x"] { width: 0; }', + 'foo-left-x[attr="x"] { width: 0; }' + ), + array( + #
+ '.foo[data-left="x"] { width: 0; }', + '.foo[data-left="x"] { width: 0; }' + ), + ); + } +} diff --git a/tests/phpunit/includes/libs/CSSMinTest.php b/tests/phpunit/includes/libs/CSSMinTest.php new file mode 100644 index 00000000..a3827756 --- /dev/null +++ b/tests/phpunit/includes/libs/CSSMinTest.php @@ -0,0 +1,142 @@ +oldServer = $wgServer; + $this->oldCanServer = $wgCanonicalServer; + $wgServer = $wgCanonicalServer = 'http://wiki.example.org'; + } + + function tearDown() { + // Restore $wgServer and $wgCanonicalServer + global $wgServer, $wgCanonicalServer; + $wgServer = $this->oldServer; + $wgCanonicalServer = $this->oldCanServer; + + parent::tearDown(); + } + + /** + * @dataProvider provideMinifyCases + */ + function testMinify( $code, $expectedOutput ) { + $minified = CSSMin::minify( $code ); + + $this->assertEquals( $expectedOutput, $minified, 'Minified output should be in the form expected.' ); + } + + function provideMinifyCases() { + return array( + // Whitespace + array( "\r\t\f \v\n\r", "" ), + array( "foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ), + + // Loose comments + array( "/* foo */", "" ), + array( "/*******\n foo\n *******/", "" ), + array( "/*!\n foo\n */", "" ), + + // Inline comments in various different places + array( "/* comment */foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ), + array( "foo/* comment */, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ), + array( "foo,/* comment */ bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ), + array( "foo, bar/* comment */ {\n\tprop: value;\n}", "foo,bar{prop:value}" ), + array( "foo, bar {\n\t/* comment */prop: value;\n}", "foo,bar{prop:value}" ), + array( "foo, bar {\n\tprop: /* comment */value;\n}", "foo,bar{prop:value}" ), + array( "foo, bar {\n\tprop: value /* comment */;\n}", "foo,bar{prop:value }" ), + array( "foo, bar {\n\tprop: value; /* comment */\n}", "foo,bar{prop:value; }" ), + + // Keep track of things that aren't as minified as much as they + // could be (bug 35493) + array( 'foo { prop: value ;}', 'foo{prop:value }' ), + array( 'foo { prop : value; }', 'foo{prop :value}' ), + array( 'foo { prop: value ; }', 'foo{prop:value }' ), + array( 'foo { font-family: "foo" , "bar"; }', 'foo{font-family:"foo" ,"bar"}' ), + array( "foo { src:\n\turl('foo') ,\n\turl('bar') ; }", "foo{src:url('foo') ,url('bar') }" ), + + // Interesting cases with string values + // - Double quotes, single quotes + array( 'foo { content: ""; }', 'foo{content:""}' ), + array( "foo { content: ''; }", "foo{content:''}" ), + array( 'foo { content: "\'"; }', 'foo{content:"\'"}' ), + array( "foo { content: '\"'; }", "foo{content:'\"'}" ), + // - Whitespace in string values + array( 'foo { content: " "; }', 'foo{content:" "}' ), + ); + } + + /** + * @dataProvider provideRemapCases + */ + function testRemap( $message, $params, $expectedOutput ) { + $remapped = call_user_func_array( 'CSSMin::remap', $params ); + + $messageAdd = " Case: $message"; + $this->assertEquals( $expectedOutput, $remapped, 'CSSMin::remap should return the expected url form.' . $messageAdd ); + } + + function provideRemapCases() { + // Parameter signature: + // CSSMin::remap( $code, $local, $remote, $embedData = true ) + return array( + array( + 'Simple case', + array( 'foo { prop: url(bar.png); }', false, 'http://example.org', false ), + 'foo { prop: url(http://example.org/bar.png); }', + ), + array( + 'Without trailing slash', + array( 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux', false ), + 'foo { prop: url(http://example.org/quux/../bar.png); }', + ), + array( + 'With trailing slash on remote (bug 27052)', + array( 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux/', false ), + 'foo { prop: url(http://example.org/quux/../bar.png); }', + ), + array( + 'Guard against stripping double slashes from query', + array( 'foo { prop: url(bar.png?corge=//grault); }', false, 'http://example.org/quux/', false ), + 'foo { prop: url(http://example.org/quux/bar.png?corge=//grault); }', + ), + array( + 'Expand absolute paths', + array( 'foo { prop: url(/w/skin/images/bar.png); }', false, 'http://example.org/quux', false ), + 'foo { prop: url(http://wiki.example.org/w/skin/images/bar.png); }', + ), + ); + } + + /** + * Seperated because they are currently broken (bug 35492) + * + * @group Broken + * @dataProvider provideStringCases + */ + function testMinifyWithCSSStringValues( $code, $expectedOutput ) { + $this->testMinifyOutput( $code, $expectedOutput ); + } + + function provideStringCases() { + return array( + // String values should be respected + // - More than one space in a string value + array( 'foo { content: " "; }', 'foo{content:" "}' ), + // - Using a tab in a string value (turns into a space) + array( "foo { content: '\t'; }", "foo{content:'\t'}" ), + // - Using css-like syntax in string values + array( 'foo::after { content: "{;}"; position: absolute; }', 'foo::after{content:"{;}";position:absolute}' ), + ); + } +} diff --git a/tests/phpunit/includes/libs/GenericArrayObjectTest.php b/tests/phpunit/includes/libs/GenericArrayObjectTest.php new file mode 100644 index 00000000..70fce111 --- /dev/null +++ b/tests/phpunit/includes/libs/GenericArrayObjectTest.php @@ -0,0 +1,245 @@ + + */ +abstract class GenericArrayObjectTest extends MediaWikiTestCase { + + /** + * Returns objects that can serve as elements in the concrete GenericArrayObject deriving class being tested. + * + * @since 1.20 + * + * @return array + */ + public abstract function elementInstancesProvider(); + + /** + * Returns the name of the concrete class being tested. + * + * @since 1.20 + * + * @return string + */ + public abstract function getInstanceClass(); + + /** + * Provides instances of the concrete class being tested. + * + * @since 1.20 + * + * @return array + */ + public function instanceProvider() { + $instances = array(); + + foreach ( $this->elementInstancesProvider() as $elementInstances ) { + $instances[] = $this->getNew( $elementInstances ); + } + + return $this->arrayWrap( $instances ); + } + + /** + * @since 1.20 + * + * @param array $elements + * + * @return GenericArrayObject + */ + protected function getNew( array $elements = array() ) { + $class = $this->getInstanceClass(); + return new $class( $elements ); + } + + /** + * @dataProvider elementInstancesProvider + * + * @since 1.20 + * + * @param array $elements + */ + public function testConstructor( array $elements ) { + $arrayObject = $this->getNew( $elements ); + + $this->assertEquals( count( $elements ), $arrayObject->count() ); + } + + /** + * @dataProvider elementInstancesProvider + * + * @since 1.20 + * + * @param array $elements + */ + public function testIsEmpty( array $elements ) { + $arrayObject = $this->getNew( $elements ); + + $this->assertEquals( $elements === array(), $arrayObject->isEmpty() ); + } + + /** + * @dataProvider instanceProvider + * + * @since 1.20 + * + * @param GenericArrayObject $list + */ + public function testUnset( GenericArrayObject $list ) { + if ( !$list->isEmpty() ) { + $offset = $list->getIterator()->key(); + $count = $list->count(); + $list->offsetUnset( $offset ); + $this->assertEquals( $count - 1, $list->count() ); + } + + if ( !$list->isEmpty() ) { + $offset = $list->getIterator()->key(); + $count = $list->count(); + unset( $list[$offset] ); + $this->assertEquals( $count - 1, $list->count() ); + } + + $exception = null; + try { $list->offsetUnset( 'sdfsedtgsrdysftu' ); } catch ( \Exception $exception ){} + $this->assertInstanceOf( '\Exception', $exception ); + } + + /** + * @dataProvider elementInstancesProvider + * + * @since 1.20 + * + * @param array $elements + */ + public function testAppend( array $elements ) { + $list = $this->getNew(); + + $listSize = count( $elements ); + + foreach ( $elements as $element ) { + $list->append( $element ); + } + + $this->assertEquals( $listSize, $list->count() ); + + $list = $this->getNew(); + + foreach ( $elements as $element ) { + $list[] = $element; + } + + $this->assertEquals( $listSize, $list->count() ); + + $this->checkTypeChecks( function( GenericArrayObject $list, $element ) { + $list->append( $element ); + } ); + } + + /** + * @since 1.20 + * + * @param callback $function + */ + protected function checkTypeChecks( $function ) { + $excption = null; + $list = $this->getNew(); + + $elementClass = $list->getObjectType(); + + foreach ( array( 42, 'foo', array(), new \stdClass(), 4.2 ) as $element ) { + $validValid = $element instanceof $elementClass; + + try{ + call_user_func( $function, $list, $element ); + $valid = true; + } + catch ( InvalidArgumentException $exception ) { + $valid = false; + } + + $this->assertEquals( + $validValid, + $valid, + 'Object of invalid type got successfully added to a GenericArrayObject' + ); + } + } + + /** + * @dataProvider elementInstancesProvider + * + * @since 1.20 + * + * @param array $elements + */ + public function testOffsetSet( array $elements ) { + if ( $elements === array() ) { + $this->assertTrue( true ); + return; + } + + $list = $this->getNew(); + + $element = reset( $elements ); + $list->offsetSet( 42, $element ); + $this->assertEquals( $element, $list->offsetGet( 42 ) ); + + $list = $this->getNew(); + + $element = reset( $elements ); + $list['oHai'] = $element; + $this->assertEquals( $element, $list['oHai'] ); + + $list = $this->getNew(); + + $element = reset( $elements ); + $list->offsetSet( 9001, $element ); + $this->assertEquals( $element, $list[9001] ); + + $list = $this->getNew(); + + $element = reset( $elements ); + $list->offsetSet( null, $element ); + $this->assertEquals( $element, $list[0] ); + + $list = $this->getNew(); + $offset = 0; + + foreach ( $elements as $element ) { + $list->offsetSet( null, $element ); + $this->assertEquals( $element, $list[$offset++] ); + } + + $this->assertEquals( count( $elements ), $list->count() ); + + $this->checkTypeChecks( function( GenericArrayObject $list, $element ) { + $list->offsetSet( mt_rand(), $element ); + } ); + } + +} diff --git a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php index d2bfeedf..f121b018 100644 --- a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php +++ b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php @@ -4,9 +4,18 @@ class JavaScriptMinifierTest extends MediaWikiTestCase { function provideCases() { return array( - // Basic tokens + + // Basic whitespace and comments that should be stripped entirely array( "\r\t\f \v\n\r", "" ), array( "/* Foo *\n*bar\n*/", "" ), + + /** + * Slashes used inside block comments (bug 26931). + * At some point there was a bug that caused this comment to be ended at '* /', + * causing /M... to be left as the beginning of a regex. + */ + array( "/**\n * Foo\n * {\n * 'bar' : {\n * //Multiple rules with configurable operators\n * 'baz' : false\n * }\n */", ""), + /** * ' Foo \' bar \ * baz \' quox ' . @@ -15,11 +24,13 @@ class JavaScriptMinifierTest extends MediaWikiTestCase { array( "\" Foo \\\" bar \\\n baz \\\" quox \" .length", "\" Foo \\\" bar \\\n baz \\\" quox \".length" ), array( "// Foo b/ar baz", "" ), array( "/ Foo \\/ bar [ / \\] / ] baz / .length", "/ Foo \\/ bar [ / \\] / ] baz /.length" ), + // HTML comments array( " bar", "" ), array( "--> Foo", "" ), array( "x --> y", "x-->y" ), + // Semicolon insertion array( "(function(){return\nx;})", "(function(){return\nx;})" ), array( "throw\nx;", "throw\nx;" ), @@ -35,12 +46,19 @@ class JavaScriptMinifierTest extends MediaWikiTestCase { array( "5.\nx;", "5.\nx;" ), array( "0xFF.\nx;", "0xFF.x;" ), array( "5.3.\nx;", "5.3.x;" ), + + // Semicolon insertion between an expression having an inline + // comment after it, and a statement on the next line (bug 27046). + array( "var a = this //foo bar \n for ( b = 0; c < d; b++ ) {}", "var a=this\nfor(b=0;cassertEquals( $expectedOutput, $minified, "Minified output should be in the form expected." ); } - /** - * @dataProvider provideBug32548 - */ - function testBug32548Exponent($num) { - // Long line breaking was being incorrectly done between the base and - // exponent part of a number, causing a syntax error. The line should - // instead break at the start of the number. - $prefix = 'var longVarName' . str_repeat('_', 973) . '='; - $suffix = ',shortVarName=0;'; - - $input = $prefix . $num . $suffix; - $expected = $prefix . "\n" . $num . $suffix; - - $minified = JavaScriptMinifier::minify( $input ); - - $this->assertEquals( $expected, $minified, "Line breaks must not occur in middle of exponent"); - } - function provideBug32548() { return array( array( @@ -145,4 +149,22 @@ class JavaScriptMinifierTest extends MediaWikiTestCase { ), ); } + + /** + * @dataProvider provideBug32548 + */ + function testBug32548Exponent( $num ) { + // Long line breaking was being incorrectly done between the base and + // exponent part of a number, causing a syntax error. The line should + // instead break at the start of the number. + $prefix = 'var longVarName' . str_repeat( '_', 973 ) . '='; + $suffix = ',shortVarName=0;'; + + $input = $prefix . $num . $suffix; + $expected = $prefix . "\n" . $num . $suffix; + + $minified = JavaScriptMinifier::minify( $input ); + + $this->assertEquals( $expected, $minified, "Line breaks must not occur in middle of exponent"); + } } -- cgit v1.2.2