--- /dev/null
+<?php
+
+class JavascriptContentTest extends WikitextContentTest {
+
+ public function newContent( $text ) {
+ return new JavascriptContent( $text );
+ }
+
+
+ public function dataGetParserOutput() {
+ return array(
+ array("hello <world>\n", "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello <world>\n\n</pre>\n"),
+ // @todo: more...?
+ );
+ }
+
+ public function dataGetSection() {
+ return array(
+ array( WikitextContentTest::$sections,
+ "0",
+ null
+ ),
+ array( WikitextContentTest::$sections,
+ "2",
+ null
+ ),
+ array( WikitextContentTest::$sections,
+ "8",
+ null
+ ),
+ );
+ }
+
+ public function dataReplaceSection() {
+ return array(
+ array( WikitextContentTest::$sections,
+ "0",
+ "No more",
+ null,
+ null
+ ),
+ array( WikitextContentTest::$sections,
+ "",
+ "No more",
+ null,
+ null
+ ),
+ array( WikitextContentTest::$sections,
+ "2",
+ "== TEST ==\nmore fun",
+ null,
+ null
+ ),
+ array( WikitextContentTest::$sections,
+ "8",
+ "No more",
+ null,
+ null
+ ),
+ array( WikitextContentTest::$sections,
+ "new",
+ "No more",
+ "New",
+ null
+ ),
+ );
+ }
+
+ public function testAddSectionHeader( ) {
+ $content = $this->newContent( 'hello world' );
+ $c = $content->addSectionHeader( 'test' );
+
+ $this->assertTrue( $content->equals( $c ) );
+ }
+
+ public function dataPreSaveTransform() {
+ return array(
+ array( 'hello this is ~~~',
+ "hello this is ~~~",
+ ),
+ array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
+ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
+ ),
+ );
+ }
+
+ public function dataPreloadTransform() {
+ return array(
+ array( 'hello this is ~~~',
+ "hello this is ~~~",
+ ),
+ array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
+ 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
+ ),
+ );
+ }
+
+ public function dataGetRedirectTarget() {
+ return array(
+ array( '#REDIRECT [[Test]]',
+ null,
+ ),
+ array( '#REDIRECT Test',
+ null,
+ ),
+ array( '* #REDIRECT [[Test]]',
+ null,
+ ),
+ );
+ }
+
+ /**
+ * @todo: test needs database!
+ */
+ /*
+ public function getRedirectChain() {
+ $text = $this->getNativeData();
+ return Title::newFromRedirectArray( $text );
+ }
+ */
+
+ /**
+ * @todo: test needs database!
+ */
+ /*
+ public function getUltimateRedirectTarget() {
+ $text = $this->getNativeData();
+ return Title::newFromRedirectRecurse( $text );
+ }
+ */
+
+
+ public function dataIsCountable() {
+ return array(
+ array( '',
+ null,
+ 'any',
+ true
+ ),
+ array( 'Foo',
+ null,
+ 'any',
+ true
+ ),
+ array( 'Foo',
+ null,
+ 'comma',
+ false
+ ),
+ array( 'Foo, bar',
+ null,
+ 'comma',
+ false
+ ),
+ array( 'Foo',
+ null,
+ 'link',
+ false
+ ),
+ array( 'Foo [[bar]]',
+ null,
+ 'link',
+ false
+ ),
+ array( 'Foo',
+ true,
+ 'link',
+ false
+ ),
+ array( 'Foo [[bar]]',
+ false,
+ 'link',
+ false
+ ),
+ array( '#REDIRECT [[bar]]',
+ true,
+ 'any',
+ true
+ ),
+ array( '#REDIRECT [[bar]]',
+ true,
+ 'comma',
+ false
+ ),
+ array( '#REDIRECT [[bar]]',
+ true,
+ 'link',
+ false
+ ),
+ );
+ }
+
+ public function dataGetTextForSummary() {
+ return array(
+ array( "hello\nworld.",
+ 16,
+ 'hello world.',
+ ),
+ array( 'hello world.',
+ 8,
+ 'hello...',
+ ),
+ array( '[[hello world]].',
+ 8,
+ '[[hel...',
+ ),
+ );
+ }
+
+ # =================================================================================================================
+
+ public function getModelName() {
+ $content = $this->newContent( "hello world." );
+
+ $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getModelName() );
+ }
+
+ public function getContentHandler() {
+ $content = $this->newContent( "hello world." );
+
+ $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getContentHandler()->getModelName() );
+ }
+
+ public function dataEquals( ) {
+ return array(
+ array( new JavascriptContent( "hallo" ), null, false ),
+ array( new JavascriptContent( "hallo" ), new JavascriptContent( "hallo" ), true ),
+ array( new JavascriptContent( "hallo" ), new CssContent( "hallo" ), false ),
+ array( new JavascriptContent( "hallo" ), new JavascriptContent( "HALLO" ), false ),
+ );
+ }
+
+}
function setUp() {
global $wgContLang;
$wgContLang = Language::factory( 'en' );
+
$globalSet = array(
'wgLegacyEncoding' => false,
'wgCompressRevisions' => false,
+
+ 'wgContentHandlerTextFallback' => $GLOBALS['wgContentHandlerTextFallback'],
+ 'wgExtraNamespaces' => $GLOBALS['wgExtraNamespaces'],
+ 'wgNamespaceContentModels' => $GLOBALS['wgNamespaceContentModels'],
+ 'wgContentHandlers' => $GLOBALS['wgContentHandlers'],
);
+
foreach ( $globalSet as $var => $data ) {
$this->saveGlobals[$var] = $GLOBALS[$var];
$GLOBALS[$var] = $data;
}
+
+ global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers;
+ $wgExtraNamespaces[ 12312 ] = 'Dummy';
+ $wgExtraNamespaces[ 12313 ] = 'Dummy_talk';
+
+ $wgNamespaceContentModels[ 12312 ] = 'DUMMY';
+ $wgContentHandlers[ 'DUMMY' ] = 'DummyContentHandlerForTesting';
+
+ global $wgContentHandlerTextFallback;
+ $wgContentHandlerTextFallback = 'ignore';
}
function tearDown() {
$this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
Revision::getRevisionText( $row ), "getRevisionText" );
}
+
+ # =================================================================================================================
+
+ /**
+ * @param string $text
+ * @param string $title
+ * @param string $model
+ * @return Revision
+ */
+ function newTestRevision( $text, $title = "Test", $model = CONTENT_MODEL_WIKITEXT, $format = null ) {
+ if ( is_string( $title ) ) {
+ $title = Title::newFromText( $title );
+ }
+
+ $content = ContentHandler::makeContent( $text, $title, $model, $format );
+
+ $rev = new Revision(
+ array(
+ 'id' => 42,
+ 'page' => 23,
+ 'title' => $title,
+
+ 'content' => $content,
+ 'length' => $content->getSize(),
+ 'comment' => "testing",
+ 'minor_edit' => false,
+
+ 'content_format' => $format,
+ )
+ );
+
+ return $rev;
+ }
+
+ function dataGetContentModel() {
+ return array(
+ array( 'hello world', 'Hello', null, null, CONTENT_MODEL_WIKITEXT ),
+ array( 'hello world', 'User:hello/there.css', null, null, CONTENT_MODEL_CSS ),
+ array( serialize('hello world'), 'Dummy:Hello', null, null, 'DUMMY' ),
+ );
+ }
+
+ /**
+ * @dataProvider dataGetContentModel
+ */
+ function testGetContentModel( $text, $title, $model, $format, $expectedModel ) {
+ $rev = $this->newTestRevision( $text, $title, $model, $format );
+
+ $this->assertEquals( $expectedModel, $rev->getContentModelName() );
+ }
+
+ function dataGetContentFormat() {
+ return array(
+ array( 'hello world', 'Hello', null, null, 'application/x-wikitext' ),
+ array( 'hello world', 'Hello', CONTENT_MODEL_CSS, null, 'text/css' ),
+ array( 'hello world', 'User:hello/there.css', null, null, 'text/css' ),
+ array( serialize('hello world'), 'Dummy:Hello', null, null, 'dummy' ),
+ );
+ }
+
+ /**
+ * @dataProvider dataGetContentFormat
+ */
+ function testGetContentFormat( $text, $title, $model, $format, $expectedFormat ) {
+ $rev = $this->newTestRevision( $text, $title, $model, $format );
+
+ $this->assertEquals( $expectedFormat, $rev->getContentFormat() );
+ }
+
+ function dataGetContentHandler() {
+ return array(
+ array( 'hello world', 'Hello', null, null, 'WikitextContentHandler' ),
+ array( 'hello world', 'User:hello/there.css', null, null, 'CssContentHandler' ),
+ array( serialize('hello world'), 'Dummy:Hello', null, null, 'DummyContentHandlerForTesting' ),
+ );
+ }
+
+ /**
+ * @dataProvider dataGetContentHandler
+ */
+ function testGetContentHandler( $text, $title, $model, $format, $expectedClass ) {
+ $rev = $this->newTestRevision( $text, $title, $model, $format );
+
+ $this->assertEquals( $expectedClass, get_class( $rev->getContentHandler() ) );
+ }
+
+ function dataGetContent() {
+ return array(
+ array( 'hello world', 'Hello', null, null, Revision::FOR_PUBLIC, 'hello world' ),
+ array( serialize('hello world'), 'Hello', 'DUMMY', null, Revision::FOR_PUBLIC, serialize('hello world') ),
+ array( serialize('hello world'), 'Dummy:Hello', null, null, Revision::FOR_PUBLIC, serialize('hello world') ),
+ );
+ }
+
+ /**
+ * @dataProvider dataGetContent
+ */
+ function testGetContent( $text, $title, $model, $format, $audience, $expectedSerialization ) {
+ $rev = $this->newTestRevision( $text, $title, $model, $format );
+ $content = $rev->getContent( $audience );
+
+ $this->assertEquals( $expectedSerialization, is_null( $content ) ? null : $content->serialize( $format ) );
+ }
+
+ function dataGetText() {
+ return array(
+ array( 'hello world', 'Hello', null, null, Revision::FOR_PUBLIC, 'hello world' ),
+ array( serialize('hello world'), 'Hello', 'DUMMY', null, Revision::FOR_PUBLIC, null ),
+ array( serialize('hello world'), 'Dummy:Hello', null, null, Revision::FOR_PUBLIC, null ),
+ );
+ }
+
+ /**
+ * @dataProvider dataGetText
+ */
+ function testGetText( $text, $title, $model, $format, $audience, $expectedText ) {
+ $rev = $this->newTestRevision( $text, $title, $model, $format );
+
+ $this->assertEquals( $expectedText, $rev->getText( $audience ) );
+ }
+
+ /**
+ * @dataProvider dataGetText
+ */
+ function testGetRawText( $text, $title, $model, $format, $audience, $expectedText ) {
+ $rev = $this->newTestRevision( $text, $title, $model, $format );
+
+ $this->assertEquals( $expectedText, $rev->getRawText( $audience ) );
+ }
+
+ // @todo: set up testing environment with database to tgest loading and inserting revisions
+
}