Index: trunk/phase3/tests/XmlTest.php |
— | — | @@ -0,0 +1,115 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class XmlTest extends PHPUnit_Framework_TestCase { |
| 5 | + |
| 6 | + function testElementOpen() { |
| 7 | + $this->assertEquals( |
| 8 | + '<element>', |
| 9 | + Xml::element( 'element', null, null ), |
| 10 | + 'Opening element with no attributes' |
| 11 | + ); |
| 12 | + } |
| 13 | + |
| 14 | + function testElementEmpty() { |
| 15 | + $this->assertEquals( |
| 16 | + '<element />', |
| 17 | + Xml::element( 'element', null, '' ), |
| 18 | + 'Terminated empty element' |
| 19 | + ); |
| 20 | + } |
| 21 | + |
| 22 | + function testElementEscaping() { |
| 23 | + $this->assertEquals( |
| 24 | + '<element>hello <there> you & you</element>', |
| 25 | + Xml::element( 'element', null, 'hello <there> you & you' ), |
| 26 | + 'Element with no attributes and content that needs escaping' |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + function testElementAttributes() { |
| 31 | + $this->assertEquals( |
| 32 | + '<element key="value" <>="<>">', |
| 33 | + Xml::element( 'element', array( 'key' => 'value', '<>' => '<>' ), null ), |
| 34 | + 'Element attributes, keys are not escaped' |
| 35 | + ); |
| 36 | + } |
| 37 | + |
| 38 | + function testOpenElement() { |
| 39 | + $this->assertEquals( |
| 40 | + '<element k="v">', |
| 41 | + Xml::openElement( 'element', array( 'k' => 'v' ) ), |
| 42 | + 'openElement() shortcut' |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + function testCloseElement() { |
| 47 | + $this->assertEquals( '</element>', Xml::closeElement( 'element' ), 'closeElement() shortcut' ); |
| 48 | + } |
| 49 | + |
| 50 | + # |
| 51 | + # textarea |
| 52 | + # |
| 53 | + function testTextareaNoContent() { |
| 54 | + $this->assertEquals( |
| 55 | + '<textarea name="name" id="name" cols="40" rows="5"></textarea>', |
| 56 | + Xml::textarea( 'name', '' ), |
| 57 | + 'textarea() with not content' |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + function testTextareaAttribs() { |
| 62 | + $this->assertEquals( |
| 63 | + '<textarea name="name" id="name" cols="20" rows="10"><txt></textarea>', |
| 64 | + Xml::textarea( 'name', '<txt>', 20, 10 ), |
| 65 | + 'textarea() with custom attribs' |
| 66 | + ); |
| 67 | + } |
| 68 | + |
| 69 | + # |
| 70 | + # JS |
| 71 | + # |
| 72 | + function testEscapeJsStringSpecialChars() { |
| 73 | + $this->assertEquals( |
| 74 | + '\\\\\r\n', |
| 75 | + Xml::escapeJsString( "\\\r\n" ), |
| 76 | + 'escapeJsString() with special characters' |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + function testEncodeJsVarBoolean() { |
| 81 | + $this->assertEquals( |
| 82 | + 'true', |
| 83 | + Xml::encodeJsVar( true ), |
| 84 | + 'encodeJsVar() with boolean' |
| 85 | + ); |
| 86 | + } |
| 87 | + |
| 88 | + function testEncodeJsVarNull() { |
| 89 | + $this->assertEquals( |
| 90 | + 'null', |
| 91 | + Xml::encodeJsVar( null ), |
| 92 | + 'encodeJsVar() with null' |
| 93 | + ); |
| 94 | + } |
| 95 | + |
| 96 | + function testEncodeJsVarArray() { |
| 97 | + $this->assertEquals( |
| 98 | + '["a", 1]', |
| 99 | + Xml::encodeJsVar( array( 'a', 1 ) ), |
| 100 | + 'encodeJsVar() with array' |
| 101 | + ); |
| 102 | + $this->assertEquals( |
| 103 | + '{"a": "a", "b": 1}', |
| 104 | + Xml::encodeJsVar( array( 'a' => 'a', 'b' => 1 ) ), |
| 105 | + 'encodeJsVar() with associative array' |
| 106 | + ); |
| 107 | + } |
| 108 | + |
| 109 | + function testEncodeJsVarObject() { |
| 110 | + $this->assertEquals( |
| 111 | + '{"a": "a", "b": 1}', |
| 112 | + Xml::encodeJsVar( (object)array( 'a' => 'a', 'b' => 1 ) ), |
| 113 | + 'encodeJsVar() with object' |
| 114 | + ); |
| 115 | + } |
| 116 | +} |
Property changes on: trunk/phase3/tests/XmlTest.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 117 | + native |
Index: trunk/phase3/tests/LicensesTest.php |
— | — | @@ -0,0 +1,17 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * @group Broken |
| 6 | + */ |
| 7 | +class LicensesTest extends PHPUnit_Framework_TestCase { |
| 8 | + |
| 9 | + function testLicenses() { |
| 10 | + $str = " |
| 11 | +* Free licenses: |
| 12 | +** GFLD|Debian disagrees |
| 13 | +"; |
| 14 | + |
| 15 | + $lc = new Licenses( $str ); |
| 16 | + $this->assertTrue( is_a( $lc, 'Licenses' ), 'Correct class' ); |
| 17 | + } |
| 18 | +} |
\ No newline at end of file |
Property changes on: trunk/phase3/tests/LicensesTest.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 19 | + native |
Index: trunk/phase3/tests/SanitizerTest.php |
— | — | @@ -0,0 +1,71 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +global $IP; |
| 5 | +require_once( "$IP/includes/Sanitizer.php" ); |
| 6 | + |
| 7 | +class SanitizerTest extends PHPUnit_Framework_TestCase { |
| 8 | + |
| 9 | + function testDecodeNamedEntities() { |
| 10 | + $this->assertEquals( |
| 11 | + "\xc3\xa9cole", |
| 12 | + Sanitizer::decodeCharReferences( 'école' ), |
| 13 | + 'decode named entities' |
| 14 | + ); |
| 15 | + } |
| 16 | + |
| 17 | + function testDecodeNumericEntities() { |
| 18 | + $this->assertEquals( |
| 19 | + "\xc4\x88io bonas dans l'\xc3\xa9cole!", |
| 20 | + Sanitizer::decodeCharReferences( "Ĉio bonas dans l'école!" ), |
| 21 | + 'decode numeric entities' |
| 22 | + ); |
| 23 | + } |
| 24 | + |
| 25 | + function testDecodeMixedEntities() { |
| 26 | + $this->assertEquals( |
| 27 | + "\xc4\x88io bonas dans l'\xc3\xa9cole!", |
| 28 | + Sanitizer::decodeCharReferences( "Ĉio bonas dans l'école!" ), |
| 29 | + 'decode mixed numeric/named entities' |
| 30 | + ); |
| 31 | + } |
| 32 | + |
| 33 | + function testDecodeMixedComplexEntities() { |
| 34 | + $this->assertEquals( |
| 35 | + "\xc4\x88io bonas dans l'\xc3\xa9cole! (mais pas Ĉio dans l'école)", |
| 36 | + Sanitizer::decodeCharReferences( |
| 37 | + "Ĉio bonas dans l'école! (mais pas &#x108;io dans l'&eacute;cole)" |
| 38 | + ), |
| 39 | + 'decode mixed complex entities' |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + function testInvalidAmpersand() { |
| 44 | + $this->assertEquals( |
| 45 | + 'a & b', |
| 46 | + Sanitizer::decodeCharReferences( 'a & b' ), |
| 47 | + 'Invalid ampersand' |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + function testInvalidEntities() { |
| 52 | + $this->assertEquals( |
| 53 | + '&foo;', |
| 54 | + Sanitizer::decodeCharReferences( '&foo;' ), |
| 55 | + 'Invalid named entity' |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + function testInvalidNumberedEntities() { |
| 60 | + $this->assertEquals( UTF8_REPLACEMENT, Sanitizer::decodeCharReferences( "�" ), 'Invalid numbered entity' ); |
| 61 | + } |
| 62 | + |
| 63 | + function testSelfClosingTag() { |
| 64 | + $GLOBALS['wgUseTidy'] = false; |
| 65 | + $this->assertEquals( |
| 66 | + '<div>Hello world</div>', |
| 67 | + Sanitizer::removeHTMLtags( '<div>Hello world</div />' ), |
| 68 | + 'Self-closing closing div' |
| 69 | + ); |
| 70 | + } |
| 71 | +} |
| 72 | + |
Property changes on: trunk/phase3/tests/SanitizerTest.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 73 | + native |
Index: trunk/phase3/tests/TimeAdjustTest.php |
— | — | @@ -0,0 +1,40 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class TimeAdjustTest extends PHPUnit_Framework_TestCase { |
| 5 | + |
| 6 | + public function setUp() { |
| 7 | + $this->iniSet( 'precision', 15 ); |
| 8 | + } |
| 9 | + |
| 10 | + # Test offset usage for a given language::userAdjust |
| 11 | + function testUserAdjust() { |
| 12 | + global $wgLocalTZoffset, $wgContLang, $wgUser; |
| 13 | + |
| 14 | + $wgContLang = $en = Language::factory( 'en' ); |
| 15 | + |
| 16 | + # Collection of parameters for Language_t_Offset. |
| 17 | + # Format: date to be formatted, localTZoffset value, expected date |
| 18 | + $userAdjust_tests = array( |
| 19 | + array( 20061231235959, 0, 20061231235959 ), |
| 20 | + array( 20061231235959, 5, 20070101000459 ), |
| 21 | + array( 20061231235959, 15, 20070101001459 ), |
| 22 | + array( 20061231235959, 60, 20070101005959 ), |
| 23 | + array( 20061231235959, 90, 20070101012959 ), |
| 24 | + array( 20061231235959, 120, 20070101015959 ), |
| 25 | + array( 20061231235959, 540, 20070101085959 ), |
| 26 | + array( 20061231235959, -5, 20061231235459 ), |
| 27 | + array( 20061231235959, -30, 20061231232959 ), |
| 28 | + array( 20061231235959, -60, 20061231225959 ), |
| 29 | + ); |
| 30 | + |
| 31 | + foreach( $userAdjust_tests as $data ) { |
| 32 | + $wgLocalTZoffset = $data[1]; |
| 33 | + |
| 34 | + $this->assertEquals( |
| 35 | + strval( $data[2] ), |
| 36 | + strval( $en->userAdjust( $data[0], '' ) ), |
| 37 | + "User adjust {$data[0]} by {$data[1]} minutes should give {$data[2]}" |
| 38 | + ); |
| 39 | + } |
| 40 | + } |
| 41 | +} |
Property changes on: trunk/phase3/tests/TimeAdjustTest.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 42 | + native |
Index: trunk/phase3/tests/TitleTest.php |
— | — | @@ -0,0 +1,17 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class TitleTest extends PHPUnit_Framework_TestCase { |
| 5 | + |
| 6 | + function testLegalChars() { |
| 7 | + $titlechars = Title::legalChars(); |
| 8 | + |
| 9 | + foreach ( range( 1, 255 ) as $num ) { |
| 10 | + $chr = chr( $num ); |
| 11 | + if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\\x00-\\x1f\\x7f]/", $chr ) ) { |
| 12 | + $this->assertFalse( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is not a valid titlechar" ); |
| 13 | + } else { |
| 14 | + $this->assertTrue( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is a valid titlechar" ); |
| 15 | + } |
| 16 | + } |
| 17 | + } |
| 18 | +} |
Property changes on: trunk/phase3/tests/TitleTest.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 19 | + native |