hello world\n
" ), // TODO: more...? ); } public static function dataGetSecondaryDataUpdates() { return array( array( "WikitextContentTest_testGetSecondaryDataUpdates_1", CONTENT_MODEL_WIKITEXT, "hello ''world''\n", array( 'LinksUpdate' => array( 'mRecursive' => true, 'mLinks' => array() ) ) ), array( "WikitextContentTest_testGetSecondaryDataUpdates_2", CONTENT_MODEL_WIKITEXT, "hello [[world test 21344]]\n", array( 'LinksUpdate' => array( 'mRecursive' => true, 'mLinks' => array( array( 'World_test_21344' => 0 ) ) ) ) ), // TODO: more...? ); } /** * @dataProvider dataGetSecondaryDataUpdates * @group Database * @covers WikitextContent::getSecondaryDataUpdates */ public function testGetSecondaryDataUpdates( $title, $model, $text, $expectedStuff ) { $ns = $this->getDefaultWikitextNS(); $title = Title::newFromText( $title, $ns ); $content = ContentHandler::makeContent( $text, $title, $model ); $page = WikiPage::factory( $title ); $page->doEditContent( $content, '' ); $updates = $content->getSecondaryDataUpdates( $title ); // make updates accessible by class name foreach ( $updates as $update ) { $class = get_class( $update ); $updates[$class] = $update; } foreach ( $expectedStuff as $class => $fieldValues ) { $this->assertArrayHasKey( $class, $updates, "missing an update of type $class" ); $update = $updates[$class]; foreach ( $fieldValues as $field => $value ) { $v = $update->$field; #if the field doesn't exist, just crash and burn $this->assertEquals( $value, $v, "unexpected value for field $field in instance of $class" ); } } $page->doDeleteArticle( '' ); } public static function dataGetSection() { return array( array( WikitextContentTest::$sections, "0", "Intro" ), array( WikitextContentTest::$sections, "2", "== test == just a test" ), array( WikitextContentTest::$sections, "8", false ), ); } /** * @dataProvider dataGetSection * @covers WikitextContent::getSection */ public function testGetSection( $text, $sectionId, $expectedText ) { $content = $this->newContent( $text ); $sectionContent = $content->getSection( $sectionId ); if ( is_object( $sectionContent ) ) { $sectionText = $sectionContent->getNativeData(); } else { $sectionText = $sectionContent; } $this->assertEquals( $expectedText, $sectionText ); } public static function dataReplaceSection() { return array( array( WikitextContentTest::$sections, "0", "No more", null, trim( preg_replace( '/^Intro/sm', 'No more', WikitextContentTest::$sections ) ) ), array( WikitextContentTest::$sections, "", "No more", null, "No more" ), array( WikitextContentTest::$sections, "2", "== TEST ==\nmore fun", null, trim( preg_replace( '/^== test ==.*== foo ==/sm', "== TEST ==\nmore fun\n\n== foo ==", WikitextContentTest::$sections ) ) ), array( WikitextContentTest::$sections, "8", "No more", null, WikitextContentTest::$sections ), array( WikitextContentTest::$sections, "new", "No more", "New", trim( WikitextContentTest::$sections ) . "\n\n\n== New ==\n\nNo more" ), ); } /** * @dataProvider dataReplaceSection * @covers WikitextContent::replaceSection */ public function testReplaceSection( $text, $section, $with, $sectionTitle, $expected ) { $content = $this->newContent( $text ); $c = $content->replaceSection( $section, $this->newContent( $with ), $sectionTitle ); $this->assertEquals( $expected, is_null( $c ) ? null : $c->getNativeData() ); } /** * @covers WikitextContent::addSectionHeader */ public function testAddSectionHeader() { $content = $this->newContent( 'hello world' ); $content = $content->addSectionHeader( 'test' ); $this->assertEquals( "== test ==\n\nhello world", $content->getNativeData() ); } public static function dataPreSaveTransform() { return array( array( 'hello this is ~~~', "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]", ), array( 'hello \'\'this\'\' is