--- /dev/null
+<?php
+
+class CssContentTest extends JavascriptContentTest {
+
+ public function newContent( $text ) {
+ return new CssContent( $text );
+ }
+
+
+ public function dataGetParserOutput() {
+ return array(
+ array("hello <world>\n", "<pre class=\"mw-code mw-css\" dir=\"ltr\">\nhello <world>\n\n</pre>\n"),
+ // @todo: more...?
+ );
+ }
+
+
+ # =================================================================================================================
+
+ 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 CssContent( "hallo" ), null, false ),
+ array( new CssContent( "hallo" ), new CssContent( "hallo" ), true ),
+ array( new CssContent( "hallo" ), new WikitextContent( "hallo" ), false ),
+ array( new CssContent( "hallo" ), new CssContent( "HALLO" ), false ),
+ );
+ }
+
+}
--- /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 ),
+ );
+ }
+
+}
$this->context->setTitle( Title::newFromText( "Test" ) );
}
+ public function newContent( $text ) {
+ return new WikitextContent( $text );
+ }
+
public function dataGetParserOutput() {
return array(
array("hello ''world''\n", "<p>hello <i>world</i>\n</p>"),
* @dataProvider dataGetParserOutput
*/
public function testGetParserOutput( $text, $expectedHtml ) {
- $content = new WikitextContent( $text );
+ $content = $this->newContent( $text );
$po = $content->getParserOutput( $this->context );
* @dataProvider dataGetSection
*/
public function testGetSection( $text, $sectionId, $expectedText ) {
- $content = new WikitextContent( $text );
+ $content = $this->newContent( $text );
$sectionContent = $content->getSection( $sectionId );
- $this->assertEquals( $expectedText, $sectionContent->getNativeData() );
+ $this->assertEquals( $expectedText, is_null( $sectionContent ) ? null : $sectionContent->getNativeData() );
}
public function dataReplaceSection() {
* @dataProvider dataReplaceSection
*/
public function testReplaceSection( $text, $section, $with, $sectionTitle, $expected ) {
- $content = new WikitextContent( $text );
- $c = $content->replaceSection( $section, new WikitextContent( $with ), $sectionTitle );
+ $content = $this->newContent( $text );
+ $c = $content->replaceSection( $section, $this->newContent( $with ), $sectionTitle );
- $this->assertEquals( $expected, $c->getNativeData() );
+ $this->assertEquals( $expected, is_null( $c ) ? null : $c->getNativeData() );
}
- /**
- * Returns a new WikitextContent object with the given section heading prepended.
- *
- * @param $header String
- * @return Content
- */
public function testAddSectionHeader( ) {
- $content = new WikitextContent( 'hello world' );
+ $content = $this->newContent( 'hello world' );
$content = $content->addSectionHeader( 'test' );
$this->assertEquals( "== test ==\n\nhello world", $content->getNativeData() );
* @dataProvider dataPreSaveTransform
*/
public function testPreSaveTransform( $text, $expected ) {
- $content = new WikitextContent( $text );
+ $content = $this->newContent( $text );
$content = $content->preSaveTransform( $this->context->getTitle(), $this->context->getUser() );
$this->assertEquals( $expected, $content->getNativeData() );
* @dataProvider dataPreloadTransform
*/
public function testPreloadTransform( $text, $expected ) {
- $content = new WikitextContent( $text );
+ $content = $this->newContent( $text );
$content = $content->preloadTransform( $this->context->getTitle() );
$this->assertEquals( $expected, $content->getNativeData() );
* @dataProvider dataGetRedirectTarget
*/
public function testGetRedirectTarget( $text, $expected ) {
- $content = new WikitextContent( $text );
+ $content = $this->newContent( $text );
$t = $content->getRedirectTarget( );
if ( is_null( $expected ) ) $this->assertNull( $t, "text should not have generated a redirect target: $text" );
* @dataProvider dataGetRedirectTarget
*/
public function isRedirect( $text, $expected ) {
- $content = new WikitextContent( $text );
+ $content = $this->newContent( $text );
$this->assertEquals( !is_null($expected), $content->isRedirect() );
}
$old = $wgArticleCountMethod;
$wgArticleCountMethod = $mode;
- $content = new WikitextContent( $text );
+ $content = $this->newContent( $text );
$v = $content->isCountable( $hasLinks, $this->context );
$wgArticleCountMethod = $old;
* @dataProvider dataGetTextForSummary
*/
public function testGetTextForSummary( $text, $maxlength, $expected ) {
- $content = new WikitextContent( $text );
+ $content = $this->newContent( $text );
$this->assertEquals( $expected, $content->getTextForSummary( $maxlength ) );
}
public function testGetTextForSearchIndex( ) {
- $content = new WikitextContent( "hello world." );
+ $content = $this->newContent( "hello world." );
$this->assertEquals( "hello world.", $content->getTextForSearchIndex() );
}
public function testCopy() {
- $content = new WikitextContent( "hello world." );
+ $content = $this->newContent( "hello world." );
$copy = $content->copy();
$this->assertTrue( $content->equals( $copy ), "copy must be equal to original" );
}
public function testGetSize( ) {
- $content = new WikitextContent( "hello world." );
+ $content = $this->newContent( "hello world." );
$this->assertEquals( 12, $content->getSize() );
}
public function testGetNativeData( ) {
- $content = new WikitextContent( "hello world." );
+ $content = $this->newContent( "hello world." );
$this->assertEquals( "hello world.", $content->getNativeData() );
}
public function testGetWikitextForTransclusion( ) {
- $content = new WikitextContent( "hello world." );
+ $content = $this->newContent( "hello world." );
$this->assertEquals( "hello world.", $content->getWikitextForTransclusion() );
}
# =================================================================================================================
public function getModelName() {
- $content = new WikitextContent( "hello world." );
+ $content = $this->newContent( "hello world." );
$this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getModelName() );
}
public function getContentHandler() {
- $content = new WikitextContent( "hello world." );
+ $content = $this->newContent( "hello world." );
$this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getContentHandler()->getModelName() );
}
* @dataProvider dataIsEmpty
*/
public function testIsEmpty( $text, $empty ) {
- $content = new WikitextContent( $text );
+ $content = $this->newContent( $text );
$this->assertEquals( $empty, $content->isEmpty() );
}